aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2020-09-18 13:11:39 -0400
committerDeterminant <[email protected]>2020-09-18 13:11:39 -0400
commit7d8c85cf8895b0f998d8eafb02f99d5b689fcd59 (patch)
tree1a7f65fcd72e77092525ab01625b8b9d365e3e40 /core
parentaa4852662bcb45607a82ed115ac57d72a16b304b (diff)
parent3ea6a7940e40677b629270dfc7a1466bca295bd3 (diff)
Merge commit '3ea6a79' into dev
Diffstat (limited to 'core')
-rw-r--r--core/types/block.go26
1 files changed, 15 insertions, 11 deletions
diff --git a/core/types/block.go b/core/types/block.go
index 0a93601..8e23488 100644
--- a/core/types/block.go
+++ b/core/types/block.go
@@ -235,7 +235,7 @@ type storageblock struct {
// The values of TxHash, UncleHash, ReceiptHash and Bloom in header
// are ignored and set to values derived from the given txs, uncles
// and receipts.
-func NewBlock(header *Header, txs []*Transaction, uncles []*Header, receipts []*Receipt, hasher Hasher, extdata *[]byte) *Block {
+func NewBlock(header *Header, txs []*Transaction, uncles []*Header, receipts []*Receipt, hasher Hasher, extdata []byte) *Block {
b := &Block{header: CopyHeader(header), td: new(big.Int)}
// TODO: panic if len(txs) != len(receipts)
@@ -265,9 +265,9 @@ func NewBlock(header *Header, txs []*Transaction, uncles []*Header, receipts []*
}
if extdata != nil {
- data := make([]byte, len(*extdata))
- b.extdata = &data
- copy(*b.extdata, *extdata)
+ _data := make([]byte, len(extdata))
+ b.extdata = &_data
+ copy(*b.extdata, extdata)
}
return b
@@ -324,7 +324,13 @@ func (b *Block) DecodeRLP(s *rlp.Stream) error {
}
func (b *Block) SetExtraData(data []byte) {
- b.extdata = &data
+ if data != nil {
+ _data := make([]byte, len(data))
+ b.extdata = &_data
+ copy(*b.extdata, data)
+ } else {
+ b.extdata = nil
+ }
b.header.ExtDataHash = rlpHash(data)
b.hash = atomic.Value{}
}
@@ -467,22 +473,20 @@ func (b *Block) WithSeal(header *Header) *Block {
// WithBody returns a new block with the given transaction and uncle contents.
func (b *Block) WithBody(transactions []*Transaction, uncles []*Header, version uint32, extdata *[]byte) *Block {
- var data *[]byte
+ var extdataCopied *[]byte
if extdata != nil {
_data := make([]byte, len(*extdata))
- data = &_data
+ extdataCopied = &_data
+ copy(*extdataCopied, *extdata)
}
block := &Block{
header: CopyHeader(b.header),
transactions: make([]*Transaction, len(transactions)),
uncles: make([]*Header, len(uncles)),
- extdata: data,
+ extdata: extdataCopied,
version: version,
}
copy(block.transactions, transactions)
- if data != nil {
- copy(*block.extdata, *extdata)
- }
for i := range uncles {
block.uncles[i] = CopyHeader(uncles[i])
}