Skip to content

update blockProcFeed in insertChain #2296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,16 @@ type BlockChain struct {
// * nil: disable tx reindexer/deleter, but still index new blocks
txLookupLimit uint64

hc *HeaderChain
rmLogsFeed event.Feed
chainFeed event.Feed
chainSideFeed event.Feed
chainHeadFeed event.Feed
logsFeed event.Feed
blockProcFeed event.Feed
scope event.SubscriptionScope
genesisBlock *types.Block
hc *HeaderChain
rmLogsFeed event.Feed
chainFeed event.Feed
chainSideFeed event.Feed
chainHeadFeed event.Feed
logsFeed event.Feed
blockProcFeed event.Feed
blockProcCounter int32
scope event.SubscriptionScope
genesisBlock *types.Block

// This mutex synchronizes chain write operations.
// Readers don't need to take it, they can just read the database.
Expand Down Expand Up @@ -1497,9 +1498,6 @@ func (bc *BlockChain) InsertChain(chain types.Blocks) (int, error) {
return 0, nil
}

bc.blockProcFeed.Send(true)
defer bc.blockProcFeed.Send(false)

// Do a sanity check that the provided chain is actually ordered and linked.
for i := 1; i < len(chain); i++ {
block, prev := chain[i], chain[i-1]
Expand Down Expand Up @@ -1527,9 +1525,6 @@ func (bc *BlockChain) InsertChain(chain types.Blocks) (int, error) {
// InsertChainWithoutSealVerification works exactly the same
// except for seal verification, seal verification is omitted
func (bc *BlockChain) InsertChainWithoutSealVerification(block *types.Block) (int, error) {
bc.blockProcFeed.Send(true)
defer bc.blockProcFeed.Send(false)

if !bc.chainmu.TryLock() {
return 0, errChainStopped
}
Expand All @@ -1551,6 +1546,15 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, er
return 0, nil
}

if atomic.AddInt32(&bc.blockProcCounter, 1) == 1 {
bc.blockProcFeed.Send(true)
}
defer func() {
if atomic.AddInt32(&bc.blockProcCounter, -1) == 0 {
bc.blockProcFeed.Send(false)
}
}()

// Start a parallel signature recovery (signer will fluke on fork transition, minimal perf loss)
SenderCacher.RecoverFromBlocks(types.MakeSigner(bc.chainConfig, chain[0].Number(), chain[0].Time()), chain)

Expand Down
Loading