Skip to content

Commit

Permalink
fix: ut build
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal committed Sep 19, 2024
1 parent 8aea9de commit f203c52
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 27 deletions.
3 changes: 2 additions & 1 deletion l1infotreesync/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 3 additions & 4 deletions reorgdetector/reorgdetector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions reorgdetector/reorgdetector_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 2 additions & 19 deletions sync/evmdriver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit f203c52

Please sign in to comment.