Skip to content

Commit 10b540c

Browse files
committed
fix: address comment
1 parent 5a03a6b commit 10b540c

File tree

5 files changed

+47
-27
lines changed

5 files changed

+47
-27
lines changed

crates/chain-orchestrator/src/event.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub enum ChainOrchestratorEvent {
4444
l1_block_number: u64,
4545
},
4646
/// A batch has been finalized returning a list of finalized batches.
47-
BatchFinalized {
47+
BatchFinalizeIndexed {
4848
/// The L1 block info at which the batch finalization event was received.
4949
l1_block_info: BlockInfo,
5050
/// The list of batches that have been triggered for the derivation pipeline.

crates/chain-orchestrator/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ impl<
814814
self.derivation_pipeline.push_batch(*batch, BatchStatus::Finalized).await;
815815
}
816816

817-
Ok(Some(ChainOrchestratorEvent::BatchFinalized { l1_block_info, triggered_batches }))
817+
Ok(Some(ChainOrchestratorEvent::BatchFinalizeIndexed { l1_block_info, triggered_batches }))
818818
}
819819

820820
/// Handles a batch revert event by updating the database.

crates/node/src/test_utils/event_utils.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ impl<'a> EventWaiter<'a> {
121121
Ok(())
122122
}
123123

124+
/// Wait for batch commit indexed event on all specified nodes.
125+
pub async fn batch_commit_indexed(self) -> eyre::Result<()> {
126+
self.wait_for_event_on_all(|e| {
127+
matches!(e, ChainOrchestratorEvent::BatchCommitIndexed { .. }).then_some(())
128+
})
129+
.await?;
130+
Ok(())
131+
}
132+
124133
/// Wait for batch consolidated event on all specified nodes.
125134
pub async fn batch_consolidated(self) -> eyre::Result<()> {
126135
self.wait_for_event_on_all(|e| {
@@ -143,10 +152,10 @@ impl<'a> EventWaiter<'a> {
143152
Ok(())
144153
}
145154

146-
/// Wait for batch finalized event on all specified nodes.
147-
pub async fn batch_finalized(self) -> eyre::Result<()> {
155+
/// Wait for batch finalize indexed event on all specified nodes.
156+
pub async fn batch_finalize_indexed(self) -> eyre::Result<()> {
148157
self.wait_for_event_on_all(|e| {
149-
matches!(e, ChainOrchestratorEvent::BatchFinalized { .. }).then_some(())
158+
matches!(e, ChainOrchestratorEvent::BatchFinalizeIndexed { .. }).then_some(())
150159
})
151160
.await?;
152161
Ok(())

crates/node/src/test_utils/fixture.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ pub struct AnvilConfig {
275275
pub chain_id: Option<u64>,
276276
/// Optional block time for Anvil (in seconds).
277277
pub block_time: Option<u64>,
278+
/// Optional slots in an epoch for Anvil.
279+
pub slots_in_an_epoch: Option<u64>,
278280
}
279281

280282
/// Builder for creating test fixtures with a fluent API.
@@ -528,12 +530,14 @@ impl TestFixtureBuilder {
528530
state_path: Option<PathBuf>,
529531
chain_id: Option<u64>,
530532
block_time: Option<u64>,
533+
slots_in_an_epoch: Option<u64>,
531534
) -> Self {
532535
self.anvil_config.enabled = true;
533536
self.anvil_config.state_path =
534537
state_path.or_else(|| Some(PathBuf::from("./tests/testdata/anvil_state.json")));
535538
self.anvil_config.chain_id = chain_id;
536539
self.anvil_config.block_time = block_time;
540+
self.anvil_config.slots_in_an_epoch = slots_in_an_epoch;
537541
self
538542
}
539543

@@ -545,9 +549,11 @@ impl TestFixtureBuilder {
545549
// Start Anvil if requested
546550
let anvil = if self.anvil_config.enabled {
547551
let handle = Self::spawn_anvil(
552+
None,
548553
self.anvil_config.state_path.as_deref(),
549554
self.anvil_config.chain_id,
550555
self.anvil_config.block_time,
556+
None,
551557
)
552558
.await?;
553559

@@ -623,19 +629,18 @@ impl TestFixtureBuilder {
623629

624630
/// Spawn an Anvil instance with the given configuration.
625631
async fn spawn_anvil(
632+
port: Option<u16>,
626633
state_path: Option<&std::path::Path>,
627634
chain_id: Option<u64>,
628635
block_time: Option<u64>,
636+
slots_in_an_epoch: Option<u64>,
629637
) -> eyre::Result<anvil::NodeHandle> {
630-
let mut config = anvil::NodeConfig::default();
638+
let mut config = anvil::NodeConfig { port: port.unwrap_or(8544), ..Default::default() };
631639

632-
// Configure chain ID
633640
if let Some(id) = chain_id {
634641
config.chain_id = Some(id);
635642
}
636643

637-
config.port = 8544;
638-
639644
// Configure block time
640645
if let Some(time) = block_time {
641646
config.block_time = Some(std::time::Duration::from_secs(time));
@@ -650,6 +655,8 @@ impl TestFixtureBuilder {
650655
config.init_state = Some(state);
651656
}
652657

658+
config.slots_in_an_epoch = slots_in_an_epoch.unwrap_or(1);
659+
653660
// Spawn Anvil and return the NodeHandle
654661
let (_api, handle) = anvil::spawn(config).await;
655662
Ok(handle)

crates/node/tests/l1_sync.rs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ async fn test_l1_sync_batch_commit() -> eyre::Result<()> {
125125
let mut fixture = TestFixture::builder()
126126
.followers(1)
127127
.skip_l1_synced_notifications() // Prevents automatic L1Synced, simulates initial sync
128-
.with_anvil(None, Some(22222222), None)
128+
.with_anvil(None, Some(22222222), None, None)
129129
.build()
130130
.await?;
131131

@@ -140,10 +140,9 @@ async fn test_l1_sync_batch_commit() -> eyre::Result<()> {
140140
let commit_batch_tx = read_test_transaction("commitBatch", &i.to_string())?;
141141
fixture.anvil_inject_tx(commit_batch_tx).await?;
142142
}
143-
// fixture.anvil_mine_blocks(1).await?;
144-
145-
// Allow time for L1 block processing
146-
tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
143+
for _ in 1..=6 {
144+
fixture.expect_event().batch_commit_indexed().await?;
145+
}
147146

148147
// Step 3: Verify safe head hasn't moved - events should be buffered
149148
let status = fixture.get_status(0).await?;
@@ -194,7 +193,7 @@ async fn test_l1_sync_batch_finalized() -> eyre::Result<()> {
194193
let mut fixture = TestFixture::builder()
195194
.followers(1)
196195
.skip_l1_synced_notifications()
197-
.with_anvil(None, Some(22222222), None)
196+
.with_anvil(None, Some(22222222), None, None)
198197
.build()
199198
.await?;
200199

@@ -213,8 +212,9 @@ async fn test_l1_sync_batch_finalized() -> eyre::Result<()> {
213212
let commit_batch_tx = read_test_transaction("commitBatch", &i.to_string())?;
214213
fixture.anvil_inject_tx(commit_batch_tx).await?;
215214
}
216-
217-
tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
215+
for _ in 1..=6 {
216+
fixture.expect_event().batch_commit_indexed().await?;
217+
}
218218

219219
// Step 3: Verify safe head hasn't changed (still syncing)
220220
let status = fixture.get_status(0).await?;
@@ -225,16 +225,15 @@ async fn test_l1_sync_batch_finalized() -> eyre::Result<()> {
225225
);
226226

227227
// Step 4: Send BatchFinalized transactions (batches 1-3) while syncing
228-
// Mine 64 blocks to ensure the BatchFinalized events are themselves finalized on L1
228+
// Mine blocks to ensure the BatchFinalized events are themselves finalized on L1
229229
// This should trigger all unprocessed BatchCommit events up to the finalized batch
230230
for i in 1..=3 {
231231
let finalize_batch_tx = read_test_transaction("finalizeBatch", &i.to_string())?;
232232
fixture.anvil_inject_tx(finalize_batch_tx).await?;
233233
}
234-
fixture.anvil_mine_blocks(64).await?;
234+
fixture.anvil_mine_blocks(2).await?;
235235

236236
for _ in 1..=3 {
237-
// fixture.expect_event().batch_finalized().await?;
238237
fixture.expect_event().batch_consolidated().await?;
239238
}
240239

@@ -275,10 +274,11 @@ async fn test_l1_sync_batch_finalized() -> eyre::Result<()> {
275274
"Finalized head should not advance before BatchFinalized event are finalized on L1"
276275
);
277276

278-
fixture.anvil_mine_blocks(64).await?;
279277
for _ in 1..=3 {
280-
fixture.expect_event().batch_finalized().await?;
278+
fixture.expect_event().batch_finalize_indexed().await?;
281279
}
280+
fixture.anvil_mine_blocks(2).await?;
281+
fixture.expect_event().l1_block_finalized().await?;
282282

283283
// Step 8: Verify only finalized head advanced (safe head managed by BatchCommit)
284284
let batch_finalized_status = fixture.get_status(0).await?;
@@ -317,7 +317,7 @@ async fn test_l1_sync_batch_revert() -> eyre::Result<()> {
317317
let mut fixture = TestFixture::builder()
318318
.followers(1)
319319
.skip_l1_synced_notifications()
320-
.with_anvil(None, Some(22222222), None)
320+
.with_anvil(None, Some(22222222), None, None)
321321
.build()
322322
.await?;
323323

@@ -331,6 +331,9 @@ async fn test_l1_sync_batch_revert() -> eyre::Result<()> {
331331
let commit_batch_tx = read_test_transaction("commitBatch", &i.to_string())?;
332332
fixture.anvil_inject_tx(commit_batch_tx).await?;
333333
}
334+
for _ in 1..=6 {
335+
fixture.expect_event().batch_commit_indexed().await?;
336+
}
334337

335338
// Step 3: Complete L1 sync
336339
fixture.l1().sync().await?;
@@ -391,7 +394,7 @@ async fn test_l1_reorg_batch_commit() -> eyre::Result<()> {
391394
let mut fixture = TestFixture::builder()
392395
.followers(1)
393396
.skip_l1_synced_notifications()
394-
.with_anvil(None, Some(22222222), None)
397+
.with_anvil(None, Some(22222222), None, None)
395398
.build()
396399
.await?;
397400

@@ -432,6 +435,7 @@ async fn test_l1_reorg_batch_commit() -> eyre::Result<()> {
432435

433436
// Step 4: Perform L1 reorg to remove batches 4-6 (reorg depth 3)
434437
fixture.anvil_reorg(3).await?;
438+
tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
435439

436440
// Wait for reorg detection
437441
fixture.expect_event().l1_reorg().await?;
@@ -474,7 +478,7 @@ async fn test_l1_reorg_batch_finalized() -> eyre::Result<()> {
474478
let mut fixture = TestFixture::builder()
475479
.followers(1)
476480
.skip_l1_synced_notifications()
477-
.with_anvil(None, Some(22222222), None)
481+
.with_anvil(None, Some(22222222), None, None)
478482
.build()
479483
.await?;
480484

@@ -496,7 +500,7 @@ async fn test_l1_reorg_batch_finalized() -> eyre::Result<()> {
496500
fixture.anvil_inject_tx(finalize_batch_tx).await?;
497501
}
498502
for _ in 1..=2 {
499-
fixture.expect_event().batch_finalized().await?;
503+
fixture.expect_event().batch_finalize_indexed().await?;
500504
}
501505

502506
// Record finalized head after finalization
@@ -553,7 +557,7 @@ async fn test_l1_reorg_batch_revert() -> eyre::Result<()> {
553557
let mut fixture = TestFixture::builder()
554558
.followers(1)
555559
.skip_l1_synced_notifications()
556-
.with_anvil(None, Some(22222222), None)
560+
.with_anvil(None, Some(22222222), None, None)
557561
.build()
558562
.await?;
559563

0 commit comments

Comments
 (0)