diff --git a/l1infotreesync/downloader.go b/l1infotreesync/downloader.go index 83d343291..a47ed0621 100644 --- a/l1infotreesync/downloader.go +++ b/l1infotreesync/downloader.go @@ -86,7 +86,8 @@ func buildAppender(client EthClienter, globalExitRoot, rollupManager common.Addr l, err, ) } - log.Infof("updateL1InfoTreeSignatureV2: expected root: %s", common.BytesToHash(l1InfoTreeUpdate.CurrentL1InfoRoot[:]).String()) + log.Infof("updateL1InfoTreeSignatureV2: expected root: %s", + common.BytesToHash(l1InfoTreeUpdate.CurrentL1InfoRoot[:]).String()) return nil } diff --git a/reorgdetector/reorgdetector.go b/reorgdetector/reorgdetector.go index 5e0d17383..970a154ff 100644 --- a/reorgdetector/reorgdetector.go +++ b/reorgdetector/reorgdetector.go @@ -125,9 +125,8 @@ func (rd *ReorgDetector) detectReorgInTrackedList(ctx context.Context) error { for _, id := range subscriberIDs { id := id - // This is done like this because of a possible deadlock between AddBlocksToTrack and detectReorgInTrackedList - // because detectReorgInTrackedList would take the trackedBlocksLock and try to notify the subscriber in case of a reorg - // but the subscriber would be trying to add a block to track and save it to trackedBlocks, resulting in a deadlock + // This is done like this because of a possible deadlock + // between AddBlocksToTrack and detectReorgInTrackedList rd.trackedBlocksLock.RLock() hdrs, ok := rd.trackedBlocks[id] rd.trackedBlocksLock.RUnlock() @@ -162,7 +161,7 @@ func (rd *ReorgDetector) detectReorgInTrackedList(ctx context.Context) error { continue } - log.Info("[ReorgDetector] Reorg detected", "blockNum", hdr.Num) + log.Info("[ReorgDetector] Reorg detected", " blockNum ", hdr.Num) // Notify the subscriber about the reorg rd.notifySubscriber(id, hdr) diff --git a/reorgdetector/reorgdetector_db.go b/reorgdetector/reorgdetector_db.go index 552f9d695..79bd6cd42 100644 --- a/reorgdetector/reorgdetector_db.go +++ b/reorgdetector/reorgdetector_db.go @@ -55,9 +55,8 @@ func (rd *ReorgDetector) getTrackedBlocks(ctx context.Context) (map[string]*head func (rd *ReorgDetector) saveTrackedBlock(ctx context.Context, id string, b header) error { rd.trackedBlocksLock.Lock() - // this has to go after the lock, because of a possible deadlock between AddBlocksToTrack and detectReorgInTrackedList - // because AddBlocksToTrack would start a transaction on db, but detectReorgInTrackedList would lock the trackedBlocksLock - // and then try to start a transaction on db, resulting in a deadlock + // this has to go after the lock, because of a possible deadlock + // between AddBlocksToTrack and detectReorgInTrackedList tx, err := rd.db.BeginRw(ctx) if err != nil { return err diff --git a/sync/evmdriver_test.go b/sync/evmdriver_test.go index 907dac28f..c17370e14 100644 --- a/sync/evmdriver_test.go +++ b/sync/evmdriver_test.go @@ -198,36 +198,19 @@ func TestHandleReorg(t *testing.T) { // happy path _, cancel := context.WithCancel(ctx) - downloadCh := make(chan EVMBlock) firstReorgedBlock := uint64(5) pm.On("Reorg", ctx, firstReorgedBlock).Return(nil) - go driver.handleReorg(ctx, cancel, downloadCh, firstReorgedBlock) - close(downloadCh) + go driver.handleReorg(ctx, cancel, firstReorgedBlock) done := <-reorgProcessed require.True(t, done) - // download ch sends some garbage - _, cancel = context.WithCancel(ctx) - downloadCh = make(chan EVMBlock) - firstReorgedBlock = uint64(6) - pm.On("Reorg", ctx, firstReorgedBlock).Return(nil) - go driver.handleReorg(ctx, cancel, downloadCh, firstReorgedBlock) - downloadCh <- EVMBlock{} - downloadCh <- EVMBlock{} - downloadCh <- EVMBlock{} - close(downloadCh) - done = <-reorgProcessed - require.True(t, done) - // processor fails 2 times _, cancel = context.WithCancel(ctx) - downloadCh = make(chan EVMBlock) firstReorgedBlock = uint64(7) pm.On("Reorg", ctx, firstReorgedBlock).Return(errors.New("foo")).Once() pm.On("Reorg", ctx, firstReorgedBlock).Return(errors.New("foo")).Once() pm.On("Reorg", ctx, firstReorgedBlock).Return(nil).Once() - go driver.handleReorg(ctx, cancel, downloadCh, firstReorgedBlock) - close(downloadCh) + go driver.handleReorg(ctx, cancel, firstReorgedBlock) done = <-reorgProcessed require.True(t, done) }