From f52cc229ef1e1e9486ea5a23919468a5428cc675 Mon Sep 17 00:00:00 2001 From: Goran Rojovic Date: Mon, 20 Jan 2025 15:33:28 +0100 Subject: [PATCH] fix: driver handling closing download channel --- l1infotreesync/e2e_test.go | 10 ++++------ sync/evmdriver.go | 10 +++++++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/l1infotreesync/e2e_test.go b/l1infotreesync/e2e_test.go index 2e22e138..0ab65201 100644 --- a/l1infotreesync/e2e_test.go +++ b/l1infotreesync/e2e_test.go @@ -228,9 +228,6 @@ func TestWithReorgs(t *testing.T) { // Block 4, 5, 6 after the fork commitBlocks(t, client, 3, time.Millisecond*500) - // Make sure syncer is up to date - waitForSyncerToCatchUp(ctx, t, syncer, client) - // Assert rollup exit root after the fork - should be zero since there are no events in the block after the fork expectedRollupExitRoot, err = verifySC.GetRollupExitRoot(&bind.CallOpts{Pending: false}) require.NoError(t, err) @@ -244,11 +241,12 @@ func TestWithReorgs(t *testing.T) { require.NoError(t, err) time.Sleep(time.Millisecond * 500) + commitBlocks(t, client, 1, time.Millisecond*100) + // create some events and update the trees updateL1InfoTreeAndRollupExitTree(2, 1) - // Block 4, 5, 6, 7 after the fork - commitBlocks(t, client, 4, time.Millisecond*100) + commitBlocks(t, client, 1, time.Millisecond*100) // Make sure syncer is up to date waitForSyncerToCatchUp(ctx, t, syncer, client) @@ -360,7 +358,7 @@ func waitForSyncerToCatchUp(ctx context.Context, t *testing.T, syncer *l1infotre require.NoError(t, err) lb, err := client.Client().BlockNumber(ctx) require.NoError(t, err) - if lpb == lb { + if lpb == lb-1 || lpb == lb { syncerUpToDate = true break } diff --git a/sync/evmdriver.go b/sync/evmdriver.go index 89fdf7c6..72bd053b 100644 --- a/sync/evmdriver.go +++ b/sync/evmdriver.go @@ -81,7 +81,7 @@ reset: cancellableCtx, cancel := context.WithCancel(ctx) defer cancel() - log.Info("Starting sync...", " lastProcessedBlock", lastProcessedBlock) + log.Info("Starting sync...", " lastProcessedBlock ", lastProcessedBlock) // start downloading downloadCh := make(chan EVMBlock, d.downloadBufferSize) go d.downloader.Download(cancellableCtx, lastProcessedBlock+1, downloadCh) @@ -92,9 +92,13 @@ reset: d.log.Info("sync stopped due to context done") cancel() return - case b := <-downloadCh: + case b, ok := <-downloadCh: d.log.Debugf("handleNewBlock, blockNum: %d, blockHash: %s", b.Num, b.Hash) - d.handleNewBlock(ctx, cancel, b) + if ok { + // when channel is closing, it is sending an empty block with num = 0, and empty hash + // because it is not passing object by reference, but by value, so do not handle that since it is closing + d.handleNewBlock(ctx, cancel, b) + } case firstReorgedBlock := <-d.reorgSub.ReorgedBlock: d.log.Info("handleReorg from block: ", firstReorgedBlock) d.handleReorg(ctx, cancel, firstReorgedBlock)