Skip to content

Commit

Permalink
bugfix: combinePendingHeader works on a copy instead of modifying the…
Browse files Browse the repository at this point in the history
… pointer to the header
  • Loading branch information
gameofpointers authored and wizeguyy committed Jan 25, 2023
1 parent 9d65e73 commit 7424d42
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions core/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,21 +513,24 @@ func (sl *Slice) ConstructLocalBlock(header *types.Header) *types.Block {

// combinePendingHeader updates the pending header at the given index with the value from given header.
func (sl *Slice) combinePendingHeader(header *types.Header, slPendingHeader *types.Header, index int) *types.Header {
slPendingHeader.SetParentHash(header.ParentHash(index), index)
slPendingHeader.SetUncleHash(header.UncleHash(index), index)
slPendingHeader.SetNumber(header.Number(index), index)
slPendingHeader.SetExtra(header.Extra())
slPendingHeader.SetBaseFee(header.BaseFee(index), index)
slPendingHeader.SetGasLimit(header.GasLimit(index), index)
slPendingHeader.SetGasUsed(header.GasUsed(index), index)
slPendingHeader.SetTxHash(header.TxHash(index), index)
slPendingHeader.SetReceiptHash(header.ReceiptHash(index), index)
slPendingHeader.SetRoot(header.Root(index), index)
slPendingHeader.SetDifficulty(header.Difficulty(index), index)
slPendingHeader.SetCoinbase(header.Coinbase(index), index)
slPendingHeader.SetBloom(header.Bloom(index), index)

return slPendingHeader
// copying the slPendingHeader and updating the copy to remove any shared memory access issues
combinedPendingHeader := types.CopyHeader(slPendingHeader)

combinedPendingHeader.SetParentHash(header.ParentHash(index), index)
combinedPendingHeader.SetUncleHash(header.UncleHash(index), index)
combinedPendingHeader.SetNumber(header.Number(index), index)
combinedPendingHeader.SetExtra(header.Extra())
combinedPendingHeader.SetBaseFee(header.BaseFee(index), index)
combinedPendingHeader.SetGasLimit(header.GasLimit(index), index)
combinedPendingHeader.SetGasUsed(header.GasUsed(index), index)
combinedPendingHeader.SetTxHash(header.TxHash(index), index)
combinedPendingHeader.SetReceiptHash(header.ReceiptHash(index), index)
combinedPendingHeader.SetRoot(header.Root(index), index)
combinedPendingHeader.SetDifficulty(header.Difficulty(index), index)
combinedPendingHeader.SetCoinbase(header.Coinbase(index), index)
combinedPendingHeader.SetBloom(header.Bloom(index), index)

return combinedPendingHeader
}

// MakeDomClient creates the quaiclient for the given domurl
Expand Down

0 comments on commit 7424d42

Please sign in to comment.