@@ -1798,6 +1798,12 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
17981798 if err := blockBatch .Write (); err != nil {
17991799 log .Crit ("Failed to write block into disk" , "err" , err )
18001800 }
1801+ bc .hc .tdCache .Add (block .Hash (), externTd )
1802+ bc .blockCache .Add (block .Hash (), block )
1803+ bc .receiptsCache .Add (block .Hash (), receipts )
1804+ if bc .chainConfig .IsCancun (block .Number (), block .Time ()) {
1805+ bc .sidecarsCache .Add (block .Hash (), block .Sidecars ())
1806+ }
18011807 wg .Done ()
18021808 }()
18031809
@@ -1908,30 +1914,26 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
19081914
19091915// WriteBlockAndSetHead writes the given block and all associated state to the database,
19101916// and applies the block as the new chain head.
1911- func (bc * BlockChain ) WriteBlockAndSetHead (block * types.Block , receipts []* types.Receipt , logs []* types.Log , state * state.StateDB , emitHeadEvent bool , mux * event. TypeMux ) (status WriteStatus , err error ) {
1917+ func (bc * BlockChain ) WriteBlockAndSetHead (block * types.Block , receipts []* types.Receipt , logs []* types.Log , state * state.StateDB , emitHeadEvent bool ) (status WriteStatus , err error ) {
19121918 if ! bc .chainmu .TryLock () {
19131919 return NonStatTy , errChainStopped
19141920 }
19151921 defer bc .chainmu .Unlock ()
19161922
1917- return bc .writeBlockAndSetHead (block , receipts , logs , state , emitHeadEvent , mux )
1923+ return bc .writeBlockAndSetHead (block , receipts , logs , state , emitHeadEvent )
19181924}
19191925
19201926// writeBlockAndSetHead is the internal implementation of WriteBlockAndSetHead.
19211927// This function expects the chain mutex to be held.
1922- func (bc * BlockChain ) writeBlockAndSetHead (block * types.Block , receipts []* types.Receipt , logs []* types.Log , state * state.StateDB , emitHeadEvent bool , mux * event.TypeMux ) (status WriteStatus , err error ) {
1928+ func (bc * BlockChain ) writeBlockAndSetHead (block * types.Block , receipts []* types.Receipt , logs []* types.Log , state * state.StateDB , emitHeadEvent bool ) (status WriteStatus , err error ) {
1929+ if err := bc .writeBlockWithState (block , receipts , state ); err != nil {
1930+ return NonStatTy , err
1931+ }
19231932 currentBlock := bc .CurrentBlock ()
19241933 reorg , err := bc .forker .ReorgNeededWithFastFinality (currentBlock , block .Header ())
19251934 if err != nil {
19261935 return NonStatTy , err
19271936 }
1928- if reorg && mux != nil {
1929- mux .Post (NewSealedBlockEvent {Block : block })
1930- }
1931-
1932- if err := bc .writeBlockWithState (block , receipts , state ); err != nil {
1933- return NonStatTy , err
1934- }
19351937 if reorg {
19361938 // Reorganise the chain if the parent is not the head block
19371939 if block .ParentHash () != currentBlock .Hash () {
@@ -2304,7 +2306,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
23042306 // Don't set the head, only insert the block
23052307 err = bc .writeBlockWithState (block , receipts , statedb )
23062308 } else {
2307- status , err = bc .writeBlockAndSetHead (block , receipts , logs , statedb , false , nil )
2309+ status , err = bc .writeBlockAndSetHead (block , receipts , logs , statedb , false )
23082310 }
23092311 if err != nil {
23102312 return it .index , err
0 commit comments