2023-08-27 01:23:45 +00:00
|
|
|
# Nimbus
|
2024-03-28 11:59:23 +00:00
|
|
|
# Copyright (c) 2023-2024 Status Research & Development GmbH
|
2023-08-27 01:23:45 +00:00
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
|
|
|
# at your option.
|
|
|
|
# This file may not be copied, modified, or distributed except according to
|
|
|
|
# those terms.
|
|
|
|
|
|
|
|
import
|
|
|
|
std/[typetraits],
|
|
|
|
eth/common,
|
|
|
|
../web3_eth_conv,
|
|
|
|
../beacon_engine,
|
2023-12-08 09:35:50 +00:00
|
|
|
web3/execution_types,
|
2023-08-27 01:23:45 +00:00
|
|
|
./api_utils,
|
|
|
|
chronicles
|
|
|
|
|
|
|
|
{.push gcsafe, raises:[CatchableError].}
|
|
|
|
|
2023-10-23 13:59:57 +00:00
|
|
|
proc getPayload*(ben: BeaconEngineRef,
|
|
|
|
expectedVersion: Version,
|
|
|
|
id: PayloadID): GetPayloadV2Response =
|
2023-08-27 01:23:45 +00:00
|
|
|
trace "Engine API request received",
|
|
|
|
meth = "GetPayload", id
|
|
|
|
|
2023-10-23 13:59:57 +00:00
|
|
|
var payloadGeneric: ExecutionPayload
|
2023-08-27 01:23:45 +00:00
|
|
|
var blockValue: UInt256
|
2024-06-14 07:31:08 +00:00
|
|
|
var blobsBundle: Opt[BlobsBundleV1]
|
2024-05-15 03:07:59 +00:00
|
|
|
if not ben.get(id, blockValue, payloadGeneric, blobsBundle):
|
2023-08-27 01:23:45 +00:00
|
|
|
raise unknownPayload("Unknown payload")
|
|
|
|
|
2023-10-23 13:59:57 +00:00
|
|
|
let version = payloadGeneric.version
|
|
|
|
if version > expectedVersion:
|
|
|
|
raise unsupportedFork("getPayload" & $expectedVersion &
|
2024-05-15 03:07:59 +00:00
|
|
|
" expect ExecutionPayload" & $expectedVersion &
|
|
|
|
" but get ExecutionPayload" & $version)
|
|
|
|
if blobsBundle.isSome:
|
|
|
|
raise unsupportedFork("getPayload" & $expectedVersion &
|
|
|
|
" contains unsupported BlobsBundleV1")
|
2023-10-23 13:59:57 +00:00
|
|
|
|
2023-08-27 01:23:45 +00:00
|
|
|
GetPayloadV2Response(
|
2023-10-23 13:59:57 +00:00
|
|
|
executionPayload: payloadGeneric.V1V2,
|
2023-08-27 01:23:45 +00:00
|
|
|
blockValue: blockValue
|
|
|
|
)
|
|
|
|
|
|
|
|
proc getPayloadV3*(ben: BeaconEngineRef, id: PayloadID): GetPayloadV3Response =
|
|
|
|
trace "Engine API request received",
|
|
|
|
meth = "GetPayload", id
|
|
|
|
|
2023-10-23 13:59:57 +00:00
|
|
|
var payloadGeneric: ExecutionPayload
|
2023-08-27 01:23:45 +00:00
|
|
|
var blockValue: UInt256
|
2024-06-14 07:31:08 +00:00
|
|
|
var blobsBundle: Opt[BlobsBundleV1]
|
2024-05-15 03:07:59 +00:00
|
|
|
if not ben.get(id, blockValue, payloadGeneric, blobsBundle):
|
2023-08-27 01:23:45 +00:00
|
|
|
raise unknownPayload("Unknown payload")
|
|
|
|
|
2023-10-23 13:59:57 +00:00
|
|
|
let version = payloadGeneric.version
|
|
|
|
if version != Version.V3:
|
|
|
|
raise unsupportedFork("getPayloadV3 expect ExecutionPayloadV3 but get ExecutionPayload" & $version)
|
2024-05-15 03:07:59 +00:00
|
|
|
if blobsBundle.isNone:
|
|
|
|
raise unsupportedFork("getPayloadV3 is missing BlobsBundleV1")
|
2023-10-23 13:59:57 +00:00
|
|
|
|
|
|
|
let payload = payloadGeneric.V3
|
2023-08-27 01:23:45 +00:00
|
|
|
let com = ben.com
|
|
|
|
if not com.isCancunOrLater(ethTime payload.timestamp):
|
|
|
|
raise unsupportedFork("payload timestamp is less than Cancun activation")
|
|
|
|
|
|
|
|
GetPayloadV3Response(
|
|
|
|
executionPayload: payload,
|
|
|
|
blockValue: blockValue,
|
2024-05-15 03:07:59 +00:00
|
|
|
blobsBundle: blobsBundle.get,
|
2023-10-05 13:54:51 +00:00
|
|
|
shouldOverrideBuilder: false
|
2023-08-27 01:23:45 +00:00
|
|
|
)
|
2024-03-28 11:59:23 +00:00
|
|
|
|
|
|
|
proc getPayloadV4*(ben: BeaconEngineRef, id: PayloadID): GetPayloadV4Response =
|
|
|
|
trace "Engine API request received",
|
|
|
|
meth = "GetPayload", id
|
|
|
|
|
|
|
|
var payloadGeneric: ExecutionPayload
|
|
|
|
var blockValue: UInt256
|
2024-06-14 07:31:08 +00:00
|
|
|
var blobsBundle: Opt[BlobsBundleV1]
|
2024-05-15 03:07:59 +00:00
|
|
|
if not ben.get(id, blockValue, payloadGeneric, blobsBundle):
|
2024-03-28 11:59:23 +00:00
|
|
|
raise unknownPayload("Unknown payload")
|
|
|
|
|
|
|
|
let version = payloadGeneric.version
|
|
|
|
if version != Version.V4:
|
|
|
|
raise unsupportedFork("getPayloadV4 expect ExecutionPayloadV4 but get ExecutionPayload" & $version)
|
2024-05-15 03:07:59 +00:00
|
|
|
if blobsBundle.isNone:
|
|
|
|
raise unsupportedFork("getPayloadV4 is missing BlobsBundleV1")
|
2024-03-28 11:59:23 +00:00
|
|
|
|
|
|
|
let payload = payloadGeneric.V4
|
|
|
|
let com = ben.com
|
|
|
|
if not com.isPragueOrLater(ethTime payload.timestamp):
|
|
|
|
raise unsupportedFork("payload timestamp is less than Prague activation")
|
|
|
|
|
|
|
|
GetPayloadV4Response(
|
|
|
|
executionPayload: payload,
|
|
|
|
blockValue: blockValue,
|
2024-05-15 03:07:59 +00:00
|
|
|
blobsBundle: blobsBundle.get,
|
2024-03-28 11:59:23 +00:00
|
|
|
shouldOverrideBuilder: false
|
|
|
|
)
|