Skip to content

Commit 288ee28

Browse files
authored
Integrate PoS payload attributes into txPool (#2998)
* Integrate PoS payload attributes into txPool * Fix test_txpool
1 parent 6e83a48 commit 288ee28

File tree

9 files changed

+162
-154
lines changed

9 files changed

+162
-154
lines changed

nimbus/beacon/beacon_engine.nim

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Nimbus
2-
# Copyright (c) 2023-2024 Status Research & Development GmbH
2+
# Copyright (c) 2023-2025 Status Research & Development GmbH
33
# Licensed under either of
44
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
55
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
@@ -16,7 +16,7 @@ import
1616
./payload_conv,
1717
./payload_queue,
1818
./api_handler/api_utils,
19-
../core/[tx_pool, casper, chain]
19+
../core/[tx_pool, chain]
2020

2121
export
2222
chain,
@@ -68,12 +68,12 @@ const
6868
# Private helpers
6969
# ------------------------------------------------------------------------------
7070

71-
func setWithdrawals(ctx: CasperRef, attrs: PayloadAttributes) =
71+
func setWithdrawals(xp: TxPoolRef, attrs: PayloadAttributes) =
7272
case attrs.version
7373
of Version.V2, Version.V3:
74-
ctx.withdrawals = ethWithdrawals attrs.withdrawals.get
74+
xp.withdrawals = ethWithdrawals attrs.withdrawals.get
7575
else:
76-
ctx.withdrawals = @[]
76+
xp.withdrawals = @[]
7777

7878
template wrapException(body: untyped): auto =
7979
try:
@@ -146,19 +146,18 @@ proc generateExecutionBundle*(ben: BeaconEngineRef,
146146
wrapException:
147147
let
148148
xp = ben.txPool
149-
pos = xp.com.pos
150149
headBlock = ben.chain.latestHeader
151150

152-
pos.prevRandao = attrs.prevRandao
153-
pos.timestamp = ethTime attrs.timestamp
154-
pos.feeRecipient = attrs.suggestedFeeRecipient
151+
xp.prevRandao = attrs.prevRandao
152+
xp.timestamp = ethTime attrs.timestamp
153+
xp.feeRecipient = attrs.suggestedFeeRecipient
155154

156155
if attrs.parentBeaconBlockRoot.isSome:
157-
pos.parentBeaconBlockRoot = attrs.parentBeaconBlockRoot.get
156+
xp.parentBeaconBlockRoot = attrs.parentBeaconBlockRoot.get
158157

159-
pos.setWithdrawals(attrs)
158+
xp.setWithdrawals(attrs)
160159

161-
if pos.timestamp <= headBlock.timestamp:
160+
if xp.timestamp <= headBlock.timestamp:
162161
return err "timestamp must be strictly later than parent"
163162

164163
# someBaseFee = true: make sure bundle.blk.header

nimbus/common/common.nim

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Nimbus
2-
# Copyright (c) 2022-2024 Status Research & Development GmbH
2+
# Copyright (c) 2022-2025 Status Research & Development GmbH
33
# Licensed under either of
44
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
55
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
@@ -11,7 +11,6 @@
1111

1212
import
1313
chronicles,
14-
../core/casper,
1514
../db/[core_db, ledger, storage_types],
1615
../utils/[utils],
1716
".."/[constants, errors, version],
@@ -90,9 +89,6 @@ type
9089
## installing a snapshot pivot. The default value for this field is
9190
## `GENESIS_PARENT_HASH` to start at the very beginning.
9291

93-
pos: CasperRef
94-
## Proof Of Stake descriptor
95-
9692
pruneHistory: bool
9793
## Must not not set for a full node, might go away some time
9894

@@ -181,7 +177,6 @@ proc init(com : CommonRef,
181177
com.syncProgress= SyncProgress()
182178
com.syncState = Waiting
183179
com.pruneHistory= pruneHistory
184-
com.pos = CasperRef.new
185180
com.extraData = ShortClientId
186181
com.taskpool = taskpool
187182
com.gasLimit = DEFAULT_GAS_LIMIT
@@ -202,7 +197,6 @@ proc init(com : CommonRef,
202197
toGenesisHeader(genesis, fork, com.db)
203198

204199
com.setForkId(com.genesisHeader)
205-
com.pos.timestamp = genesis.timestamp
206200

207201
# By default, history begins at genesis.
208202
com.startOfHistory = GENESIS_PARENT_HASH
@@ -276,7 +270,6 @@ func clone*(com: CommonRef, db: CoreDbRef): CommonRef =
276270
genesisHeader: com.genesisHeader,
277271
syncProgress : com.syncProgress,
278272
networkId : com.networkId,
279-
pos : com.pos,
280273
pruneHistory : com.pruneHistory)
281274

282275
func clone*(com: CommonRef): CommonRef =
@@ -363,10 +356,6 @@ func startOfHistory*(com: CommonRef): Hash32 =
363356
## Getter
364357
com.startOfHistory
365358

366-
func pos*(com: CommonRef): CasperRef =
367-
## Getter
368-
com.pos
369-
370359
func db*(com: CommonRef): CoreDbRef =
371360
com.db
372361

nimbus/core/casper.nim

Lines changed: 0 additions & 56 deletions
This file was deleted.

nimbus/core/tx_pool.nim

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Nimbus
2-
# Copyright (c) 2018-2024 Status Research & Development GmbH
2+
# Copyright (c) 2018-2025 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)
@@ -42,8 +42,7 @@ import
4242
./tx_pool/tx_item,
4343
./tx_pool/tx_desc,
4444
./tx_pool/tx_packer,
45-
./chain/forked_chain,
46-
./casper
45+
./chain/forked_chain
4746

4847
from eth/common/eth_types_rlp import rlpHash
4948

@@ -143,7 +142,7 @@ proc assembleBlock*(
143142
return err(error)
144143

145144
var blk = EthBlock(
146-
header: pst.assembleHeader
145+
header: pst.assembleHeader(xp)
147146
)
148147
var blobsBundle: BlobsBundle
149148
for item in pst.packedTxs:
@@ -160,7 +159,7 @@ proc assembleBlock*(
160159

161160
let com = xp.vmState.com
162161
if com.isShanghaiOrLater(blk.header.timestamp):
163-
blk.withdrawals = Opt.some(com.pos.withdrawals)
162+
blk.withdrawals = Opt.some(xp.withdrawals)
164163

165164
if not com.isCancunOrLater(blk.header.timestamp) and blobsBundle.commitments.len > 0:
166165
return err("PooledTransaction contains blobs prior to Cancun")
@@ -187,3 +186,37 @@ proc assembleBlock*(
187186
blobsBundle: blobsBundleOpt,
188187
blockValue: pst.blockValue,
189188
executionRequests: executionRequestsOpt)
189+
190+
# ------------------------------------------------------------------------------
191+
# PoS payload attributes getters
192+
# ------------------------------------------------------------------------------
193+
194+
export
195+
feeRecipient,
196+
timestamp,
197+
prevRandao,
198+
withdrawals,
199+
parentBeaconBlockRoot
200+
201+
# feeRecipient(xp: TxPoolRef): Address
202+
# timestamp(xp: TxPoolRef): EthTime
203+
# prevRandao(xp: TxPoolRef): Bytes32
204+
# withdrawals(xp: TxPoolRef): seq[Withdrawal]
205+
# parentBeaconBlockRoot(xp: TxPoolRef): Hash32
206+
207+
# ------------------------------------------------------------------------------
208+
# PoS payload attributes setters
209+
# ------------------------------------------------------------------------------
210+
211+
export
212+
`feeRecipient=`,
213+
`timestamp=`,
214+
`prevRandao=`,
215+
`withdrawals=`,
216+
`parentBeaconBlockRoot=`
217+
218+
# `feeRecipient=`(xp: TxPoolRef, val: Address)
219+
# `timestamp=`(xp: TxPoolRef, val: EthTime)
220+
# `prevRandao=`(xp: TxPoolRef, val: Bytes32)
221+
# `withdrawals=`(xp: TxPoolRef, val: sink seq[Withdrawal])
222+
# `parentBeaconBlockRoot=`(xp: TxPoolRef, val: Hash32)

0 commit comments

Comments
 (0)