Skip to content

Commit 8460999

Browse files
authored
init payloadV5 (#201)
* init payloadV5 * fix other v5 stuff
1 parent d35250b commit 8460999

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

tests/test_json_marshalling.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ suite "JSON-RPC Quantity":
209209
checkRandomObject(ExecutionPayloadV1OrV2)
210210
checkRandomObject(ExecutionPayloadV3)
211211
checkRandomObject(BlobsBundleV1)
212+
checkRandomObject(BlobsBundleV2)
212213
checkRandomObject(BlobAndProofV1)
213214
checkRandomObject(BlobAndProofV2)
214215
checkRandomObject(ExecutionPayloadBodyV1)

web3/conversions.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ ExecutionPayloadV2.useDefaultSerializationIn JrpcConv
5959
ExecutionPayloadV1OrV2.useDefaultSerializationIn JrpcConv
6060
ExecutionPayloadV3.useDefaultSerializationIn JrpcConv
6161
BlobsBundleV1.useDefaultSerializationIn JrpcConv
62+
BlobsBundleV2.useDefaultSerializationIn JrpcConv
6263
BlobAndProofV1.useDefaultSerializationIn JrpcConv
6364
BlobAndProofV2.useDefaultSerializationIn JrpcConv
6465
ExecutionPayloadBodyV1.useDefaultSerializationIn JrpcConv
@@ -73,6 +74,7 @@ GetPayloadV2Response.useDefaultSerializationIn JrpcConv
7374
GetPayloadV2ResponseExact.useDefaultSerializationIn JrpcConv
7475
GetPayloadV3Response.useDefaultSerializationIn JrpcConv
7576
GetPayloadV4Response.useDefaultSerializationIn JrpcConv
77+
GetPayloadV5Response.useDefaultSerializationIn JrpcConv
7678
ClientVersionV1.useDefaultSerializationIn JrpcConv
7779

7880
#------------------------------------------------------------------------------

web3/engine_api.nim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ createRpcSigsFromNim(RpcClient):
3636
proc engine_getPayloadV2_exact(payloadId: Bytes8): GetPayloadV2ResponseExact
3737
proc engine_getPayloadV3(payloadId: Bytes8): GetPayloadV3Response
3838
proc engine_getPayloadV4(payloadId: Bytes8): GetPayloadV4Response
39+
proc engine_getPayloadV5(payloadId: Bytes8): GetPayloadV5Response
3940
proc engine_getPayloadBodiesByHashV1(hashes: seq[Hash32]): seq[Opt[ExecutionPayloadBodyV1]]
4041
proc engine_getPayloadBodiesByRangeV1(start: Quantity, count: Quantity): seq[Opt[ExecutionPayloadBodyV1]]
4142
proc engine_getBlobsV1(blob_versioned_hashes: seq[VersionedHash]): GetBlobsV1Response
@@ -109,6 +110,12 @@ template getPayload*(
109110
payloadId: Bytes8): Future[GetPayloadV4Response] =
110111
engine_getPayloadV4(rpcClient, payloadId)
111112

113+
template getPayload*(
114+
rpcClient: RpcClient,
115+
T: type GetPayloadV5Response,
116+
payloadId: Bytes8): Future[GetPayloadV5Response] =
117+
engine_getPayloadV5(rpcClient, payloadId)
118+
112119
template getBlobs*(
113120
rpcClient: RpcClient,
114121
T: type GetBlobsV1Response,

web3/engine_api_types.nim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ type
127127
proofs*: seq[KzgProof]
128128
blobs*: seq[Blob]
129129

130+
BlobsBundleV2* = object
131+
commitments*: seq[KzgCommitment]
132+
proofs*: seq[KzgProof]
133+
blobs*: seq[Blob]
134+
130135
# https://github.com/ethereum/execution-apis/blob/40088597b8b4f48c45184da002e27ffc3c37641f/src/engine/cancun.md#blobandproofv1
131136
BlobAndProofV1* = object
132137
blob*: Blob
@@ -226,6 +231,13 @@ type
226231
shouldOverrideBuilder*: bool
227232
executionRequests*: seq[seq[byte]]
228233

234+
GetPayloadV5Response* = object
235+
executionPayload*: ExecutionPayloadV3
236+
blockValue*: UInt256
237+
blobsBundle*: BlobsBundleV2
238+
shouldOverrideBuilder*: bool
239+
executionRequests*: seq[seq[byte]]
240+
229241
GetBlobsV1Response* = seq[BlobAndProofV1]
230242

231243
GetBlobsV2Response* = seq[BlobAndProofV2]

web3/execution_types.nim

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type
5353
executionPayload*: ExecutionPayload
5454
blockValue*: Opt[UInt256]
5555
blobsBundle*: Opt[BlobsBundleV1]
56+
blobsBundleV2*: Opt[BlobsBundleV2]
5657
shouldOverrideBuilder*: Opt[bool]
5758
executionRequests*: Opt[seq[seq[byte]]]
5859

@@ -61,6 +62,7 @@ type
6162
V2
6263
V3
6364
V4
65+
V5
6466

6567
func version*(payload: ExecutionPayload): Version =
6668
if payload.blobGasUsed.isSome or payload.excessBlobGas.isSome:
@@ -79,7 +81,10 @@ func version*(attr: PayloadAttributes): Version =
7981
Version.V1
8082

8183
func version*(res: GetPayloadResponse): Version =
82-
if res.executionRequests.isSome:
84+
if res.blobsBundleV2.isSome and
85+
res.blobsBundleV2.get.proofs.len == (CELLS_PER_EXT_BLOB * res.blobsBundleV2.get.blobs.len):
86+
Version.V5
87+
elif res.executionRequests.isSome:
8388
Version.V4
8489
elif res.blobsBundle.isSome or res.shouldOverrideBuilder.isSome:
8590
Version.V3
@@ -388,6 +393,15 @@ func V4*(res: GetPayloadResponse): GetPayloadV4Response =
388393
executionRequests: res.executionRequests.get,
389394
)
390395

396+
func V5*(res: GetPayloadResponse): GetPayloadV5Response =
397+
GetPayloadV5Response(
398+
executionPayload: res.executionPayload.V3,
399+
blockValue: res.blockValue.get,
400+
blobsBundle: res.blobsBundleV2.get(BlobsBundleV2()),
401+
shouldOverrideBuilder: res.shouldOverrideBuilder.get(false),
402+
executionRequests: res.executionRequests.get,
403+
)
404+
391405
func getPayloadResponse*(x: ExecutionPayloadV1): GetPayloadResponse =
392406
GetPayloadResponse(executionPayload: x.executionPayload)
393407

@@ -402,6 +416,7 @@ func getPayloadResponse*(x: GetPayloadV3Response): GetPayloadResponse =
402416
executionPayload: x.executionPayload.executionPayload,
403417
blockValue: Opt.some(x.blockValue),
404418
blobsBundle: Opt.some(x.blobsBundle),
419+
blobsBundleV2: Opt.none(BlobsBundleV2),
405420
shouldOverrideBuilder: Opt.some(x.shouldOverrideBuilder)
406421
)
407422

@@ -413,3 +428,13 @@ func getPayloadResponse*(x: GetPayloadV4Response): GetPayloadResponse =
413428
shouldOverrideBuilder: Opt.some(x.shouldOverrideBuilder),
414429
executionRequests: Opt.some(x.executionRequests),
415430
)
431+
432+
func getPayloadResponse*(x: GetPayloadV5Response): GetPayloadResponse =
433+
GetPayloadResponse(
434+
executionPayload: x.executionPayload.executionPayload,
435+
blockValue: Opt.some(x.blockValue),
436+
blobsBundle: Opt.none(BlobsBundleV1),
437+
blobsBundleV2: Opt.some(x.blobsBundle),
438+
shouldOverrideBuilder: Opt.some(x.shouldOverrideBuilder),
439+
executionRequests: Opt.some(x.executionRequests),
440+
)

0 commit comments

Comments
 (0)