Skip to content

Commit d443601

Browse files
authored
Align PooledTransaction to the spec (#3350)
1 parent f917387 commit d443601

File tree

15 files changed

+74
-70
lines changed

15 files changed

+74
-70
lines changed

execution_chain/beacon/beacon_engine.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# those terms.
99

1010
import
11-
std/[sequtils, tables],
11+
std/[tables],
1212
eth/common/[hashes, headers],
1313
chronicles,
1414
minilru,
@@ -178,7 +178,7 @@ proc generateExecutionBundle*(ben: BeaconEngineRef,
178178
blobsBundle = Opt.some BlobsBundleV1(
179179
commitments: blobData.commitments,
180180
proofs: blobData.proofs,
181-
blobs: blobData.blobs.mapIt it.Web3Blob)
181+
blobs: blobData.blobs)
182182

183183
ok ExecutionBundle(
184184
payload: executionPayload(bundle.blk),

execution_chain/beacon/web3_eth_conv.nim

Lines changed: 1 addition & 2 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))
@@ -27,7 +27,6 @@ type
2727
Web3Quantity* = web3types.Quantity
2828
Web3ExtraData* = web3types.DynamicBytes[0, 32]
2929
Web3Tx* = engine_api_types.TypedTransaction
30-
Web3Blob* = engine_api_types.Blob
3130

3231
{.push gcsafe, raises:[].}
3332

