implement Electra beacon API publishBlindedBlock (#6185)
This commit is contained in:
parent
41a3b62fe2
commit
ba45a1821c
|
@ -1034,11 +1034,7 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
||||||
return RestApiResponse.jsonError(Http400, BlockIncorrectFork)
|
return RestApiResponse.jsonError(Http400, BlockIncorrectFork)
|
||||||
|
|
||||||
withConsensusFork(currentEpochFork):
|
withConsensusFork(currentEpochFork):
|
||||||
when consensusFork >= ConsensusFork.Electra:
|
when consensusFork >= ConsensusFork.Deneb:
|
||||||
debugRaiseAssert "beacon API builder API"
|
|
||||||
return RestApiResponse.jsonError(
|
|
||||||
Http400, $consensusFork & " builder API unsupported")
|
|
||||||
elif consensusFork >= ConsensusFork.Deneb:
|
|
||||||
let
|
let
|
||||||
restBlock = decodeBodyJsonOrSsz(
|
restBlock = decodeBodyJsonOrSsz(
|
||||||
consensusFork.SignedBlindedBeaconBlock, body).valueOr:
|
consensusFork.SignedBlindedBeaconBlock, body).valueOr:
|
||||||
|
|
|
@ -173,6 +173,7 @@ RestJson.useDefaultSerializationFor(
|
||||||
SignedValidatorRegistrationV1,
|
SignedValidatorRegistrationV1,
|
||||||
SignedVoluntaryExit,
|
SignedVoluntaryExit,
|
||||||
SubmitBlindedBlockResponseDeneb,
|
SubmitBlindedBlockResponseDeneb,
|
||||||
|
SubmitBlindedBlockResponseElectra,
|
||||||
SyncAggregate,
|
SyncAggregate,
|
||||||
SyncAggregatorSelectionData,
|
SyncAggregatorSelectionData,
|
||||||
SyncCommittee,
|
SyncCommittee,
|
||||||
|
@ -328,6 +329,7 @@ type
|
||||||
bellatrix_mev.SignedBlindedBeaconBlock |
|
bellatrix_mev.SignedBlindedBeaconBlock |
|
||||||
capella_mev.SignedBlindedBeaconBlock |
|
capella_mev.SignedBlindedBeaconBlock |
|
||||||
deneb_mev.SignedBlindedBeaconBlock |
|
deneb_mev.SignedBlindedBeaconBlock |
|
||||||
|
electra_mev.SignedBlindedBeaconBlock |
|
||||||
SignedValidatorRegistrationV1 |
|
SignedValidatorRegistrationV1 |
|
||||||
SignedVoluntaryExit |
|
SignedVoluntaryExit |
|
||||||
Web3SignerRequest |
|
Web3SignerRequest |
|
||||||
|
|
|
@ -574,6 +574,7 @@ type
|
||||||
ProduceBlindedBlockResponse* = ForkedBlindedBeaconBlock
|
ProduceBlindedBlockResponse* = ForkedBlindedBeaconBlock
|
||||||
ProduceSyncCommitteeContributionResponse* = DataEnclosedObject[SyncCommitteeContribution]
|
ProduceSyncCommitteeContributionResponse* = DataEnclosedObject[SyncCommitteeContribution]
|
||||||
SubmitBlindedBlockResponseDeneb* = DataEnclosedObject[deneb_mev.ExecutionPayloadAndBlobsBundle]
|
SubmitBlindedBlockResponseDeneb* = DataEnclosedObject[deneb_mev.ExecutionPayloadAndBlobsBundle]
|
||||||
|
SubmitBlindedBlockResponseElectra* = DataEnclosedObject[electra_mev.ExecutionPayloadAndBlobsBundle]
|
||||||
GetValidatorsActivityResponse* = DataEnclosedObject[seq[RestActivityItem]]
|
GetValidatorsActivityResponse* = DataEnclosedObject[seq[RestActivityItem]]
|
||||||
GetValidatorsLivenessResponse* = DataEnclosedObject[seq[RestLivenessItem]]
|
GetValidatorsLivenessResponse* = DataEnclosedObject[seq[RestLivenessItem]]
|
||||||
SubmitBeaconCommitteeSelectionsResponse* = DataEnclosedObject[seq[RestBeaconCommitteeSelection]]
|
SubmitBeaconCommitteeSelectionsResponse* = DataEnclosedObject[seq[RestBeaconCommitteeSelection]]
|
||||||
|
|
|
@ -393,7 +393,8 @@ template kind*(
|
||||||
electra.TrustedBeaconBlockBody |
|
electra.TrustedBeaconBlockBody |
|
||||||
electra.SigVerifiedSignedBeaconBlock |
|
electra.SigVerifiedSignedBeaconBlock |
|
||||||
electra.MsgTrustedSignedBeaconBlock |
|
electra.MsgTrustedSignedBeaconBlock |
|
||||||
electra.TrustedSignedBeaconBlock]): ConsensusFork =
|
electra.TrustedSignedBeaconBlock |
|
||||||
|
electra_mev.SignedBlindedBeaconBlock]): ConsensusFork =
|
||||||
ConsensusFork.Electra
|
ConsensusFork.Electra
|
||||||
|
|
||||||
template BeaconState*(kind: static ConsensusFork): auto =
|
template BeaconState*(kind: static ConsensusFork): auto =
|
||||||
|
@ -507,7 +508,9 @@ template MaybeBlindedBeaconBlock*(kind: static ConsensusFork): auto =
|
||||||
static: raiseAssert "Unreachable"
|
static: raiseAssert "Unreachable"
|
||||||
|
|
||||||
template SignedBlindedBeaconBlock*(kind: static ConsensusFork): auto =
|
template SignedBlindedBeaconBlock*(kind: static ConsensusFork): auto =
|
||||||
when kind == ConsensusFork.Deneb:
|
when kind == ConsensusFork.Electra:
|
||||||
|
typedesc[electra_mev.SignedBlindedBeaconBlock]
|
||||||
|
elif kind == ConsensusFork.Deneb:
|
||||||
typedesc[deneb_mev.SignedBlindedBeaconBlock]
|
typedesc[deneb_mev.SignedBlindedBeaconBlock]
|
||||||
elif kind == ConsensusFork.Capella or kind == ConsensusFork.Bellatrix:
|
elif kind == ConsensusFork.Capella or kind == ConsensusFork.Bellatrix:
|
||||||
static: raiseAssert "Unsupported"
|
static: raiseAssert "Unsupported"
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
# beacon_chain
|
||||||
|
# Copyright (c) 2024 Status Research & Development GmbH
|
||||||
|
# Licensed and distributed under either of
|
||||||
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||||
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
|
{.push raises: [].}
|
||||||
|
|
||||||
|
import
|
||||||
|
chronos, presto/client,
|
||||||
|
".."/eth2_apis/[rest_types, eth2_rest_serialization]
|
||||||
|
|
||||||
|
export chronos, client, rest_types, eth2_rest_serialization
|
||||||
|
|
||||||
|
proc submitBlindedBlock*(body: electra_mev.SignedBlindedBeaconBlock
|
||||||
|
): RestPlainResponse {.
|
||||||
|
rest, endpoint: "/eth/v1/builder/blinded_blocks",
|
||||||
|
meth: MethodPost, connection: {Dedicated, Close}.}
|
||||||
|
## https://github.com/ethereum/builder-specs/blob/v0.4.0/apis/builder/blinded_blocks.yaml
|
|
@ -42,7 +42,7 @@ import
|
||||||
".."/[conf, beacon_clock, beacon_node],
|
".."/[conf, beacon_clock, beacon_node],
|
||||||
"."/[
|
"."/[
|
||||||
keystore_management, slashing_protection, validator_duties, validator_pool],
|
keystore_management, slashing_protection, validator_duties, validator_pool],
|
||||||
".."/spec/mev/rest_deneb_mev_calls
|
".."/spec/mev/[rest_deneb_mev_calls, rest_electra_mev_calls]
|
||||||
|
|
||||||
from std/sequtils import countIt, foldl, mapIt
|
from std/sequtils import countIt, foldl, mapIt
|
||||||
from eth/async_utils import awaitWithTimeout
|
from eth/async_utils import awaitWithTimeout
|
||||||
|
|
|
@ -15,6 +15,7 @@ import ../beacon_node
|
||||||
from eth/async_utils import awaitWithTimeout
|
from eth/async_utils import awaitWithTimeout
|
||||||
from ../spec/datatypes/bellatrix import SignedBeaconBlock
|
from ../spec/datatypes/bellatrix import SignedBeaconBlock
|
||||||
from ../spec/mev/rest_deneb_mev_calls import submitBlindedBlock
|
from ../spec/mev/rest_deneb_mev_calls import submitBlindedBlock
|
||||||
|
from ../spec/mev/rest_electra_mev_calls import submitBlindedBlock
|
||||||
|
|
||||||
const
|
const
|
||||||
BUILDER_BLOCK_SUBMISSION_DELAY_TOLERANCE = 5.seconds
|
BUILDER_BLOCK_SUBMISSION_DELAY_TOLERANCE = 5.seconds
|
||||||
|
@ -43,7 +44,9 @@ macro copyFields*(
|
||||||
|
|
||||||
proc unblindAndRouteBlockMEV*(
|
proc unblindAndRouteBlockMEV*(
|
||||||
node: BeaconNode, payloadBuilderRestClient: RestClientRef,
|
node: BeaconNode, payloadBuilderRestClient: RestClientRef,
|
||||||
blindedBlock: deneb_mev.SignedBlindedBeaconBlock):
|
blindedBlock:
|
||||||
|
deneb_mev.SignedBlindedBeaconBlock |
|
||||||
|
electra_mev.SignedBlindedBeaconBlock):
|
||||||
Future[Result[Opt[BlockRef], string]] {.async: (raises: [CancelledError]).} =
|
Future[Result[Opt[BlockRef], string]] {.async: (raises: [CancelledError]).} =
|
||||||
const consensusFork = typeof(blindedBlock).kind
|
const consensusFork = typeof(blindedBlock).kind
|
||||||
|
|
||||||
|
@ -76,14 +79,19 @@ proc unblindAndRouteBlockMEV*(
|
||||||
return err("submitBlindedBlock failed with HTTP error code " &
|
return err("submitBlindedBlock failed with HTTP error code " &
|
||||||
$response.status & ": " & $shortLog(blindedBlock))
|
$response.status & ": " & $shortLog(blindedBlock))
|
||||||
|
|
||||||
let
|
when blindedBlock is deneb_mev.SignedBlindedBeaconBlock:
|
||||||
res = decodeBytes(
|
let res = decodeBytes(
|
||||||
SubmitBlindedBlockResponseDeneb, response.data, response.contentType)
|
SubmitBlindedBlockResponseDeneb, response.data, response.contentType)
|
||||||
|
elif blindedBlock is electra_mev.SignedBlindedBeaconBlock:
|
||||||
|
let res = decodeBytes(
|
||||||
|
SubmitBlindedBlockResponseElectra, response.data, response.contentType)
|
||||||
|
else:
|
||||||
|
static: doAssert false
|
||||||
|
|
||||||
bundle = res.valueOr:
|
let bundle = res.valueOr:
|
||||||
return err("Could not decode " & $consensusFork & " blinded block: " & $res.error &
|
return err("Could not decode " & $consensusFork & " blinded block: " & $res.error &
|
||||||
" with HTTP status " & $response.status & ", Content-Type " &
|
" with HTTP status " & $response.status & ", Content-Type " &
|
||||||
$response.contentType & " and content " & $response.data)
|
$response.contentType & " and content " & $response.data)
|
||||||
|
|
||||||
template execution_payload: untyped = bundle.data.execution_payload
|
template execution_payload: untyped = bundle.data.execution_payload
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue