Skip to content

Commit

Permalink
fix receipts issue
Browse files Browse the repository at this point in the history
  • Loading branch information
joelburget committed Feb 15, 2018
1 parent 85f1bc2 commit 7672c47
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 7672c47

Please sign in to comment.