Skip to content

Commit 15c4b3b

Browse files
authored
add send l1 messages script and harden switch-to-* scripts (#371)
1 parent b1bc845 commit 15c4b3b

File tree

7 files changed

+214
-2
lines changed

7 files changed

+214
-2
lines changed

sequencer-migration/common-functions.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,46 @@ wait_for_block() {
228228
done
229229
}
230230

231+
wait_for_l2reth_to_catch_up_with_l2geth() {
232+
log_info "Waiting for L2RETH to catch up with L2GETH..."
233+
234+
local l2geth_info
235+
if ! l2geth_info=$(get_latest_block_info "$L2GETH_RPC_URL"); then
236+
log_error "Failed to get latest block info from L2GETH"
237+
exit 1
238+
fi
239+
240+
local target_block=$(echo "$l2geth_info" | awk '{print $1}')
241+
local target_hash=$(echo "$l2geth_info" | awk '{print $2}')
242+
243+
if wait_for_block "L2RETH" "$L2RETH_RPC_URL" "$target_block" "$target_hash"; then
244+
log_success "L2RETH has caught up with L2GETH at block #$target_block"
245+
else
246+
log_error "L2RETH failed to catch up with L2GETH"
247+
exit 1
248+
fi
249+
}
250+
251+
wait_for_l2geth_to_catch_up_with_l2reth() {
252+
log_info "Waiting for L2GETH to catch up with L2RETH..."
253+
254+
local l2reth_info
255+
if ! l2reth_info=$(get_latest_block_info "$L2RETH_RPC_URL"); then
256+
log_error "Failed to get latest block info from L2RETH"
257+
exit 1
258+
fi
259+
260+
local target_block=$(echo "$l2reth_info" | awk '{print $1}')
261+
local target_hash=$(echo "$l2reth_info" | awk '{print $2}')
262+
263+
if wait_for_block "L2GETH" "$L2GETH_RPC_URL" "$target_block" "$target_hash"; then
264+
log_success "L2GETH has caught up with L2RETH at block #$target_block"
265+
else
266+
log_error "L2GETH failed to catch up with L2RETH"
267+
exit 1
268+
fi
269+
}
270+
231271
# Check RPC connectivity for both nodes
232272
check_rpc_connectivity() {
233273
log_info "Checking RPC connectivity..."
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
3+
# Send L1 messages
4+
# Usage: ./send-l1-messages.sh [count]
5+
6+
set -euo pipefail
7+
8+
# Source common functions
9+
source "$(dirname "$0")/common-functions.sh"
10+
11+
# Check for required arguments
12+
if [ $# -lt 1 ]; then
13+
log_info "usage: send-l1-messages.sh [count]"
14+
log_info "example: send-l1-messages.sh 10"
15+
exit 1
16+
fi
17+
18+
check_script_env_vars() {
19+
# Check the L1 private key is provided
20+
if [[ -z "${L1_DEPLOYER_PRIVATE_KEY:-}" ]]; then
21+
log_error "L1_DEPLOYER_PRIVATE_KEY environment variable is required"
22+
exit 1
23+
fi
24+
25+
# Check the L1 RPC URL is provided
26+
if [[ -z "${SCROLL_L1_DEPLOYMENT_RPC:-}" ]]; then
27+
log_error "SCROLL_L1_DEPLOYMENT_RPC environment variable is required"
28+
exit 1
29+
fi
30+
31+
# Check the L1 message queue proxy address is provided
32+
if [[ -z "${L1_MESSAGE_QUEUE_V2_PROXY_ADDR:-}" ]]; then
33+
log_error "L1_MESSAGE_QUEUE_V2_PROXY_ADDR environment variable is required"
34+
exit 1
35+
fi
36+
37+
# Check the L1 enforced tx gateway proxy address is provided
38+
if [[ -z "${L1_ENFORCED_TX_GATEWAY_PROXY_ADDR:-}" ]]; then
39+
log_error "L1_ENFORCED_TX_GATEWAY_PROXY_ADDR environment variable is required"
40+
exit 1
41+
fi
42+
43+
# Check the L1 scroll messenger proxy address is provided
44+
if [[ -z "${L1_SCROLL_MESSENGER_PROXY_ADDR:-}" ]]; then
45+
log_error "L1_SCROLL_MESSENGER_PROXY_ADDR environment variable is required"
46+
exit 1
47+
fi
48+
}
49+
50+
main() {
51+
log_info "=== SENDING L1 MESSAGES ==="
52+
53+
check_script_env_vars
54+
55+
address=$(cast wallet address "$L1_DEPLOYER_PRIVATE_KEY")
56+
start_nonce=$(cast nonce --rpc-url "$SCROLL_L1_DEPLOYMENT_RPC" "$address")
57+
end_nonce=$(($start_nonce + $1))
58+
59+
log_info "Address: $address"
60+
log_info "Start nonce: $start_nonce"
61+
log_info "End nonce: $end_nonce"
62+
63+
for (( ii = $start_nonce; ii < $end_nonce; ii += 2 )); do
64+
log_info ""
65+
log_info "Sending deposit tx with nonce #$ii"
66+
cast send --async --rpc-url "$SCROLL_L1_DEPLOYMENT_RPC" --private-key "$L1_DEPLOYER_PRIVATE_KEY" --legacy --gas-price 0.1gwei --nonce "$ii" --gas-limit 200000 --value 0.001ether "$L1_SCROLL_MESSENGER_PROXY_ADDR" "sendMessage(address _to, uint256 _value, bytes memory _message, uint256 _gasLimit)" 0x0000000000000000000000000000000000000002 0x1 0x 200000
67+
68+
log_info ""
69+
next_queue_index=$(cast call --rpc-url "$SCROLL_L1_DEPLOYMENT_RPC" "$L1_MESSAGE_QUEUE_V2_PROXY_ADDR" "nextCrossDomainMessageIndex()(uint256)")
70+
log_info "Next queue index: $next_queue_index "
71+
72+
log_info ""
73+
log_info "Sending enforced tx with nonce #$(( $ii + 1 ))"
74+
cast send --async --rpc-url "$SCROLL_L1_DEPLOYMENT_RPC" --private-key "$L1_DEPLOYER_PRIVATE_KEY" --legacy --gas-price 0.1gwei --nonce "$(( $ii + 1 ))" --gas-limit 200000 --value 0.001ether "$L1_ENFORCED_TX_GATEWAY_PROXY_ADDR" "sendTransaction(address _target, uint256 _value, uint256 _gasLimit, bytes calldata _data)" 0x0000000000000000000000000000000000000001 1 200000 0x
75+
76+
log_info ""
77+
next_queue_index=$(cast call --rpc-url "$SCROLL_L1_DEPLOYMENT_RPC" "$L1_MESSAGE_QUEUE_V2_PROXY_ADDR" "nextCrossDomainMessageIndex()(uint256)")
78+
log_info "Next queue index: $next_queue_index "
79+
done
80+
81+
echo "Done"
82+
}

sequencer-migration/sepolia.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export SCROLL_L1_DEPLOYMENT_RPC="https://0xrpc.io/sep"
2+
export L1_MESSAGE_QUEUE_V2_PROXY_ADDR="0xA0673eC0A48aa924f067F1274EcD281A10c5f19F"
3+
export L1_ENFORCED_TX_GATEWAY_PROXY_ADDR="0x97f421CA37889269a11ae0fef558114b984C7487"
4+
export L1_SCROLL_MESSENGER_PROXY_ADDR="0x50c7d3e7f7c656493D1D76aaa1a836CedfCBB16A"

sequencer-migration/switch-to-l2geth.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ perform_sequencing_switch() {
1919
log_info "--- Phase 1: Disabling L2RETH sequencing ---"
2020
disable_l2reth_sequencing
2121

22+
# wait for l2geth to catch up with l2reth
23+
log_info "-- Phase 1.5: Waiting for L2GETH to catch up with L2RETH ---"
24+
wait_for_l2geth_to_catch_up_with_l2reth
25+
2226
# Phase 2: Enable L2GETH sequencing
2327
log_info "--- Phase 2: Enabling L2GETH sequencing ---"
2428
start_l2geth_mining
@@ -38,6 +42,15 @@ perform_sequencing_switch() {
3842
log_error "L2GETH failed to produce new blocks after sequencing was enabled"
3943
exit 1
4044
fi
45+
46+
log_info "Verifying L2RETH is following blocks..."
47+
48+
if wait_for_l2reth_to_catch_up_with_l2geth; then
49+
log_success "L2RETH is successfully following blocks"
50+
else
51+
log_error "L2RETH failed to follow new blocks after L2GETH sequencing was enabled"
52+
exit 1
53+
fi
4154
}
4255

4356
main() {
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/bash
2+
3+
# Switch Sequencing to L2RETH Script
4+
# Disables L2RETH sequencing and enables L2RETH sequencing
5+
# Usage: ./switch-to-l2reth.sh
6+
7+
set -euo pipefail
8+
9+
# Source common functions
10+
source "$(dirname "$0")/common-functions.sh"
11+
12+
# Global variables to track state
13+
START_TIME=$(date +%s)
14+
15+
perform_sequencing_switch() {
16+
log_info "=== SWITCHING SEQUENCING TO L2RETH ==="
17+
18+
# Phase 1: Disable L2GETH sequencing
19+
log_info "--- Phase 1: Disabling L2GETH sequencing ---"
20+
stop_l2geth_mining
21+
22+
# wait for l2reth to catch up with l2geth
23+
log_info "-- Phase 1.5: Waiting for L2RETH to catch up with L2GETH ---"
24+
wait_for_l2reth_to_catch_up_with_l2geth
25+
26+
# Phase 2: Enable L2GETH sequencing
27+
log_info "--- Phase 2: Enabling L2GETH sequencing ---"
28+
enable_l2reth_sequencing
29+
30+
# Phase 3: Verify L2RETH is producing blocks
31+
log_info "--- Phase 3: Verifying L2RETH block production ---"
32+
33+
# Get current block and wait for next block
34+
local current_block=$(get_block_number "$L2RETH_RPC_URL")
35+
local target_block=$((current_block + 1))
36+
37+
log_info "Current L2RETH block: #$current_block, waiting for block #$target_block..."
38+
39+
if wait_for_block "L2RETH" "$L2RETH_RPC_URL" "$target_block" ""; then
40+
log_success "L2RETH is successfully producing blocks"
41+
else
42+
log_error "L2RETH failed to produce new blocks after sequencing was enabled"
43+
exit 1
44+
fi
45+
46+
log_info "Verifying L2GETH is following blocks..."
47+
48+
if wait_for_l2geth_to_catch_up_with_l2reth; then
49+
log_success "L2GETH is successfully following blocks"
50+
else
51+
log_error "L2GETH failed to follow new blocks after L2RETH sequencing was enabled"
52+
exit 1
53+
fi
54+
}
55+
56+
main() {
57+
log_info "Starting sequencer switch: L2GETH -> L2RETH"
58+
59+
check_env_vars
60+
perform_pre_flight_checks
61+
62+
# Final confirmation
63+
read -p "Proceed with switching sequencing to L2RETH? (y/N): " confirm
64+
if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then
65+
log_warning "Sequencing switch cancelled by user"
66+
exit 0
67+
fi
68+
69+
perform_sequencing_switch
70+
}
71+
72+
# Run main function
73+
main "$@"

tests/launch_rollup_node_follower.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
set -e
33

4-
export RUST_LOG=sqlx=off,scroll=trace,reth=trace,rollup=trace,trace
4+
export RUST_LOG=sqlx=off,scroll=trace,reth=info,rollup=trace,info
55

66
exec rollup-node node --chain /l2reth/l2reth-genesis-e2e.json --datadir=/l2reth --metrics=0.0.0.0:6060 \
77
--disable-discovery \

tests/launch_rollup_node_sequencer.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ echo -n "0xd510c4b7c61a604f800c4f06803b1ee14b9a63de345e53426ae50425f2dbb058" > /
88
echo -n "01c0d9156e199d89814d4b18e9eb64e25de3927f3f6d27b778177f3ff6b610ad" > /l2reth/nodekey
99
# -> enode://e7f7e271f62bd2b697add14e6987419758c97e83b0478bd948f5f2d271495728e7edef5bd78ad65258ac910f28e86928ead0c42ee51f2a0168d8ca23ba939766@rollup-node-sequencer:30303
1010

11-
export RUST_LOG=sqlx=off,scroll=trace,reth=trace,rollup=trace,trace
11+
export RUST_LOG=sqlx=off,scroll=trace,reth=info,rollup=trace,info
1212

1313
exec rollup-node node --chain /l2reth/l2reth-genesis-e2e.json --datadir=/l2reth --metrics=0.0.0.0:6060 \
1414
--disable-discovery \

0 commit comments

Comments
 (0)