use `PayloadAttributesV3` in `nimbus_light_client` for Deneb (#5654)

* use `PayloadAttributesV3` in `nimbus_light_client` for Deneb

From Deneb onward, `forkchoiceUpdated` requires `PayloadAttributesV3`.
In `nimbus_light_client` we still used `PayloadAttributesV2`.

Also clean up two other locations that were already correctly using
`PayloadAttributesV3`, to reduce code duplication.

* fix letter case
This commit is contained in:
Etan Kissling 2023-12-07 18:10:22 +01:00 committed by GitHub
parent 4776fecc33
commit 0a5d9ee027
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 46 deletions

View File

@ -168,18 +168,13 @@ proc updateExecutionClientHead(self: ref ConsensusManager,
payloadAttributes = none attributes)
# Can't use dag.head here because it hasn't been updated yet
let (payloadExecutionStatus, _) =
case self.dag.cfg.consensusForkAtEpoch(newHead.blck.bid.slot.epoch)
of ConsensusFork.Deneb:
callForkchoiceUpdated(PayloadAttributesV3)
of ConsensusFork.Capella:
# https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.3/src/engine/shanghai.md#specification-1
# Consensus layer client MUST call this method instead of
# `engine_forkchoiceUpdatedV1` under any of the following conditions:
# `headBlockHash` references a block which `timestamp` is greater or
# equal to the Shanghai timestamp
callForkchoiceUpdated(PayloadAttributesV2)
of ConsensusFork.Phase0, ConsensusFork.Altair, ConsensusFork.Bellatrix:
let
consensusFork =
self.dag.cfg.consensusForkAtEpoch(newHead.blck.bid.slot.epoch)
(payloadExecutionStatus, _) = withConsensusFork(consensusFork):
when consensusFork >= ConsensusFork.Bellatrix:
callForkchoiceUpdated(consensusFork.PayloadAttributes)
else:
callForkchoiceUpdated(PayloadAttributesV1)
case payloadExecutionStatus

View File

@ -642,21 +642,11 @@ proc storeBlock(
finalizedBlockHash = newHead.get.finalizedExecutionPayloadHash,
payloadAttributes = none attributes)
case self.consensusManager.dag.cfg.consensusForkAtEpoch(
let consensusFork = self.consensusManager.dag.cfg.consensusForkAtEpoch(
newHead.get.blck.bid.slot.epoch)
of ConsensusFork.Deneb:
callForkchoiceUpdated(PayloadAttributesV3)
of ConsensusFork.Capella:
# https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.3/src/engine/shanghai.md#specification-1
# Consensus layer client MUST call this method instead of
# `engine_forkchoiceUpdatedV1` under any of the following conditions:
# `headBlockHash` references a block which `timestamp` is greater or
# equal to the Shanghai timestamp
callForkchoiceUpdated(PayloadAttributesV2)
of ConsensusFork.Bellatrix:
callForkchoiceUpdated(PayloadAttributesV1)
of ConsensusFork.Phase0, ConsensusFork.Altair:
discard
withConsensusFork(consensusFork):
when consensusFork >= ConsensusFork.Bellatrix:
callForkchoiceUpdated(consensusFork.PayloadAttributes)
else:
let
headExecutionPayloadHash =

View File

@ -109,12 +109,7 @@ programMain:
opt = signedBlock.toBlockId(),
wallSlot = getBeaconTime().slotOrZero
withBlck(signedBlock):
when consensusFork >= ConsensusFork.Capella:
# https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.3/src/engine/shanghai.md#specification-1
# Consensus layer client MUST call this method instead of
# `engine_forkchoiceUpdatedV1` under any of the following conditions:
# `headBlockHash` references a block which `timestamp` is greater or
# equal to the Shanghai timestamp
when consensusFork >= ConsensusFork.Bellatrix:
if forkyBlck.message.is_execution_block:
template payload(): auto = forkyBlck.message.body.execution_payload
@ -124,18 +119,7 @@ programMain:
headBlockHash = payload.block_hash,
safeBlockHash = payload.block_hash, # stub value
finalizedBlockHash = ZERO_HASH,
payloadAttributes = none PayloadAttributesV2)
elif consensusFork >= ConsensusFork.Bellatrix:
if forkyBlck.message.is_execution_block:
template payload(): auto = forkyBlck.message.body.execution_payload
if elManager != nil and not payload.block_hash.isZero:
discard await elManager.newExecutionPayload(forkyBlck.message)
discard await elManager.forkchoiceUpdated(
headBlockHash = payload.block_hash,
safeBlockHash = payload.block_hash, # stub value
finalizedBlockHash = ZERO_HASH,
payloadAttributes = none PayloadAttributesV1)
payloadAttributes = none(consensusFork.PayloadAttributes))
else: discard
optimisticProcessor = initOptimisticProcessor(
getBeaconTime, optimisticHandler)

View File

@ -531,6 +531,17 @@ template BlindedBlockContents*(
else:
{.error: "BlindedBlockContents does not support " & $kind.}
template PayloadAttributes*(
kind: static ConsensusFork): auto =
when kind >= ConsensusFork.Deneb:
typedesc[PayloadAttributesV3]
elif kind >= ConsensusFork.Capella:
typedesc[PayloadAttributesV2]
elif kind >= ConsensusFork.Bellatrix:
typedesc[PayloadAttributesV1]
else:
{.error: "PayloadAttributes does not support " & $kind.}
# TODO when https://github.com/nim-lang/Nim/issues/21086 fixed, use return type
# `ref T`
func new*(T: type ForkedHashedBeaconState, data: phase0.BeaconState):