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

Commit c068eea

Browse files
committed
remove BlockWithExtData in favor of WithBlockExtras taking a recalc argument
1 parent 3922e9e commit c068eea

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
@@ -523,7 +523,7 @@ func ReadBlock(db ethdb.Reader, hash common.Hash, number uint64) *types.Block {
523523
return nil
524524
}
525525
block := types.NewBlockWithHeader(header).WithBody(body.Transactions, body.Uncles)
526-
block = types.BlockWithExtData(block, body.Version, body.ExtData)
526+
block = types.WithBlockExtras(block, body.Version, body.ExtData, false)
527527
return block
528528
}
529529

core/types/block_ext.go

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

86-
func BlockWithExtData(b *Block, version uint32, extdata *[]byte) *Block {
87-
BlockExtras(b).version = version
88-
setExtDataHelper(b, extdata, false)
89-
return b
90-
}
91-
92-
func setExtDataHelper(b *Block, data *[]byte, recalc bool) {
93-
if data == nil {
94-
setExtData(b, nil, recalc)
95-
return
96-
}
97-
setExtData(b, *data, recalc)
98-
}
99-
100-
func setExtData(b *Block, data []byte, recalc bool) {
101-
_data := make([]byte, len(data))
102-
extras := BlockExtras(b)
103-
extras.extdata = &_data
104-
copy(*extras.extdata, data)
105-
if recalc {
106-
header := b.Header()
107-
headerExtra := HeaderExtras(header)
108-
headerExtra.ExtDataHash = CalcExtDataHash(_data)
109-
b.SetHeader(header)
110-
}
111-
}
112-
11386
func BlockExtData(b *Block) []byte {
11487
extras := BlockExtras(b)
11588
if extras.extdata == nil {
@@ -140,7 +113,7 @@ func NewBlockWithExtData(
140113
header *Header, txs []*Transaction, uncles []*Header, receipts []*Receipt,
141114
hasher TrieHasher, extdata []byte, recalc bool,
142115
) *Block {
143-
b := ethtypes.NewBlock(header, txs, uncles, receipts, hasher)
116+
b := NewBlock(header, txs, uncles, receipts, hasher)
144117
const version = 0
145118
return WithBlockExtras(b, version, &extdata, recalc)
146119
}

core/types/libevm.go

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

3737
func WithBlockExtras(b *Block, version uint32, extdata *[]byte, recalc bool) *Block {
38-
BlockExtras(b).version = version
39-
setExtDataHelper(b, extdata, recalc)
38+
extras := BlockExtras(b)
39+
40+
extras.version = version
41+
42+
cpy := make([]byte, 0)
43+
if extdata != nil {
44+
cpy = make([]byte, len(*extdata))
45+
copy(cpy, *extdata)
46+
}
47+
48+
extras.extdata = &cpy
49+
if recalc {
50+
header := b.Header()
51+
headerExtra := HeaderExtras(header)
52+
headerExtra.ExtDataHash = CalcExtDataHash(cpy)
53+
b.SetHeader(header)
54+
}
55+
4056
return b
4157
}

0 commit comments

Comments
 (0)