Skip to content

Commit 1e0dafc

Browse files
authored
Merge pull request #519 from EspressoSystems/tw/netns
Run test in separate network namespaces
2 parents 77a0b61 + 9e841eb commit 1e0dafc

30 files changed

+959
-128
lines changed

.github/workflows/build-and-test.yml

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ jobs:
2626
~/.cargo/git/db/
2727
target/
2828
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
29-
- name: Install Just
30-
run: |
31-
wget https://github.com/casey/just/releases/download/1.14.0/just-1.14.0-x86_64-unknown-linux-musl.tar.gz
32-
tar -vxf just-1.14.0-x86_64-unknown-linux-musl.tar.gz just
33-
sudo cp just /usr/bin/just
29+
- uses: taiki-e/install-action@just
3430
- name: Install rustfmt for nightly
3531
run: rustup component add --toolchain nightly rustfmt
3632
- name: Install Foundry
@@ -59,11 +55,7 @@ jobs:
5955
run: |
6056
sudo apt-get update
6157
sudo apt-get install -y protobuf-compiler
62-
- name: Install Just
63-
run: |
64-
wget https://github.com/casey/just/releases/download/1.14.0/just-1.14.0-x86_64-unknown-linux-musl.tar.gz
65-
tar -vxf just-1.14.0-x86_64-unknown-linux-musl.tar.gz just
66-
sudo cp just /usr/bin/just
58+
- uses: taiki-e/install-action@just
6759
- name: Install rustfmt for nightly
6860
run: rustup component add --toolchain nightly rustfmt
6961
- name: Install Foundry
@@ -82,11 +74,7 @@ jobs:
8274
run: |
8375
sudo apt-get update
8476
sudo apt-get install -y protobuf-compiler
85-
- name: Install Just
86-
run: |
87-
wget https://github.com/casey/just/releases/download/1.14.0/just-1.14.0-x86_64-unknown-linux-musl.tar.gz
88-
tar -vxf just-1.14.0-x86_64-unknown-linux-musl.tar.gz just
89-
sudo cp just /usr/bin/just
77+
- uses: taiki-e/install-action@just
9078
- name: Install rustfmt for nightly
9179
run: rustup component add --toolchain nightly rustfmt
9280
- name: Install Foundry
@@ -104,11 +92,7 @@ jobs:
10492
submodules: recursive
10593
fetch-depth: 0
10694
- uses: docker/setup-buildx-action@v3
107-
- name: Install Just
108-
run: |
109-
wget https://github.com/casey/just/releases/download/1.14.0/just-1.14.0-x86_64-unknown-linux-musl.tar.gz
110-
tar -vxf just-1.14.0-x86_64-unknown-linux-musl.tar.gz just
111-
sudo cp just /usr/bin/just
95+
- uses: taiki-e/install-action@just
11296
- name: Build Docker
11397
run: just build_docker
11498

@@ -124,11 +108,7 @@ jobs:
124108
run: |
125109
sudo apt-get update
126110
sudo apt-get install -y protobuf-compiler
127-
- name: Install Just
128-
run: |
129-
wget https://github.com/casey/just/releases/download/1.14.0/just-1.14.0-x86_64-unknown-linux-musl.tar.gz
130-
tar -vxf just-1.14.0-x86_64-unknown-linux-musl.tar.gz just
131-
sudo cp just /usr/bin/just
111+
- uses: taiki-e/install-action@just
132112
- name: Install rustfmt for nightly
133113
run: rustup component add --toolchain nightly rustfmt
134114
- name: Install Foundry
@@ -144,18 +124,36 @@ jobs:
144124
- name: Test dynamic committee change
145125
run: just test-dyn-comm
146126

