Skip to content

Commit 2d25530

Browse files
committed
Merge branch 'main' into ak/handover-test
# Conflicts: # Cargo.lock # tests/src/tests/timeboost.rs # tests/src/tests/timeboost/handover.rs # timeboost-sequencer/src/decrypt.rs
2 parents 9fb7649 + bb787d4 commit 2d25530

File tree

27 files changed

+967
-611
lines changed

27 files changed

+967
-611
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ members = [
1010
"sailfish-rbc",
1111
"sailfish-types",
1212
"tests",
13+
"test-utils",
1314
"timeboost",
1415
"timeboost-builder",
1516
"timeboost-config",
@@ -72,7 +73,6 @@ jiff = { version = "0.2", default-features = false, features = ["serde", "std"]
7273
minicbor = { version = "2.1.1", features = ["full"] }
7374
nohash-hasher = "0.2"
7475
parking_lot = "0.12.3"
75-
portpicker = "0.1.1"
7676
prometheus = "0.14"
7777
prost = "0.14.1"
7878
quickcheck = "1.0.3"
@@ -94,7 +94,7 @@ thiserror = "2.0"
9494
tokio = { version = "1", default-features = false, features = ["full"] }
9595
tokio-stream = "0.1.17"
9696
tokio-tungstenite = { version = "0.27.0", features = ["rustls-tls-webpki-roots", "url"] }
97-
tokio-util = "0.7.15"
97+
tokio-util = { version = "0.7.15", features = ["compat", "rt"] }
9898
toml = "0.9"
9999
toml_edit = "0.22"
100100
tonic = "0.14.1"

cliquenet/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ turmoil = { workspace = true, optional = true }
2424

2525
[dev-dependencies]
2626
criterion = { workspace = true }
27-
portpicker = { workspace = true }
2827
quickcheck = { workspace = true }
2928

3029
[[bench]]
3130
name = "network_bytes"
3231
harness = false
33-

cliquenet/tests/frame-handling.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::net::{Ipv4Addr, SocketAddr};
33
use bytes::BytesMut;
44
use cliquenet::{Network, NetworkMetrics, Overlay, overlay::Data};
55
use multisig::{Keypair, PublicKey, x25519};
6-
use portpicker::pick_unused_port;
76
use rand::{Rng, RngCore};
87
use tokio::time::{Duration, timeout};
98

@@ -20,12 +19,12 @@ async fn multiple_frames() {
2019
(
2120
party_a_sign.public_key(),
2221
party_a_dh.public_key(),
23-
(Ipv4Addr::LOCALHOST, pick_unused_port().unwrap()).into(),
22+
(Ipv4Addr::LOCALHOST, 50000).into(),
2423
),
2524
(
2625
party_b_sign.public_key(),
2726
party_b_dh.public_key(),
28-
(Ipv4Addr::LOCALHOST, pick_unused_port().unwrap()).into(),
27+
(Ipv4Addr::LOCALHOST, 51000).into(),
2928
),
3029
];
3130

justfile

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ build_docker:
2121
build-contracts:
2222
forge build
2323

24+
[private]
25+
build-test-utils:
26+
cargo build --release -p test-utils --features ports
27+
2428
####################
2529
###CHECK COMMANDS###
2630
####################
@@ -122,26 +126,30 @@ mkconfig_nitro DATETIME *ARGS:
122126
--output "test-configs/nitro-ci-committee" {{ARGS}}
123127

124128
verify_blocks *ARGS:
125-
cargo run --release --bin block-verifier --features bin {{ARGS}}
129+
cargo run --release --bin block-verifier --features verifier {{ARGS}}
126130

127131
####################
128132
####TEST COMMANDS###
129133
####################
130-
test *ARGS:
131-
cargo nextest run {{ARGS}}
134+
test *ARGS: build-test-utils
135+
target/release/run --with target/release/port-alloc cargo nextest run -- {{ARGS}}
132136
@if [ "{{ARGS}}" == "" ]; then cargo test --doc; fi
133137

134138
test-contracts: build-contracts
135139
forge test
136140

137-
test_ci *ARGS:
138-
env {{LOG_LEVELS}} NO_COLOR=1 cargo nextest run --workspace {{ARGS}}
141+
test_ci *ARGS: build-test-utils
142+
env {{LOG_LEVELS}} NO_COLOR=1 target/release/run \
143+
--with target/release/port-alloc \
144+
-- cargo nextest run --workspace {{ARGS}}
139145
env {{LOG_LEVELS}} NO_COLOR=1 cargo test --doc {{ARGS}}
140146

141-
test-individually:
147+
test-individually: build-test-utils
142148
@for pkg in $(cargo metadata --no-deps --format-version 1 | jq -r '.packages[].name'); do \
143149
echo "Testing $pkg"; \
144-
cargo nextest run --no-tests=pass -p $pkg || exit 1; \
150+
target/release/run \
151+
--with target/release/port-alloc \
152+
-- cargo nextest run --no-tests=pass -p $pkg || exit 1; \
145153
done
146154

147155
test-contract-deploy *ARGS:

test-utils/Cargo.toml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[package]
2+
name = "test-utils"
3+
version.workspace = true
4+
edition.workspace = true
5+
rust-version.workspace = true
6+
7+
[features]
8+
ports = ["dep:bincode", "dep:tokio-util"]
9+
verifier = ["dep:alloy", "dep:timeboost-utils"]
10+
11+
[dependencies]
12+
anyhow = { workspace = true }
13+
clap = { workspace = true }
14+
futures = { workspace = true }
15+
tokio = { workspace = true }
16+
tracing = { workspace = true }
17+
# optional
18+
alloy = { workspace = true, optional = true }
19+
bincode = { workspace = true, optional = true }
20+
tokio-util = { workspace = true, optional = true }
21+
timeboost-utils = { path = "../timeboost-utils", optional = true }
22+
23+
[[bin]]
24+
name = "block-verifier"
25+
path = "src/binaries/block-verifier.rs"
26+
required-features = ["verifier"]
27+
28+
[[bin]]
29+
name = "run"
30+
path = "src/binaries/run.rs"
31+
32+
[[bin]]
33+
name = "port-alloc"
34+
path = "src/binaries/port-alloc.rs"
35+
required-features = ["ports"]
File renamed without changes.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
use std::{
2+
net::Ipv4Addr,
3+
sync::{
4+
Arc,
5+
atomic::{AtomicU16, Ordering},
6+
},
7+
};
8+
9+
use anyhow::{Context, Result};
10+
use bincode::config::standard;
11+
use test_utils::ports::{ALLOCATOR_PORT, Request, Response};
12+
use tokio::{
13+
io::{AsyncReadExt, AsyncWriteExt},
14+
net::{TcpListener, TcpStream},
15+
};
16+
use tokio_util::task::TaskTracker;
17+
18+
#[tokio::main]
19+
async fn main() -> Result<()> {
20+
let tasks = TaskTracker::new();
21+
let counter = Arc::new(AtomicU16::new(2048));
22+
23+
let listener = TcpListener::bind((Ipv4Addr::LOCALHOST, ALLOCATOR_PORT))
24+
.await
25+
.context("allocator port is in use")?;
26+
27+
loop {
28+
let Ok((stream, _)) = listener.accept().await else {
29+
continue;
30+
};
31+
tasks.spawn(alloc(stream, counter.clone()));
32+
}
33+
}
34+
35+
async fn alloc(mut stream: TcpStream, ctr: Arc<AtomicU16>) -> Result<()> {
36+
let len = stream.read_u32().await?;
37+
let mut buf = vec![0; len as usize];
38+
stream.read_exact(&mut buf).await?;
39+
match bincode::decode_from_slice(&buf, standard())? {
40+
(Request::Alloc(n), _) => {
41+
let mut ports = Vec::new();
42+
for _ in 0..n {
43+
loop {
44+
let port = ctr.fetch_add(1, Ordering::Relaxed);
45+
if TcpListener::bind((Ipv4Addr::LOCALHOST, port)).await.is_ok() {
46+
ports.push(port);
47+
break;
48+
}
49+
}
50+
}
51+
buf.clear();
52+
bincode::encode_into_std_write(Response::Ports(ports), &mut buf, standard())?;
53+
stream
54+
.write_u32(buf.len().try_into().expect("response fits into u32 bytes"))
55+
.await?;
56+
stream.write_all(&buf).await?;
57+
}
58+
}
59+
Ok(())
60+
}

test-utils/src/binaries/run.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
use std::ffi::OsStr;
2+
use std::process::exit;
3+
4+
use anyhow::{Result, anyhow};
5+
use clap::Parser;
6+
use tokio::process::Command;
7+
use tokio::select;
8+
use tokio::signal::unix::{SignalKind, signal};
9+
10+
#[derive(Parser, Debug)]
11+
struct Args {
12+
#[clap(long, short)]
13+
with: String,
14+
main: Vec<String>,
15+
}
16+
17+
#[tokio::main]
18+
async fn main() -> Result<()> {
19+
let args = Args::parse();
20+
21+
let mut with = command(args.with.split_whitespace())?.spawn()?;
22+
let mut main = command(args.main)?.spawn()?;
23+
24+
let mut intr = signal(SignalKind::interrupt())?;
25+
let mut term = signal(SignalKind::terminate())?;
26+
let mut quit = signal(SignalKind::quit())?;
27+
28+
select! {
29+
status = main.wait() => {
30+
let _ = with.kill().await;
31+
exit(status?.code().unwrap_or_default())
32+
}
33+
_ = with.wait() => {
34+
let _ = main.kill().await;
35+
exit(-1)
36+
}
37+
_ = intr.recv() => {
38+
let _ = main.kill().await;
39+
let _ = with.kill().await;
40+
}
41+
_ = term.recv() => {
42+
let _ = main.kill().await;
43+
let _ = with.kill().await;
44+
}
45+
_ = quit.recv() => {
46+
let _ = main.kill().await;
47+
let _ = with.kill().await;
48+
}
49+
}
50+
51+
Ok(())
52+
}
53+
54+
fn command<I, S>(it: I) -> Result<Command>
55+
where
56+
I: IntoIterator<Item = S>,
57+
S: AsRef<OsStr>,
58+
{
59+
let mut args = it.into_iter();
60+
let exe = args
61+
.next()
62+
.ok_or_else(|| anyhow!("invalid command-line args"))?;
63+
let mut cmd = Command::new(exe);
64+
for a in args {
65+
cmd.arg(a);
66+
}
67+
Ok(cmd)
68+
}

test-utils/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#[cfg(feature = "ports")]
2+
pub mod ports;

0 commit comments

Comments
 (0)