Skip to content

Commit 1698194

Browse files
committed
Ensure inclusion lists of a round are equal.
1 parent 3696f6b commit 1698194

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
use std::convert::Infallible;
22
use std::net::Ipv4Addr;
33
use std::path::PathBuf;
4+
use std::process::exit;
45
use std::sync::atomic::{AtomicU64, Ordering};
56

67
use anyhow::Result;
78
use bytes::Bytes;
89
use clap::Parser;
910
use prost::Message;
1011
use quick_cache::sync::Cache;
12+
use sailfish::types::RoundNumber;
1113
use timeboost::config::CommitteeConfig;
1214
use timeboost::proto::block::Block;
1315
use timeboost::proto::forward::forward_api_server::{ForwardApi, ForwardApiServer};
@@ -36,7 +38,7 @@ struct Args {
3638
/// GRPC service that accepts inclusion lists and broadcasts them to clients.
3739
struct Service {
3840
next_block: AtomicU64,
39-
cache: Cache<Bytes, u64>,
41+
cache: Cache<RoundNumber, (Bytes, u64)>,
4042
output: broadcast::Sender<Block>,
4143
}
4244

@@ -65,13 +67,21 @@ impl ForwardApi for Service {
6567
r: Request<InclusionList>,
6668
) -> Result<Response<()>, Status> {
6769
let list = r.into_inner();
70+
let round = RoundNumber::from(list.round);
6871
let bytes = Bytes::from(list.encode_to_vec());
69-
let bnum = self
72+
let (prev, bnum) = self
7073
.cache
71-
.get_or_insert_with(&bytes, || -> Result<u64, Infallible> {
72-
Ok(self.next_block.fetch_add(1, Ordering::Relaxed))
74+
.get_or_insert_with(&round, || -> Result<_, Infallible> {
75+
Ok((
76+
bytes.clone(),
77+
self.next_block.fetch_add(1, Ordering::Relaxed),
78+
))
7379
})
7480
.expect("infallible insert");
81+
if bytes != prev {
82+
error!(%round, "inclusion list mismatch");
83+
exit(1)
84+
}
7585
let block = Block {
7686
number: bnum,
7787
round: list.round,

0 commit comments

Comments
 (0)