Skip to content

Commit f02c20c

Browse files
committed
fix EIP-4844: txpool missing dataGasUsed when generate block header
1 parent 7229bca commit f02c20c

File tree

3 files changed

+73
-9
lines changed

3 files changed

+73
-9
lines changed

nimbus/core/tx_pool/tx_tasks/tx_packer.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ proc vmExecCommit(pst: TxPackerStateRef)
253253
# EIP-4844
254254
let excessDataGas = calcExcessDataGas(vmState.parent)
255255
xp.chain.excessDataGas = some(excessDataGas)
256+
xp.chain.dataGasUsed = some(pst.dataGasUsed)
256257

257258
proc balanceDelta: UInt256 =
258259
let postBalance = vmState.readOnlyStateDB.getBalance(xp.chain.feeRecipient)

tests/test_txpool.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,7 @@ when isMainModule:
900900

901901
runTxPoolCliqueTest()
902902
runTxPoolPosTest()
903+
runTxPoolBlobhashTest()
903904
noisy.runTxHeadDelta
904905

905906
#noisy.runTxLoader(dir = ".")

tests/test_txpool2.nim

Lines changed: 71 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ proc makeTx*(t: var TestEnv, recipient: EthAddress, amount: UInt256, payload: op
7070
inc t.nonce
7171
signTransaction(tx, t.vaultKey, t.chainId, eip155 = true)
7272

73-
proc initEnv(ttd: Option[UInt256] = none(UInt256)): TestEnv =
73+
proc initEnv(envFork: HardFork): TestEnv =
7474
var
7575
conf = makeConfig(@[
7676
"--engine-signer:658bdf435d810c91414ec09147daa6db62406379",
@@ -81,8 +81,14 @@ proc initEnv(ttd: Option[UInt256] = none(UInt256)): TestEnv =
8181
code: contractCode
8282
)
8383

84-
if ttd.isSome:
85-
conf.networkParams.config.terminalTotalDifficulty = ttd
84+
if envFork >= MergeFork:
85+
conf.networkParams.config.terminalTotalDifficulty = some(100.u256)
86+
87+
if envFork >= Shanghai:
88+
conf.networkParams.config.shanghaiTime = some(0.fromUnix)
89+
90+
if envFork >= Cancun:
91+
conf.networkParams.config.cancunTime = some(0.fromUnix)
8692

8793
let
8894
com = CommonRef.new(
@@ -112,7 +118,7 @@ const
112118

113119
proc runTxPoolCliqueTest*() =
114120
var
115-
env = initEnv()
121+
env = initEnv(London)
116122

117123
var
118124
tx = env.makeTx(recipient, amount)
@@ -173,7 +179,6 @@ proc runTxPoolCliqueTest*() =
173179
check rr == ValidationResult.OK
174180

175181
test "Do not kick the signer out of list":
176-
let timestamp = blk.header.timestamp
177182
check xp.smartHead(blk.header)
178183

179184
let tx = env.makeTx(recipient, amount)
@@ -207,7 +212,7 @@ proc runTxPoolCliqueTest*() =
207212

208213
proc runTxPoolPosTest*() =
209214
var
210-
env = initEnv(some(100.u256))
215+
env = initEnv(MergeFork)
211216

212217
var
213218
tx = env.makeTx(recipient, amount)
@@ -260,13 +265,69 @@ proc runTxPoolPosTest*() =
260265
let bal = sdb.getBalance(feeRecipient)
261266
check not bal.isZero
262267

268+
proc runTxPoolBlobhashTest*() =
269+
var
270+
env = initEnv(Cancun)
271+
272+
var
273+
tx = env.makeTx(recipient, amount)
274+
xp = env.xp
275+
com = env.com
276+
chain = env.chain
277+
body: BlockBody
278+
blk: EthBlock
279+
280+
suite "Test TxPool with blobhash block":
281+
test "TxPool addLocal":
282+
let res = xp.addLocal(tx, force = true)
283+
check res.isOk
284+
if res.isErr:
285+
debugEcho res.error
286+
return
287+
288+
test "TxPool jobCommit":
289+
check xp.nItems.total == 1
290+
291+
test "TxPool ethBlock":
292+
com.pos.prevRandao = prevRandao
293+
com.pos.feeRecipient = feeRecipient
294+
com.pos.timestamp = getTime()
295+
296+
blk = xp.ethBlock()
297+
298+
check com.isBlockAfterTtd(blk.header)
299+
300+
body = BlockBody(
301+
transactions: blk.txs,
302+
uncles: blk.uncles,
303+
withdrawals: some[seq[Withdrawal]](@[])
304+
)
305+
check blk.txs.len == 1
306+
307+
test "Blobhash persistBlocks":
308+
let rr = chain.persistBlocks([blk.header], [body])
309+
check rr == ValidationResult.OK
310+
311+
test "validate TxPool prevRandao setter":
312+
var sdb = newAccountStateDB(com.db.db, blk.header.stateRoot, pruneTrie = false)
313+
let (val, ok) = sdb.getStorage(recipient, slot)
314+
let randao = Hash256(data: val.toBytesBE)
315+
check ok
316+
check randao == prevRandao
317+
318+
test "feeRecipient rewarded":
319+
check blk.header.coinbase == feeRecipient
320+
var sdb = newAccountStateDB(com.db.db, blk.header.stateRoot, pruneTrie = false)
321+
let bal = sdb.getBalance(feeRecipient)
322+
check not bal.isZero
323+
263324
proc runTxHeadDelta*(noisy = true) =
264325
## see github.com/status-im/nimbus-eth1/issues/1031
265326

266327
suite "TxPool: Synthesising blocks (covers issue #1031)":
267328
test "Packing and adding multiple blocks to chain":
268329
var
269-
env = initEnv(some(100.u256))
330+
env = initEnv(MergeFork)
270331
xp = env.xp
271332
com = env.com
272333
chain = env.chain
@@ -336,7 +397,8 @@ when isMainModule:
336397
setErrorLevel() # mute logger
337398

338399
runTxPoolCliqueTest()
339-
#runTxPoolPosTest()
340-
#noisy.runTxHeadDelta
400+
runTxPoolPosTest()
401+
runTxPoolBlobhashTest()
402+
noisy.runTxHeadDelta
341403

342404
# End

0 commit comments

Comments
 (0)