Skip to content

Commit

Permalink
lock
Browse files Browse the repository at this point in the history
  • Loading branch information
pkieltyka committed Sep 12, 2023
1 parent 234f738 commit f84ce06
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ethmonitor/ethmonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ func (m *Monitor) monitor() error {
// build deterministic set of add/remove events which construct the canonical chain
events, err = m.buildCanonicalChain(ctx, nextBlock, nextBlockPayload, events)
if err != nil {
// TODO: polygon-zkevm stuck here.. retrying to find the block hash for too long.. prob cuz the block is gone..
m.log.Warnf("ethmonitor: error reported '%v', failed to build chain for next blockNum:%d blockHash:%s, retrying..",
err, nextBlock.NumberU64(), nextBlock.Hash().Hex())

Expand Down Expand Up @@ -427,7 +428,9 @@ func (m *Monitor) addLogs(ctx context.Context, blocks Blocks) {
// do not attempt to get logs for re-org'd blocks as the data
// will be inconsistent and may never be available.
if block.Event == Removed {
m.chain.mu.Lock()
block.OK = true
m.chain.mu.Unlock()
continue
}

Expand All @@ -444,6 +447,7 @@ func (m *Monitor) addLogs(ctx context.Context, blocks Blocks) {
// check the logsBloom from the block to check if we should be expecting logs. logsBloom
// will be included for any indexed logs.
if len(logs) > 0 || block.Bloom() == (types.Bloom{}) {
m.chain.mu.Lock()
// successful backfill
if logs == nil {
block.Logs = []types.Log{}
Expand All @@ -452,13 +456,16 @@ func (m *Monitor) addLogs(ctx context.Context, blocks Blocks) {
}
block.LogsPayload = m.setPayload(logsPayload)
block.OK = true
m.chain.mu.Unlock()
continue
}
}

// mark for backfilling
m.chain.mu.Lock()
block.Logs = nil
block.OK = false
m.chain.mu.Unlock()

// NOTE: we do not error here as these logs will be backfilled before they are published anyways,
// but we log the error anyways.
Expand Down

0 comments on commit f84ce06

Please sign in to comment.