Skip to content

Commit 8fbb795

Browse files
authored
implement EIP-7872 (#3902)
* implement EIP-7872 * Apply suggestion from @tersec * Apply suggestion from @tersec
1 parent 8a4d9ee commit 8fbb795

File tree

6 files changed

+37
-21
lines changed

6 files changed

+37
-21
lines changed

config.nims

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Nimbus
2-
# Copyright (c) 2018-2025 Status Research & Development GmbH
2+
# Copyright (c) 2018-2026 Status Research & Development GmbH
33
# Licensed under either of
44
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
55
# http://www.apache.org/licenses/LICENSE-2.0)
@@ -90,10 +90,6 @@ if defined(disableMarchNative):
9090
else:
9191
switch("passC", "-mssse3")
9292
switch("passL", "-mssse3")
93-
elif defined(macosx) and defined(arm64):
94-
# Apple's Clang can't handle "-march=native" on M1: https://github.com/status-im/nimbus-eth2/issues/2758
95-
switch("passC", "-mcpu=apple-m1")
96-
switch("passL", "-mcpu=apple-m1")
9793
elif defined(riscv64):
9894
# riscv64 needs specification of ISA with extensions. 'gc' is widely supported
9995
# and seems to be the minimum extensions needed to build.
@@ -103,7 +99,8 @@ elif defined(linux) and defined(arm64):
10399
# clang can't handle "-march=native"
104100
switch("passC", "-march=armv8-a")
105101
switch("passL", "-march=armv8-a")
106-
else:
102+
elif not(defined(macos) and defined(arm64)):
103+
# Apple's Clang can't handle "-march=native" on M1: https://github.com/status-im/nimbus-eth2/issues/2758
107104
switch("passC", "-march=native")
108105
switch("passL", "-march=native")
109106
if defined(i386) or defined(amd64):

execution_chain/conf.nim

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# This file may not be copied, modified, or distributed except according to
77
# those terms.
88

9-
{.push raises: [].}
9+
{.push raises: [], gcsafe.}
1010

1111
import
1212
std/[options, strutils, os, uri, net],
@@ -461,6 +461,11 @@ type
461461
defaultValueDesc: "*"
462462
name: "allowed-origins" .}: seq[string]
463463

