Skip to content

Commit

Permalink
prepare builder API, modify electra BuilderBid
Browse files Browse the repository at this point in the history
  • Loading branch information
agnxsh committed Jan 25, 2025
1 parent 5547d2a commit f86ab23
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 18 deletions.
1 change: 1 addition & 0 deletions beacon_chain/spec/mev/electra_mev.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type
BuilderBid* = object
header*: electra.ExecutionPayloadHeader
blob_kzg_commitments*: KzgCommitments
execution_requests*: ExecutionRequests # [New in Electra]
value*: UInt256
pubkey*: ValidatorPubKey

Expand Down
1 change: 1 addition & 0 deletions beacon_chain/spec/mev/fulu_mev.nim
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type
BuilderBid* = object
header*: ExecutionPayloadHeader
blob_kzg_commitments*: KzgCommitments
execution_requests*: ExecutionRequests # [New in Electra]
value*: UInt256
pubkey*: ValidatorPubKey

Expand Down
6 changes: 4 additions & 2 deletions beacon_chain/spec/state_transition.nim
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,8 @@ proc makeBeaconBlockWithRewards*(
hash_tree_root(sync_aggregate),
execution_payload_root.get,
hash_tree_root(validator_changes.bls_to_execution_changes),
hash_tree_root(kzg_commitments.get)
hash_tree_root(kzg_commitments.get),
hash_tree_root(execution_requests)
])
else:
raiseAssert "Attempt to use non-Electra payload with post-Deneb state"
Expand All @@ -577,7 +578,8 @@ proc makeBeaconBlockWithRewards*(
hash_tree_root(sync_aggregate),
execution_payload_root.get,
hash_tree_root(validator_changes.bls_to_execution_changes),
hash_tree_root(kzg_commitments.get)
hash_tree_root(kzg_commitments.get),
hash_tree_root(execution_requests)
])
else:
raiseAssert "Attempt to use non-Fulu payload with post-Electra state"
Expand Down
73 changes: 57 additions & 16 deletions beacon_chain/validators/beacon_validators.nim
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type

BuilderBid[SBBB] = object
blindedBlckPart*: SBBB
executionRequests*: Opt[ExecutionRequests]
executionPayloadValue*: UInt256
consensusBlockValue*: UInt256

Expand Down Expand Up @@ -707,11 +708,27 @@ proc getBlindedExecutionPayload[
return err "getBlindedExecutionPayload: signature verification failed"

template builderBid: untyped = blindedHeader.data.message
return ok(BuilderBid[EPH](
blindedBlckPart: EPH(
execution_payload_header: builderBid.header,
blob_kzg_commitments: builderBid.blob_kzg_commitments),
executionPayloadValue: builderBid.value))
when EPH is deneb_mev.BlindedExecutionPayloadAndBlobsBundle:
return ok(BuilderBid[EPH](
blindedBlckPart: EPH(
execution_payload_header: builderBid.header,
blob_kzg_commitments: builderBid.blob_kzg_commitments),
executionRequests: Opt.none(ExecutionRequests),
executionPayloadValue: builderBid.value))
elif EPH is electra_mev.BlindedExecutionPayloadAndBlobsBundle:
return ok(BuilderBid[EPH](
blindedBlckPart: EPH(
execution_payload_header: builderBid.header,
blob_kzg_commitments: builderBid.blob_kzg_commitments),
executionRequests: Opt.some(builderBid.execution_requests),
executionPayloadValue: builderBid.value))
elif EPH is fulu_mev.BlindedExecutionPayloadAndBlobsBundle:
return ok(BuilderBid[EPH](
blindedBlckPart: EPH(
execution_payload_header: builderBid.header,
blob_kzg_commitments: builderBid.blob_kzg_commitments),
executionRequests: Opt.some(builderBid.execution_requests),
executionPayloadValue: builderBid.value))

from ./message_router_mev import
copyFields, getFieldNames, unblindAndRouteBlockMEV
Expand Down Expand Up @@ -1072,11 +1089,26 @@ proc getBuilderBid[
if unsignedBlindedBlock.isErr:
return err unsignedBlindedBlock.error()

ok(BuilderBid[SBBB](
blindedBlckPart: unsignedBlindedBlock.get,
executionPayloadValue: bidValue,
consensusBlockValue: consensusValue
))
template execution_requests: untyped =
unsignedBlindedBlock.get.message.body.execution_requests
when SBBB is deneb_mev.SignedBlindedBeaconBlock:
return ok(BuilderBid[SBBB](
blindedBlckPart: unsignedBlindedBlock.get,
executionRequests: Opt.none(ExecutionRequests),
executionPayloadValue: bidValue,
consensusBlockValue: consensusValue))
elif SBBB is electra_mev.SignedBlindedBeaconBlock:
return ok(BuilderBid[SBBB](
blindedBlckPart: unsignedBlindedBlock.get,
executionRequests: Opt.some(execution_requests),
executionPayloadValue: bidValue,
consensusBlockValue: consensusValue))
elif SBBB is fulu_mev.SignedBlindedBeaconBlock:
return ok(BuilderBid[SBBB](
blindedBlckPart: unsignedBlindedBlock.get,
executionRequests: Opt.some(execution_requests),
executionPayloadValue: bidValue,
consensusBlockValue: consensusValue))

proc proposeBlockMEV(
node: BeaconNode, payloadBuilderClient: RestClientRef,
Expand Down Expand Up @@ -1164,16 +1196,25 @@ proc makeBlindedBeaconBlockForHeadAndSlot*[BBB: ForkyBlindedBeaconBlock](
blindedBlockParts.get
withBlck(forkedBlck):
when consensusFork >= ConsensusFork.Deneb:
when ((consensusFork == ConsensusFork.Deneb and
EPH is deneb_mev.BlindedExecutionPayloadAndBlobsBundle) or
(consensusFork == ConsensusFork.Electra and
EPH is electra_mev.BlindedExecutionPayloadAndBlobsBundle) or
(consensusFork == ConsensusFork.Fulu and
EPH is fulu_mev.BlindedExecutionPayloadAndBlobsBundle)):
when (consensusFork == ConsensusFork.Deneb and
EPH is deneb_mev.BlindedExecutionPayloadAndBlobsBundle):
return ok(
BuilderBid[BBB](
blindedBlckPart:
constructPlainBlindedBlock[BBB](forkyBlck, executionPayloadHeader),
executionRequests: Opt.none(ExecutionRequests),
executionPayloadValue: bidValue,
consensusBlockValue: consensusValue))

elif (consensusFork == ConsensusFork.Electra and
EPH is electra_mev.BlindedExecutionPayloadAndBlobsBundle) or
(consensusFork == ConsensusFork.Fulu and
EPH is fulu_mev.BlindedExecutionPayloadAndBlobsBundle):
return ok(
BuilderBid[BBB](
blindedBlckPart:
constructPlainBlindedBlock[BBB](forkyBlck, executionPayloadHeader),
executionRequests: Opt.some(forkyBlck.body.execution_requests),
executionPayloadValue: bidValue,
consensusBlockValue: consensusValue))
else:
Expand Down

0 comments on commit f86ab23

Please sign in to comment.