diff --git a/nimbus/beacon/api_handler/api_forkchoice.nim b/nimbus/beacon/api_handler/api_forkchoice.nim index 3b521b1e0..ee77a1482 100644 --- a/nimbus/beacon/api_handler/api_forkchoice.nim +++ b/nimbus/beacon/api_handler/api_forkchoice.nim @@ -19,7 +19,7 @@ import {.push gcsafe, raises:[CatchableError].} -template validateVersion(attrsOpt, com) = +template validateVersion(attrsOpt, com, expectedVersion) = if attrsOpt.isSome: let attr = attrsOpt.get @@ -39,7 +39,13 @@ template validateVersion(attrsOpt, com) = raise invalidParams("if timestamp is earlier than Shanghai," & " payloadAttributes must be PayloadAttributesV1") + if version != expectedVersion: + raise invalidParams("forkChoiceUpdated" & $expectedVersion & + " expect PayloadAttributes" & $expectedVersion & + " but got PayloadAttributes" & $version) + proc forkchoiceUpdated*(ben: BeaconEngineRef, + expectedVersion: Version, update: ForkchoiceStateV1, attrsOpt: Option[PayloadAttributes]): ForkchoiceUpdatedResponse = @@ -49,7 +55,7 @@ proc forkchoiceUpdated*(ben: BeaconEngineRef, chain = ben.chain blockHash = ethHash update.headBlockHash - validateVersion(attrsOpt, com) + validateVersion(attrsOpt, com, expectedVersion) if blockHash == common.Hash256(): warn "Forkchoice requested update to zero hash" diff --git a/nimbus/beacon/api_handler/api_newpayload.nim b/nimbus/beacon/api_handler/api_newpayload.nim index 153aec86a..f679aac51 100644 --- a/nimbus/beacon/api_handler/api_newpayload.nim +++ b/nimbus/beacon/api_handler/api_newpayload.nim @@ -19,7 +19,7 @@ import {.push gcsafe, raises:[CatchableError].} -template validateVersion(com, timestamp, version) = +template validateVersion(com, timestamp, version, expectedVersion) = if com.isCancunOrLater(timestamp): if version != Version.V3: raise invalidParams("if timestamp is Cancun or later, " & @@ -38,7 +38,14 @@ template validateVersion(com, timestamp, version) = raise invalidParams("if timestamp is earlier than Shanghai, " & "payload must be ExecutionPayloadV1") + if version != expectedVersion: + raise invalidParams("newPayload" & $expectedVersion & + " expect ExecutionPayload" & $expectedVersion & + " but got ExecutionPayload" & $version) + + proc newPayload*(ben: BeaconEngineRef, + expectedVersion: Version, payload: ExecutionPayload, beaconRoot = none(Web3Hash)): PayloadStatusV1 = @@ -53,7 +60,7 @@ proc newPayload*(ben: BeaconEngineRef, timestamp = ethTime payload.timestamp version = payload.version - validateVersion(com, timestamp, version) + validateVersion(com, timestamp, version, expectedVersion) var header = blockHeader(payload, ethHash beaconRoot) let blockHash = ethHash payload.blockHash diff --git a/nimbus/rpc/engine_api.nim b/nimbus/rpc/engine_api.nim index 266557610..b284d4866 100644 --- a/nimbus/rpc/engine_api.nim +++ b/nimbus/rpc/engine_api.nim @@ -44,17 +44,17 @@ proc setupEngineAPI*(engine: BeaconEngineRef, server: RpcServer) = return methods.filterIt(supportedMethods.contains(it)) server.rpc("engine_newPayloadV1") do(payload: ExecutionPayloadV1) -> PayloadStatusV1: - return engine.newPayload(payload.executionPayload) + return engine.newPayload(Version.V1, payload.executionPayload) server.rpc("engine_newPayloadV2") do(payload: ExecutionPayload) -> PayloadStatusV1: - return engine.newPayload(payload) + return engine.newPayload(Version.V2, payload) server.rpc("engine_newPayloadV3") do(payload: ExecutionPayload, expectedBlobVersionedHashes: seq[Web3Hash], parentBeaconBlockRoot: Web3Hash) -> PayloadStatusV1: if not validateVersionedHashed(payload, expectedBlobVersionedHashes): return invalidStatus() - return engine.newPayload(payload, some(parentBeaconBlockRoot)) + return engine.newPayload(Version.V3, payload, some(parentBeaconBlockRoot)) server.rpc("engine_getPayloadV1") do(payloadId: PayloadID) -> ExecutionPayloadV1: return engine.getPayload(payloadId).executionPayload.V1 @@ -71,15 +71,15 @@ proc setupEngineAPI*(engine: BeaconEngineRef, server: RpcServer) = server.rpc("engine_forkchoiceUpdatedV1") do(update: ForkchoiceStateV1, attrs: Option[PayloadAttributesV1]) -> ForkchoiceUpdatedResponse: - return engine.forkchoiceUpdated(update, attrs.payloadAttributes) + return engine.forkchoiceUpdated(Version.V1, update, attrs.payloadAttributes) server.rpc("engine_forkchoiceUpdatedV2") do(update: ForkchoiceStateV1, attrs: Option[PayloadAttributes]) -> ForkchoiceUpdatedResponse: - return engine.forkchoiceUpdated(update, attrs) + return engine.forkchoiceUpdated(Version.V2, update, attrs) server.rpc("engine_forkchoiceUpdatedV3") do(update: ForkchoiceStateV1, attrs: Option[PayloadAttributes]) -> ForkchoiceUpdatedResponse: - return engine.forkchoiceUpdated(update, attrs) + return engine.forkchoiceUpdated(Version.V3, update, attrs) server.rpc("engine_getPayloadBodiesByHashV1") do(hashes: seq[Web3Hash]) -> seq[Option[ExecutionPayloadBodyV1]]: