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],
|
|
|
|
../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,
|
2024-10-16 01:34:12 +00:00
|
|
|
id: Bytes8): GetPayloadV2Response =
|
2023-08-27 01:23:45 +00:00
|
|
|
trace "Engine API request received",
|
|
|
|
meth = "GetPayload", id
|
|
|
|
|
2024-11-02 01:45:27 +00:00
|
|
|
var bundle: ExecutionBundle
|
|
|
|
if not ben.get(id, bundle):
|
|
|
|
raise unknownPayload("Unknown bundle")
|
2023-08-27 01:23:45 +00:00
|
|
|
|
2024-11-02 01:45:27 +00:00
|
|
|
let version = bundle.payload.version
|
2023-10-23 13:59:57 +00:00
|
|
|
if version > expectedVersion:
|
|
|
|
raise unsupportedFork("getPayload" & $expectedVersion &
|
2024-11-02 01:45:27 +00:00
|
|
|
" expect payload" & $expectedVersion &
|
|
|
|
" but get payload" & $version)
|
|
|
|
if bundle.blobsBundle.isSome:
|
2024-05-15 03:07:59 +00:00
|
|
|
raise unsupportedFork("getPayload" & $expectedVersion &
|
|
|
|
" contains unsupported BlobsBundleV1")
|
2023-10-23 13:59:57 +00:00
|
|
|
|
2023-08-27 01:23:45 +00:00
|
|
|
GetPayloadV2Response(
|
2024-11-02 01:45:27 +00:00
|
|
|
executionPayload: bundle.payload.V1V2,
|
|
|
|
blockValue: bundle.blockValue
|
2023-08-27 01:23:45 +00:00
|
|
|
)
|
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
proc getPayloadV3*(ben: BeaconEngineRef, id: Bytes8): GetPayloadV3Response =
|
2023-08-27 01:23:45 +00:00
|
|
|
trace "Engine API request received",
|
|
|
|
meth = "GetPayload", id
|
|
|
|
|
2024-11-02 01:45:27 +00:00
|
|
|
var bundle: ExecutionBundle
|
|
|
|
if not ben.get(id, bundle):
|
|
|
|
raise unknownPayload("Unknown bundle")
|
2023-08-27 01:23:45 +00:00
|
|
|
|
2024-11-02 01:45:27 +00:00
|
|
|
let version = bundle.payload.version
|
2023-10-23 13:59:57 +00:00
|
|
|
if version != Version.V3:
|
2024-11-02 01:45:27 +00:00
|
|
|
raise unsupportedFork("getPayloadV3 expect payloadV3 but get payload" & $version)
|
|
|
|
if bundle.blobsBundle.isNone:
|
2024-05-15 03:07:59 +00:00
|
|
|
raise unsupportedFork("getPayloadV3 is missing BlobsBundleV1")
|
2023-10-23 13:59:57 +00:00
|
|
|
|
2023-08-27 01:23:45 +00:00
|
|
|
let com = ben.com
|
2024-11-02 01:45:27 +00:00
|
|
|
if not com.isCancunOrLater(ethTime bundle.payload.timestamp):
|
|
|
|
raise unsupportedFork("bundle timestamp is less than Cancun activation")
|
2023-08-27 01:23:45 +00:00
|
|
|
|
|
|
|
GetPayloadV3Response(
|
2024-11-02 01:45:27 +00:00
|
|
|
executionPayload: bundle.payload.V3,
|
|
|
|
blockValue: bundle.blockValue,
|
|
|
|
blobsBundle: bundle.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
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
proc getPayloadV4*(ben: BeaconEngineRef, id: Bytes8): GetPayloadV4Response =
|
2024-03-28 11:59:23 +00:00
|
|
|
trace "Engine API request received",
|
|
|
|
meth = "GetPayload", id
|
|
|
|
|
2024-11-02 01:45:27 +00:00
|
|
|
var bundle: ExecutionBundle
|
|
|
|
if not ben.get(id, bundle):
|
|
|
|
raise unknownPayload("Unknown bundle")
|
2024-03-28 11:59:23 +00:00
|
|
|
|
2024-11-02 01:45:27 +00:00
|
|
|
let version = bundle.payload.version
|
2024-10-18 09:38:18 +00:00
|
|
|
if version != Version.V3:
|
2024-11-02 01:45:27 +00:00
|
|
|
raise unsupportedFork("getPayloadV4 expect payloadV3 but get payload" & $version)
|
|
|
|
if bundle.blobsBundle.isNone:
|
2024-05-15 03:07:59 +00:00
|
|
|
raise unsupportedFork("getPayloadV4 is missing BlobsBundleV1")
|
2024-11-02 01:45:27 +00:00
|
|
|
if bundle.executionRequests.isNone:
|
2024-10-18 09:38:18 +00:00
|
|
|
raise unsupportedFork("getPayloadV4 is missing executionRequests")
|
2024-03-28 11:59:23 +00:00
|
|
|
|
|
|
|
let com = ben.com
|
2024-11-02 01:45:27 +00:00
|
|
|
if not com.isPragueOrLater(ethTime bundle.payload.timestamp):
|
|
|
|
raise unsupportedFork("bundle timestamp is less than Prague activation")
|
2024-03-28 11:59:23 +00:00
|
|
|
|
|
|
|
GetPayloadV4Response(
|
2024-11-02 01:45:27 +00:00
|
|
|
executionPayload: bundle.payload.V3,
|
|
|
|
blockValue: bundle.blockValue,
|
|
|
|
blobsBundle: bundle.blobsBundle.get,
|
2024-10-18 09:38:18 +00:00
|
|
|
shouldOverrideBuilder: false,
|
2024-11-02 01:45:27 +00:00
|
|
|
executionRequests: bundle.executionRequests.get,
|
2024-03-28 11:59:23 +00:00
|
|
|
)
|