Skip to content

Commit 989a887

Browse files
committed
Add appropriate comments and clean up.
1 parent 19bb4e9 commit 989a887

File tree

8 files changed

+127
-90
lines changed

8 files changed

+127
-90
lines changed

tests/src/tests/timeboost.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ async fn start_certifier_with_retry(cert_conf: CertifierConfig) -> Certifier {
211211
.await
212212
}
213213

214-
async fn create_network_with_retry(cfg: &SequencerConfig) -> Network {
214+
async fn start_network_with_retry(cfg: &SequencerConfig) -> Network {
215215
with_retry(
216216
|| async {
217217
Network::create(

tests/src/tests/timeboost/block_order.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
use multisig::Certificate;
21
use std::collections::HashMap;
32
use std::iter::once;
43
use std::num::NonZeroUsize;
54
use std::sync::Arc;
65
use std::time::Duration;
6+
7+
use multisig::Certificate;
78
use timeboost::sequencer::Output;
89
use timeboost::types::{Block, BlockInfo};
910
use timeboost_utils::types::logging::init_logging;

tests/src/tests/timeboost/handover.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
use std::future::pending;
2+
use std::iter::repeat_with;
3+
use std::net::Ipv4Addr;
4+
use std::num::NonZeroUsize;
5+
use std::time::Duration;
6+
17
use alloy::eips::BlockNumberOrTag;
28
use cliquenet::{Address, AddressableCommittee, Overlay};
39
use futures::FutureExt;
@@ -7,11 +13,6 @@ use sailfish::consensus::Consensus;
713
use sailfish::rbc::Rbc;
814
use sailfish::types::{ConsensusTime, RoundNumber, Timestamp};
915
use sailfish::{Coordinator, Event};
10-
use std::future::pending;
11-
use std::iter::repeat_with;
12-
use std::net::Ipv4Addr;
13-
use std::num::NonZeroUsize;
14-
use std::time::Duration;
1516
use timeboost::config::{ChainConfig, ParentChain};
1617
use timeboost::crypto::prelude::DkgDecKey;
1718
use timeboost::sequencer::SequencerConfig;
@@ -25,7 +26,7 @@ use tokio_stream::wrappers::UnboundedReceiverStream;
2526
use tracing::info;
2627
use url::Url;
2728

28-
use super::create_network_with_retry;
29+
use super::start_network_with_retry;
2930

3031
#[derive(Debug, Clone)]
3132
enum Cmd {
@@ -70,7 +71,8 @@ where
7071
.map(|c| c.sailfish_address().clone())
7172
.chain(
7273
repeat_with(|| {
73-
Address::from((Ipv4Addr::LOCALHOST, portpicker::pick_unused_port().unwrap()))
74+
let p = portpicker::pick_unused_port().unwrap();
75+
Address::from((Ipv4Addr::LOCALHOST, p))
7476
})
7577
.take(add.get()),
7678
)
@@ -171,7 +173,7 @@ where
171173
///
172174
/// NB that the decryption parts of the config are not used yet.
173175
async fn mk_node(cfg: &SequencerConfig) -> Coordinator<Timestamp, Rbc<Timestamp>> {
174-
let mut net = create_network_with_retry(cfg).await;
176+
let mut net = start_network_with_retry(cfg).await;
175177

176178
if let Some(prev) = &cfg.previous_sailfish_committee() {
177179
let old = prev.diff(cfg.sailfish_committee());

tests/src/tests/timeboost/timeboost_handover.rs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ async fn run_handover(
3737
next: Vec<(DecryptionKeyCell, SequencerConfig, CertifierConfig)>,
3838
) {
3939
const NEXT_COMMITTEE_DELAY: u64 = 15;
40-
const NUM_OF_BLOCKS: usize = 50;
40+
const NUM_OF_BLOCKS_PER_EPOCH: usize = 50;
4141

42-
let mut out1 = Vec::new();
4342
let tasks = TaskTracker::new();
4443
let (bcast, _) = broadcast::channel(500);
4544
let finish = CancellationToken::new();
@@ -49,18 +48,19 @@ async fn run_handover(
4948
let a2 = next[0].1.sailfish_committee().clone();
5049
let c1 = a1.committee().id();
5150
let c2 = a2.committee().id();
52-
let num = a1.committee().size();
53-
let quorum = a1.committee().one_honest_threshold();
54-
5551
let d2 = next[0].1.decrypt_committee().clone();
5652

53+
let num = a1.committee().size();
54+
let quorum = a1.committee().one_honest_threshold();
5755
let diff = a1.diff(&a2).count();
56+
5857
assert!(diff > 0);
5958
assert_ne!(c1, c2);
6059

61-
// run committee 1:
60+
let mut out1 = Vec::new();
61+
62+
// run committee 1 (current):
6263
for (_, seq_conf, cert_conf) in &curr {
63-
// Clone the configs so they are owned and can be moved into the async block
6464
let seq_conf = seq_conf.clone();
6565
let cert_conf = cert_conf.clone();
6666
let (tx, rx) = mpsc::unbounded_channel();
@@ -72,8 +72,8 @@ async fn run_handover(
7272
tasks.spawn(async move {
7373
let mut s = start_sequencer_with_retry(seq_conf).await;
7474
let mut c = start_certifier_with_retry(cert_conf).await;
75-
let mut r: Option<sailfish_types::RoundNumber> = None;
76-
let handle = c.handle();
75+
let mut r: Option<RoundNumber> = None;
76+
let c_handle = c.handle();
7777

7878
loop {
7979
select! {
@@ -85,7 +85,7 @@ async fn run_handover(
8585
Ok(Cmd::Bundle(bundle)) => {
8686
s.add_bundles(once(bundle));
8787
}
88-
Err(err) => panic!("Command channel error: {err}")
88+
Err(err) => panic!("command channel error: {err}")
8989
},
9090
out = s.next() => match out {
9191
Ok(o) => {
@@ -97,7 +97,7 @@ async fn run_handover(
9797
r = Some(round);
9898
let i = r2b.get(round);
9999
let b = Block::new(i, *round, hash(&transactions));
100-
handle.enqueue(b).await.unwrap()
100+
c_handle.enqueue(b).await.unwrap()
101101
}
102102
Output::UseCommittee(round) => {
103103
c.use_committee(round).await.unwrap();
@@ -130,8 +130,7 @@ async fn run_handover(
130130
key.read().await;
131131
}
132132

133-
tokio::time::sleep(Duration::from_secs(5)).await;
134-
133+
// generate bundles
135134
tasks.spawn({
136135
let (key, _, _) = &curr[0];
137136
let key = key.clone();
@@ -148,13 +147,16 @@ async fn run_handover(
148147
}
149148
});
150149

150+
// wait for the current to become active
151+
tokio::time::sleep(Duration::from_secs(5)).await;
152+
151153
// inform about upcoming committee change
152154
let t = ConsensusTime(Timestamp::now() + NEXT_COMMITTEE_DELAY);
153155
bcast.send(Cmd::NextCommittee(t, a2, d2.1)).unwrap();
154156

155157
let mut out2 = Vec::new();
156158

157-
// run committee 2:
159+
// run committee 2 (next):
158160
for (_, seq_conf, cert_conf) in &next {
159161
let ours = seq_conf.sign_keypair().public_key();
160162

@@ -176,7 +178,7 @@ async fn run_handover(
176178
let mut s = start_sequencer_with_retry(seq_conf).await;
177179
let mut c = start_certifier_with_retry(cert_conf).await;
178180
let mut r: Option<sailfish_types::RoundNumber> = None;
179-
let handle = c.handle();
181+
let c_handle = c.handle();
180182

181183
loop {
182184
select! {
@@ -188,7 +190,7 @@ async fn run_handover(
188190
Ok(Cmd::Bundle(bundle)) => {
189191
s.add_bundles(once(bundle));
190192
}
191-
Err(err) => panic!("Command channel error: {err}")
193+
Err(err) => panic!("command channel error: {err}")
192194
},
193195
out = s.next() => match out {
194196
Ok(o) => {
@@ -200,7 +202,7 @@ async fn run_handover(
200202
r = Some(round);
201203
let i = r2b.get(round);
202204
let b = Block::new(i, *round, hash(&transactions));
203-
handle.enqueue(b).await.unwrap()
205+
c_handle.enqueue(b).await.unwrap()
204206
}
205207
Output::UseCommittee(round) => {
206208
c.use_committee(round).await.unwrap();
@@ -230,7 +232,7 @@ async fn run_handover(
230232

231233
let mut map: HashMap<BlockInfo, usize> = HashMap::new();
232234

233-
for b in 0..NUM_OF_BLOCKS {
235+
for b in 0..NUM_OF_BLOCKS_PER_EPOCH {
234236
map.clear();
235237
info!(block = %b);
236238
for (node, r) in &mut out1 {
@@ -247,7 +249,7 @@ async fn run_handover(
247249
panic!("outputs do not match")
248250
}
249251

250-
for b in 0..NUM_OF_BLOCKS {
252+
for b in 0..NUM_OF_BLOCKS_PER_EPOCH {
251253
map.clear();
252254
info!(block = %b);
253255
for (node, r) in &mut out2 {
@@ -259,7 +261,7 @@ async fn run_handover(
259261
.values()
260262
.any(|n| *n >= min(diff, quorum.get()) && *n <= num.get())
261263
{
262-
// votes only collected for new nodes
264+
// votes only collected from new nodes in next
263265
continue;
264266
}
265267
for (info, n) in map {

timeboost-builder/src/certifier.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ fn translate_addr(c: AddressableCommittee) -> AddressableCommittee {
170170
let shifted_entries = c
171171
.entries()
172172
.map(|(pk, dh, addr)| {
173-
let dec_port = addr.port().saturating_add(2000);
174-
let new_addr = addr.with_port(dec_port);
173+
let cert_port = addr.port().saturating_add(2000);
174+
let new_addr = addr.with_port(cert_port);
175175
(pk, dh, new_addr)
176176
})
177177
.collect::<Vec<_>>();

0 commit comments

Comments
 (0)