Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #65 from graphops/petko/add-notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
pete-eiger authored Mar 16, 2023
2 parents 1e2809c + 5f9d64e commit 009070d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "poi-radio"
version = "0.0.10"
version = "0.0.11"
edition = "2021"
authors = ["GraphOps (axiomatic-aardvark, hopeyen)"]
description="POI Radio monitors subgraph data integrity in real time using Graphcast SDK"
Expand All @@ -10,8 +10,7 @@ keywords=["graphprotocol", "data-integrity", "Indexer", "waku", "p2p"]
categories=["network-programming", "web-programming::http-client"]

[dependencies]
# graphcast-sdk = { path = "../graphcast-rs"}
graphcast-sdk = { git = "https://github.com/graphops/graphcast-sdk", rev = "55076ee" }
graphcast-sdk = "0.0.14"
prost = "0.11"
once_cell = "1.15"
chrono = "0.4"
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ RUN apt-get update \
ca-certificates \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
COPY --from=build-image "/poi-radio/target/release/poi-radio" "/usr/bin/local/poi-radio"
ENTRYPOINT [ "/usr/bin/local/poi-radio" ]
COPY --from=build-image "/poi-radio/target/release/poi-radio" "/usr/local/bin/poi-radio"
ENTRYPOINT [ "/usr/local/bin/poi-radio" ]
8 changes: 7 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ impl Display for ComparisonResult {
/// with the same NPOI from an Indexer (NOTE: one Indexer can only send 1 attestation per subgraph per block). The attestations are then sorted
/// and we take the one with the highest total stake-weight.
pub async fn compare_attestations(
network_name: NetworkName,
attestation_block: u64,
remote: RemoteAttestationsMap,
local: Arc<AsyncMutex<LocalAttestationsMap>>,
Expand Down Expand Up @@ -343,7 +344,8 @@ pub async fn compare_attestations(
attestation_block, remote_attestations, "Local attestation", local_attestation
);
Ok(ComparisonResult::Divergent(format!(
"POIs don't match for subgraph {ipfs_hash} on block {attestation_block}!\nlocal attestation: {local:#?}\nremote attestations: {remote:#?}"
"❗ POIs don't match for subgraph {} on network {} at block {}!\n\nLocal attestation:\n{:#?}\n\nRemote attestations:\n{:#?}",
ipfs_hash, network_name, attestation_block, local_attestation, remote_attestations
)))
}
}
Expand Down Expand Up @@ -530,6 +532,7 @@ mod tests {
#[tokio::test]
async fn test_compare_attestations_generic_fail() {
let res = compare_attestations(
NetworkName::Goerli,
42,
HashMap::new(),
Arc::new(AsyncMutex::new(HashMap::new())),
Expand Down Expand Up @@ -570,6 +573,7 @@ mod tests {
local_attestations.insert("different-awesome-hash".to_string(), local_blocks);

let res = compare_attestations(
NetworkName::Goerli,
42,
remote_attestations,
Arc::new(AsyncMutex::new(local_attestations)),
Expand All @@ -596,6 +600,7 @@ mod tests {
local_attestations.insert("my-awesome-hash".to_string(), local_blocks);

let res = compare_attestations(
NetworkName::Goerli,
42,
remote_attestations,
Arc::new(AsyncMutex::new(local_attestations)),
Expand Down Expand Up @@ -636,6 +641,7 @@ mod tests {
local_attestations.insert("my-awesome-hash".to_string(), local_blocks);

let res = compare_attestations(
NetworkName::Goerli,
42,
remote_attestations,
Arc::new(AsyncMutex::new(local_attestations)),
Expand Down
27 changes: 27 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use chrono::Utc;

use dotenv::dotenv;
use ethers::signers::LocalWallet;
use graphcast_sdk::bots::{DiscordBot, SlackBot};
/// Radio specific query function to fetch Proof of Indexing for each allocated subgraph
use graphcast_sdk::config::{Config, NetworkName};
use graphcast_sdk::graphcast_agent::message_typing::GraphcastMessage;
Expand Down Expand Up @@ -239,6 +240,7 @@ async fn main() {
};

let comparison_result = compare_attestations(
network_name,
compare_block,
remote_attestations.clone(),
Arc::clone(&local_attestations),
Expand Down Expand Up @@ -266,6 +268,31 @@ async fn main() {
}
Ok(ComparisonResult::Divergent(msg)) => {
error!("{}", msg);

if let (Some(token), Some(channel)) =
(&config.slack_token, &config.slack_channel)
{
if let Err(e) = SlackBot::send_webhook(
token.to_string(),
channel.as_str(),
radio_name,
msg.as_str(),
)
.await
{
warn!("Failed to send notification to Slack: {}", e);
}
}

if let Some(webhook_url) = &config.discord_webhook {
if let Err(e) =
DiscordBot::send_webhook(webhook_url, radio_name, msg.as_str())
.await
{
warn!("Failed to send notification to Discord: {}", e);
}
}

comparison_result_strings.push(ComparisonResult::Divergent(msg.clone()));
// TODO: perhaps add conditional remove by timestamps
MESSAGES.get().unwrap().lock().unwrap().retain(|msg| {
Expand Down

0 comments on commit 009070d

Please sign in to comment.