Skip to content

Commit

Permalink
Update acceptor tip before sending chain events to subscribers (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronbuchwald authored and darioush committed Jan 23, 2024
1 parent 60356fe commit 7d360b2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,12 @@ func (bc *BlockChain) startAcceptor() {
logs := bc.collectUnflattenedLogs(next, false)
bc.acceptedLogsCache.Put(next.Hash(), logs)

// Update the acceptor tip before sending events to ensure that any client acting based off of
// the events observes the updated acceptorTip on subsequent requests
bc.acceptorTipLock.Lock()
bc.acceptorTip = next
bc.acceptorTipLock.Unlock()

// Update accepted feeds
flattenedLogs := types.FlattenLogs(logs)
bc.chainAcceptedFeed.Send(ChainEvent{Block: next, Hash: next.Hash(), Logs: flattenedLogs})
Expand All @@ -617,9 +623,6 @@ func (bc *BlockChain) startAcceptor() {
bc.txAcceptedFeed.Send(NewTxsEvent{next.Transactions()})
}

bc.acceptorTipLock.Lock()
bc.acceptorTip = next
bc.acceptorTipLock.Unlock()
bc.acceptorWg.Done()

acceptorWorkTimer.Inc(time.Since(start).Milliseconds())
Expand Down

0 comments on commit 7d360b2

Please sign in to comment.