diff --git a/miner/worker.go b/miner/worker.go index 635e931b9f13..7ceaf58fa705 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -128,7 +128,7 @@ type worker struct { coinbase common.Address extra []byte - snapshotMu sync.RWMutex // The lock used to protect the block snapshot and state snapshot + snapshotMu sync.RWMutex // The lock used to protect the snapshots below snapshotBlock *types.Block snapshotReceipts types.Receipts snapshotState *state.StateDB @@ -475,6 +475,16 @@ func (self *worker) push(work *Work) { } } +// copyReceipts makes a deep copy of the given receipts. +func copyReceipts(receipts []*types.Receipt) []*types.Receipt { + result := make([]*types.Receipt, len(receipts)) + for i, l := range receipts { + cpy := *l + result[i] = &cpy + } + return result +} + // makeCurrent creates a new environment for the current cycle. func (self *worker) makeCurrent(parent *types.Block, header *types.Header) error { // Retrieve the parent state to execute on top and start a prefetcher for @@ -534,7 +544,7 @@ func (w *worker) updateSnapshot() { nil, w.current.receipts, ) - w.snapshotReceipts = w.current.receipts + w.snapshotReceipts = copyReceipts(w.current.receipts) w.snapshotState = w.current.state.Copy() }