Skip to content

Commit ab82386

Browse files
authored
track execution requests for builder API (#7103)
* track execution requests for builder API * insert the builder execution requests into the shim state transition
1 parent c7e5caf commit ab82386

File tree

4 files changed

+31
-47
lines changed

4 files changed

+31
-47
lines changed

beacon_chain/spec/mev/electra_mev.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ type
6868
message*: BlindedBeaconBlock
6969
signature*: ValidatorSig
7070

71+
# https://github.com/ethereum/builder-specs/blob/v0.5.0/specs/deneb/builder.md#executionpayloadandblobsbundle
7172
ExecutionPayloadAndBlobsBundle* = object
7273
execution_payload*: electra.ExecutionPayload
7374
blobs_bundle*: BlobsBundle

beacon_chain/spec/mev/fulu_mev.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type
7070
message*: BlindedBeaconBlock
7171
signature*: ValidatorSig
7272

73+
# https://github.com/ethereum/builder-specs/blob/v0.5.0/specs/deneb/builder.md#executionpayloadandblobsbundle
7374
ExecutionPayloadAndBlobsBundle* = object
7475
execution_payload*: ExecutionPayload
7576
blobs_bundle*: BlobsBundle

beacon_chain/spec/state_transition.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,4 +681,4 @@ proc makeBeaconBlock*(
681681
transactions_root = Opt.none Eth2Digest,
682682
execution_payload_root = Opt.none Eth2Digest,
683683
kzg_commitments = Opt.none KzgCommitments,
684-
execution_requests = default(ExecutionRequests))
684+
execution_requests = static(default(ExecutionRequests)))

beacon_chain/validators/beacon_validators.nim

Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ proc makeBeaconBlockForHeadAndSlot*(
449449
execution_payload_root: Opt[Eth2Digest],
450450
withdrawals_root: Opt[Eth2Digest],
451451
kzg_commitments: Opt[KzgCommitments],
452-
execution_requests: ExecutionRequests):
452+
builder_execution_requests: Opt[ExecutionRequests]):
453453
Future[ForkedBlockResult] {.async: (raises: [CancelledError]).} =
454454
# Advance state to the slot that we're proposing for
455455
var cache = StateCache()
@@ -528,8 +528,7 @@ proc makeBeaconBlockForHeadAndSlot*(
528528
slot, validator_index
529529
return err("Unable to get execution payload")
530530

531-
# Don't use the requests passed in, TODO remove that
532-
let execution_requests_actual =
531+
let execution_requests_actual = builder_execution_requests.valueOr:
533532
when PayloadType.kind >= ConsensusFork.Electra:
534533
# Don't want un-decoded SSZ going any further/deeper
535534
var
@@ -614,7 +613,9 @@ proc makeBeaconBlockForHeadAndSlot*(
614613
else:
615614
err(res.error)
616615

617-
# TODO what is this for
616+
# For VC, which only uses this for pre-Bellatrix blocks.
617+
# TODO move this into VC and just have it specify all these
618+
# Opt.none()'s directly
618619
proc makeBeaconBlockForHeadAndSlot*(
619620
PayloadType: type ForkyExecutionPayloadForSigning, node: BeaconNode, randao_reveal: ValidatorSig,
620621
validator_index: ValidatorIndex, graffiti: GraffitiBytes, head: BlockRef,
@@ -627,7 +628,7 @@ proc makeBeaconBlockForHeadAndSlot*(
627628
execution_payload_root = Opt.none(Eth2Digest),
628629
withdrawals_root = Opt.none(Eth2Digest),
629630
kzg_commitments = Opt.none(KzgCommitments),
630-
execution_requests = static(default(ExecutionRequests)))
631+
builder_execution_requests = static(Opt.none(ExecutionRequests)))
631632

632633
proc getBlindedExecutionPayload[
633634
EPH: deneb_mev.BlindedExecutionPayloadAndBlobsBundle |
@@ -673,8 +674,7 @@ proc getBlindedExecutionPayload[
673674
" with HTTP status " & $response.status & ", Content-Type " &
674675
$response.contentType & " and content " & $response.data)
675676
elif EPH is fulu_mev.BlindedExecutionPayloadAndBlobsBundle:
676-
677-
debugFuluComment "Because electra MEV isn't working yet, this is a placeholder copy"
677+
debugFuluComment "Because fulu MEV isn't working yet, this is a placeholder copy"
678678
let
679679
response = awaitWithTimeout(
680680
payloadBuilderClient.getHeaderFulu(
@@ -727,7 +727,8 @@ from ./message_router_mev import
727727

728728
func constructSignableBlindedBlock[T: deneb_mev.SignedBlindedBeaconBlock](
729729
blck: deneb.BeaconBlock,
730-
blindedBundle: deneb_mev.BlindedExecutionPayloadAndBlobsBundle): T =
730+
blindedBundle: deneb_mev.BlindedExecutionPayloadAndBlobsBundle,
731+
_: ExecutionRequests): T =
731732
# Leaves signature field default, to be filled in by caller
732733
const
733734
blckFields = getFieldNames(typeof(blck))
@@ -747,11 +748,13 @@ func constructSignableBlindedBlock[T: deneb_mev.SignedBlindedBeaconBlock](
747748

748749
blindedBlock
749750

750-
func constructSignableBlindedBlock[T: electra_mev.SignedBlindedBeaconBlock |
751-
fulu_mev.SignedBlindedBeaconBlock](
751+
func constructSignableBlindedBlock[T:
752+
electra_mev.SignedBlindedBeaconBlock | fulu_mev.SignedBlindedBeaconBlock](
752753
blck: electra.BeaconBlock | fulu.BeaconBlock,
753-
blindedBundle: electra_mev.BlindedExecutionPayloadAndBlobsBundle |
754-
fulu_mev.BlindedExecutionPayloadAndBlobsBundle): T =
754+
blindedBundle:
755+
electra_mev.BlindedExecutionPayloadAndBlobsBundle |
756+
fulu_mev.BlindedExecutionPayloadAndBlobsBundle,
757+
executionRequests: ExecutionRequests): T =
755758
# Leaves signature field default, to be filled in by caller
756759
const
757760
blckFields = getFieldNames(typeof(blck))
@@ -768,28 +771,8 @@ func constructSignableBlindedBlock[T: electra_mev.SignedBlindedBeaconBlock |
768771
assign(
769772
blindedBlock.message.body.blob_kzg_commitments,
770773
blindedBundle.blob_kzg_commitments)
771-
772-
blindedBlock
773-
774-
func constructSignableBlindedBlock[T: fulu_mev.SignedBlindedBeaconBlock](
775-
blck: fulu.BeaconBlock,
776-
blindedBundle: fulu_mev.BlindedExecutionPayloadAndBlobsBundle): T =
777-
# Leaves signature field default, to be filled in by caller
778-
const
779-
blckFields = getFieldNames(typeof(blck))
780-
blckBodyFields = getFieldNames(typeof(blck.body))
781-
782-
var blindedBlock: T
783-
784-
# https://github.com/ethereum/builder-specs/blob/v0.4.0/specs/bellatrix/validator.md#block-proposal
785-
copyFields(blindedBlock.message, blck, blckFields)
786-
copyFields(blindedBlock.message.body, blck.body, blckBodyFields)
787774
assign(
788-
blindedBlock.message.body.execution_payload_header,
789-
blindedBundle.execution_payload_header)
790-
assign(
791-
blindedBlock.message.body.blob_kzg_commitments,
792-
blindedBundle.blob_kzg_commitments)
775+
blindedBlock.message.body.execution_requests, executionRequests)
793776

794777
blindedBlock
795778

@@ -836,8 +819,8 @@ func getUnsignedBlindedBeaconBlock[
836819
validator_index: ValidatorIndex, forkedBlock: ForkedBeaconBlock,
837820
executionPayloadHeader: deneb_mev.BlindedExecutionPayloadAndBlobsBundle |
838821
electra_mev.BlindedExecutionPayloadAndBlobsBundle |
839-
fulu_mev.BlindedExecutionPayloadAndBlobsBundle):
840-
Result[T, string] =
822+
fulu_mev.BlindedExecutionPayloadAndBlobsBundle,
823+
executionRequests: ExecutionRequests): Result[T, string] =
841824
withBlck(forkedBlock):
842825
when consensusFork >= ConsensusFork.Deneb:
843826
when not (
@@ -850,7 +833,7 @@ func getUnsignedBlindedBeaconBlock[
850833
return err("getUnsignedBlindedBeaconBlock: mismatched block/payload types")
851834
else:
852835
return ok constructSignableBlindedBlock[T](
853-
forkyBlck, executionPayloadHeader)
836+
forkyBlck, executionPayloadHeader, executionRequests)
854837
else:
855838
return err("getUnsignedBlindedBeaconBlock: attempt to construct pre-Deneb blinded block")
856839

@@ -861,7 +844,7 @@ proc getBlindedBlockParts[
861844
node: BeaconNode, payloadBuilderClient: RestClientRef, head: BlockRef,
862845
pubkey: ValidatorPubKey, slot: Slot, randao: ValidatorSig,
863846
validator_index: ValidatorIndex, graffiti: GraffitiBytes):
864-
Future[Result[(EPH, UInt256, UInt256, ForkedBeaconBlock), string]]
847+
Future[Result[(EPH, UInt256, UInt256, ForkedBeaconBlock, ExecutionRequests), string]]
865848
{.async: (raises: [CancelledError]).} =
866849
let
867850
executionBlockHash = node.dag.loadExecutionBlockHash(head).valueOr:
@@ -958,7 +941,7 @@ proc getBlindedBlockParts[
958941
execution_payload_root = Opt.some hash_tree_root(actualEPH),
959942
withdrawals_root = withdrawals_root,
960943
kzg_commitments = kzg_commitments,
961-
execution_requests = execution_requests)
944+
builder_execution_requests = Opt.some execution_requests)
962945

963946
if newBlock.isErr():
964947
# Haven't committed to the MEV block, so allow EL fallback.
@@ -968,9 +951,8 @@ proc getBlindedBlockParts[
968951

969952
return ok(
970953
(blindedBlockRes.get.blindedBlckPart,
971-
blindedBlockRes.get.executionPayloadValue,
972-
forkedBlck.consensusBlockValue,
973-
forkedBlck.blck))
954+
blindedBlockRes.get.executionPayloadValue, forkedBlck.consensusBlockValue,
955+
forkedBlck.blck, execution_requests))
974956

975957
proc getBuilderBid[
976958
SBBB: deneb_mev.SignedBlindedBeaconBlock |
@@ -1001,17 +983,17 @@ proc getBuilderBid[
1001983

1002984
# These, together, get combined into the blinded block for signing and
1003985
# proposal through the relay network.
1004-
let (executionPayloadHeader, bidValue, consensusValue, forkedBlck) =
986+
let (executionPayloadHeader, bidValue, consensusValue, forkedBlck,
987+
executionRequests) =
1005988
blindedBlockParts.get
1006989

1007990
let unsignedBlindedBlock = getUnsignedBlindedBeaconBlock[SBBB](
1008-
node, slot, validator_index, forkedBlck, executionPayloadHeader)
991+
node, slot, validator_index, forkedBlck, executionPayloadHeader,
992+
executionRequests)
1009993

1010994
if unsignedBlindedBlock.isErr:
1011995
return err unsignedBlindedBlock.error()
1012996

1013-
template execution_requests: untyped =
1014-
unsignedBlindedBlock.get.message.body.execution_requests
1015997
when SBBB is deneb_mev.SignedBlindedBeaconBlock:
1016998
return ok(BuilderBid[SBBB](
1017999
blindedBlckPart: unsignedBlindedBlock.get,
@@ -1022,7 +1004,7 @@ proc getBuilderBid[
10221004
SBBB is fulu_mev.SignedBlindedBeaconBlock:
10231005
return ok(BuilderBid[SBBB](
10241006
blindedBlckPart: unsignedBlindedBlock.get,
1025-
executionRequests: execution_requests,
1007+
executionRequests: executionRequests,
10261008
executionPayloadValue: bidValue,
10271009
consensusBlockValue: consensusValue))
10281010
else:

0 commit comments

Comments
 (0)