464+
# https://eips.ethereum.org/EIPS/eip-7872
465+
maxBlobs* {.
466+
desc: "EIP-7872 maximum blobs used when building a local payload"
467+
name: "max-blobs" .}: Option[uint8]
468+
464469
# https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/authentication.md#key-distribution
465470
jwtSecret* {.
466471
desc: "Path to a file containing a 32 byte hex-encoded shared secret" &

execution_chain/core/chain/forked_chain.nim

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Nimbus
2-
# Copyright (c) 2024-2025 Status Research & Development GmbH
2+
# Copyright (c) 2024-2026 Status Research & Development GmbH
33
# Licensed under either of
44
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
55
# http://www.apache.org/licenses/LICENSE-2.0)
@@ -8,7 +8,7 @@
88
# at your option. This file may not be copied, modified, or distributed except
99
# according to those terms.
1010

11-
{.push raises: [].}
11+
{.push raises: [], gcsafe.}
1212

1313
import
1414
std/[tables, algorithm, strformat],
@@ -78,7 +78,7 @@ func appendBlock(c: ForkedChainRef,
7878
c.heads.add newBlock
7979
newBlock
8080

81-
proc fcuSetHead(c: ForkedChainRef,
81+
func fcuSetHead(c: ForkedChainRef,
8282
txFrame: CoreDbTxRef,
8383
header: Header,
8484
hash: Hash32,
@@ -196,7 +196,7 @@ func calculateNewBase(
196196

197197
doAssert(false, "Unreachable code, target base should exists")
198198

199-
proc removeBlockFromCache(c: ForkedChainRef, b: BlockRef) =
199+
func removeBlockFromCache(c: ForkedChainRef, b: BlockRef) =
200200
c.hashToBlock.del(b.hash)
201201
for tx in b.blk.transactions:
202202
c.txRecords.del(computeRlpHash(tx))
@@ -210,15 +210,15 @@ proc removeBlockFromCache(c: ForkedChainRef, b: BlockRef) =
210210
# Clear parent and let GC claim the memory earlier
211211
b.parent = nil
212212

213-
proc updateHead(c: ForkedChainRef, head: BlockRef) =
213+
func updateHead(c: ForkedChainRef, head: BlockRef) =
214214
## Update head if the new head is different from current head.
215215

216216
c.fcuSetHead(head.txFrame,
217217
head.header,
218218
head.hash,
219219
head.number)
220220

221-
proc updateFinalized(c: ForkedChainRef, finalized: BlockRef, fcuHead: BlockRef) =
221+
func updateFinalized(c: ForkedChainRef, finalized: BlockRef, fcuHead: BlockRef) =
222222
# Pruning
223223
# ::
224224
# - B5 - B6 - B7 - B8
@@ -617,6 +617,7 @@ proc init*(
617617
persistBatchSize = PersistBatchSize;
618618
dynamicBatchSize = false;
619619
eagerStateRoot = false;
620+
maxBlobs = none(uint8);
620621
enableQueue = false;
621622
): T =
622623
## Constructor that uses the current database ledger state for initialising.
@@ -658,6 +659,7 @@ proc init*(
658659
baseDistance: baseDistance,
659660
persistBatchSize: persistBatchSize,
660661
dynamicBatchSize: dynamicBatchSize,
662+
maxBlobs: maxBlobs,
661663
quarantine: Quarantine.init(),
662664
fcuHead: fcuHead,
663665
fcuSafe: fcuSafe,

execution_chain/core/chain/forked_chain/chain_desc.nim

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Nimbus
2-
# Copyright (c) 2024-2025 Status Research & Development GmbH
2+
# Copyright (c) 2024-2026 Status Research & Development GmbH
33
# Licensed under either of
44
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
55
# http://www.apache.org/licenses/LICENSE-2.0)
@@ -87,6 +87,9 @@ type
8787
# Enable adjusting the persistBatchSize dynamically based on the
8888
# time it takes to update base.
8989

90+
maxBlobs*: Option[uint8]
91+
# For EIP-7872; allows constraining of max blobs packed into each payload
92+
9093
portal*: HistoryExpiryRef
9194
# History Expiry tracker and portal access entry point
9295

execution_chain/core/tx_pool/tx_packer.nim

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Nimbus
2-
# Copyright (c) 2018-2025 Status Research & Development GmbH
2+
# Copyright (c) 2018-2026 Status Research & Development GmbH
33
# Licensed under either of
44
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
55
# http://www.apache.org/licenses/LICENSE-2.0)
@@ -12,7 +12,7 @@
1212
## =============================================================
1313
##
1414

15-
{.push raises: [].}
15+
{.push raises: [], gcsafe.}
1616

1717
import
1818
stew/sorted_set,
@@ -76,14 +76,14 @@ proc classifyValidatePacked(vmState: BaseVMState; item: TxItemRef): bool =
7676
roDB.validateTransaction(
7777
item.tx, item.sender, gasLimit, baseFee, excessBlobGas, vmState.com, fork).isOk
7878

79-
proc classifyPacked(vmState: BaseVMState; moreBurned: GasInt): bool =
79+
func classifyPacked(vmState: BaseVMState; moreBurned: GasInt): bool =
8080
## Classifier for *packing* (i.e. adding up `gasUsed` values after executing
8181
## in the VM.) This function checks whether the sum of the arguments
8282
## `gasBurned` and `moreGasBurned` is within acceptable constraints.
8383
let totalGasUsed = vmState.cumulativeGasUsed + moreBurned
8484
totalGasUsed < vmState.blockCtx.gasLimit
8585

86-
proc classifyPackedNext(vmState: BaseVMState): bool =
86+
func classifyPackedNext(vmState: BaseVMState): bool =
8787
## Classifier for *packing* (i.e. adding up `gasUsed` values after executing
8888
## in the VM.) This function returns `true` if the packing level is still
8989
## low enough to proceed trying to accumulate more items.
@@ -166,7 +166,15 @@ proc vmExecGrabItem(pst: var TxPacker; item: TxItemRef, xp: TxPoolRef): bool =
166166
if vmState.fork >= FkOsaka and item.tx.versionedHashes.len.uint64 > MAX_BLOBS_PER_TX:
167167
return ContinueWithNextAccount
168168

169-
let maxBlobsPerBlock = getMaxBlobsPerBlock(vmState.com, vmState.fork)
169+
let
170+
maxForkBlobsPerBlock = getMaxBlobsPerBlock(vmState.com, vmState.fork)
171+
maxBlobsPerBlock =
172+
if xp.chain.maxBlobs.isSome:
173+
# https://eips.ethereum.org/EIPS/eip-7872#specification
174+
# "If the minimum is zero, set the minimum to one."
175+
min(max(xp.chain.maxBlobs.get, 1).uint64, maxForkBlobsPerBlock)
176+
else:
177+
maxForkBlobsPerBlock
170178
if (pst.numBlobPerBlock + item.tx.versionedHashes.len).uint64 > maxBlobsPerBlock:
171179
return ContinueWithNextAccount
172180

@@ -265,7 +273,7 @@ func getExtraData(com: CommonRef): seq[byte] =
265273
else:
266274
com.extraData.toBytes
267275

268-
proc assembleHeader*(pst: TxPacker, xp: TxPoolRef): Header =
276+
func assembleHeader*(pst: TxPacker, xp: TxPoolRef): Header =
269277
## Generate a new header, a child of the cached `head`
270278
let
271279
vmState = pst.vmState

execution_chain/nimbus_execution_client.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# This file may not be copied, modified, or distributed except according to
88
# those terms.
99

10-
{.push raises: [].}
10+
{.push raises: [], gcsafe.}
1111

1212
import
1313
../execution_chain/compile_info
@@ -61,6 +61,7 @@ proc basicServices(nimbus: NimbusNode, config: ExecutionClientConf, com: CommonR
6161
eagerStateRoot = config.eagerStateRootCheck,
6262
persistBatchSize = config.persistBatchSize,
6363
dynamicBatchSize = config.dynamicBatchSize,
64+
maxBlobs = config.maxBlobs,
6465
enableQueue = true)
6566
if config.deserializeFcState:
6667
fc.deserialize().isOkOr:

0 commit comments

Comments
 (0)