Skip to content

Commit

Permalink
ethreceipts: lock when mutating NumBlocksToFinality
Browse files Browse the repository at this point in the history
ReceiptsListener.lazyInit writes to NumBlocksToFinality, we need to lock everywhere we read from it.
  • Loading branch information
attente committed Sep 11, 2024
1 parent 0e4aa2e commit cad6a76
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ethreceipts/ethreceipts.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ func NewReceiptsListener(log logger.Logger, provider ethrpc.Interface, monitor *
}

func (l *ReceiptsListener) lazyInit(ctx context.Context) error {
l.mu.Lock()
defer l.mu.Unlock()

if l.options.NumBlocksToFinality <= 0 {
chainID, err := getChainID(ctx, l.provider)
if err != nil {
Expand Down Expand Up @@ -776,6 +779,9 @@ func (l *ReceiptsListener) getMaxWaitBlocks(maxWait *int) uint64 {
if maxWait == nil {
return uint64(l.options.FilterMaxWaitNumBlocks)
} else if *maxWait < 0 {
l.mu.RLock()
defer l.mu.RUnlock()

return uint64(l.options.NumBlocksToFinality * 2)
} else {
return uint64(*maxWait)
Expand All @@ -788,6 +794,10 @@ func (l *ReceiptsListener) isBlockFinal(blockNum *big.Int) bool {
return false
}
diff := big.NewInt(0).Sub(latestBlockNum, blockNum)

l.mu.RLock()
defer l.mu.RUnlock()

return diff.Cmp(big.NewInt(int64(l.options.NumBlocksToFinality))) >= 0
}

Expand Down

0 comments on commit cad6a76

Please sign in to comment.