Skip to content

Commit

Permalink
remove BlockWithExtData in favor of WithBlockExtras taking a reca…
Browse files Browse the repository at this point in the history
…lc argument
  • Loading branch information
qdm12 committed Jan 21, 2025
1 parent 3922e9e commit c068eea
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 31 deletions.
2 changes: 1 addition & 1 deletion core/rawdb/accessors_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ func ReadBlock(db ethdb.Reader, hash common.Hash, number uint64) *types.Block {
return nil
}
block := types.NewBlockWithHeader(header).WithBody(body.Transactions, body.Uncles)
block = types.BlockWithExtData(block, body.Version, body.ExtData)
block = types.WithBlockExtras(block, body.Version, body.ExtData, false)
return block
}

Expand Down
29 changes: 1 addition & 28 deletions core/types/block_ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,33 +83,6 @@ func (b *blockSerializable) updateToExtras(extras *BlockExtra) {
extras.extdata = b.ExtData
}

func BlockWithExtData(b *Block, version uint32, extdata *[]byte) *Block {
BlockExtras(b).version = version
setExtDataHelper(b, extdata, false)
return b
}

func setExtDataHelper(b *Block, data *[]byte, recalc bool) {
if data == nil {
setExtData(b, nil, recalc)
return
}
setExtData(b, *data, recalc)
}

func setExtData(b *Block, data []byte, recalc bool) {
_data := make([]byte, len(data))
extras := BlockExtras(b)
extras.extdata = &_data
copy(*extras.extdata, data)
if recalc {
header := b.Header()
headerExtra := HeaderExtras(header)
headerExtra.ExtDataHash = CalcExtDataHash(_data)
b.SetHeader(header)
}
}

func BlockExtData(b *Block) []byte {
extras := BlockExtras(b)
if extras.extdata == nil {
Expand Down Expand Up @@ -140,7 +113,7 @@ func NewBlockWithExtData(
header *Header, txs []*Transaction, uncles []*Header, receipts []*Receipt,
hasher TrieHasher, extdata []byte, recalc bool,
) *Block {
b := ethtypes.NewBlock(header, txs, uncles, receipts, hasher)
b := NewBlock(header, txs, uncles, receipts, hasher)
const version = 0
return WithBlockExtras(b, version, &extdata, recalc)
}
Expand Down
20 changes: 18 additions & 2 deletions core/types/libevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,23 @@ func BlockExtras(b *Block) *BlockExtra {
}

func WithBlockExtras(b *Block, version uint32, extdata *[]byte, recalc bool) *Block {
BlockExtras(b).version = version
setExtDataHelper(b, extdata, recalc)
extras := BlockExtras(b)

extras.version = version

cpy := make([]byte, 0)
if extdata != nil {
cpy = make([]byte, len(*extdata))
copy(cpy, *extdata)
}

extras.extdata = &cpy
if recalc {
header := b.Header()
headerExtra := HeaderExtras(header)
headerExtra.ExtDataHash = CalcExtDataHash(cpy)
b.SetHeader(header)
}

return b
}

0 comments on commit c068eea

Please sign in to comment.