From dfe2a7ff2e8c53f099fa5b0bf55a21a8d856bee6 Mon Sep 17 00:00:00 2001 From: Aaron Buchwald Date: Thu, 16 Nov 2023 11:17:14 -0500 Subject: [PATCH] Update acceptor tip before sending chain events to subscribers --- core/blockchain.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 928c0e2e4b..cb67c4005b 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -583,6 +583,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}) @@ -593,9 +599,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())