Skip to content

Commit

Permalink
forkchoiceUpdate support (#3199)
Browse files Browse the repository at this point in the history
  • Loading branch information
tersec authored Dec 17, 2021
1 parent 4a72def commit 57974ce
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
15 changes: 15 additions & 0 deletions beacon_chain/eth1/eth1_monitor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,21 @@ proc executePayload*(p: Web3DataProviderRef,
payload: engine_api.ExecutionPayloadV1): Future[ExecutePayloadResponse] =
p.web3.provider.engine_executePayloadV1(payload)

proc forkchoiceUpdated*(p: Web3DataProviderRef,
headBlock, finalizedBlock: Eth2Digest):
Future[engine_api.ForkchoiceUpdatedResponse] =
p.web3.provider.engine_forkchoiceUpdatedV1(
ForkchoiceStateV1(
headBlockHash: headBlock.asBlockHash,

# https://hackmd.io/@n0ble/kintsugi-spec#Engine-API
# "CL client software MUST use headBlockHash value as a stub for the
# safeBlockHash parameter"
safeBlockHash: headBlock.asBlockHash,

finalizedBlockHash: finalizedBlock.asBlockHash),
none(engine_api.PayloadAttributesV1))

proc forkchoiceUpdated*(p: Web3DataProviderRef,
headBlock, finalizedBlock: Eth2Digest,
timestamp: uint64,
Expand Down
19 changes: 19 additions & 0 deletions beacon_chain/validators/validator_duties.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import
json_serialization/std/[options, sets, net], serialization/errors,
eth/db/kvstore,
eth/keys, eth/p2p/discoveryv5/[protocol, enr],
web3/ethtypes,

# Local modules
../spec/datatypes/[phase0, altair, merge],
Expand Down Expand Up @@ -416,6 +417,24 @@ proc getBlockProposalEth1Data*(node: BeaconNode,
state, finalizedEpochRef.eth1_data,
finalizedEpochRef.eth1_deposit_index)

proc forkchoice_updated(state: merge.BeaconState,
head_block_hash: Eth2Digest,
finalized_block_hash: Eth2Digest,
fee_recipient: ethtypes.Address,
execution_engine: Web3DataProviderRef):
Future[Option[merge.PayloadId]] {.async.} =
let
timestamp = compute_timestamp_at_slot(state, state.slot)
random = get_randao_mix(state, get_current_epoch(state))
payloadId =
(await execution_engine.forkchoiceUpdated(
head_block_hash, finalized_block_hash, timestamp, random.data,
fee_recipient)).payloadId
return if payloadId.isSome:
some(merge.PayloadId(payloadId.get))
else:
none(merge.PayloadId)

proc makeBeaconBlockForHeadAndSlot*(node: BeaconNode,
randao_reveal: ValidatorSig,
validator_index: ValidatorIndex,
Expand Down

0 comments on commit 57974ce

Please sign in to comment.