Skip to content

Commit db82ea2

Browse files
core: reset txpool on sethead (ethereum#26392)
This change sends a HeadChainEvent when SetHead is invoked. The txpool will then reset the txnoncer on receiving the event.
1 parent c87f321 commit db82ea2

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

core/blockchain.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,12 @@ func (bc *BlockChain) loadLastState() error {
532532
// was fast synced or full synced and in which state, the method will try to
533533
// delete minimal data from disk whilst retaining chain consistency.
534534
func (bc *BlockChain) SetHead(head uint64) error {
535-
_, err := bc.setHeadBeyondRoot(head, common.Hash{}, false)
536-
return err
535+
if _, err := bc.setHeadBeyondRoot(head, common.Hash{}, false); err != nil {
536+
return err
537+
}
538+
// Send chain head event to update the transaction pool
539+
bc.chainHeadFeed.Send(ChainHeadEvent{Block: bc.CurrentBlock()})
540+
return nil
537541
}
538542

539543
// SetFinalized sets the finalized block.

ethclient/gethclient/gethclient_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,6 @@ func TestGethClient(t *testing.T) {
118118
}, {
119119
"TestGetNodeInfo",
120120
func(t *testing.T) { testGetNodeInfo(t, client) },
121-
}, {
122-
"TestSetHead",
123-
func(t *testing.T) { testSetHead(t, client) },
124121
}, {
125122
"TestSubscribePendingTxHashes",
126123
func(t *testing.T) { testSubscribePendingTransactions(t, client) },
@@ -138,6 +135,9 @@ func TestGethClient(t *testing.T) {
138135
{
139136
"TestAccessList",
140137
func(t *testing.T) { testAccessList(t, client) },
138+
}, {
139+
"TestSetHead",
140+
func(t *testing.T) { testSetHead(t, client) },
141141
},
142142
}
143143
for _, tt := range tests {

0 commit comments

Comments
 (0)