Skip to content

Commit ec95ab4

Browse files
committed
all: implement eip 7928 block access lists
1 parent b9b4347 commit ec95ab4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+4899
-1271
lines changed

beacon/engine/gen_ed.go

Lines changed: 43 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

beacon/engine/types.go

Lines changed: 54 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package engine
1818

1919
import (
2020
"fmt"
21+
"github.com/ethereum/go-ethereum/core/types/bal"
2122
"math/big"
2223
"slices"
2324

@@ -82,24 +83,25 @@ type payloadAttributesMarshaling struct {
8283

8384
// ExecutableData is the data necessary to execute an EL payload.
8485
type ExecutableData struct {
85-
ParentHash common.Hash `json:"parentHash" gencodec:"required"`
86-
FeeRecipient common.Address `json:"feeRecipient" gencodec:"required"`
87-
StateRoot common.Hash `json:"stateRoot" gencodec:"required"`
88-
ReceiptsRoot common.Hash `json:"receiptsRoot" gencodec:"required"`
89-
LogsBloom []byte `json:"logsBloom" gencodec:"required"`
90-
Random common.Hash `json:"prevRandao" gencodec:"required"`
91-
Number uint64 `json:"blockNumber" gencodec:"required"`
92-
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
93-
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
94-
Timestamp uint64 `json:"timestamp" gencodec:"required"`
95-
ExtraData []byte `json:"extraData" gencodec:"required"`
96-
BaseFeePerGas *big.Int `json:"baseFeePerGas" gencodec:"required"`
97-
BlockHash common.Hash `json:"blockHash" gencodec:"required"`
98-
Transactions [][]byte `json:"transactions" gencodec:"required"`
99-
Withdrawals []*types.Withdrawal `json:"withdrawals"`
100-
BlobGasUsed *uint64 `json:"blobGasUsed"`
101-
ExcessBlobGas *uint64 `json:"excessBlobGas"`
102-
SlotNumber *uint64 `json:"slotNumber"`
86+
ParentHash common.Hash `json:"parentHash" gencodec:"required"`
87+
FeeRecipient common.Address `json:"feeRecipient" gencodec:"required"`
88+
StateRoot common.Hash `json:"stateRoot" gencodec:"required"`
89+
ReceiptsRoot common.Hash `json:"receiptsRoot" gencodec:"required"`
90+
LogsBloom []byte `json:"logsBloom" gencodec:"required"`
91+
Random common.Hash `json:"prevRandao" gencodec:"required"`
92+
Number uint64 `json:"blockNumber" gencodec:"required"`
93+
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
94+
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
95+
Timestamp uint64 `json:"timestamp" gencodec:"required"`
96+
ExtraData []byte `json:"extraData" gencodec:"required"`
97+
BaseFeePerGas *big.Int `json:"baseFeePerGas" gencodec:"required"`
98+
BlockHash common.Hash `json:"blockHash" gencodec:"required"`
99+
Transactions [][]byte `json:"transactions" gencodec:"required"`
100+
Withdrawals []*types.Withdrawal `json:"withdrawals"`
101+
BlobGasUsed *uint64 `json:"blobGasUsed"`
102+
ExcessBlobGas *uint64 `json:"excessBlobGas"`
103+
BlockAccessList *bal.BlockAccessList `json:"blockAccessList"`
104+
SlotNumber *uint64 `json:"slotNumber"`
103105
}
104106

105107
// JSON type overrides for executableData.
@@ -303,6 +305,8 @@ func ExecutableDataToBlockNoHash(data ExecutableData, versionedHashes []common.H
303305
requestsHash = &h
304306
}
305307

308+
body := types.Body{Transactions: txs, Uncles: nil, Withdrawals: data.Withdrawals}
309+
306310
header := &types.Header{
307311
ParentHash: data.ParentHash,
308312
UncleHash: types.EmptyUncleHash,
@@ -326,33 +330,41 @@ func ExecutableDataToBlockNoHash(data ExecutableData, versionedHashes []common.H
326330
RequestsHash: requestsHash,
327331
SlotNumber: data.SlotNumber,
328332
}
329-
return types.NewBlockWithHeader(header).
330-
WithBody(types.Body{Transactions: txs, Uncles: nil, Withdrawals: data.Withdrawals}),
331-
nil
333+
334+
if data.BlockAccessList != nil {
335+
balHash := data.BlockAccessList.Hash()
336+
header.BlockAccessListHash = &balHash
337+
block := types.NewBlockWithHeader(header).WithBody(body).WithAccessList(data.BlockAccessList)
338+
return block, nil
339+
}
340+
341+
return types.NewBlockWithHeader(header).WithBody(body), nil
342+
332343
}
333344

334345
// BlockToExecutableData constructs the ExecutableData structure by filling the
335346
// fields from the given block. It assumes the given block is post-merge block.
336347
func BlockToExecutableData(block *types.Block, fees *big.Int, sidecars []*types.BlobTxSidecar, requests [][]byte) *ExecutionPayloadEnvelope {
337348
data := &ExecutableData{
338-
BlockHash: block.Hash(),
339-
ParentHash: block.ParentHash(),
340-
FeeRecipient: block.Coinbase(),
341-
StateRoot: block.Root(),
342-
Number: block.NumberU64(),
343-
GasLimit: block.GasLimit(),
344-
GasUsed: block.GasUsed(),
345-
BaseFeePerGas: block.BaseFee(),
346-
Timestamp: block.Time(),
347-
ReceiptsRoot: block.ReceiptHash(),
348-
LogsBloom: block.Bloom().Bytes(),
349-
Transactions: encodeTransactions(block.Transactions()),
350-
Random: block.MixDigest(),
351-
ExtraData: block.Extra(),
352-
Withdrawals: block.Withdrawals(),
353-
BlobGasUsed: block.BlobGasUsed(),
354-
ExcessBlobGas: block.ExcessBlobGas(),
355-
SlotNumber: block.SlotNumber(),
349+
BlockHash: block.Hash(),
350+
ParentHash: block.ParentHash(),
351+
FeeRecipient: block.Coinbase(),
352+
StateRoot: block.Root(),
353+
Number: block.NumberU64(),
354+
GasLimit: block.GasLimit(),
355+
GasUsed: block.GasUsed(),
356+
BaseFeePerGas: block.BaseFee(),
357+
Timestamp: block.Time(),
358+
ReceiptsRoot: block.ReceiptHash(),
359+
LogsBloom: block.Bloom().Bytes(),
360+
Transactions: encodeTransactions(block.Transactions()),
361+
Random: block.MixDigest(),
362+
ExtraData: block.Extra(),
363+
Withdrawals: block.Withdrawals(),
364+
BlobGasUsed: block.BlobGasUsed(),
365+
ExcessBlobGas: block.ExcessBlobGas(),
366+
BlockAccessList: block.AccessList(),
367+
SlotNumber: block.SlotNumber(),
356368
}
357369

358370
// Add blobs.
@@ -391,8 +403,9 @@ func BlockToExecutableData(block *types.Block, fees *big.Int, sidecars []*types.
391403

392404
// ExecutionPayloadBody is used in the response to GetPayloadBodiesByHash and GetPayloadBodiesByRange
393405
type ExecutionPayloadBody struct {
394-
TransactionData []hexutil.Bytes `json:"transactions"`
395-
Withdrawals []*types.Withdrawal `json:"withdrawals"`
406+
TransactionData []hexutil.Bytes `json:"transactions"`
407+
Withdrawals []*types.Withdrawal `json:"withdrawals"`
408+
AccessList *bal.BlockAccessList `json:"blockAccessList"`
396409
}
397410

398411
// Client identifiers to support ClientVersionV1.

build/checksums.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
# https://github.com/ethereum/execution-spec-tests/releases/download/v5.1.0
66
a3192784375acec7eaec492799d5c5d0c47a2909a3cc40178898e4ecd20cc416 fixtures_develop.tar.gz
77

8+
# version:spec-tests-bal v5.0.0
9+
# https://github.com/ethereum/execution-spec-tests/releases
10+
# https://github.com/ethereum/execution-spec-tests/releases/download/bal%40v5.1.0
11+
c8a7406e6337c1dfd2540f0477afb8abe965c5ed2a63382d7a483eb818f79939 fixtures_bal.tar.gz
12+
813
# version:golang 1.25.7
914
# https://go.dev/dl/
1015
178f2832820274b43e177d32f06a3ebb0129e427dd20a5e4c88df2c1763cf10a go1.25.7.src.tar.gz

build/ci.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ var (
172172

173173
// This is where the tests should be unpacked.
174174
executionSpecTestsDir = "tests/spec-tests"
175+
176+
// This is where the bal-specific release of the tests should be unpacked.
177+
executionSpecTestsBALDir = "tests/spec-tests-bal"
175178
)
176179

177180
var GOBIN, _ = filepath.Abs(filepath.Join("build", "bin"))
@@ -380,6 +383,7 @@ func doTest(cmdline []string) {
380383
// Get test fixtures.
381384
if !*short {
382385
downloadSpecTestFixtures(csdb, *cachedir)
386+
downloadBALSpecTestFixtures(csdb, *cachedir)
383387
}
384388

385389
// Configure the toolchain.
@@ -445,6 +449,19 @@ func downloadSpecTestFixtures(csdb *download.ChecksumDB, cachedir string) string
445449
return filepath.Join(cachedir, base)
446450
}
447451

452+
func downloadBALSpecTestFixtures(csdb *download.ChecksumDB, cachedir string) string {
453+
ext := ".tar.gz"
454+
base := "fixtures_bal"
455+
archivePath := filepath.Join(cachedir, base+ext)
456+
if err := csdb.DownloadFileFromKnownURL(archivePath); err != nil {
457+
log.Fatal(err)
458+
}
459+
if err := build.ExtractArchive(archivePath, executionSpecTestsBALDir); err != nil {
460+
log.Fatal(err)
461+
}
462+
return filepath.Join(cachedir, base)
463+
}
464+
448465
// doCheckGenerate ensures that re-generating generated files does not cause
449466
// any mutations in the source file tree.
450467
func doCheckGenerate() {

cmd/evm/blockrunner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func runBlockTest(ctx *cli.Context, fname string) ([]testResult, error) {
117117
test := tests[name]
118118
result := &testResult{Name: name, Pass: true}
119119
var finalRoot *common.Hash
120-
if err := test.Run(false, rawdb.PathScheme, ctx.Bool(WitnessCrossCheckFlag.Name), tracer, func(res error, chain *core.BlockChain) {
120+
if err := test.Run(false, rawdb.PathScheme, ctx.Bool(WitnessCrossCheckFlag.Name), false, tracer, func(res error, chain *core.BlockChain) {
121121
if ctx.Bool(DumpFlag.Name) {
122122
if s, _ := chain.State(); s != nil {
123123
result.State = dump(s)

cmd/geth/config.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,21 @@ func makeFullNode(ctx *cli.Context) *node.Node {
240240
cfg.Eth.OverrideVerkle = &v
241241
}
242242

243-
// Start metrics export if enabled.
243+
if ctx.IsSet(utils.BlockAccessListExecutionModeFlag.Name) {
244+
val := ctx.String(utils.BlockAccessListExecutionModeFlag.Name)
245+
switch val {
246+
case utils.BalExecutionModeFull:
247+
cfg.Eth.BALExecutionMode = 0
248+
case utils.BalExecutionModeNoBatchIO:
249+
cfg.Eth.BALExecutionMode = 1
250+
case utils.BalExecutionModeSequential:
251+
cfg.Eth.BALExecutionMode = 2
252+
default:
253+
utils.Fatalf("invalid option for --bal.executionmode: %s. acceptable values are full|nobatchio|sequential", val)
254+
}
255+
}
256+
257+
// Start metrics export if enabled
244258
utils.SetupMetrics(&cfg.Metrics)
245259

246260
// Setup OpenTelemetry reporting if enabled.

cmd/geth/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ func init() {
273273
consoleFlags,
274274
debug.Flags,
275275
metricsFlags,
276+
[]cli.Flag{utils.BlockAccessListExecutionModeFlag},
276277
)
277278
flags.AutoEnvVars(app.Flags, "GETH")
278279

cmd/utils/flags.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,31 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.
11081108
Name: "era.format",
11091109
Usage: "Archive format: 'era1' or 'erae'",
11101110
}
1111+
1112+
// Block Access List flags
1113+
ExperimentalBALFlag = &cli.BoolFlag{
1114+
Name: "experimental.bal",
1115+
Usage: "Enable generation of EIP-7928 block access lists when importing post-Cancun blocks which lack them. When this flag is specified, importing blocks containing access lists triggers validation of their correctness and execution based off them. The header block access list field is not set with blocks created when this flag is specified, nor is it validated when importing blocks that contain access lists. This is used for development purposes only. Do not enable it otherwise.",
1116+
Category: flags.MiscCategory,
1117+
}
1118+
// block access list flags
1119+
1120+
BlockAccessListExecutionModeFlag = &cli.StringFlag{
1121+
Name: "bal.executionmode",
1122+
Usage: `
1123+
block access list execution type. possible inputs are:
1124+
- sequential: no performance acceleration
1125+
- full: parallel transaction execution, state root calculation, async warming of access list reads
1126+
- nobatchio: same as 'full', but without async warming of access list reads`,
1127+
Value: BalExecutionModeFull,
1128+
Category: flags.MiscCategory,
1129+
}
1130+
)
1131+
1132+
const (
1133+
BalExecutionModeFull = "full"
1134+
BalExecutionModeNoBatchIO = "nobatchio"
1135+
BalExecutionModeSequential = "sequential"
11111136
)
11121137

11131138
var (

0 commit comments

Comments
 (0)