127+
netsim:
128+
runs-on: ubuntu-latest
129+
timeout-minutes: 25
130+
steps:
131+
- uses: actions/checkout@v5
132+
with:
133+
submodules: recursive
134+
fetch-depth: 0
135+
- name: Show net devices
136+
run: ip -o addr show scope global
137+
- name: Install protobuf compiler
138+
run: |
139+
sudo apt-get update
140+
sudo apt-get install -y protobuf-compiler
141+
- uses: taiki-e/install-action@just
142+
- name: Install rustfmt for nightly
143+
run: rustup component add --toolchain nightly rustfmt
144+
- name: Install Foundry
145+
uses: foundry-rs/foundry-toolchain@v1
146+
- name: Run network simulation
147+
run: just forward-ipv4 true create-net netsim
148+
147149
contracts:
148150
runs-on: ubuntu-latest
149151
steps:
150152
- uses: actions/checkout@v4
151153
with:
152154
submodules: recursive
153155
fetch-depth: 0
154-
- name: Install Just
155-
run: |
156-
wget https://github.com/casey/just/releases/download/1.14.0/just-1.14.0-x86_64-unknown-linux-musl.tar.gz
157-
tar -vxf just-1.14.0-x86_64-unknown-linux-musl.tar.gz just
158-
sudo cp just /usr/bin/just
156+
- uses: taiki-e/install-action@just
159157
- name: Install rustfmt for nightly
160158
run: rustup component add --toolchain nightly rustfmt
161159
- name: Install Foundry
@@ -175,11 +173,7 @@ jobs:
175173
run: |
176174
sudo apt-get update
177175
sudo apt-get install -y protobuf-compiler
178-
- name: Install Just
179-
run: |
180-
wget https://github.com/casey/just/releases/download/1.14.0/just-1.14.0-x86_64-unknown-linux-musl.tar.gz
181-
tar -vxf just-1.14.0-x86_64-unknown-linux-musl.tar.gz just
182-
sudo cp just /usr/bin/just
176+
- uses: taiki-e/install-action@just
183177
- name: Install rustfmt for nightly
184178
run: rustup component add --toolchain nightly rustfmt
185179
- name: Install Foundry
@@ -203,4 +197,3 @@ jobs:
203197
- name: Docker Logs Sequencer 2
204198
if: failure()
205199
run: docker logs test-node-sequencer_b-1
206-

.github/workflows/push-docker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ jobs:
4747
push: true
4848
platforms: linux/amd64
4949
file: ./docker/timeboost.Dockerfile
50-
tags: ghcr.io/espressosystems/timeboost:${{ env.TAG }}
50+
tags: ghcr.io/espressosystems/timeboost:${{ env.TAG }}

Cargo.lock

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

Cargo.toml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ rust-version = "1.85.0"
3131

