implement Electra beacon API publishBlindedBlock (#6185)

This commit is contained in:
tersec 2024-04-08 16:03:20 +00:00 committed by GitHub
parent 41a3b62fe2
commit ba45a1821c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 45 additions and 15 deletions

View File

@ -1034,11 +1034,7 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
return RestApiResponse.jsonError(Http400, BlockIncorrectFork)
withConsensusFork(currentEpochFork):
when consensusFork >= ConsensusFork.Electra:
debugRaiseAssert "beacon API builder API"
return RestApiResponse.jsonError(
Http400, $consensusFork & " builder API unsupported")
elif consensusFork >= ConsensusFork.Deneb:
when consensusFork >= ConsensusFork.Deneb:
let
restBlock = decodeBodyJsonOrSsz(
consensusFork.SignedBlindedBeaconBlock, body).valueOr:

View File

@ -173,6 +173,7 @@ RestJson.useDefaultSerializationFor(
SignedValidatorRegistrationV1,
SignedVoluntaryExit,
SubmitBlindedBlockResponseDeneb,
SubmitBlindedBlockResponseElectra,
SyncAggregate,
SyncAggregatorSelectionData,
SyncCommittee,
@ -328,6 +329,7 @@ type
bellatrix_mev.SignedBlindedBeaconBlock |
capella_mev.SignedBlindedBeaconBlock |
deneb_mev.SignedBlindedBeaconBlock |
electra_mev.SignedBlindedBeaconBlock |
SignedValidatorRegistrationV1 |
SignedVoluntaryExit |
Web3SignerRequest |

View File

@ -574,6 +574,7 @@ type
ProduceBlindedBlockResponse* = ForkedBlindedBeaconBlock
ProduceSyncCommitteeContributionResponse* = DataEnclosedObject[SyncCommitteeContribution]
SubmitBlindedBlockResponseDeneb* = DataEnclosedObject[deneb_mev.ExecutionPayloadAndBlobsBundle]
SubmitBlindedBlockResponseElectra* = DataEnclosedObject[electra_mev.ExecutionPayloadAndBlobsBundle]
GetValidatorsActivityResponse* = DataEnclosedObject[seq[RestActivityItem]]
GetValidatorsLivenessResponse* = DataEnclosedObject[seq[RestLivenessItem]]
SubmitBeaconCommitteeSelectionsResponse* = DataEnclosedObject[seq[RestBeaconCommitteeSelection]]

View File

@ -393,7 +393,8 @@ template kind*(
electra.TrustedBeaconBlockBody |
electra.SigVerifiedSignedBeaconBlock |
electra.MsgTrustedSignedBeaconBlock |
electra.TrustedSignedBeaconBlock]): ConsensusFork =
electra.TrustedSignedBeaconBlock |
electra_mev.SignedBlindedBeaconBlock]): ConsensusFork =
ConsensusFork.Electra
template BeaconState*(kind: static ConsensusFork): auto =
@ -507,7 +508,9 @@ template MaybeBlindedBeaconBlock*(kind: static ConsensusFork): auto =
static: raiseAssert "Unreachable"
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]
elif kind == ConsensusFork.Capella or kind == ConsensusFork.Bellatrix:
static: raiseAssert "Unsupported"

View File

@ -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

View File

@ -42,7 +42,7 @@ import
".."/[conf, beacon_clock, beacon_node],
"."/[
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 eth/async_utils import awaitWithTimeout

View File

@ -15,6 +15,7 @@ import ../beacon_node
from eth/async_utils import awaitWithTimeout
from ../spec/datatypes/bellatrix import SignedBeaconBlock
from ../spec/mev/rest_deneb_mev_calls import submitBlindedBlock
from ../spec/mev/rest_electra_mev_calls import submitBlindedBlock
const
BUILDER_BLOCK_SUBMISSION_DELAY_TOLERANCE = 5.seconds
@ -43,7 +44,9 @@ macro copyFields*(
proc unblindAndRouteBlockMEV*(
node: BeaconNode, payloadBuilderRestClient: RestClientRef,
blindedBlock: deneb_mev.SignedBlindedBeaconBlock):
blindedBlock:
deneb_mev.SignedBlindedBeaconBlock |
electra_mev.SignedBlindedBeaconBlock):
Future[Result[Opt[BlockRef], string]] {.async: (raises: [CancelledError]).} =
const consensusFork = typeof(blindedBlock).kind
@ -76,14 +79,19 @@ proc unblindAndRouteBlockMEV*(
return err("submitBlindedBlock failed with HTTP error code " &
$response.status & ": " & $shortLog(blindedBlock))
let
res = decodeBytes(
when blindedBlock is deneb_mev.SignedBlindedBeaconBlock:
let res = decodeBytes(
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:
return err("Could not decode " & $consensusFork & " blinded block: " & $res.error &
" with HTTP status " & $response.status & ", Content-Type " &
$response.contentType & " and content " & $response.data)
let bundle = res.valueOr:
return err("Could not decode " & $consensusFork & " blinded block: " & $res.error &
" with HTTP status " & $response.status & ", Content-Type " &
$response.contentType & " and content " & $response.data)
template execution_payload: untyped = bundle.data.execution_payload