From 8d565201f959cc7d5a60f28e4b4db95d0167bcea Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 31 Oct 2023 10:47:44 +0100 Subject: [PATCH] core: fix receipts when AddUncheckedReceipt is used --- core/chain_makers.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/core/chain_makers.go b/core/chain_makers.go index 2afa89fdc9..31c111b73e 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -372,14 +372,28 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse block, receipts := genblock(i, parent, triedb, statedb) // Post-process the receipts. + // Here we assign the final block hash and other info into the receipt. + // In order for DeriveFields to work, the transaction and receipt lists need to be + // of equal length. If AddUncheckedTx or AddUncheckedReceipt are used, there will be + // extra ones, so we just trim the lists here. + receiptsCount := len(receipts) + txs := block.Transactions() + if len(receipts) > len(txs) { + receipts = receipts[:len(txs)] + } else if len(receipts) < len(txs) { + txs = txs[:len(receipts)] + } var blobGasPrice *big.Int if block.ExcessBlobGas() != nil { blobGasPrice = eip4844.CalcBlobFee(*block.ExcessBlobGas()) } - if err := receipts.DeriveFields(config, block.Hash(), block.NumberU64(), block.Time(), block.BaseFee(), blobGasPrice, block.Transactions()); err != nil { + if err := receipts.DeriveFields(config, block.Hash(), block.NumberU64(), block.Time(), block.BaseFee(), blobGasPrice, txs); err != nil { panic(err) } + // Re-expand to ensure all receipts are returned. + receipts = receipts[:receiptsCount] + // Advance the chain. cm.add(block, receipts) parent = block