From 7672c47b7020677a23890e5b063d6a98e905709f Mon Sep 17 00:00:00 2001 From: Joel Burget Date: Thu, 8 Feb 2018 10:55:52 -0500 Subject: [PATCH] fix receipts issue --- core/blockchain.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/core/blockchain.go b/core/blockchain.go index 66273bc67b..9487999de4 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -887,6 +887,27 @@ func (bc *BlockChain) InsertChain(chain types.Blocks) (int, error) { return n, err } +// Given a slice of public receipts and an overlapping (smaller) slice of +// private receipts, return a new slice where the default for each location is +// the public receipt but we take the private receipt in each place we have +// one. +func mergeReceipts(pub, priv types.Receipts) types.Receipts { + m := make(map[common.Hash]*types.Receipt) + for _, receipt := range pub { + m[receipt.TxHash] = receipt + } + for _, receipt := range priv { + m[receipt.TxHash] = receipt + } + + ret := make(types.Receipts, 0, len(pub)) + for _, pubReceipt := range pub { + ret = append(ret, m[pubReceipt.TxHash]) + } + + return ret +} + // insertChain will execute the actual chain insertion and event aggregation. The // only reason this method exists as a separate one is to make locking cleaner // with deferred statements. @@ -1025,7 +1046,8 @@ func (bc *BlockChain) insertChain(chain types.Blocks) (int, []interface{}, []*ty } // /Quorum - allReceipts := append(receipts, privateReceipts...) + allReceipts := mergeReceipts(receipts, privateReceipts) + // Write the block to the chain and get the status. status, err := bc.WriteBlockAndState(block, allReceipts, state) if err != nil {