Skip to content

Commit 08b0f0f

Browse files
committed
simplify scripts and remove duplicate code
1 parent 9d7bd3c commit 08b0f0f

File tree

4 files changed

+40
-107
lines changed

4 files changed

+40
-107
lines changed

sequencer-migration/common-functions.sh

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,22 @@ disable_l2reth_sequencing() {
139139
}
140140

141141
# Wait for a specific block to be reached
142+
# Parameters:
143+
# $1: node_name - Human readable name for logging
144+
# $2: rpc_url - RPC URL to query
145+
# $3: target_block - Block number to wait for
146+
# $4: target_hash (optional) - If provided, will verify exact hash match
142147
wait_for_block() {
143148
local node_name="$1"
144149
local rpc_url="$2"
145150
local target_block="$3"
146151
local target_hash="$4"
147152

148-
log_info "Waiting for $node_name to reach block #$target_block (hash: $target_hash)..."
153+
if [[ -n "$target_hash" ]]; then
154+
log_info "Waiting for $node_name to reach block #$target_block (hash: $target_hash)..."
155+
else
156+
log_info "Waiting for $node_name to reach block #$target_block or higher..."
157+
fi
149158

150159
local start_time=$(date +%s)
151160
while true; do
@@ -156,9 +165,11 @@ wait_for_block() {
156165
if [[ $elapsed -gt $SYNC_TIMEOUT ]]; then
157166
log_error "Timeout waiting for $node_name to reach block #$target_block"
158167

159-
local current_block=$(echo "$block_info" | awk '{print $1}')
160-
local current_hash=$(echo "$block_info" | awk '{print $2}')
161-
log_error "$node_name is at block $current_block (hash: $current_hash)"
168+
if block_info=$(get_latest_block_info "$rpc_url" 2>/dev/null); then
169+
local current_block=$(echo "$block_info" | awk '{print $1}')
170+
local current_hash=$(echo "$block_info" | awk '{print $2}')
171+
log_error "$node_name is at block $current_block (hash: $current_hash)"
172+
fi
162173

163174
return 1
164175
fi
@@ -169,14 +180,21 @@ wait_for_block() {
169180
local current_hash=$(echo "$block_info" | awk '{print $2}')
170181

171182
if [[ "$current_block" -ge "$target_block" ]]; then
172-
if [[ "$current_block" -eq "$target_block" && "$current_hash" == "$target_hash" ]]; then
173-
log_success "$node_name reached target block #$target_block (hash: $target_hash)"
174-
return 0
175-
elif [[ "$current_block" -gt "$target_block" ]]; then
176-
log_success "$node_name surpassed target, now at block #$current_block (hash: $current_hash)"
177-
return 0
183+
if [[ -n "$target_hash" ]]; then
184+
# Hash verification mode
185+
if [[ "$current_block" -eq "$target_block" && "$current_hash" == "$target_hash" ]]; then
186+
log_success "$node_name reached target block #$target_block (hash: $target_hash)"
187+
return 0
188+
elif [[ "$current_block" -gt "$target_block" ]]; then
189+
log_success "$node_name surpassed target, now at block #$current_block (hash: $current_hash)"
190+
return 0
191+
else
192+
log_warning "$node_name at block #$current_block but hash mismatch: expected $target_hash, got $current_hash"
193+
fi
178194
else
179-
log_warning "$node_name at block #$current_block but hash mismatch: expected $target_hash, got $current_hash"
195+
# Block number only mode
196+
log_success "$node_name reached block #$current_block (hash: $current_hash)"
197+
return 0
180198
fi
181199
fi
182200
fi

sequencer-migration/migrate-sequencer.sh

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -158,30 +158,13 @@ main() {
158158
log_info "=== PHASE 6: RESUMING L2GETH SEQUENCING ==="
159159
start_l2geth_mining
160160

161-
# TODO: change wait for method so that this can be done as well.
162-
# Wait for at least one new block to confirm
163-
log_info "Waiting for L2GETH to produce at least one new block..."
161+
# Wait for at least one new block to confirm sequencing resumed
164162
local confirmation_target=$((L2RETH_FINAL_BLOCK + 1))
165-
local start_time=$(date +%s)
166-
while true; do
167-
local current_time=$(date +%s)
168-
local elapsed=$((current_time - start_time))
169-
170-
if [[ $elapsed -gt 5 ]]; then # 5 seconds timeout for first block
171-
log_error "Timeout waiting for L2GETH to produce new block"
172-
exit 1
173-
fi
174-
175-
local current_block=$(get_block_number "$L2GETH_RPC_URL")
176-
if [[ $current_block -ge $confirmation_target ]]; then
177-
local confirm_info=$(get_latest_block_info "$L2GETH_RPC_URL")
178-
local confirm_hash=$(echo "$confirm_info" | awk '{print $2}')
179-
log_success "L2GETH sequencing resumed, produced block #$current_block (hash: $confirm_hash)"
180-
break
181-
fi
182-
183-
sleep $POLL_INTERVAL
184-
done
163+
if ! wait_for_block "L2GETH" "$L2GETH_RPC_URL" "$confirmation_target" ""; then
164+
log_error "L2GETH failed to produce new block after resuming sequencing"
165+
exit 1
166+
fi
167+
log_success "L2GETH sequencing resumed successfully"
185168

186169
print_summary
187170
}

sequencer-migration/revert-l2geth-to-block.sh

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ set -euo pipefail
99
# Source common functions
1010
source "$(dirname "$0")/common-functions.sh"
1111

12-
# Script-specific configuration
13-
BLOCK_PRODUCTION_TIMEOUT=60 # 60 seconds timeout for new block production
14-
1512
# Global variables to track state
1613
START_TIME=$(date +%s)
1714
TARGET_BLOCK=""
@@ -35,34 +32,6 @@ reset_l2geth_to_block() {
3532
fi
3633
}
3734

38-
# Wait for new block production after reset
39-
wait_for_new_block_production() {
40-
local starting_block="$1"
41-
local expected_next_block=$((starting_block + 1))
42-
43-
log_info "Waiting for l2geth to produce new blocks starting from #$expected_next_block..."
44-
45-
local start_time=$(date +%s)
46-
while true; do
47-
local current_time=$(date +%s)
48-
local elapsed=$((current_time - start_time))
49-
50-
if [[ $elapsed -gt $BLOCK_PRODUCTION_TIMEOUT ]]; then
51-
log_error "Timeout waiting for l2geth to produce new block (waited ${BLOCK_PRODUCTION_TIMEOUT}s)"
52-
return 1
53-
fi
54-
55-
local current_block=$(get_block_number "$L2GETH_RPC_URL")
56-
if [[ $current_block -ge $expected_next_block ]]; then
57-
local block_info=$(get_latest_block_info "$L2GETH_RPC_URL")
58-
local block_hash=$(echo "$block_info" | awk '{print $2}')
59-
log_success "L2GETH produced new block #$current_block (hash: $block_hash)"
60-
return 0
61-
fi
62-
63-
sleep $POLL_INTERVAL
64-
done
65-
}
6635

6736

6837
pre_flight_checks() {
@@ -193,8 +162,11 @@ main() {
193162

194163
# Phase 5: Wait for new block production
195164
log_info "=== PHASE 5: MONITORING NEW BLOCK PRODUCTION ==="
196-
# TODO: combine with wait_for_block ?
197-
wait_for_new_block_production "$TARGET_BLOCK"
165+
local expected_next_block=$((TARGET_BLOCK + 1))
166+
if ! wait_for_block "L2GETH" "$L2GETH_RPC_URL" "$expected_next_block" ""; then
167+
log_error "L2GETH failed to produce new block after reset"
168+
exit 1
169+
fi
198170

199171
print_summary
200172
}

tests/tests/migrate_sequencer.rs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,6 @@
11
use eyre::Result;
22
use tests::*;
33

4-
///
5-
/// This integration test validates that blocks can be successfully propagated between
6-
/// different Ethereum client implementations (l2geth and rollup-node) in various
7-
/// network topologies. The test exercises:
8-
///
9-
/// 1. **Isolated Network Segments**: Initially runs l2geth nodes in isolation, verifying they can
10-
/// produce and sync blocks independently
11-
/// - Topology: `l2geth_follower -> l2geth_sequencer`
12-
/// - l2geth_sequencer produces blocks, l2geth_follower syncs
13-
/// - Rollup nodes remain disconnected at block 0
14-
///
15-
/// 2. **Cross-Client Synchronization**: Connects rollup nodes to the l2geth network, ensuring they
16-
/// can catch up to the current chain state
17-
/// - Topology: `[rn_follower, rn_sequencer, l2geth_follower] -> l2geth_sequencer`
18-
/// - All nodes connect to l2geth_sequencer as the single source of truth
19-
/// - Rollup nodes sync from block 0 to current height
20-
///
21-
/// 3. **Sequencer Handoff**: Transitions block production from l2geth to rollup-node, testing that
22-
/// all nodes stay synchronized during the transition
23-
/// - Topology remains: `[rn_follower, rn_sequencer, l2geth_follower] -> l2geth_sequencer`
24-
/// - Block production switches from l2geth_sequencer to rn_sequencer
25-
/// - All nodes receive new blocks from rn_sequencer via l2geth_sequencer relay
26-
///
27-
/// 4. **Network Partition Recovery**: Disconnects l2geth nodes, continues production on rollup
28-
/// nodes, then reconnects to verify successful resynchronization
29-
/// - Initial partition: `rn_follower -> rn_sequencer` (isolated rollup network)
30-
/// - l2geth nodes disconnected, fall behind in block height
31-
/// - Reconnection topology: `[l2geth_follower, l2geth_sequencer] -> rn_sequencer`
32-
/// - l2geth nodes catch up by syncing from rn_sequencer
33-
///
34-
/// 5. **Bidirectional Compatibility**: Returns block production to l2geth after rollup nodes have
35-
/// extended the chain, ensuring backward compatibility
36-
/// - Final topology: `[rn_follower, l2geth_follower, l2geth_sequencer] -> rn_sequencer`
37-
/// - Block production returns to l2geth_sequencer
38-
/// - Validates that l2geth can continue the chain after rollup node blocks
39-
///
40-
/// The test validates that both client implementations maintain consensus despite
41-
/// network topology changes, sequencer transitions, and temporary network partitions.
42-
/// Each topology change tests different aspects of peer discovery, block gossip,
43-
/// and chain synchronization across heterogeneous client implementations.
444
#[tokio::test]
455
async fn docker_test_migrate_sequencer() -> Result<()> {
466
reth_tracing::init_test_tracing();

0 commit comments

Comments
 (0)