miner: fix deep copy in copyReceipts, close XFN-49 (#1620)

This commit is contained in:
Daniel Liu 2025-11-03 18:44:27 +08:00 committed by GitHub
parent 5732c4b11b
commit 3cab0036ed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -530,9 +530,35 @@ func (w *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
for i, receipt := range receipts {
cpyReceipt := *receipt
if len(receipt.PostState) > 0 {
cpyReceipt.PostState = make([]byte, len(receipt.PostState))
copy(cpyReceipt.PostState, receipt.PostState)
}
if cpyReceipt.EffectiveGasPrice = new(big.Int); receipt.EffectiveGasPrice != nil {
cpyReceipt.EffectiveGasPrice.Set(receipt.EffectiveGasPrice)
}
if cpyReceipt.BlockNumber = new(big.Int); receipt.BlockNumber != nil {
cpyReceipt.BlockNumber.Set(receipt.BlockNumber)
}
// deep copy logs
if len(receipt.Logs) > 0 {
cpyReceipt.Logs = make([]*types.Log, len(receipt.Logs))
for i, log := range receipt.Logs {
cpyLog := *log
if len(log.Topics) > 0 {
cpyLog.Topics = make([]common.Hash, len(log.Topics))
copy(cpyLog.Topics, log.Topics)
}
if len(log.Data) > 0 {
cpyLog.Data = make([]byte, len(log.Data))
copy(cpyLog.Data, log.Data)
}
cpyReceipt.Logs[i] = &cpyLog
}
}
result[i] = &cpyReceipt
}
return result
}