From b14bbb2db6896774ffc66cdd2ec0e2648735bb93 Mon Sep 17 00:00:00 2001 From: Darioush Jalali Date: Tue, 23 Jan 2024 12:14:28 -0800 Subject: [PATCH] Update acceptor tip before sending chain events to subscribers (#392) (#1060) Co-authored-by: aaronbuchwald --- core/blockchain.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 3167e166a9..f42e6d9125 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -605,6 +605,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}) @@ -615,9 +621,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())