|
| 1 | +use std::{collections::BTreeSet, path::PathBuf}; |
| 2 | + |
| 3 | +use anyhow::Result; |
| 4 | +use clap::Parser; |
| 5 | +use either::Either; |
| 6 | +use multisig::Committee; |
| 7 | +use robusta::{Client, Config, Watcher, espresso_types::NamespaceId}; |
| 8 | +use sailfish::types::CommitteeVec; |
| 9 | +use timeboost::config::{CommitteeConfig, NodeConfig}; |
| 10 | +use timeboost_utils::types::logging::init_logging; |
| 11 | +use tracing::{debug, info}; |
| 12 | + |
| 13 | +#[derive(Parser, Debug)] |
| 14 | +struct Args { |
| 15 | + #[clap(long, short)] |
| 16 | + config: PathBuf, |
| 17 | + |
| 18 | + #[clap(long)] |
| 19 | + committee: PathBuf, |
| 20 | + |
| 21 | + #[clap(long)] |
| 22 | + committee_id: u64, |
| 23 | + |
| 24 | + #[clap(long, short)] |
| 25 | + blocks: usize, |
| 26 | +} |
| 27 | + |
| 28 | +#[tokio::main] |
| 29 | +async fn main() -> Result<()> { |
| 30 | + init_logging(); |
| 31 | + |
| 32 | + let args = Args::parse(); |
| 33 | + |
| 34 | + let committees = { |
| 35 | + let conf = CommitteeConfig::read(&args.committee).await?; |
| 36 | + let mems = conf |
| 37 | + .members |
| 38 | + .into_iter() |
| 39 | + .enumerate() |
| 40 | + .map(|(i, m)| (i as u8, m.signing_key)); |
| 41 | + CommitteeVec::<1>::new(Committee::new(args.committee_id, mems)) |
| 42 | + }; |
| 43 | + |
| 44 | + let node = NodeConfig::read(&args.config).await?; |
| 45 | + |
| 46 | + let conf = Config::builder() |
| 47 | + .base_url(node.espresso.base_url) |
| 48 | + .wss_base_url(node.espresso.websockets_base_url) |
| 49 | + .label("block-checker") |
| 50 | + .build(); |
| 51 | + |
| 52 | + let client = Client::new(conf.clone()); |
| 53 | + let height = client.height().await?; |
| 54 | + let nspace = NamespaceId::from(node.chain.namespace); |
| 55 | + |
| 56 | + let mut watcher = Watcher::new(conf, height, nspace); |
| 57 | + let mut set = BTreeSet::new(); |
| 58 | + let mut offset = 0; |
| 59 | + |
| 60 | + while offset < args.blocks { |
| 61 | + let Either::Right(hdr) = watcher.next().await else { |
| 62 | + continue; |
| 63 | + }; |
| 64 | + debug!(height = %hdr.height(), "inspecting header"); |
| 65 | + set.extend(client.verified(nspace, &hdr, &committees).await); |
| 66 | + let start = set.iter().skip(offset); |
| 67 | + offset += start |
| 68 | + .clone() |
| 69 | + .zip(start.skip(1)) |
| 70 | + .take_while(|(a, b)| **a + 1 == **b) |
| 71 | + .count(); |
| 72 | + info!(blocks = %offset, "validated") |
| 73 | + } |
| 74 | + |
| 75 | + Ok(()) |
| 76 | +} |
0 commit comments