Skip to content

Commit b117d9a

Browse files
committed
Even closer to geth, modifying WithBody to copy the body withdrawals
1 parent 9f1862b commit b117d9a

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed

beacon/engine/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func ExecutableDataToBlock(params ExecutableData, versionedHashes []common.Hash,
255255
ParentBeaconRoot: beaconRoot,
256256
}
257257
block := types.NewBlockWithHeader(header).
258-
WithBody(types.Body{Transactions: txs, Uncles: nil}).WithWithdrawals(params.Withdrawals)
258+
WithBody(types.Body{Transactions: txs, Uncles: nil, Withdrawals: params.Withdrawals})
259259
if block.Hash() != params.BlockHash {
260260
return nil, fmt.Errorf("blockhash mismatch, want %x, got %x", params.BlockHash, block.Hash())
261261
}

cmd/evm/internal/t8ntool/block.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func (i *bbInput) ToBlock() *types.Block {
160160
if i.Header.Difficulty != nil {
161161
header.Difficulty = i.Header.Difficulty
162162
}
163-
return types.NewBlockWithHeader(header).WithBody(types.Body{Transactions: i.Txs, Uncles: i.Ommers}).WithWithdrawals(i.Withdrawals)
163+
return types.NewBlockWithHeader(header).WithBody(types.Body{Transactions: i.Txs, Uncles: i.Ommers, Withdrawals: i.Withdrawals})
164164
}
165165

166166
// SealBlock seals the given block using the configured engine.

core/rawdb/accessors_chain.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ func ReadBlock(db ethdb.Reader, hash common.Hash, number uint64) *types.Block {
753753
if body == nil {
754754
return nil
755755
}
756-
return types.NewBlockWithHeader(header).WithBody(*body).WithWithdrawals(body.Withdrawals)
756+
return types.NewBlockWithHeader(header).WithBody(*body)
757757
}
758758

759759
// WriteBlock serializes a block into the database, header and body separately.
@@ -846,7 +846,6 @@ func ReadBadBlock(db ethdb.Reader, hash common.Hash) *types.Block {
846846
block := types.NewBlockWithHeader(bad.Header)
847847
if bad.Body != nil {
848848
block = block.WithBody(*bad.Body)
849-
block = block.WithWithdrawals(bad.Body.Withdrawals)
850849
}
851850
return block
852851
}
@@ -870,7 +869,6 @@ func ReadAllBadBlocks(db ethdb.Reader) []*types.Block {
870869
block := types.NewBlockWithHeader(bad.Header)
871870
if bad.Body != nil {
872871
block = block.WithBody(*bad.Body)
873-
block = block.WithWithdrawals(bad.Body.Withdrawals)
874872
}
875873
blocks = append(blocks, block)
876874
}

core/types/block.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"io"
2424
"math/big"
2525
"reflect"
26+
"slices"
2627
"sync/atomic"
2728
"time"
2829

@@ -465,7 +466,7 @@ func (b *Block) WithBody(body Body) *Block {
465466
header: b.header,
466467
transactions: make([]*Transaction, len(body.Transactions)),
467468
uncles: make([]*Header, len(body.Uncles)),
468-
withdrawals: b.withdrawals,
469+
withdrawals: slices.Clone(body.Withdrawals),
469470
}
470471
copy(block.transactions, body.Transactions)
471472
for i := range body.Uncles {

eth/downloader/downloader.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ func (d *Downloader) importBlockResults(results []*fetchResult) error {
15001500
)
15011501
blocks := make([]*types.Block, len(results))
15021502
for i, result := range results {
1503-
blocks[i] = types.NewBlockWithHeader(result.Header).WithBody(result.body()).WithWithdrawals(result.Withdrawals)
1503+
blocks[i] = types.NewBlockWithHeader(result.Header).WithBody(result.body())
15041504
}
15051505
// Downloaded blocks are always regarded as trusted after the
15061506
// transition. Because the downloaded chain is guided by the
@@ -1718,7 +1718,7 @@ func (d *Downloader) commitSnapSyncData(results []*fetchResult, stateSync *state
17181718
blocks := make([]*types.Block, len(results))
17191719
receipts := make([]types.Receipts, len(results))
17201720
for i, result := range results {
1721-
blocks[i] = types.NewBlockWithHeader(result.Header).WithBody(result.body()).WithWithdrawals(result.Withdrawals)
1721+
blocks[i] = types.NewBlockWithHeader(result.Header).WithBody(result.body())
17221722
receipts[i] = result.Receipts
17231723
}
17241724
if index, err := d.blockchain.InsertReceiptChain(blocks, receipts, d.ancientLimit); err != nil {
@@ -1729,7 +1729,7 @@ func (d *Downloader) commitSnapSyncData(results []*fetchResult, stateSync *state
17291729
}
17301730

17311731
func (d *Downloader) commitPivotBlock(result *fetchResult) error {
1732-
block := types.NewBlockWithHeader(result.Header).WithBody(result.body()).WithWithdrawals(result.Withdrawals)
1732+
block := types.NewBlockWithHeader(result.Header).WithBody(result.body())
17331733
log.Debug("Committing snap sync pivot as new head", "number", block.Number(), "hash", block.Hash())
17341734

17351735
// Commit the pivot block as the new head, will require full sync from here on

ethclient/ethclient.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ func (ec *Client) getBlock(ctx context.Context, method string, args ...interface
195195
types.Body{
196196
Transactions: txs,
197197
Uncles: uncles,
198-
}).WithWithdrawals(body.Withdrawals), nil
198+
Withdrawals: body.Withdrawals,
199+
}), nil
199200
}
200201

201202
// HeaderByHash returns the block header with the given hash.

0 commit comments

Comments
 (0)