3232
[workspace.dependencies]
3333
aes-gcm = { version = "0.10.3" }
34-
alloy = { version = "1.0", features = ["default", "arbitrary", "k256", "serde", "rlp", "node-bindings", "getrandom", "signer-mnemonic", "transport-ws"] }
3534
alloy-chains = "0.2"
3635
# derive feature is not exposed via `alloy`, thus has to explicitly declare here
3736
alloy-rlp = { version = "0.3.12", features = ["derive"] }
@@ -69,6 +68,7 @@ ethereum_ssz = "0.9.0"
6968
futures = { version = "0.3", default-features = false, features = ["alloc"] }
7069
generic-array = { version = "0.14.7", features = ["serde", "zeroize"] }
7170
http = "1.3.1"
71+
ipnet = { version = "2.11.0", features = ["serde"] }
7272
itertools = "0.14.0"
7373
jiff = { version = "0.2", default-features = false, features = ["serde", "std"] }
7474
minicbor = { version = "2.1.1", features = ["full"] }
@@ -115,6 +115,20 @@ espresso-types = { git = "https://github.com/EspressoSystems/espresso-network.gi
115115
hotshot-query-service = { git = "https://github.com/EspressoSystems/espresso-network.git" }
116116
hotshot-types = { git = "https://github.com/EspressoSystems/espresso-network.git" }
117117

118+
[workspace.dependencies.alloy]
119+
version = "1.0"
120+
features = [
121+
"arbitrary",
122+
"default",
123+
"getrandom",
124+
"k256",
125+
"node-bindings",
126+
"rlp",
127+
"serde",
128+
"signer-mnemonic",
129+
"transport-ws"
130+
]
131+
118132
[profile.test]
119133
codegen-units = 16
120134
incremental = false

justfile

Lines changed: 59 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
set export
2-
31
export RUSTDOCFLAGS := '-D warnings'
42

5-
LOG_LEVELS := "RUST_LOG=timeboost=debug,sailfish=debug,cliquenet=debug,tests=debug"
3+
log_levels := "RUST_LOG=timeboost=debug,sailfish=debug,cliquenet=debug,tests=debug"
4+
run_as_root := if env("CI", "") == "true" { "sudo" } else { "run0" }
65

76
####################
87
###BUILD COMMANDS###
@@ -34,7 +33,7 @@ build-port-alloc:
3433

3534
[private]
3635
build-test-utils:
37-
cargo build --release -p test-utils
36+
cargo build --release -p test-utils --all-features
3837

3938
####################
4039
###CHECK COMMANDS###
@@ -159,10 +158,10 @@ test-contracts: build-contracts
159158
forge test
160159

161160
test_ci *ARGS: build-port-alloc
162-
env {{LOG_LEVELS}} NO_COLOR=1 target/release/run \
161+
env {{log_levels}} NO_COLOR=1 target/release/run \
163162
--spawn target/release/port-alloc \
164163
cargo nextest run -- --workspace {{ARGS}}
165-
env {{LOG_LEVELS}} NO_COLOR=1 cargo test --doc {{ARGS}}
164+
env {{log_levels}} NO_COLOR=1 cargo test --doc {{ARGS}}
166165

167166
test-individually: build-port-alloc
168167
@for pkg in $(cargo metadata --no-deps --format-version 1 | jq -r '.packages[].name'); do \
@@ -176,30 +175,28 @@ test-contract-deploy *ARGS:
176175
scripts/test-contract-deploy {{ARGS}}
177176

178177
test-all: build_release build-test-utils
179-
env RUST_LOG=timeboost_builder::submit=debug,block_checker=info,warn target/release/run \
178+
env RUST_LOG=timeboost_builder::submit=debug,block_checker=info,warn \
179+
target/release/run \
180180
--verbose \
181181
--timeout 120 \
182182
--spawn "1:anvil --port 8545" \
183183
--run "2:sleep 3" \
184-
--run "3:scripts/deploy-contract-local" \
185-
--spawn "4:target/release/block-maker --port 55000 --committee test-configs/local/committee.toml" \
186-
--spawn "4:target/release/yapper --keyset-file test-configs/local/committee.toml" \
187-
--spawn "5:target/release/run-committee --configs test-configs/local/ --committee-id 0 --timeboost target/release/timeboost" \
188-
target/release/block-checker -- \
189-
--config test-configs/local/node_0.toml \
190-
--committee test-configs/local/committee.toml \
191-
--committee-id 0 \
192-
--blocks 1000
184+
--run "3:scripts/deploy-contract-local test-configs/local/committee.toml http://localhost:8545" \
185+
--spawn "4:target/release/block-maker --bind 127.0.0.1:55000 -c test-configs/local/committee.toml" \
186+
--spawn "4:target/release/yapper -c test-configs/local/committee.toml" \
187+
--spawn "5:target/release/run-committee -c test-configs/local/" \
188+
target/release/block-checker -- -c test-configs/local -b 1000
193189

194190
test-dyn-comm: build_release_until build-test-utils
195-
env RUST_LOG=sailfish=warn,yapper=error,timeboost=info,info target/release/run \
191+
env RUST_LOG=sailfish=warn,timeboost=info,info target/release/run \
196192
--verbose \
197193
--timeout 120 \
198194
--spawn "1:anvil --port 8545" \
199195
--run "2:sleep 2" \
200-
--run "3:scripts/deploy-contract-local" \
201-
--spawn "4:target/release/run-committee --configs test-configs/c0/ --committee-id 0 --until 2000" \
196+
--run "3:scripts/deploy-contract-local test-configs/local/committee.toml http://localhost:8545" \
197+
--spawn "4:target/release/run-committee -c test-configs/c0/ --until 2000" \
202198
--run "5:target/release/mkconfig -n 4 \
199+
--committee-id 1 \
203200
--public-addr 127.0.0.1:9000 \
204201
--internal-addr 127.0.0.1:9003 \
205202
--http-api 127.0.0.1:9004 \
@@ -226,11 +223,51 @@ test-dyn-comm: build_release_until build-test-utils
226223
-k 0x2bbf15bc655c4cc157b769cfcb1ea9924b9e1a35 \
227224
-c test-configs/c1/committee.toml" \
228225
--spawn "9:target/release/yapper \
229-
--keyset-file test-configs/c1/committee.toml \
226+
--config test-configs/c1/committee.toml \
230227
--parent-url http://localhost:8545 \
231228
--key-manager-contract 0x2bbf15bc655c4cc157b769cfcb1ea9924b9e1a35" \
232229
target/release/run-committee -- \
233-
--configs test-configs/c1/ \
234-
--committee-id 1 \
230+
-c test-configs/c1/ \
235231
--until 800 \
236232
--required-decrypt-rounds 3 && rm -rf test-configs/c1
233+
234+
[linux]
235+
forward-ipv4 val: build-test-utils
236+
{{run_as_root}} target/release/net-setup system --forward-ipv4 {{val}}
237+
238+
[linux]
239+
create-net: build-test-utils
240+
{{run_as_root}} target/release/net-setup create -c test-configs/linux/net.toml
241+
242+
[linux]
243+
delete-net: build-test-utils
244+
{{run_as_root}} target/release/net-setup delete -c test-configs/linux/net.toml
245+
246+
[linux]
247+
netsim: build_release build-test-utils
248+
#!/usr/bin/env bash
249+
set -eo pipefail
250+
function run_as_root {
251+
if [ "$CI" == "true" ]; then
252+
sudo --preserve-env=PATH,HOME,RUST_LOG "$@"
253+
else
254+
run0 --setenv=PATH --setenv=HOME --setenv=RUST_LOG "$@"
255+
fi
256+
}
257+
export RUST_LOG=timeboost_builder::submit=debug,block_checker=info,warn
258+
run_as_root target/release/run \
259+
--verbose \
260+
--timeout 120 \
261+
--clear-env \
262+
--env PATH \
263+
--env HOME \
264+
--env RUST_LOG \
265+
--uid $(id -u) \
266+
--gid $(id -g) \
267+
--spawn "1:anvil --host 11.0.1.0 --port 8545" \
268+
--run "2:sleep 3" \
269+
--run "3:scripts/deploy-contract-local test-configs/linux/committee.toml http://11.0.1.0:8545" \
270+
--spawn "4:target/release/block-maker --bind 11.0.1.0:55000 -c test-configs/linux/committee.toml" \
271+
--spawn "4:target/release/yapper -c test-configs/linux/committee.toml" \
272+
--spawn-as-root "5:target/release/run-committee -u $(id -u) -g $(id -g) -c test-configs/linux/" \
273+
target/release/block-checker -- -c test-configs/linux -b 200

scripts/deploy-contract-local

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22

33
set -euo pipefail
44

5+
COMMITTEE="$1"
6+
URL="$2"
7+
58
MANAGER_MNEMONIC="attend year erase basket blind adapt stove broccoli isolate unveil acquire category"
69
MANAGER_ACCOUNT_INDEX=0
710
MANAGER_ADDRESS="0x36561082951eed7ffD59cFD82D70570C57072d02"
811
FAUCET_PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
9-
URL="http://localhost:8545"
1012
DEPLOYMENT_FILE=$(mktemp -t timeboost-deployment-XXXXX)
1113

1214
# Fund manager account && create deployment file
13-
cast send --value 1ether --private-key "$FAUCET_PRIVATE_KEY" "$MANAGER_ADDRESS"
14-
env RUST_LOG=info cargo run --release --bin deploy -- \
15+
cast send --value 1ether -r "$URL" --private-key "$FAUCET_PRIVATE_KEY" "$MANAGER_ADDRESS"
16+
env RUST_LOG=info target/release/deploy \
1517
-m "$MANAGER_MNEMONIC" \
1618
-i "$MANAGER_ACCOUNT_INDEX" \
1719
-u "$URL" \
@@ -21,13 +23,13 @@ env RUST_LOG=info cargo run --release --bin deploy -- \
2123
km_addr=$(sed -nr 's/^key_manager.*=.*"(.+)"/\1/p' "$DEPLOYMENT_FILE")
2224

2325
# Update the contract
24-
env RUST_LOG=info cargo run --release --bin register -- \
26+
env RUST_LOG=info target/release/register \
2527
-a new-committee \
2628
-m "$MANAGER_MNEMONIC" \
2729
-i "$MANAGER_ACCOUNT_INDEX" \
2830
-u "$URL" \
2931
-k "$km_addr" \
30-
-c "test-configs/c0/committee.toml"
32+
-c "$COMMITTEE"
3133

3234
# Clean up the temporary deployment file
3335
rm -f "$DEPLOYMENT_FILE"

scripts/run-timeboost-demo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ done
142142
if $yapper; then
143143
cmd=(target/release/yapper
144144
--tps $tps
145-
--keyset-file "$config_dir/committee.toml")
145+
--config "$config_dir/committee.toml")
146146
if [ $nitro_url ]; then
147147
cmd+=(--nitro-url "$nitro_url")
148148
fi

test-configs/c0/committee.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
id = 0
12
effective_timestamp = "2025-09-01T02:00:00Z"
23

34
[[members]]

test-configs/docker/committee.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
id = 0
12
effective_timestamp = "2025-09-01T02:00:00Z"
23

34
[[members]]

0 commit comments

Comments
 (0)