Skip to content
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

fix: cache data after successful writing[BNB-12] #17

Merged
merged 2 commits into from
Jan 5, 2024
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
17 changes: 9 additions & 8 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1873,14 +1873,6 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals, setHead bool)
vtime := time.Since(vstart)
proctime := time.Since(start) // processing + validation

// pre-cache the block and receipts, so that it can be retrieved quickly by rcp
bc.CacheBlock(block.Hash(), block)
err = types.Receipts(receipts).DeriveFields(bc.chainConfig, block.Hash(), block.NumberU64(), block.Time(), block.BaseFee(), block.Transactions())
if err != nil {
log.Warn("Failed to derive receipt fields", "block", block.Hash(), "err", err)
}
bc.CacheReceipts(block.Hash(), receipts)

// Update the metrics touched during block processing and validation
accountReadTimer.Update(statedb.AccountReads) // Account reads are complete(in processing)
storageReadTimer.Update(statedb.StorageReads) // Storage reads are complete(in processing)
Expand Down Expand Up @@ -1912,6 +1904,15 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals, setHead bool)
if err != nil {
return it.index, err
}

// pre-cache the block and receipts, so that it can be retrieved quickly by rcp
bc.CacheBlock(block.Hash(), block)
err = types.Receipts(receipts).DeriveFields(bc.chainConfig, block.Hash(), block.NumberU64(), block.Time(), block.BaseFee(), block.Transactions())
if err != nil {
log.Warn("Failed to derive receipt fields", "block", block.Hash(), "err", err)
}
bc.CacheReceipts(block.Hash(), receipts)

// Update the metrics touched during block commit
accountCommitTimer.Update(statedb.AccountCommits) // Account commits are complete, we can mark them
storageCommitTimer.Update(statedb.StorageCommits) // Storage commits are complete, we can mark them
Expand Down