@@ -723,10 +723,13 @@ func (bc *BlockChain) Rollback(chain []common.Hash) {
723723}
724724
725725// SetReceiptsData computes all the non-consensus fields of the receipts
726- func SetReceiptsData (config * params.ChainConfig , block * types.Block , receipts types.Receipts ) {
726+ func SetReceiptsData (config * params.ChainConfig , block * types.Block , receipts types.Receipts ) error {
727727 signer := types .MakeSigner (config , block .Number ())
728728
729729 transactions , logIndex := block .Transactions (), uint (0 )
730+ if len (transactions ) != len (receipts ) {
731+ return errors .New ("transaction and receipt count mismatch" )
732+ }
730733
731734 for j := 0 ; j < len (receipts ); j ++ {
732735 // The transaction hash can be retrieved from the transaction itself
@@ -754,6 +757,7 @@ func SetReceiptsData(config *params.ChainConfig, block *types.Block, receipts ty
754757 logIndex ++
755758 }
756759 }
760+ return nil
757761}
758762
759763// InsertReceiptChain attempts to complete an already existing header chain with
@@ -794,7 +798,9 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
794798 continue
795799 }
796800 // Compute all the non-consensus fields of the receipts
797- SetReceiptsData (bc .chainConfig , block , receipts )
801+ if err := SetReceiptsData (bc .chainConfig , block , receipts ); err != nil {
802+ return i , fmt .Errorf ("failed to set receipts data: %v" , err )
803+ }
798804 // Write all the data out into the database
799805 if err := WriteBody (batch , block .Hash (), block .NumberU64 (), block .Body ()); err != nil {
800806 return i , fmt .Errorf ("failed to write block body: %v" , err )
0 commit comments