2021-10-05 23:31:35 +00:00
|
|
|
# Nimbus
|
2024-02-21 09:14:20 +00:00
|
|
|
# Copyright (c) 2021-2024 Status Research & Development GmbH
|
2021-10-05 23:31:35 +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
|
2023-08-27 01:23:45 +00:00
|
|
|
std/[typetraits, sequtils, sets],
|
2023-01-31 01:32:17 +00:00
|
|
|
json_rpc/rpcserver,
|
2023-12-08 09:35:50 +00:00
|
|
|
web3/[conversions, execution_types],
|
2023-08-27 01:23:45 +00:00
|
|
|
../beacon/api_handler,
|
|
|
|
../beacon/beacon_engine,
|
2024-05-29 07:20:50 +00:00
|
|
|
../version
|
2021-10-05 23:31:35 +00:00
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
from ../beacon/web3_eth_conv import Hash32
|
|
|
|
|
2023-01-31 01:32:17 +00:00
|
|
|
{.push raises: [].}
|
|
|
|
|
2023-03-09 23:40:55 +00:00
|
|
|
const supportedMethods: HashSet[string] =
|
|
|
|
toHashSet([
|
|
|
|
"engine_newPayloadV1",
|
|
|
|
"engine_newPayloadV2",
|
2023-08-08 03:44:29 +00:00
|
|
|
"engine_newPayloadV3",
|
2024-03-28 11:59:23 +00:00
|
|
|
"engine_newPayloadV4",
|
2023-03-09 23:40:55 +00:00
|
|
|
"engine_getPayloadV1",
|
|
|
|
"engine_getPayloadV2",
|
2023-08-08 03:44:29 +00:00
|
|
|
"engine_getPayloadV3",
|
2024-03-28 11:59:23 +00:00
|
|
|
"engine_getPayloadV4",
|
2023-03-09 23:40:55 +00:00
|
|
|
"engine_exchangeTransitionConfigurationV1",
|
|
|
|
"engine_forkchoiceUpdatedV1",
|
|
|
|
"engine_forkchoiceUpdatedV2",
|
2023-08-08 07:29:23 +00:00
|
|
|
"engine_forkchoiceUpdatedV3",
|
2023-08-17 00:27:34 +00:00
|
|
|
"engine_getPayloadBodiesByHashV1",
|
|
|
|
"engine_getPayloadBodiesByRangeV1",
|
2024-05-29 07:20:50 +00:00
|
|
|
"engine_getClientVersionV1",
|
2023-03-09 23:40:55 +00:00
|
|
|
])
|
|
|
|
|
|
|
|
# I'm trying to keep the handlers below very thin, and move the
|
|
|
|
# bodies up to the various procs above. Once we have multiple
|
|
|
|
# versions, they'll need to be able to share code.
|
2023-08-27 01:23:45 +00:00
|
|
|
proc setupEngineAPI*(engine: BeaconEngineRef, server: RpcServer) =
|
2021-10-05 23:31:35 +00:00
|
|
|
|
2023-03-09 23:40:55 +00:00
|
|
|
server.rpc("engine_exchangeCapabilities") do(methods: seq[string]) -> seq[string]:
|
|
|
|
return methods.filterIt(supportedMethods.contains(it))
|
2022-12-10 01:32:55 +00:00
|
|
|
|
2023-03-09 23:40:55 +00:00
|
|
|
server.rpc("engine_newPayloadV1") do(payload: ExecutionPayloadV1) -> PayloadStatusV1:
|
2023-10-23 02:25:03 +00:00
|
|
|
return engine.newPayload(Version.V1, payload.executionPayload)
|
2023-05-16 13:52:44 +00:00
|
|
|
|
2023-08-08 07:29:23 +00:00
|
|
|
server.rpc("engine_newPayloadV2") do(payload: ExecutionPayload) -> PayloadStatusV1:
|
2023-10-23 02:25:03 +00:00
|
|
|
return engine.newPayload(Version.V2, payload)
|
2023-08-08 07:29:23 +00:00
|
|
|
|
|
|
|
server.rpc("engine_newPayloadV3") do(payload: ExecutionPayload,
|
2024-10-16 01:34:12 +00:00
|
|
|
expectedBlobVersionedHashes: Opt[seq[Hash32]],
|
|
|
|
parentBeaconBlockRoot: Opt[Hash32]) -> PayloadStatusV1:
|
2024-04-19 19:43:13 +00:00
|
|
|
return engine.newPayload(Version.V3, payload, expectedBlobVersionedHashes, parentBeaconBlockRoot)
|
2022-12-10 01:32:55 +00:00
|
|
|
|
2024-03-28 11:59:23 +00:00
|
|
|
server.rpc("engine_newPayloadV4") do(payload: ExecutionPayload,
|
2024-10-16 01:34:12 +00:00
|
|
|
expectedBlobVersionedHashes: Opt[seq[Hash32]],
|
2024-10-18 09:38:18 +00:00
|
|
|
parentBeaconBlockRoot: Opt[Hash32],
|
|
|
|
executionRequests: Opt[array[3, seq[byte]]]) -> PayloadStatusV1:
|
|
|
|
return engine.newPayload(Version.V4, payload,
|
|
|
|
expectedBlobVersionedHashes, parentBeaconBlockRoot, executionRequests)
|
2024-03-28 11:59:23 +00:00
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
server.rpc("engine_getPayloadV1") do(payloadId: Bytes8) -> ExecutionPayloadV1:
|
2023-10-23 13:59:57 +00:00
|
|
|
return engine.getPayload(Version.V1, payloadId).executionPayload.V1
|
2021-10-05 23:31:35 +00:00
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
server.rpc("engine_getPayloadV2") do(payloadId: Bytes8) -> GetPayloadV2Response:
|
2023-10-23 13:59:57 +00:00
|
|
|
return engine.getPayload(Version.V2, payloadId)
|
2021-10-05 23:31:35 +00:00
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
server.rpc("engine_getPayloadV3") do(payloadId: Bytes8) -> GetPayloadV3Response:
|
2023-08-27 01:23:45 +00:00
|
|
|
return engine.getPayloadV3(payloadId)
|
2023-08-08 07:29:23 +00:00
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
server.rpc("engine_getPayloadV4") do(payloadId: Bytes8) -> GetPayloadV4Response:
|
2024-03-28 11:59:23 +00:00
|
|
|
return engine.getPayloadV4(payloadId)
|
|
|
|
|
2023-08-27 01:23:45 +00:00
|
|
|
server.rpc("engine_exchangeTransitionConfigurationV1") do(
|
|
|
|
conf: TransitionConfigurationV1) -> TransitionConfigurationV1:
|
|
|
|
return engine.exchangeConf(conf)
|
2021-10-05 23:31:35 +00:00
|
|
|
|
2023-08-27 01:23:45 +00:00
|
|
|
server.rpc("engine_forkchoiceUpdatedV1") do(update: ForkchoiceStateV1,
|
2024-06-14 07:31:08 +00:00
|
|
|
attrs: Opt[PayloadAttributesV1]) -> ForkchoiceUpdatedResponse:
|
2023-10-23 02:25:03 +00:00
|
|
|
return engine.forkchoiceUpdated(Version.V1, update, attrs.payloadAttributes)
|
2022-02-22 08:55:04 +00:00
|
|
|
|
2023-08-27 01:23:45 +00:00
|
|
|
server.rpc("engine_forkchoiceUpdatedV2") do(update: ForkchoiceStateV1,
|
2024-06-14 07:31:08 +00:00
|
|
|
attrs: Opt[PayloadAttributes]) -> ForkchoiceUpdatedResponse:
|
2023-10-23 02:25:03 +00:00
|
|
|
return engine.forkchoiceUpdated(Version.V2, update, attrs)
|
2023-08-08 07:29:23 +00:00
|
|
|
|
2023-08-27 01:23:45 +00:00
|
|
|
server.rpc("engine_forkchoiceUpdatedV3") do(update: ForkchoiceStateV1,
|
2024-06-14 07:31:08 +00:00
|
|
|
attrs: Opt[PayloadAttributes]) -> ForkchoiceUpdatedResponse:
|
2023-10-23 02:25:03 +00:00
|
|
|
return engine.forkchoiceUpdated(Version.V3, update, attrs)
|
2023-03-09 23:40:55 +00:00
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
server.rpc("engine_getPayloadBodiesByHashV1") do(hashes: seq[Hash32]) ->
|
2024-06-14 07:31:08 +00:00
|
|
|
seq[Opt[ExecutionPayloadBodyV1]]:
|
2023-08-27 01:23:45 +00:00
|
|
|
return engine.getPayloadBodiesByHash(hashes)
|
2022-02-22 08:55:04 +00:00
|
|
|
|
2023-08-17 00:27:34 +00:00
|
|
|
server.rpc("engine_getPayloadBodiesByRangeV1") do(
|
2024-06-14 07:31:08 +00:00
|
|
|
start: Quantity, count: Quantity) -> seq[Opt[ExecutionPayloadBodyV1]]:
|
2023-08-27 01:23:45 +00:00
|
|
|
return engine.getPayloadBodiesByRange(start.uint64, count.uint64)
|
2024-05-29 07:20:50 +00:00
|
|
|
|
|
|
|
server.rpc("engine_getClientVersionV1") do(version: ClientVersionV1) ->
|
|
|
|
seq[ClientVersionV1]:
|
|
|
|
# TODO: what should we do with the `version` parameter?
|
|
|
|
return @[ClientVersionV1(
|
|
|
|
code: "NB",
|
|
|
|
name: NimbusName,
|
|
|
|
version: NimbusVersion,
|
|
|
|
commit: FixedBytes[4](GitRevisionBytes),
|
|
|
|
)]
|