consistently use SignedBlindedBeaconBlockContents; remove more Bellatrix Builder API remnants (#5493)
This commit is contained in:
parent
48197e4d55
commit
edc5c03230
|
@ -994,16 +994,16 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
||||||
case currentEpochFork
|
case currentEpochFork
|
||||||
of ConsensusFork.Deneb:
|
of ConsensusFork.Deneb:
|
||||||
let
|
let
|
||||||
restBlock = decodeBodyJsonOrSsz(deneb_mev.SignedBlindedBeaconBlock,
|
restBlockContents = decodeBodyJsonOrSsz(deneb_mev.SignedBlindedBeaconBlockContents,
|
||||||
body).valueOr:
|
body).valueOr:
|
||||||
return RestApiResponse.jsonError(error)
|
return RestApiResponse.jsonError(error)
|
||||||
|
|
||||||
payloadBuilderClient = node.getPayloadBuilderClient(
|
payloadBuilderClient = node.getPayloadBuilderClient(
|
||||||
restBlock.message.proposer_index).valueOr:
|
restBlockContents.signed_blinded_block.message.proposer_index).valueOr:
|
||||||
return RestApiResponse.jsonError(
|
return RestApiResponse.jsonError(
|
||||||
Http400, "Unable to initialize payload builder client: " & $error)
|
Http400, "Unable to initialize payload builder client: " & $error)
|
||||||
res = await node.unblindAndRouteBlockMEV(
|
res = await node.unblindAndRouteBlockMEV(
|
||||||
payloadBuilderClient, restBlock)
|
payloadBuilderClient, restBlockContents)
|
||||||
|
|
||||||
if res.isErr():
|
if res.isErr():
|
||||||
return RestApiResponse.jsonError(
|
return RestApiResponse.jsonError(
|
||||||
|
|
|
@ -119,3 +119,10 @@ func shortLog*(v: SignedBlindedBeaconBlock): auto =
|
||||||
blck: shortLog(v.message),
|
blck: shortLog(v.message),
|
||||||
signature: shortLog(v.signature)
|
signature: shortLog(v.signature)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# needs to match SignedBlindedBeaconBlock
|
||||||
|
func shortLog*(v: SignedBlindedBeaconBlockContents): auto =
|
||||||
|
(
|
||||||
|
blck: shortLog(v.signed_blinded_block.message),
|
||||||
|
signature: shortLog(v.signed_blinded_block.signature)
|
||||||
|
)
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
# Standard library
|
# Standard library
|
||||||
std/[os, tables, sequtils],
|
std/[os, tables],
|
||||||
|
|
||||||
# Nimble packages
|
# Nimble packages
|
||||||
stew/[assign2, byteutils],
|
stew/[assign2, byteutils],
|
||||||
|
@ -41,8 +41,9 @@ 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_capella_mev_calls
|
".."/spec/mev/[rest_capella_mev_calls, rest_deneb_mev_calls]
|
||||||
|
|
||||||
|
from std/sequtils import mapIt
|
||||||
from eth/async_utils import awaitWithTimeout
|
from eth/async_utils import awaitWithTimeout
|
||||||
|
|
||||||
const
|
const
|
||||||
|
@ -563,25 +564,20 @@ proc makeBeaconBlockForHeadAndSlot*(
|
||||||
withdrawals_root = Opt.none(Eth2Digest))
|
withdrawals_root = Opt.none(Eth2Digest))
|
||||||
|
|
||||||
proc getBlindedExecutionPayload[
|
proc getBlindedExecutionPayload[
|
||||||
EPH: bellatrix.ExecutionPayloadHeader | capella.ExecutionPayloadHeader |
|
EPH: capella.ExecutionPayloadHeader | deneb.ExecutionPayloadHeader](
|
||||||
deneb.ExecutionPayloadHeader](
|
|
||||||
node: BeaconNode, payloadBuilderClient: RestClientRef, slot: Slot,
|
node: BeaconNode, payloadBuilderClient: RestClientRef, slot: Slot,
|
||||||
executionBlockRoot: Eth2Digest, pubkey: ValidatorPubKey):
|
executionBlockRoot: Eth2Digest, pubkey: ValidatorPubKey):
|
||||||
Future[BlindedBlockResult[EPH]] {.async.} =
|
Future[BlindedBlockResult[EPH]] {.async.} =
|
||||||
when EPH is deneb.ExecutionPayloadHeader:
|
when EPH is deneb.ExecutionPayloadHeader:
|
||||||
let blindedHeader = default(RestResponse[GetHeaderResponseDeneb])
|
let blindedHeader = awaitWithTimeout(
|
||||||
debugRaiseAssert $denebImplementationMissing &
|
payloadBuilderClient.getHeaderDeneb(slot, executionBlockRoot, pubkey),
|
||||||
": makeBlindedBeaconBlockForHeadAndSlot"
|
BUILDER_PROPOSAL_DELAY_TOLERANCE):
|
||||||
|
return err "Timeout obtaining Deneb blinded header from builder"
|
||||||
elif EPH is capella.ExecutionPayloadHeader:
|
elif EPH is capella.ExecutionPayloadHeader:
|
||||||
let blindedHeader = awaitWithTimeout(
|
let blindedHeader = awaitWithTimeout(
|
||||||
payloadBuilderClient.getHeaderCapella(slot, executionBlockRoot, pubkey),
|
payloadBuilderClient.getHeaderCapella(slot, executionBlockRoot, pubkey),
|
||||||
BUILDER_PROPOSAL_DELAY_TOLERANCE):
|
BUILDER_PROPOSAL_DELAY_TOLERANCE):
|
||||||
return err "Timeout obtaining Capella blinded header from builder"
|
return err "Timeout obtaining Capella blinded header from builder"
|
||||||
elif EPH is bellatrix.ExecutionPayloadHeader:
|
|
||||||
let blindedHeader = awaitWithTimeout(
|
|
||||||
payloadBuilderClient.getHeaderBellatrix(slot, executionBlockRoot, pubkey),
|
|
||||||
BUILDER_PROPOSAL_DELAY_TOLERANCE):
|
|
||||||
return err "Timeout obtaining Bellatrix blinded header from builder"
|
|
||||||
else:
|
else:
|
||||||
static: doAssert false
|
static: doAssert false
|
||||||
|
|
||||||
|
@ -636,7 +632,7 @@ func constructPlainBlindedBlock[
|
||||||
|
|
||||||
blindedBlock
|
blindedBlock
|
||||||
|
|
||||||
proc blindedBlockCheckSlashingAndSign[T](
|
proc blindedBlockCheckSlashingAndSign[T: capella_mev.SignedBlindedBeaconBlock](
|
||||||
node: BeaconNode, slot: Slot, validator: AttachedValidator,
|
node: BeaconNode, slot: Slot, validator: AttachedValidator,
|
||||||
validator_index: ValidatorIndex, nonsignedBlindedBlock: T):
|
validator_index: ValidatorIndex, nonsignedBlindedBlock: T):
|
||||||
Future[Result[T, string]] {.async.} =
|
Future[Result[T, string]] {.async.} =
|
||||||
|
@ -671,19 +667,25 @@ proc blindedBlockCheckSlashingAndSign[T](
|
||||||
|
|
||||||
return ok blindedBlock
|
return ok blindedBlock
|
||||||
|
|
||||||
|
proc blindedBlockCheckSlashingAndSign[
|
||||||
|
T: deneb_mev.SignedBlindedBeaconBlockContents](
|
||||||
|
node: BeaconNode, slot: Slot, validator: AttachedValidator,
|
||||||
|
validator_index: ValidatorIndex, nonsignedBlindedBlock: T):
|
||||||
|
Future[Result[T, string]] {.async.} =
|
||||||
|
debugRaiseAssert $denebImplementationMissing
|
||||||
|
|
||||||
proc getUnsignedBlindedBeaconBlock[
|
proc getUnsignedBlindedBeaconBlock[
|
||||||
T: capella_mev.SignedBlindedBeaconBlock |
|
T: capella_mev.SignedBlindedBeaconBlock |
|
||||||
deneb_mev.SignedBlindedBeaconBlock](
|
deneb_mev.SignedBlindedBeaconBlock](
|
||||||
node: BeaconNode, slot: Slot, validator: AttachedValidator,
|
node: BeaconNode, slot: Slot, validator: AttachedValidator,
|
||||||
validator_index: ValidatorIndex, forkedBlock: ForkedBeaconBlock,
|
validator_index: ValidatorIndex, forkedBlock: ForkedBeaconBlock,
|
||||||
executionPayloadHeader: bellatrix.ExecutionPayloadHeader |
|
executionPayloadHeader: capella.ExecutionPayloadHeader |
|
||||||
capella.ExecutionPayloadHeader |
|
|
||||||
deneb.ExecutionPayloadHeader): Result[T, string] =
|
deneb.ExecutionPayloadHeader): Result[T, string] =
|
||||||
withBlck(forkedBlock):
|
withBlck(forkedBlock):
|
||||||
when consensusFork >= ConsensusFork.Deneb:
|
when consensusFork >= ConsensusFork.Deneb:
|
||||||
debugRaiseAssert $denebImplementationMissing & ": getUnsignedBlindedBeaconBlock"
|
debugRaiseAssert $denebImplementationMissing & ": getUnsignedBlindedBeaconBlock"
|
||||||
return err("getUnsignedBlindedBeaconBlock: Deneb blinded block creation not implemented")
|
return err("getUnsignedBlindedBeaconBlock: Deneb blinded block creation not implemented")
|
||||||
elif consensusFork >= ConsensusFork.Bellatrix:
|
elif consensusFork >= ConsensusFork.Capella:
|
||||||
when not (
|
when not (
|
||||||
(T is capella_mev.SignedBlindedBeaconBlock and
|
(T is capella_mev.SignedBlindedBeaconBlock and
|
||||||
consensusFork == ConsensusFork.Capella)):
|
consensusFork == ConsensusFork.Capella)):
|
||||||
|
@ -692,7 +694,7 @@ proc getUnsignedBlindedBeaconBlock[
|
||||||
return ok constructSignableBlindedBlock[T](
|
return ok constructSignableBlindedBlock[T](
|
||||||
forkyBlck, executionPayloadHeader)
|
forkyBlck, executionPayloadHeader)
|
||||||
else:
|
else:
|
||||||
return err("getUnsignedBlindedBeaconBlock: attempt to construct pre-Bellatrix blinded block")
|
return err("getUnsignedBlindedBeaconBlock: attempt to construct pre-Capella blinded block")
|
||||||
|
|
||||||
proc getBlindedBlockParts[EPH: ForkyExecutionPayloadHeader](
|
proc getBlindedBlockParts[EPH: ForkyExecutionPayloadHeader](
|
||||||
node: BeaconNode, payloadBuilderClient: RestClientRef, head: BlockRef,
|
node: BeaconNode, payloadBuilderClient: RestClientRef, head: BlockRef,
|
||||||
|
@ -772,7 +774,7 @@ proc getBlindedBlockParts[EPH: ForkyExecutionPayloadHeader](
|
||||||
|
|
||||||
proc getBuilderBid[
|
proc getBuilderBid[
|
||||||
SBBB: capella_mev.SignedBlindedBeaconBlock |
|
SBBB: capella_mev.SignedBlindedBeaconBlock |
|
||||||
deneb_mev.SignedBlindedBeaconBlock](
|
deneb_mev.SignedBlindedBeaconBlockContents](
|
||||||
node: BeaconNode, payloadBuilderClient: RestClientRef, head: BlockRef,
|
node: BeaconNode, payloadBuilderClient: RestClientRef, head: BlockRef,
|
||||||
validator: AttachedValidator, slot: Slot, randao: ValidatorSig,
|
validator: AttachedValidator, slot: Slot, randao: ValidatorSig,
|
||||||
validator_index: ValidatorIndex):
|
validator_index: ValidatorIndex):
|
||||||
|
@ -781,7 +783,7 @@ proc getBuilderBid[
|
||||||
## Used by the BN's own validators, but not the REST server
|
## Used by the BN's own validators, but not the REST server
|
||||||
when SBBB is capella_mev.SignedBlindedBeaconBlock:
|
when SBBB is capella_mev.SignedBlindedBeaconBlock:
|
||||||
type EPH = capella.ExecutionPayloadHeader
|
type EPH = capella.ExecutionPayloadHeader
|
||||||
elif SBBB is deneb_mev.SignedBlindedBeaconBlock:
|
elif SBBB is deneb_mev.SignedBlindedBeaconBlockContents:
|
||||||
type EPH = deneb.ExecutionPayloadHeader
|
type EPH = deneb.ExecutionPayloadHeader
|
||||||
else:
|
else:
|
||||||
static: doAssert false
|
static: doAssert false
|
||||||
|
@ -884,11 +886,9 @@ proc makeBlindedBeaconBlockForHeadAndSlot*[
|
||||||
|
|
||||||
let (executionPayloadHeader, bidValue, forkedBlck) = blindedBlockParts.get
|
let (executionPayloadHeader, bidValue, forkedBlck) = blindedBlockParts.get
|
||||||
withBlck(forkedBlck):
|
withBlck(forkedBlck):
|
||||||
when consensusFork >= ConsensusFork.Deneb:
|
when consensusFork >= ConsensusFork.Capella:
|
||||||
debugRaiseAssert $denebImplementationMissing & ": makeBlindedBeaconBlockForHeadAndSlot"
|
when ((consensusFork == ConsensusFork.Deneb and
|
||||||
elif consensusFork >= ConsensusFork.Bellatrix:
|
EPH is deneb.ExecutionPayloadHeader) or
|
||||||
when ((consensusFork == ConsensusFork.Bellatrix and
|
|
||||||
EPH is bellatrix.ExecutionPayloadHeader) or
|
|
||||||
(consensusFork == ConsensusFork.Capella and
|
(consensusFork == ConsensusFork.Capella and
|
||||||
EPH is capella.ExecutionPayloadHeader)):
|
EPH is capella.ExecutionPayloadHeader)):
|
||||||
return ok (constructPlainBlindedBlock[BBB, EPH](
|
return ok (constructPlainBlindedBlock[BBB, EPH](
|
||||||
|
@ -896,7 +896,7 @@ proc makeBlindedBeaconBlockForHeadAndSlot*[
|
||||||
else:
|
else:
|
||||||
return err("makeBlindedBeaconBlockForHeadAndSlot: mismatched block/payload types")
|
return err("makeBlindedBeaconBlockForHeadAndSlot: mismatched block/payload types")
|
||||||
else:
|
else:
|
||||||
return err("Attempt to create pre-Bellatrix blinded block")
|
return err("Attempt to create pre-Capella blinded block")
|
||||||
|
|
||||||
proc collectBidFutures(
|
proc collectBidFutures(
|
||||||
SBBB: typedesc, EPS: typedesc, node: BeaconNode,
|
SBBB: typedesc, EPS: typedesc, node: BeaconNode,
|
||||||
|
@ -1190,7 +1190,8 @@ proc proposeBlock(node: BeaconNode,
|
||||||
return
|
return
|
||||||
if slot.epoch >= node.dag.cfg.DENEB_FORK_EPOCH:
|
if slot.epoch >= node.dag.cfg.DENEB_FORK_EPOCH:
|
||||||
proposeBlockContinuation(
|
proposeBlockContinuation(
|
||||||
deneb_mev.SignedBlindedBeaconBlock, deneb.ExecutionPayloadForSigning)
|
deneb_mev.SignedBlindedBeaconBlockContents,
|
||||||
|
deneb.ExecutionPayloadForSigning)
|
||||||
elif slot.epoch >= node.dag.cfg.CAPELLA_FORK_EPOCH:
|
elif slot.epoch >= node.dag.cfg.CAPELLA_FORK_EPOCH:
|
||||||
proposeBlockContinuation(
|
proposeBlockContinuation(
|
||||||
capella_mev.SignedBlindedBeaconBlock, capella.ExecutionPayloadForSigning)
|
capella_mev.SignedBlindedBeaconBlock, capella.ExecutionPayloadForSigning)
|
||||||
|
|
|
@ -16,7 +16,7 @@ from ../spec/datatypes/bellatrix import SignedBeaconBlock
|
||||||
from ../spec/mev/rest_capella_mev_calls import submitBlindedBlock
|
from ../spec/mev/rest_capella_mev_calls import submitBlindedBlock
|
||||||
|
|
||||||
const
|
const
|
||||||
BUILDER_BLOCK_SUBMISSION_DELAY_TOLERANCE = 4.seconds
|
BUILDER_BLOCK_SUBMISSION_DELAY_TOLERANCE = 5.seconds
|
||||||
|
|
||||||
declareCounter beacon_block_builder_proposed,
|
declareCounter beacon_block_builder_proposed,
|
||||||
"Number of beacon chain blocks produced using an external block builder"
|
"Number of beacon chain blocks produced using an external block builder"
|
||||||
|
@ -76,7 +76,7 @@ proc unblindAndRouteBlockMEV*(
|
||||||
else:
|
else:
|
||||||
# Signature provided is consistent with unblinded execution payload,
|
# Signature provided is consistent with unblinded execution payload,
|
||||||
# so construct full beacon block
|
# so construct full beacon block
|
||||||
# https://github.com/ethereum/builder-specs/blob/v0.2.0/specs/validator.md#block-proposal
|
# https://github.com/ethereum/builder-specs/blob/v0.3.0/specs/bellatrix/validator.md#block-proposal
|
||||||
var signedBlock = capella.SignedBeaconBlock(
|
var signedBlock = capella.SignedBeaconBlock(
|
||||||
signature: blindedBlock.signature)
|
signature: blindedBlock.signature)
|
||||||
copyFields(
|
copyFields(
|
||||||
|
@ -111,17 +111,17 @@ proc unblindAndRouteBlockMEV*(
|
||||||
debug "unblindAndRouteBlockMEV: submitBlindedBlock failed",
|
debug "unblindAndRouteBlockMEV: submitBlindedBlock failed",
|
||||||
blindedBlock, payloadStatus = unblindedPayload.status
|
blindedBlock, payloadStatus = unblindedPayload.status
|
||||||
|
|
||||||
# https://github.com/ethereum/builder-specs/blob/v0.2.0/specs/validator.md#proposer-slashing
|
# 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
|
# This means if a validator publishes a signature for a
|
||||||
# `BlindedBeaconBlock` (via a dissemination of a
|
# `BlindedBeaconBlock` (via a dissemination of a
|
||||||
# `SignedBlindedBeaconBlock`) then the validator **MUST** not use the
|
# `SignedBlindedBeaconBlock`) then the validator **MUST** not use the
|
||||||
# local build process as a fallback, even in the event of some failure
|
# local build process as a fallback, even in the event of some failure
|
||||||
# with the external buildernetwork.
|
# with the external builder network.
|
||||||
return err("unblindAndRouteBlockMEV error")
|
return err("unblindAndRouteBlockMEV error")
|
||||||
|
|
||||||
# TODO currently cannot be combined into one generic function
|
# TODO currently cannot be combined into one generic function
|
||||||
proc unblindAndRouteBlockMEV*(
|
proc unblindAndRouteBlockMEV*(
|
||||||
node: BeaconNode, payloadBuilderRestClient: RestClientRef,
|
node: BeaconNode, payloadBuilderRestClient: RestClientRef,
|
||||||
blindedBlock: deneb_mev.SignedBlindedBeaconBlock):
|
blindedBlockContents: deneb_mev.SignedBlindedBeaconBlockContents):
|
||||||
Future[Result[Opt[BlockRef], string]] {.async.} =
|
Future[Result[Opt[BlockRef], string]] {.async.} =
|
||||||
debugRaiseAssert $denebImplementationMissing & ": makeBlindedBeaconBlockForHeadAndSlot"
|
debugRaiseAssert $denebImplementationMissing & ": makeBlindedBeaconBlockForHeadAndSlot"
|
||||||
|
|
Loading…
Reference in New Issue