Skip to content

Commit b160cef

Browse files
committed
Add block-checker.
1 parent 2ecfa7f commit b160cef

File tree

9 files changed

+216
-20
lines changed

9 files changed

+216
-20
lines changed

Cargo.lock

Lines changed: 100 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ quick_cache = "0.6.16"
8080
rand = "0.9"
8181
rayon = "1.10"
8282
rustix = { version = "1.1.2", features = ["process"] }
83-
reqwest = { version = "0.12", features = ["json"] }
83+
reqwest = { version = "0.12", features = ["json", "brotli", "gzip", "zstd"] }
8484
secp256k1 = { version = "0.31.0", features = ["global-context", "hashes", "rand", "serde"] }
8585
serde = { version = "1", features = ["derive", "rc"] }
8686
serde_bytes = "0.11.15"

justfile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ mkconfig_nitro DATETIME *ARGS:
141141
--output "test-configs/nitro-ci-committee" {{ARGS}}
142142

143143
verify_blocks *ARGS:
144-
cargo run --release --bin block-verifier --features verifier {{ARGS}}
144+
cargo run --release --bin block-verifier {{ARGS}}
145145

146146
####################
147147
####TEST COMMANDS###
@@ -171,11 +171,17 @@ test-contract-deploy *ARGS:
171171
./scripts/test-contract-deploy {{ARGS}}
172172

173173
test-all: build_release build-test-utils
174-
env RUST_LOG=timeboost_builder::submit=info,warn target/release/run \
174+
env RUST_LOG=block_checker=info,warn target/release/run \
175+
--verbose \
176+
--timeout 120 \
175177
--spawn "1:anvil --port 8545" \
176178
--run "2:sleep 3" \
177179
--run "3:scripts/deploy-test-contract" \
178180
--spawn "4:target/release/block-maker --port 55000 --committee test-configs/c0/committee.toml" \
179181
--spawn "4:target/release/yapper --keyset-file test-configs/c0/committee.toml" \
180182
--spawn "5:target/release/run-committee --configs test-configs/local/ --committee 0 --timeboost target/release/timeboost" \
181-
sleep -- 30
183+
target/release/block-checker -- \
184+
--config test-configs/local/node_0.toml \
185+
--committee test-configs/c0/committee.toml \
186+
--committee-id 0 \
187+
--blocks 1000

robusta/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ pub use crate::watcher::{WatchError, Watcher};
2626
pub use config::{Config, ConfigBuilder};
2727
pub use espresso_types;
2828

29+
static USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
30+
2931
/// A client for the Espresso network.
3032
#[derive(Debug, Clone)]
3133
pub struct Client {
@@ -38,6 +40,7 @@ impl Client {
3840
let r = reqwest::Client::builder()
3941
.https_only(c.https_only)
4042
.timeout(Duration::from_secs(30))
43+
.user_agent(USER_AGENT)
4144
.build()
4245
.expect("TLS and DNS resolver work");
4346
Self {

test-utils/Cargo.toml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ default = [
99
"dep:alloy",
1010
"dep:bincode",
1111
"dep:bytes",
12+
"dep:either",
13+
"dep:multisig",
1214
"dep:prost",
15+
"dep:robusta",
1316
"dep:quick_cache",
17+
"dep:sailfish",
1418
"dep:tokio-util",
1519
"dep:tonic",
16-
"dep:timeboost-config",
17-
"dep:timeboost-proto",
20+
"dep:timeboost",
1821
"dep:timeboost-utils",
1922
"ports"
2023
]
@@ -31,14 +34,21 @@ tracing = { workspace = true }
3134
alloy = { workspace = true, optional = true }
3235
bincode = { workspace = true, optional = true }
3336
bytes = { workspace = true, optional = true }
37+
either = { workspace = true, optional = true }
38+
multisig = { path = "../multisig", optional = true }
3439
prost = { workspace = true, optional = true }
3540
quick_cache = { workspace = true, optional = true }
41+
robusta = { path = "../robusta", optional = true }
42+
sailfish = { path = "../sailfish", optional = true }
3643
tokio-util = { workspace = true, optional = true }
3744
tonic = { workspace = true, optional = true }
38-
timeboost-config = { path = "../timeboost-config", optional = true }
39-
timeboost-proto = { path = "../timeboost-proto", optional = true }
45+
timeboost = { path = "../timeboost", optional = true }
4046
timeboost-utils = { path = "../timeboost-utils", optional = true }
4147

48+
[[bin]]
49+
name = "block-checker"
50+
path = "src/binaries/block-checker.rs"
51+
4252
[[bin]]
4353
name = "block-maker"
4454
path = "src/binaries/block-maker.rs"
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
}

test-utils/src/binaries/block-maker.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use bytes::Bytes;
88
use clap::Parser;
99
use prost::Message;
1010
use quick_cache::sync::Cache;
11-
use timeboost_config::CommitteeConfig;
12-
use timeboost_proto::block::Block;
13-
use timeboost_proto::forward::forward_api_server::{ForwardApi, ForwardApiServer};
14-
use timeboost_proto::inclusion::InclusionList;
15-
use timeboost_proto::internal::internal_api_client::InternalApiClient;
11+
use timeboost::config::CommitteeConfig;
12+
use timeboost::proto::block::Block;
13+
use timeboost::proto::forward::forward_api_server::{ForwardApi, ForwardApiServer};
14+
use timeboost::proto::inclusion::InclusionList;
15+
use timeboost::proto::internal::internal_api_client::InternalApiClient;
1616
use timeboost_utils::types::logging::init_logging;
1717
use tokio::spawn;
1818
use tokio::sync::broadcast;

test-utils/src/binaries/run.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ async fn main() -> Result<()> {
7676
}
7777
}
7878

79+
if args.verbose {
80+
eprintln!("spawning command: {}", args.main.join(" "))
81+
}
82+
7983
let mut main = ProcessGroup::spawn(args.main)?;
8084

8185
let timeout = if let Some(d) = args.timeout {
@@ -97,7 +101,7 @@ async fn main() -> Result<()> {
97101
}
98102
_ = term.recv() => {}
99103
_ = intr.recv() => {}
100-
_ = timeout => eprintln!("timeout")
104+
_ = timeout => bail!("timeout")
101105
}
102106

103107
Ok(())

0 commit comments

Comments
 (0)