Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Commit 5d97c3b

Browse files
committed
remove BlockWithExtData in favor of WithBlockExtras taking a recalc argument
1 parent 76eca08 commit 5d97c3b

File tree

3 files changed

+20
-31
lines changed

3 files changed

+20
-31
lines changed

core/rawdb/accessors_chain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ func ReadBlock(db ethdb.Reader, hash common.Hash, number uint64) *types.Block {
524524
}
525525
block := types.NewBlockWithHeader(header).WithBody(body.Transactions, body.Uncles)
526526
bodyExtra := types.GetBodyExtra(body)
527-
block = types.BlockWithExtData(block, bodyExtra.Version, bodyExtra.ExtData)
527+
block = types.WithBlockExtras(block, bodyExtra.Version, bodyExtra.ExtData, false)
528528
return block
529529
}
530530

core/types/block_ext.go

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -92,33 +92,6 @@ func (b *blockSerializable) updateToExtras(extras *BlockExtra) {
9292
extras.extdata = b.ExtData
9393
}
9494

95-
func BlockWithExtData(b *Block, version uint32, extdata *[]byte) *Block {
96-
BlockExtras(b).version = version
97-
setExtDataHelper(b, extdata, false)
98-
return b
99-
}
100-
101-
func setExtDataHelper(b *Block, data *[]byte, recalc bool) {
102-
if data == nil {
103-
setExtData(b, nil, recalc)
104-
return
105-
}
106-
setExtData(b, *data, recalc)
107-
}
108-
109-
func setExtData(b *Block, data []byte, recalc bool) {
110-
_data := make([]byte, len(data))
111-
extras := BlockExtras(b)
112-
extras.extdata = &_data
113-
copy(*extras.extdata, data)
114-
if recalc {
115-
header := b.Header()
116-
headerExtra := HeaderExtras(header)
117-
headerExtra.ExtDataHash = CalcExtDataHash(_data)
118-
b.SetHeader(header)
119-
}
120-
}
121-
12295
func BlockExtData(b *Block) []byte {
12396
extras := BlockExtras(b)
12497
if extras.extdata == nil {
@@ -155,7 +128,7 @@ func NewBlockWithExtData(
155128
header *Header, txs []*Transaction, uncles []*Header, receipts []*Receipt,
156129
hasher TrieHasher, extdata []byte, recalc bool,
157130
) *Block {
158-
b := ethtypes.NewBlock(header, txs, uncles, receipts, hasher)
131+
b := NewBlock(header, txs, uncles, receipts, hasher)
159132
const version = 0
160133
return WithBlockExtras(b, version, &extdata, recalc)
161134
}

core/types/libevm.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,23 @@ func BlockExtras(b *Block) *BlockExtra {
4545
}
4646

4747
func WithBlockExtras(b *Block, version uint32, extdata *[]byte, recalc bool) *Block {
48-
BlockExtras(b).version = version
49-
setExtDataHelper(b, extdata, recalc)
48+
extras := BlockExtras(b)
49+
50+
extras.version = version
51+
52+
cpy := make([]byte, 0)
53+
if extdata != nil {
54+
cpy = make([]byte, len(*extdata))
55+
copy(cpy, *extdata)
56+
}
57+
58+
extras.extdata = &cpy
59+
if recalc {
60+
header := b.Header()
61+
headerExtra := HeaderExtras(header)
62+
headerExtra.ExtDataHash = CalcExtDataHash(cpy)
63+
b.SetHeader(header)
64+
}
65+
5066
return b
5167
}

0 commit comments

Comments
 (0)