diff --git a/l1infotreesync/downloader.go b/l1infotreesync/downloader.go index 83d34329..a47ed062 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 5e0d1738..970a154f 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 552f9d69..79bd6cd4 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 907dac28..c17370e1 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) } diff --git a/tree/tree_test.go b/tree/tree_test.go index 0e99a7b5..e34f378e 100644 --- a/tree/tree_test.go +++ b/tree/tree_test.go @@ -20,8 +20,6 @@ import ( ) func TestCheckExpectedRoot(t *testing.T) { - t.Parallel() - createTreeDB := func() *sql.DB { dbPath := path.Join(t.TempDir(), "file::memory:?cache=shared") log.Debug("DB created at: ", dbPath) @@ -49,8 +47,6 @@ func TestCheckExpectedRoot(t *testing.T) { } t.Run("Check when no reorg", func(t *testing.T) { - t.Parallel() - numOfLeavesToAdd := 10 indexToCheck := uint32(numOfLeavesToAdd - 1) @@ -71,8 +67,6 @@ func TestCheckExpectedRoot(t *testing.T) { }) t.Run("Check after rebuild tree when reorg", func(t *testing.T) { - t.Parallel() - numOfLeavesToAdd := 10 indexToCheck := uint32(numOfLeavesToAdd - 1) treeDB := createTreeDB()