-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.rs
40 lines (32 loc) · 1.24 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use consentry::{GossipKind, PubsubMessage, Sentry, SentryConfig};
use futures::StreamExt;
use tracing::info;
use tracing_subscriber::{EnvFilter, FmtSubscriber};
#[tokio::main]
async fn main() {
let subscriber = FmtSubscriber::builder()
.with_env_filter(EnvFilter::from_default_env())
.finish();
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");
let mut svc = Sentry::new(SentryConfig::default());
let handle = svc.handle();
handle.subscribe_topic(GossipKind::BeaconBlock);
let mut events = svc.pubsub_event_stream();
tokio::task::spawn(svc.start());
while let Some(event) = events.next().await {
if let PubsubMessage::BeaconBlock(block) = event.message {
info!(slot = %block.slot(), hash = ?block.canonical_root(), "Received block");
let block_number = block
.message()
.execution_payload()
.unwrap()
.execution_payload_ref()
.block_number();
println!(
"Received block {} (source peer: {:?}",
block_number, event.peer_id
)
}
info!("Peer count: {}", handle.peer_count().await);
}
}