Skip to content

Commit

Permalink
internal/ethapi: fix null effectiveGasPrice in GetTransactionReceipt (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
buddh0 authored Nov 14, 2023
1 parent 3fc9f75 commit 4be9481
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4be9481

Please sign in to comment.