aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKyuntae Ethan Kim <ethan.kyuntae.kim@gmail.com>2018-03-07 18:05:14 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-03-07 18:05:14 +0800
commit63687f04e441c97cbb39d6b0ebea346b154d2e73 (patch)
treeb834a42f5ef84de9d3de307b980f83537befdf3b
parentd43ffdbf6a406839bbf54bdf76f5574345abdd57 (diff)
downloaddexon-63687f04e441c97cbb39d6b0ebea346b154d2e73.tar
dexon-63687f04e441c97cbb39d6b0ebea346b154d2e73.tar.gz
dexon-63687f04e441c97cbb39d6b0ebea346b154d2e73.tar.bz2
dexon-63687f04e441c97cbb39d6b0ebea346b154d2e73.tar.lz
dexon-63687f04e441c97cbb39d6b0ebea346b154d2e73.tar.xz
dexon-63687f04e441c97cbb39d6b0ebea346b154d2e73.tar.zst
dexon-63687f04e441c97cbb39d6b0ebea346b154d2e73.zip
core: check transaction/receipt count match when reconstructing blocks (#16272)
-rw-r--r--core/blockchain.go10
-rw-r--r--light/odr_util.go4
2 files changed, 11 insertions, 3 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index 6006e6674..b33eb85a4 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -723,10 +723,13 @@ func (bc *BlockChain) Rollback(chain []common.Hash) {
}
// SetReceiptsData computes all the non-consensus fields of the receipts
-func SetReceiptsData(config *params.ChainConfig, block *types.Block, receipts types.Receipts) {
+func SetReceiptsData(config *params.ChainConfig, block *types.Block, receipts types.Receipts) error {
signer := types.MakeSigner(config, block.Number())
transactions, logIndex := block.Transactions(), uint(0)
+ if len(transactions) != len(receipts) {
+ return errors.New("transaction and receipt count mismatch")
+ }
for j := 0; j < len(receipts); j++ {
// The transaction hash can be retrieved from the transaction itself
@@ -754,6 +757,7 @@ func SetReceiptsData(config *params.ChainConfig, block *types.Block, receipts ty
logIndex++
}
}
+ return nil
}
// InsertReceiptChain attempts to complete an already existing header chain with
@@ -794,7 +798,9 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
continue
}
// Compute all the non-consensus fields of the receipts
- SetReceiptsData(bc.chainConfig, block, receipts)
+ if err := SetReceiptsData(bc.chainConfig, block, receipts); err != nil {
+ return i, fmt.Errorf("failed to set receipts data: %v", err)
+ }
// Write all the data out into the database
if err := WriteBody(batch, block.Hash(), block.NumberU64(), block.Body()); err != nil {
return i, fmt.Errorf("failed to write block body: %v", err)
diff --git a/light/odr_util.go b/light/odr_util.go
index 97ba440ac..d56330e36 100644
--- a/light/odr_util.go
+++ b/light/odr_util.go
@@ -144,7 +144,9 @@ func GetBlockReceipts(ctx context.Context, odr OdrBackend, hash common.Hash, num
genesis := core.GetCanonicalHash(odr.Database(), 0)
config, _ := core.GetChainConfig(odr.Database(), genesis)
- core.SetReceiptsData(config, block, receipts)
+ if err := core.SetReceiptsData(config, block, receipts); err != nil {
+ return nil, err
+ }
core.WriteBlockReceipts(odr.Database(), hash, number, receipts)
}
return receipts, nil