mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-02-02 09:46:26 +00:00
implement deneb block and blob unblinding (#5496)
This commit is contained in:
parent
722deedd2b
commit
ec1d98cc3a
@ -9,11 +9,13 @@
|
||||
|
||||
import std/macros
|
||||
import metrics
|
||||
import stew/assign2
|
||||
import ../beacon_node
|
||||
|
||||
from eth/async_utils import awaitWithTimeout
|
||||
from ../spec/datatypes/bellatrix import SignedBeaconBlock
|
||||
from ../spec/mev/rest_capella_mev_calls import submitBlindedBlock
|
||||
from ../spec/mev/rest_deneb_mev_calls import submitBlindedBlock
|
||||
|
||||
const
|
||||
BUILDER_BLOCK_SUBMISSION_DELAY_TOLERANCE = 5.seconds
|
||||
@ -124,4 +126,79 @@ proc unblindAndRouteBlockMEV*(
|
||||
node: BeaconNode, payloadBuilderRestClient: RestClientRef,
|
||||
blindedBlockContents: deneb_mev.SignedBlindedBeaconBlockContents):
|
||||
Future[Result[Opt[BlockRef], string]] {.async.} =
|
||||
debugRaiseAssert $denebImplementationMissing & ": makeBlindedBeaconBlockForHeadAndSlot"
|
||||
template blindedBlock: untyped = blindedBlockContents.signed_blinded_block
|
||||
|
||||
info "Proposing blinded Builder API block and blobs",
|
||||
blindedBlock = shortLog(blindedBlock)
|
||||
|
||||
# By time submitBlindedBlock is called, must already have done slashing
|
||||
# protection check
|
||||
let unblindedPayload =
|
||||
try:
|
||||
awaitWithTimeout(
|
||||
payloadBuilderRestClient.submitBlindedBlock(blindedBlockContents),
|
||||
BUILDER_BLOCK_SUBMISSION_DELAY_TOLERANCE):
|
||||
return err("Submitting blinded block and blobs timed out")
|
||||
# From here on, including error paths, disallow local EL production by
|
||||
# returning Opt.some, regardless of whether on head or newBlock.
|
||||
except RestDecodingError as exc:
|
||||
return err("REST decoding error submitting blinded block and blobs: " & exc.msg)
|
||||
except CatchableError as exc:
|
||||
return err("exception in submitBlindedBlock: " & exc.msg)
|
||||
|
||||
const httpOk = 200
|
||||
if unblindedPayload.status == httpOk:
|
||||
if hash_tree_root(
|
||||
blindedBlock.message.body.execution_payload_header) !=
|
||||
hash_tree_root(unblindedPayload.data.data.execution_payload):
|
||||
debug "unblindAndRouteBlockMEV: unblinded payload doesn't match blinded payload",
|
||||
blindedPayload =
|
||||
blindedBlock.message.body.execution_payload_header
|
||||
else:
|
||||
# Signature provided is consistent with unblinded execution payload,
|
||||
# so construct full beacon block
|
||||
# https://github.com/ethereum/builder-specs/blob/v0.3.0/specs/bellatrix/validator.md#block-proposal
|
||||
var signedBlock = deneb.SignedBeaconBlock(
|
||||
signature: blindedBlock.signature)
|
||||
copyFields(
|
||||
signedBlock.message, blindedBlock.message,
|
||||
getFieldNames(typeof(signedBlock.message)))
|
||||
copyFields(
|
||||
signedBlock.message.body, blindedBlock.message.body,
|
||||
getFieldNames(typeof(signedBlock.message.body)))
|
||||
assign(
|
||||
signedBlock.message.body.execution_payload,
|
||||
unblindedPayload.data.data.execution_payload)
|
||||
|
||||
signedBlock.root = hash_tree_root(signedBlock.message)
|
||||
|
||||
doAssert signedBlock.root == hash_tree_root(blindedBlock.message)
|
||||
|
||||
debug "unblindAndRouteBlockMEV: proposing unblinded block and blobs",
|
||||
blck = shortLog(signedBlock)
|
||||
|
||||
let newBlockRef =
|
||||
(await node.router.routeSignedBeaconBlock(
|
||||
signedBlock, Opt.none(SignedBlobSidecars))).valueOr:
|
||||
# submitBlindedBlock has run, so don't allow fallback to run
|
||||
return err("routeSignedBeaconBlock error") # Errors logged in router
|
||||
|
||||
if newBlockRef.isSome:
|
||||
beacon_block_builder_proposed.inc()
|
||||
notice "Block proposed (MEV)",
|
||||
blockRoot = shortLog(signedBlock.root), blck = shortLog(signedBlock),
|
||||
signature = shortLog(signedBlock.signature)
|
||||
|
||||
discard $denebImplementationMissing & ": route unblinded blobs"
|
||||
|
||||
return ok newBlockRef
|
||||
else:
|
||||
debug "unblindAndRouteBlockMEV: submitBlindedBlock failed",
|
||||
blindedBlock, payloadStatus = unblindedPayload.status
|
||||
|
||||
# https://github.com/ethereum/builder-specs/blob/v0.3.0/specs/bellatrix/validator.md#proposer-slashing
|
||||
# This means if a validator publishes a signature for a
|
||||
# `BlindedBeaconBlock` (via a dissemination of a
|
||||
# `SignedBlindedBeaconBlock`) then the validator **MUST** not use the
|
||||
# local build process as a fallback, even in the event of some failure
|
||||
# with the external builder network.
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 201 KiB |
Loading…
x
Reference in New Issue
Block a user