Skip to content

Commit

Permalink
fix: increase log level
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal committed Jan 21, 2025
1 parent 79bca55 commit e13886c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
29 changes: 18 additions & 11 deletions sync/evmdownloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (d *EVMDownloader) Download(ctx context.Context, fromBlock uint64, download
}

if fromBlock > toBlock {
d.log.Debugf(
d.log.Infof(
"waiting for new blocks, last block processed: %d, last block seen on L1: %d",
fromBlock-1, lastBlock,
)
Expand All @@ -113,43 +113,47 @@ func (d *EVMDownloader) Download(ctx context.Context, fromBlock uint64, download

lastFinalizedBlockNumber := lastFinalizedBlock.Number.Uint64()

d.log.Debugf("getting events from blocks %d to %d", fromBlock, toBlock)
d.log.Infof("getting events from blocks %d to %d", fromBlock, toBlock)
blocks := d.GetEventsByBlockRange(ctx, fromBlock, toBlock)

reportBlocksFn := func(numOfBlocksToReport int) {
for i := 0; i < numOfBlocksToReport; i++ {
d.log.Debugf("sending block %d to the driver (with events)", blocks[i].Num)
d.log.Infof("sending block %d to the driver (with events)", blocks[i].Num)
downloadedCh <- blocks[i]
}
}

reportEmptyBlockFn := func(blockNum uint64) {
reportEmptyFinalizedBlockFn := func() {
// Indicate the last downloaded block if there are not events on it
d.log.Debugf("sending block %d to the driver (without events)", toBlock)
header, isCanceled := d.GetBlockHeader(ctx, blockNum)
if isCanceled {
return
}
d.log.Infof("sending block %d to the driver (without events)", lastFinalizedBlockNumber)

downloadedCh <- EVMBlock{
EVMBlockHeader: header,
EVMBlockHeader: EVMBlockHeader{
Num: lastFinalizedBlock.Number.Uint64(),
Hash: lastFinalizedBlock.Hash(),
ParentHash: lastFinalizedBlock.ParentHash,
Timestamp: lastFinalizedBlock.Time,
},
}
}

if blocks.Len() == 0 {
// we have no events, keep increasing the block range until we hit a log
d.log.Infof("no events found in blocks %d to %d", fromBlock, toBlock)
if lastFinalizedBlockNumber > toBlock {
// we might be behind a lot, so go until last finalized block
toBlock = lastFinalizedBlockNumber
lastBlock = lastFinalizedBlockNumber
d.log.Infof("setting toBlock to last finalized block %d", toBlock)
}

if lastFinalizedBlockNumber-fromBlock >= d.syncBlockChunkSize {
// if we already got a lot of finalized blocks that are empty, report an empty block
// to the driver to indicate that we are still processing the chain
// this is mainly needed for tests
reportEmptyBlockFn(lastFinalizedBlockNumber)
reportEmptyFinalizedBlockFn()
fromBlock = lastFinalizedBlockNumber
d.log.Infof("setting fromBlock to last finalized block %d", fromBlock)
}

continue
Expand All @@ -159,6 +163,7 @@ func (d *EVMDownloader) Download(ctx context.Context, fromBlock uint64, download
// and we do not need to track it in the reorg detector
reportBlocksFn(blocks.Len())
fromBlock = toBlock + 1
d.log.Infof("got blocks that are lower than finalized block, setting fromBlock to %d", fromBlock)
} else if blocks[blocks.Len()-1].Num < toBlock {
// if we have logs in some of the blocks, and they are not all finalized,
// check if we have finalized blocks in gotten range, report them and
Expand All @@ -168,6 +173,7 @@ func (d *EVMDownloader) Download(ctx context.Context, fromBlock uint64, download
if exists {
reportBlocksFn(index + 1) // num of blocks to report is index + 1 since index is zero based
fromBlock = lastFinalizedBlock + 1
d.log.Infof("have some finalized blocks in the range, setting fromBlock to %d", fromBlock)
continue
}
} else {
Expand All @@ -176,6 +182,7 @@ func (d *EVMDownloader) Download(ctx context.Context, fromBlock uint64, download
// and we are not afraid to have missaligned hashes at this point
reportBlocksFn(blocks.Len())
fromBlock = toBlock + 1
d.log.Infof("have logs in the last block, setting fromBlock to %d", fromBlock)
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions sync/evmdownloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,18 +275,20 @@ func TestDownload(t *testing.T) {
Return(EVMBlocks{}, false)

// iteration 7: last finalized block is now 20, no events, report empty block
d.On("GetLastFinalizedBlock", mock.Anything).Return(&types.Header{Number: big.NewInt(20)}, nil).Once()
lastFinalizedBlock := &types.Header{Number: big.NewInt(20)}
d.On("GetLastFinalizedBlock", mock.Anything).Return(lastFinalizedBlock, nil).Once()
d.On("GetEventsByBlockRange", mock.Anything, uint64(9), uint64(19)).
Return(EVMBlocks{}, false)

b20 := EVMBlock{
EVMBlockHeader: EVMBlockHeader{
Num: 20,
Hash: common.HexToHash("20"),
Num: lastFinalizedBlock.Number.Uint64(),
Hash: lastFinalizedBlock.Hash(),
ParentHash: lastFinalizedBlock.ParentHash,
Timestamp: lastFinalizedBlock.Time,
},
}
expectedBlocks = append(expectedBlocks, b20)
d.On("GetBlockHeader", mock.Anything, uint64(20)).Return(b20.EVMBlockHeader, false) // reporting empty finalized block

// iteration 8: last finalized block is 21, no events
d.On("GetLastFinalizedBlock", mock.Anything).Return(&types.Header{Number: big.NewInt(21)}, nil).Once()
Expand Down
2 changes: 1 addition & 1 deletion sync/evmdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ reset:
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.log.Debugf("handleNewBlock, blockNum: %d, blockHash: %s", b.Num, b.Hash)
d.log.Infof("handleNewBlock, blockNum: %d, blockHash: %s", b.Num, b.Hash)
d.handleNewBlock(ctx, cancel, b)
}
case firstReorgedBlock := <-d.reorgSub.ReorgedBlock:
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func L1Setup(t *testing.T) *L1Environment {
originNetwork = 1
initialBlock = 0
retryPeriod = 0
retriesCount = 0
retriesCount = 10
)

// Bridge sync
Expand Down

0 comments on commit e13886c

Please sign in to comment.