diff --git a/core/blockchain.go b/core/blockchain.go index 454c9768a6..0d6974c1dc 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -552,7 +552,7 @@ func (bc *BlockChain) GetVMConfig() *vm.Config { return &bc.vmConfig } -func (bc *BlockChain) cacheReceipts(hash common.Hash, receipts types.Receipts) { +func (bc *BlockChain) cacheReceipts(hash common.Hash, receipts types.Receipts, block *types.Block) { // TODO, This is a hot fix for the block hash of logs is `0x0000000000000000000000000000000000000000000000000000000000000000` for system tx // Please check details in https://github.com/bnb-chain/bsc/issues/443 // This is a temporary fix, the official fix should be a hard fork. @@ -563,6 +563,16 @@ func (bc *BlockChain) cacheReceipts(hash common.Hash, receipts types.Receipts) { receipts[i].Logs[j].BlockHash = hash } } + + txs := block.Transactions() + if len(txs) != len(receipts) { + log.Warn("transaction and receipt count mismatch") + return + } + for i, receipt := range receipts { + receipt.EffectiveGasPrice = txs[i].EffectiveGasTipValue(block.BaseFee()) // basefee is supposed to be nil or zero + } + bc.receiptsCache.Add(hash, receipts) } @@ -2049,7 +2059,6 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) vtime := time.Since(vstart) proctime := time.Since(start) // processing + validation - bc.cacheReceipts(block.Hash(), receipts) bc.cacheBlock(block.Hash(), block) // Update the metrics touched during block processing and validation @@ -2082,6 +2091,9 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) if err != nil { return it.index, err } + + bc.cacheReceipts(block.Hash(), receipts, block) + // 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