execution_chain/core/eip4844.nim

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,35 +177,35 @@ func validateEip4844Header*(
177177

178178
proc validateBlobTransactionWrapper*(tx: PooledTransaction):
179179
Result[void, string] {.raises: [].} =
180-
if tx.networkPayload.isNil:
180+
if tx.blobsBundle.isNil:
181181
return err("tx wrapper is none")
182182

183183
# note: assert blobs are not malformatted
184184
let goodFormatted = tx.tx.versionedHashes.len ==
185-
tx.networkPayload.commitments.len and
185+
tx.blobsBundle.commitments.len and
186186
tx.tx.versionedHashes.len ==
187-
tx.networkPayload.blobs.len and
187+
tx.blobsBundle.blobs.len and
188188
tx.tx.versionedHashes.len ==
189-
tx.networkPayload.proofs.len
189+
tx.blobsBundle.proofs.len
190190

191191
if not goodFormatted:
192192
return err("tx wrapper is ill formatted")
193193

194-
let commitments = tx.networkPayload.commitments.mapIt(
194+
let commitments = tx.blobsBundle.commitments.mapIt(
195195
kzg.KzgCommitment(bytes: it.data))
196196

197197
# Verify that commitments match the blobs by checking the KZG proof
198198
let res = kzg.verifyBlobKzgProofBatch(
199-
tx.networkPayload.blobs.mapIt(kzg.KzgBlob(bytes: it)),
199+
tx.blobsBundle.blobs.mapIt(kzg.KzgBlob(bytes: it.bytes)),
200200
commitments,
201-
tx.networkPayload.proofs.mapIt(kzg.KzgProof(bytes: it.data)))
201+
tx.blobsBundle.proofs.mapIt(kzg.KzgProof(bytes: it.data)))
202202

203203
if res.isErr:
204204
return err(res.error)
205205

206206
# Actual verification result
207207
if not res.get():
208-
return err("Failed to verify network payload of a transaction")
208+
return err("Failed to verify blobs bundle of a transaction")
209209

210210
# Now that all commitments have been verified, check that versionedHashes matches the commitments
211211
for i in 0 ..< tx.tx.versionedHashes.len:

execution_chain/core/pooled_txs.nim

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,21 @@
1010
{.push raises: [].}
1111

1212
import
13-
eth/common/transactions
13+
eth/common/transactions,
14+
web3/primitives
1415

1516
export
16-
transactions
17+
transactions,
18+
primitives
1719

1820
type
19-
# 32 -> UInt256
20-
# 4096 -> FIELD_ELEMENTS_PER_BLOB
21-
NetworkBlob* = array[32*4096, byte]
21+
KzgBlob* = primitives.Blob
2222

23-
BlobsBundle* = object
23+
BlobsBundle* = ref object
2424
commitments*: seq[KzgCommitment]
2525
proofs*: seq[KzgProof]
26-
blobs*: seq[NetworkBlob]
27-
28-
NetworkPayload* = ref BlobsBundle
26+
blobs*: seq[KzgBlob]
2927

3028
PooledTransaction* = object
3129
tx*: Transaction
32-
networkPayload*: NetworkPayload # EIP-4844
30+
blobsBundle*: BlobsBundle # EIP-4844

execution_chain/core/pooled_txs_rlp.nim

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,45 @@ export
1717
transactions_rlp,
1818
pooled_txs
1919

20-
proc append(w: var RlpWriter, networkPayload: NetworkPayload) =
21-
w.append(networkPayload.blobs)
22-
w.append(networkPayload.commitments)
23-
w.append(networkPayload.proofs)
20+
proc append(w: var RlpWriter, blob: Blob) =
21+
w.append(blob.bytes)
22+
23+
proc append(w: var RlpWriter, blobsBundle: BlobsBundle) =
24+
w.append(blobsBundle.blobs)
25+
w.append(blobsBundle.commitments)
26+
w.append(blobsBundle.proofs)
2427

2528
proc append*(w: var RlpWriter, tx: PooledTransaction) =
2629
if tx.tx.txType != TxLegacy:
2730
w.append(tx.tx.txType)
28-
if tx.networkPayload != nil:
31+
if tx.blobsBundle != nil:
2932
w.startList(4) # spec: rlp([tx_payload, blobs, commitments, proofs])
3033
w.appendTxPayload(tx.tx)
31-
if tx.networkPayload != nil:
32-
w.append(tx.networkPayload)
34+
if tx.blobsBundle != nil:
35+
w.append(tx.blobsBundle)
36+
37+
proc read(rlp: var Rlp, T: type Blob): T {.raises: [RlpError].} =
38+
rlp.read(result.bytes)
3339

34-
proc read(rlp: var Rlp, T: type NetworkPayload): T {.raises: [RlpError].} =
35-
result = NetworkPayload()
40+
proc read(rlp: var Rlp, T: type BlobsBundle): T {.raises: [RlpError].} =
41+
result = BlobsBundle()
3642
rlp.read(result.blobs)
3743
rlp.read(result.commitments)
3844
rlp.read(result.proofs)
3945

4046
proc readTxTyped(rlp: var Rlp, tx: var PooledTransaction) {.raises: [RlpError].} =
4147
let
4248
txType = rlp.readTxType()
43-
hasNetworkPayload =
49+
hasBlobsBundle =
4450
if txType == TxEip4844:
4551
rlp.listLen == 4
4652
else:
4753
false
48-
if hasNetworkPayload:
54+
if hasBlobsBundle:
4955
rlp.tryEnterList() # spec: rlp([tx_payload, blobs, commitments, proofs])
5056
rlp.readTxPayload(tx.tx, txType)
51-
if hasNetworkPayload:
52-
rlp.read(tx.networkPayload)
57+
if hasBlobsBundle:
58+
rlp.read(tx.blobsBundle)
5359

5460
proc read*(rlp: var Rlp, T: type PooledTransaction): T {.raises: [RlpError].} =
5561
if rlp.isList:

execution_chain/core/tx_pool.nim

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,16 @@ proc assembleBlock*(
147147
var blk = EthBlock(
148148
header: pst.assembleHeader(xp)
149149
)
150-
var blobsBundle: BlobsBundle
150+
var blobsBundle = BlobsBundle()
151151
for item in pst.packedTxs:
152152
let tx = item.pooledTx
153153
blk.txs.add tx.tx
154-
if tx.networkPayload != nil:
155-
for k in tx.networkPayload.commitments:
154+
if tx.blobsBundle != nil:
155+
for k in tx.blobsBundle.commitments:
156156
blobsBundle.commitments.add k
157-
for p in tx.networkPayload.proofs:
157+
for p in tx.blobsBundle.proofs:
158158
blobsBundle.proofs.add p
159-
for blob in tx.networkPayload.blobs:
159+
for blob in tx.blobsBundle.blobs:
160160
blobsBundle.blobs.add blob
161161
blk.header.transactionsRoot = calcTxRoot(blk.txs)
162162

execution_chain/core/tx_pool/tx_desc.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,9 @@ iterator byPriceAndNonce*(xp: TxPoolRef): TxItemRef =
414414

415415
func getBlobAndProofV1*(xp: TxPoolRef, v: VersionedHash): Opt[BlobAndProofV1] =
416416
xp.blobTab.withValue(v, val):
417-
let np = val.item.pooledTx.networkPayload
417+
let np = val.item.pooledTx.blobsBundle
418418
return Opt.some(BlobAndProofV1(
419-
blob: engine_api_types.Blob(np.blobs[val.blobIndex]),
419+
blob: np.blobs[val.blobIndex],
420420
proof: np.proofs[val.blobIndex]))
421421

422422
Opt.none(BlobAndProofV1)

execution_chain/rpc/rpc_utils.nim

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ proc populateBlockObject*(blockHash: Hash32,
149149
result.mixHash = Hash32 header.mixHash
150150

151151
# discard sizeof(seq[byte]) of extraData and use actual length
152-
let size = sizeof(eth_types.Header) - sizeof(eth_api_types.Blob) + header.extraData.len
152+
type ExtraDataType = typeof(header.extraData)
153+
let size = sizeof(eth_types.Header) - sizeof(ExtraDataType) + header.extraData.len
153154
result.size = Quantity(size)
154155

155156
result.gasLimit = Quantity(header.gasLimit)
@@ -181,7 +182,7 @@ proc populateBlockObject*(blockHash: Hash32,
181182

182183
proc populateReceipt*(rec: StoredReceipt, gasUsed: GasInt, tx: Transaction,
183184
txIndex: uint64, header: Header, com: CommonRef): ReceiptObject =
184-
let
185+
let
185186
sender = tx.recoverSender()
186187
receipt = rec.to(Receipt)
187188
var res = ReceiptObject()

execution_chain/rpc/server_api.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ proc setupServerAPI*(api: ServerAPIRef, server: RpcServer, ctx: EthContext) =
499499
tx = unsignedTx(data, api.chain, accDB.getNonce(address) + 1, api.com.chainId)
500500
eip155 = api.com.isEIP155(api.chain.latestNumber)
501501
signedTx = signTransaction(tx, acc.privateKey, eip155)
502-
networkPayload =
502+
blobsBundle =
503503
if signedTx.txType == TxEip4844:
504504
if data.blobs.isNone or data.commitments.isNone or data.proofs.isNone:
505505
raise newException(ValueError, "EIP-4844 transaction needs blobs")
@@ -509,16 +509,16 @@ proc setupServerAPI*(api: ServerAPIRef, server: RpcServer, ctx: EthContext) =
509509
raise newException(ValueError, "Incorrect number of commitments")
510510
if data.proofs.get.len != signedTx.versionedHashes.len:
511511
raise newException(ValueError, "Incorrect number of proofs")
512-
NetworkPayload(
513-
blobs: data.blobs.get.mapIt it.NetworkBlob,
512+
BlobsBundle(
513+
blobs: data.blobs.get,
514514
commitments: data.commitments.get,
515515
proofs: data.proofs.get,
516516
)
517517
else:
518518
if data.blobs.isSome or data.commitments.isSome or data.proofs.isSome:
519519
raise newException(ValueError, "Blobs require EIP-4844 transaction")
520520
nil
521-
pooledTx = PooledTransaction(tx: signedTx, networkPayload: networkPayload)
521+
pooledTx = PooledTransaction(tx: signedTx, blobsBundle: blobsBundle)
522522
523523
api.txPool.addTx(pooledTx).isOkOr:
524524
raise newException(ValueError, $error)

execution_chain/utils/debug.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,13 @@ proc debug*(tx: Transaction): string =
137137
138138
proc debug*(tx: PooledTransaction): string =
139139
result.add debug(tx.tx)
140-
if tx.networkPayload.isNil:
140+
if tx.blobsBundle.isNil:
141141
result.add "networkPaylod : nil\n"
142142
else:
143143
result.add "networkPaylod : \n"
144-
result.add " - blobs : " & $tx.networkPayload.blobs.len & "\n"
145-
result.add " - commitments : " & $tx.networkPayload.commitments.len & "\n"
146-
result.add " - proofs : " & $tx.networkPayload.proofs.len & "\n"
144+
result.add " - blobs : " & $tx.blobsBundle.blobs.len & "\n"
145+
result.add " - commitments : " & $tx.blobsBundle.commitments.len & "\n"
146+
result.add " - proofs : " & $tx.blobsBundle.proofs.len & "\n"
147147
148148
proc debugSum*(h: Header): string =
149149
result.add "txRoot : " & $h.txRoot & "\n"

0 commit comments

Comments
 (0)