add Electra to ConsensusFork enum (#6169)

* add Electra to ConsensusFork enum

* fix gnosis check
This commit is contained in:
tersec 2024-04-03 14:43:43 +00:00 committed by GitHub
parent c2a2b76f93
commit 7fa32b7f02
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
36 changed files with 510 additions and 151 deletions

View File

@ -513,7 +513,8 @@ proc new*(T: type BeaconChainDB,
kvStore db.openKvStore("altair_blocks").expectDb(),
kvStore db.openKvStore("bellatrix_blocks").expectDb(),
kvStore db.openKvStore("capella_blocks").expectDb(),
kvStore db.openKvStore("deneb_blocks").expectDb()]
kvStore db.openKvStore("deneb_blocks").expectDb(),
kvStore db.openKvStore("electra_blocks").expectDb()]
stateRoots = kvStore db.openKvStore("state_roots", true).expectDb()
@ -522,7 +523,8 @@ proc new*(T: type BeaconChainDB,
kvStore db.openKvStore("altair_state_no_validators").expectDb(),
kvStore db.openKvStore("bellatrix_state_no_validators").expectDb(),
kvStore db.openKvStore("capella_state_no_validator_pubkeys").expectDb(),
kvStore db.openKvStore("deneb_state_no_validator_pubkeys").expectDb()]
kvStore db.openKvStore("deneb_state_no_validator_pubkeys").expectDb(),
kvStore db.openKvStore("electra_state_no_validator_pubkeys").expectDb()]
stateDiffs = kvStore db.openKvStore("state_diffs").expectDb()
summaries = kvStore db.openKvStore("beacon_block_summaries", true).expectDb()
@ -794,7 +796,8 @@ proc putBlock*(
proc putBlock*(
db: BeaconChainDB,
value: bellatrix.TrustedSignedBeaconBlock |
capella.TrustedSignedBeaconBlock | deneb.TrustedSignedBeaconBlock) =
capella.TrustedSignedBeaconBlock | deneb.TrustedSignedBeaconBlock |
electra.TrustedSignedBeaconBlock) =
db.withManyWrites:
db.blocks[type(value).kind].putSZSSZ(value.root.data, value)
db.putBeaconBlockSummary(value.root, value.message.toBeaconBlockSummary())
@ -844,6 +847,10 @@ template toBeaconStateNoImmutableValidators(state: deneb.BeaconState):
DenebBeaconStateNoImmutableValidators =
isomorphicCast[DenebBeaconStateNoImmutableValidators](state)
template toBeaconStateNoImmutableValidators(state: electra.BeaconState):
ElectraBeaconStateNoImmutableValidators =
isomorphicCast[ElectraBeaconStateNoImmutableValidators](state)
proc putState*(
db: BeaconChainDB, key: Eth2Digest,
value: phase0.BeaconState | altair.BeaconState) =
@ -853,7 +860,8 @@ proc putState*(
proc putState*(
db: BeaconChainDB, key: Eth2Digest,
value: bellatrix.BeaconState | capella.BeaconState | deneb.BeaconState) =
value: bellatrix.BeaconState | capella.BeaconState | deneb.BeaconState |
electra.BeaconState) =
db.updateImmutableValidators(value.validators.asSeq())
db.statesNoVal[type(value).kind].putSZSSZ(
key.data, toBeaconStateNoImmutableValidators(value))
@ -982,7 +990,7 @@ proc getBlock*(
proc getBlock*[
X: bellatrix.TrustedSignedBeaconBlock | capella.TrustedSignedBeaconBlock |
deneb.TrustedSignedBeaconBlock](
deneb.TrustedSignedBeaconBlock | electra.TrustedSignedBeaconBlock](
db: BeaconChainDB, key: Eth2Digest,
T: type X): Opt[T] =
# We only store blocks that we trust in the database
@ -1037,7 +1045,7 @@ proc getBlockSSZ*(
proc getBlockSSZ*[
X: bellatrix.TrustedSignedBeaconBlock | capella.TrustedSignedBeaconBlock |
deneb.TrustedSignedBeaconBlock](
deneb.TrustedSignedBeaconBlock | electra.TrustedSignedBeaconBlock](
db: BeaconChainDB, key: Eth2Digest, data: var seq[byte], T: type X): bool =
let dataPtr = addr data # Short-lived
var success = true
@ -1086,7 +1094,7 @@ proc getBlockSZ*(
proc getBlockSZ*[
X: bellatrix.TrustedSignedBeaconBlock | capella.TrustedSignedBeaconBlock |
deneb.TrustedSignedBeaconBlock](
deneb.TrustedSignedBeaconBlock | electra.TrustedSignedBeaconBlock](
db: BeaconChainDB, key: Eth2Digest, data: var seq[byte], T: type X): bool =
let dataPtr = addr data # Short-lived
func decode(data: openArray[byte]) =
@ -1184,7 +1192,7 @@ proc getStateOnlyMutableValidators(
proc getStateOnlyMutableValidators(
immutableValidators: openArray[ImmutableValidatorData2],
store: KvStoreRef, key: openArray[byte],
output: var (capella.BeaconState | deneb.BeaconState),
output: var (capella.BeaconState | deneb.BeaconState | electra.BeaconState),
rollback: RollbackProc): bool =
## Load state into `output` - BeaconState is large so we want to avoid
## re-allocating it if possible
@ -1269,7 +1277,7 @@ proc getState*(
proc getState*(
db: BeaconChainDB, key: Eth2Digest,
output: var (altair.BeaconState | bellatrix.BeaconState |
capella.BeaconState | deneb.BeaconState),
capella.BeaconState | deneb.BeaconState | electra.BeaconState),
rollback: RollbackProc): bool =
## Load state into `output` - BeaconState is large so we want to avoid
## re-allocating it if possible
@ -1489,7 +1497,7 @@ iterator getAncestorSummaries*(db: BeaconChainDB, root: Eth2Digest):
# Backwards compat for reading old databases, or those that for whatever
# reason lost a summary along the way..
static: doAssert ConsensusFork.high == ConsensusFork.Deneb
static: doAssert ConsensusFork.high == ConsensusFork.Electra
while true:
if db.v0.backend.getSnappySSZ(
subkey(BeaconBlockSummary, res.root), res.summary) == GetResult.found:
@ -1504,6 +1512,8 @@ iterator getAncestorSummaries*(db: BeaconChainDB, root: Eth2Digest):
res.summary = blck.get().message.toBeaconBlockSummary()
elif (let blck = db.getBlock(res.root, deneb.TrustedSignedBeaconBlock); blck.isSome()):
res.summary = blck.get().message.toBeaconBlockSummary()
elif (let blck = db.getBlock(res.root, electra.TrustedSignedBeaconBlock); blck.isSome()):
res.summary = blck.get().message.toBeaconBlockSummary()
else:
break

View File

@ -77,6 +77,9 @@ proc initLightClient*(
case node.dag.cfg.consensusForkAtEpoch(
forkyBlck.message.slot.epoch)
of ConsensusFork.Electra:
debugRaiseAssert ""
discard
of ConsensusFork.Deneb:
callForkchoiceUpdated(PayloadAttributesV3)
of ConsensusFork.Capella:

View File

@ -329,7 +329,9 @@ type
optimistic* {.serializedFieldName: "execution_optimistic".}: Option[bool]
template OnBlockAddedCallback*(kind: static ConsensusFork): auto =
when kind == ConsensusFork.Deneb:
when kind == ConsensusFork.Electra:
typedesc[OnElectraBlockAdded]
elif kind == ConsensusFork.Deneb:
typedesc[OnDenebBlockAdded]
elif kind == ConsensusFork.Capella:
typedesc[OnCapellaBlockAdded]

View File

@ -268,8 +268,11 @@ proc getForkedBlock*(db: BeaconChainDB, root: Eth2Digest):
Opt[ForkedTrustedSignedBeaconBlock] =
# When we only have a digest, we don't know which fork it's from so we try
# them one by one - this should be used sparingly
static: doAssert high(ConsensusFork) == ConsensusFork.Deneb
if (let blck = db.getBlock(root, deneb.TrustedSignedBeaconBlock);
static: doAssert high(ConsensusFork) == ConsensusFork.Electra
if (let blck = db.getBlock(root, electra.TrustedSignedBeaconBlock);
blck.isSome()):
ok(ForkedTrustedSignedBeaconBlock.init(blck.get()))
elif (let blck = db.getBlock(root, deneb.TrustedSignedBeaconBlock);
blck.isSome()):
ok(ForkedTrustedSignedBeaconBlock.init(blck.get()))
elif (let blck = db.getBlock(root, capella.TrustedSignedBeaconBlock);
@ -1001,6 +1004,9 @@ proc applyBlock(
? state_transition(
dag.cfg, state, data, cache, info,
dag.updateFlags + {slotProcessed}, noRollback)
of ConsensusFork.Electra:
debugRaiseAssert "electra applyblock missing"
return ok()
ok()
@ -1156,11 +1162,12 @@ proc init*(T: type ChainDAGRef, cfg: RuntimeConfig, db: BeaconChainDB,
let
configFork = case dag.headState.kind
of ConsensusFork.Phase0: genesisFork(cfg)
of ConsensusFork.Altair: altairFork(cfg)
of ConsensusFork.Phase0: genesisFork(cfg)
of ConsensusFork.Altair: altairFork(cfg)
of ConsensusFork.Bellatrix: bellatrixFork(cfg)
of ConsensusFork.Capella: capellaFork(cfg)
of ConsensusFork.Deneb: denebFork(cfg)
of ConsensusFork.Capella: capellaFork(cfg)
of ConsensusFork.Deneb: denebFork(cfg)
of ConsensusFork.Electra: electraFork(cfg)
stateFork = getStateField(dag.headState, fork)
# Here, we check only the `current_version` field because the spec
@ -2395,7 +2402,7 @@ proc updateHead*(
if dag.headState.kind > lastHeadKind:
case dag.headState.kind
of ConsensusFork.Phase0 .. ConsensusFork.Bellatrix:
of ConsensusFork.Phase0 .. ConsensusFork.Bellatrix, ConsensusFork.Electra:
discard
of ConsensusFork.Capella:
if dag.vanityLogs.onUpgradeToCapella != nil:

View File

@ -370,34 +370,38 @@ proc runProposalForkchoiceUpdated*(
let safeBlockHash = beaconHead.safeExecutionBlockHash
withState(self.dag.headState):
template callForkchoiceUpdated(fcPayloadAttributes: auto) =
let (status, _) = await self.elManager.forkchoiceUpdated(
headBlockHash, safeBlockHash,
beaconHead.finalizedExecutionBlockHash,
payloadAttributes = some fcPayloadAttributes)
debug "Fork-choice updated for proposal", status
debugRaiseAssert "foo"
when consensusFork != ConsensusFork.Electra:
template callForkchoiceUpdated(fcPayloadAttributes: auto) =
let (status, _) = await self.elManager.forkchoiceUpdated(
headBlockHash, safeBlockHash,
beaconHead.finalizedExecutionBlockHash,
payloadAttributes = some fcPayloadAttributes)
debug "Fork-choice updated for proposal", status
static: doAssert high(ConsensusFork) == ConsensusFork.Deneb
when consensusFork >= ConsensusFork.Deneb:
callForkchoiceUpdated(PayloadAttributesV3(
timestamp: Quantity timestamp,
prevRandao: FixedBytes[32] randomData,
suggestedFeeRecipient: feeRecipient,
withdrawals:
toEngineWithdrawals get_expected_withdrawals(forkyState.data),
parentBeaconBlockRoot: beaconHead.blck.bid.root.asBlockHash))
elif consensusFork >= ConsensusFork.Capella:
callForkchoiceUpdated(PayloadAttributesV2(
timestamp: Quantity timestamp,
prevRandao: FixedBytes[32] randomData,
suggestedFeeRecipient: feeRecipient,
withdrawals:
toEngineWithdrawals get_expected_withdrawals(forkyState.data)))
else:
callForkchoiceUpdated(PayloadAttributesV1(
timestamp: Quantity timestamp,
prevRandao: FixedBytes[32] randomData,
suggestedFeeRecipient: feeRecipient))
static: doAssert high(ConsensusFork) == ConsensusFork.Electra
when consensusFork >= ConsensusFork.Electra:
debugRaiseAssert "foobar"
elif consensusFork >= ConsensusFork.Deneb:
callForkchoiceUpdated(PayloadAttributesV3(
timestamp: Quantity timestamp,
prevRandao: FixedBytes[32] randomData,
suggestedFeeRecipient: feeRecipient,
withdrawals:
toEngineWithdrawals get_expected_withdrawals(forkyState.data),
parentBeaconBlockRoot: beaconHead.blck.bid.root.asBlockHash))
elif consensusFork >= ConsensusFork.Capella:
callForkchoiceUpdated(PayloadAttributesV2(
timestamp: Quantity timestamp,
prevRandao: FixedBytes[32] randomData,
suggestedFeeRecipient: feeRecipient,
withdrawals:
toEngineWithdrawals get_expected_withdrawals(forkyState.data)))
else:
callForkchoiceUpdated(PayloadAttributesV1(
timestamp: Quantity timestamp,
prevRandao: FixedBytes[32] randomData,
suggestedFeeRecipient: feeRecipient))
ok()

View File

@ -198,7 +198,8 @@ type
SomeEnginePayloadWithValue =
BellatrixExecutionPayloadWithValue |
GetPayloadV2Response |
GetPayloadV3Response
GetPayloadV3Response |
GetPayloadV4Response
declareCounter failed_web3_requests,
"Failed web3 requests"
@ -530,6 +531,11 @@ func asConsensusType*(rpcExecutionPayload: ExecutionPayloadV4):
List[electra.ExecutionLayerExit, MAX_EXECUTION_LAYER_EXITS_PER_PAYLOAD].init(
mapIt(rpcExecutionPayload.exits, it.getExecutionLayerExit)))
func asConsensusType*(payload: engine_api.GetPayloadV4Response):
electra.ExecutionPayloadForSigning =
debugRaiseAssert "well, not empty maybe"
default(electra.ExecutionPayloadForSigning)
func asEngineExecutionPayload*(executionPayload: bellatrix.ExecutionPayload):
ExecutionPayloadV1 =
template getTypedTransaction(tt: bellatrix.Transaction): TypedTransaction =
@ -804,6 +810,9 @@ proc getPayloadFromSingleEL(
suggestedFeeRecipient: suggestedFeeRecipient,
withdrawals: withdrawals,
parentBeaconBlockRoot: consensusHead.asBlockHash))
elif GetPayloadResponseType is engine_api.GetPayloadV4Response:
debugRaiseAssert "electra"
let response = default(ForkchoiceUpdatedResponse)
else:
static: doAssert false
@ -824,6 +833,9 @@ proc getPayloadFromSingleEL(
return BellatrixExecutionPayloadWithValue(
executionPayload: payload,
blockValue: computeBlockValue payload)
elif GetPayloadResponseType is engine_api.GetPayloadV4Response:
debugRaiseAssert "foo"
return default(engine_api.GetPayloadV4Response)
else:
return await engine_api.getPayload(rpcClient, GetPayloadResponseType, payloadId)
@ -839,6 +851,9 @@ template EngineApiResponseType*(T: type capella.ExecutionPayloadForSigning): typ
template EngineApiResponseType*(T: type deneb.ExecutionPayloadForSigning): type =
engine_api.GetPayloadV3Response
template EngineApiResponseType*(T: type electra.ExecutionPayloadForSigning): type =
engine_api.GetPayloadV4Response
template toEngineWithdrawals*(withdrawals: seq[capella.Withdrawal]): seq[WithdrawalV1] =
mapIt(withdrawals, toEngineWithdrawal(it))
@ -1150,6 +1165,9 @@ proc sendNewPayload*(m: ELManager, blck: SomeForkyBeaconBlock):
elif payload is engine_api.ExecutionPayloadV1 or
payload is engine_api.ExecutionPayloadV2:
sendNewPayloadToSingleEL(it, payload)
elif payload is engine_api.ExecutionPayloadV4:
debugRaiseAssert "similar to V3 case, check for details"
default(Future[PayloadStatusV1])
else:
static: doAssert false
trackEngineApiRequest(it, req, "newPayload", startTime, deadline)

View File

@ -442,7 +442,7 @@ iterator getBlockIds*(
# `case` ensures we're on a fork for which the `PartialBeaconState`
# definition is consistent
case db.cfg.consensusForkAtEpoch(slot.epoch)
of ConsensusFork.Phase0 .. ConsensusFork.Deneb:
of ConsensusFork.Phase0 .. ConsensusFork.Electra:
let stateSlot = (slot.era() + 1).start_slot()
if not getPartialState(
db, historical_roots, historical_summaries, stateSlot, state[]):

View File

@ -716,6 +716,9 @@ proc storeBlock(
template callForkChoiceUpdated: auto =
case self.consensusManager.dag.cfg.consensusForkAtEpoch(
newHead.get.blck.bid.slot.epoch)
of ConsensusFork.Electra:
let x = 4
debugRaiseAssert "callFCU"
of ConsensusFork.Deneb:
callExpectValidFCU(payloadAttributeType = PayloadAttributesV3)
of ConsensusFork.Capella:
@ -766,7 +769,8 @@ proc storeBlock(
quarantined = shortLog(quarantined.root)
withBlck(quarantined):
when typeof(forkyBlck).kind < ConsensusFork.Deneb:
debugRaiseAssert "electra has blobs"
when typeof(forkyBlck).kind < ConsensusFork.Deneb or typeof(forkyBlck).kind == ConsensusFork.Electra:
self[].enqueueBlock(
MsgSource.gossip, quarantined, Opt.none(BlobSidecars))
else:

View File

@ -241,8 +241,11 @@ proc processSignedBeaconBlock*(
# propagation of seemingly good blocks
trace "Block validated"
debugRaiseAssert "electra has blobs"
let blobs =
when typeof(signedBlock).kind >= ConsensusFork.Deneb:
when typeof(signedBlock).kind >= ConsensusFork.Electra:
Opt.none(BlobSidecars)
elif typeof(signedBlock).kind >= ConsensusFork.Deneb:
if self.blobQuarantine[].hasBlobs(signedBlock):
Opt.some(self.blobQuarantine[].popBlobs(signedBlock.root, signedBlock))
else:
@ -304,7 +307,10 @@ proc processBlobSidecar*(
if (let o = self.quarantine[].popBlobless(block_root); o.isSome):
let blobless = o.unsafeGet()
withBlck(blobless):
when consensusFork >= ConsensusFork.Deneb:
when consensusFork >= ConsensusFork.Electra:
debugRaiseAssert "no electra here yet"
let x = 5
elif consensusFork >= ConsensusFork.Deneb:
if self.blobQuarantine[].hasBlobs(forkyBlck):
self.blockProcessor[].enqueueBlock(
MsgSource.gossip, blobless,

View File

@ -270,7 +270,7 @@ when const_preset == "gnosis":
for network in [gnosisMetadata, chiadoMetadata]:
doAssert network.cfg.DENEB_FORK_EPOCH < FAR_FUTURE_EPOCH
doAssert network.cfg.ELECTRA_FORK_EPOCH == FAR_FUTURE_EPOCH
static: doAssert ConsensusFork.high == ConsensusFork.Deneb
static: doAssert ConsensusFork.high == ConsensusFork.Electra
elif const_preset == "mainnet":
when incbinEnabled:
@ -333,7 +333,7 @@ elif const_preset == "mainnet":
for network in [mainnetMetadata, praterMetadata, sepoliaMetadata, holeskyMetadata]:
doAssert network.cfg.DENEB_FORK_EPOCH < FAR_FUTURE_EPOCH
doAssert network.cfg.ELECTRA_FORK_EPOCH == FAR_FUTURE_EPOCH
static: doAssert ConsensusFork.high == ConsensusFork.Deneb
static: doAssert ConsensusFork.high == ConsensusFork.Electra
proc getMetadataForNetwork*(networkName: string): Eth2NetworkMetadata =
template loadRuntimeMetadata(): auto =

View File

@ -170,6 +170,8 @@ func getVanityLogs(stdoutKind: StdoutLogKind): VanityLogs =
func getVanityMascot(consensusFork: ConsensusFork): string =
case consensusFork
of ConsensusFork.Electra:
" "
of ConsensusFork.Deneb:
"🐟"
of ConsensusFork.Capella:
@ -402,7 +404,12 @@ proc initFullNode(
maybeFinalized: bool):
Future[Result[void, VerifierError]] {.async: (raises: [CancelledError]).} =
withBlck(signedBlock):
when consensusFork >= ConsensusFork.Deneb:
when consensusFork >= ConsensusFork.Electra:
debugRaiseAssert "foo"
await blockProcessor[].addBlock(MsgSource.gossip, signedBlock,
Opt.none(BlobSidecars),
maybeFinalized = maybeFinalized)
elif consensusFork >= ConsensusFork.Deneb:
if not blobQuarantine[].hasBlobs(forkyBlck):
# We don't have all the blobs for this block, so we have
# to put it in blobless quarantine.
@ -916,7 +923,8 @@ func forkDigests(node: BeaconNode): auto =
node.dag.forkDigests.altair,
node.dag.forkDigests.bellatrix,
node.dag.forkDigests.capella,
node.dag.forkDigests.deneb]
node.dag.forkDigests.deneb,
node.dag.forkDigests.electra]
forkDigestsArray
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.5/specs/phase0/p2p-interface.md#attestation-subnet-subscription
@ -1345,12 +1353,14 @@ proc updateGossipStatus(node: BeaconNode, slot: Slot) {.async.} =
let forkDigests = node.forkDigests()
debugRaiseAssert "check if electra has new gossip"
const removeMessageHandlers: array[ConsensusFork, auto] = [
removePhase0MessageHandlers,
removeAltairMessageHandlers,
removeAltairMessageHandlers, # bellatrix (altair handlers, different forkDigest)
removeCapellaMessageHandlers,
removeDenebMessageHandlers
removeDenebMessageHandlers,
removeDenebMessageHandlers # maybe duplicate is correct, don't know yet
]
for gossipFork in oldGossipForks:
@ -1361,7 +1371,8 @@ proc updateGossipStatus(node: BeaconNode, slot: Slot) {.async.} =
addAltairMessageHandlers,
addAltairMessageHandlers, # bellatrix (altair handlers, different forkDigest)
addCapellaMessageHandlers,
addDenebMessageHandlers
addDenebMessageHandlers,
addDenebMessageHandlers # repeat is probably correct
]
for gossipFork in newGossipForks:

View File

@ -237,6 +237,9 @@ proc installApiHandlers*(node: SigningNodeRef) =
(GeneralizedIndex(401), request.beaconBlockHeader.data)
of ConsensusFork.Deneb:
(GeneralizedIndex(801), request.beaconBlockHeader.data)
of ConsensusFork.Electra:
debugRaiseAssert "electra signing node missing"
(GeneralizedIndex(801*42), request.beaconBlockHeader.data)
if request.proofs.isNone() or len(request.proofs.get()) == 0:
return errorResponse(Http400, MissingMerkleProofError)

View File

@ -1003,7 +1003,11 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
RestApiResponse.jsonError(Http500, InvalidAcceptError)
withBlck(bdata.asSigned()):
when consensusFork <= ConsensusFork.Altair:
when consensusFork == ConsensusFork.Electra:
debugRaiseAssert "electra, beacon API missing"
let x = 5
RestApiResponse.jsonError(Http500, InvalidAcceptError)
elif consensusFork <= ConsensusFork.Altair:
respondSszOrJson(forkyBlck, consensusFork)
else:
respondSszOrJson(toSignedBlindedBeaconBlock(forkyBlck), consensusFork)
@ -1034,7 +1038,11 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
return RestApiResponse.jsonError(Http400, BlockIncorrectFork)
withConsensusFork(currentEpochFork):
when consensusFork >= ConsensusFork.Deneb:
when consensusFork >= ConsensusFork.Electra:
debugRaiseAssert "beacon API builder API"
return RestApiResponse.jsonError(
Http400, $consensusFork & " builder API unsupported")
elif consensusFork >= ConsensusFork.Deneb:
let
restBlock = decodeBodyJsonOrSsz(
consensusFork.SignedBlindedBeaconBlock, body).valueOr:

View File

@ -57,7 +57,11 @@ proc installDebugApiHandlers*(router: var RestRouter, node: BeaconNode) =
elif contentType == sszMediaType:
let headers = [("eth-consensus-version", state.kind.toString())]
withState(state):
RestApiResponse.sszResponse(forkyState.data, headers)
debugRaiseAssert "debug beacon API"
when consensusFork != ConsensusFork.Electra:
RestApiResponse.sszResponse(forkyState.data, headers)
else:
RestApiResponse.jsonError(Http500, InvalidAcceptError)
else:
RestApiResponse.jsonError(Http500, InvalidAcceptError)

View File

@ -13,7 +13,7 @@ import ".."/[beacon_chain_db, beacon_node],
".."/consensus_object_pools/[blockchain_dag, spec_cache,
attestation_pool, sync_committee_msg_pool],
".."/validators/beacon_validators,
".."/spec/[beaconstate, forks, network],
".."/spec/[beaconstate, forks, network, state_transition_block],
".."/spec/datatypes/[phase0, altair],
"."/[rest_utils, state_ttl_cache]
@ -408,7 +408,10 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
return
withBlck(message.blck):
let data =
when consensusFork >= ConsensusFork.Deneb:
when consensusFork >= ConsensusFork.Electra:
debugRaiseAssert "validator API, electra"
default(phase0.BeaconBlock)
elif consensusFork >= ConsensusFork.Deneb:
let blobsBundle = message.blobsBundleOpt.get()
deneb.BlockContents(
`block`: forkyBlck,
@ -522,7 +525,12 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
contextFork = node.dag.cfg.consensusForkAtEpoch(node.currentSlot.epoch)
withConsensusFork(contextFork):
when consensusFork >= ConsensusFork.Deneb:
when consensusFork >= ConsensusFork.Electra:
# why not, it's a true error message. also:
debugRaiseAssert ""
return RestApiResponse.jsonError(
Http400, "Pre-Deneb builder API unsupported")
elif consensusFork >= ConsensusFork.Deneb:
let res = await makeBlindedBeaconBlockForHeadAndSlot[
consensusFork.BlindedBeaconBlock](
node, payloadBuilderClient, qrandao,
@ -632,7 +640,10 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
return RestApiResponse.jsonError(Http400, InvalidRandaoRevealValue)
withConsensusFork(node.dag.cfg.consensusForkAtEpoch(qslot.epoch)):
when consensusFork >= ConsensusFork.Deneb:
when consensusFork >= ConsensusFork.Electra:
debugRaiseAssert "foo"
return RestApiResponse.jsonError(Http400, InvalidRandaoRevealValue)
elif consensusFork >= ConsensusFork.Deneb:
let
message = (await node.makeMaybeBlindedBeaconBlockForHeadAndSlot(
consensusFork, qrandao, qgraffiti, qhead, qslot)).valueOr:

View File

@ -597,7 +597,9 @@ proc jsonResponseBlock*(t: typedesc[RestApiResponse],
writer.writeField("execution_optimistic", execOpt.get())
writer.writeField("finalized", finalized)
withBlck(data):
writer.writeField("data", forkyBlck)
debugRaiseAssert "foo"
when consensusFork != ConsensusFork.Electra:
writer.writeField("data", forkyBlck)
writer.endRecord()
stream.getOutput(seq[byte])
except IOError:
@ -620,7 +622,9 @@ proc jsonResponseState*(t: typedesc[RestApiResponse],
if execOpt.isSome():
writer.writeField("execution_optimistic", execOpt.get())
withState(data):
writer.writeField("data", forkyState.data)
debugRaiseAssert "foo"
when consensusFork != ConsensusFork.Electra:
writer.writeField("data", forkyState.data)
writer.endRecord()
stream.getOutput(seq[byte])
except IOError:
@ -677,7 +681,9 @@ proc jsonResponseWVersion*(t: typedesc[RestApiResponse], data: auto,
var writer = JsonWriter[RestJson].init(stream)
writer.beginRecord()
writer.writeField("version", version.toString())
writer.writeField("data", data)
when (not (data is electra.BeaconState)) and (not (data is electra.HashedBeaconState)) and (not (data is electra.ExecutionPayload)) and (not (data is electra.ExecutionPayloadForSigning)) and (not (data is electra.ExecutionPayloadHeader)) and (not (data is electra.BeaconBlock)) and (not (data is electra.SignedBeaconBlock)):
debugRaiseAssert "foo"
writer.writeField("data", data)
writer.endRecord()
stream.getOutput(seq[byte])
except IOError:
@ -1517,6 +1523,10 @@ proc readValue*[BlockType: ProduceBlockResponseV2](
value = ProduceBlockResponseV2(kind: ConsensusFork.Deneb,
denebData: res)
of ConsensusFork.Electra:
debugRaiseAssert "electra"
reader.raiseUnexpectedValue("electra missing")
proc readValue*[BlockType: ForkedBlindedBeaconBlock](
reader: var JsonReader[RestJson],
value: var BlockType
@ -1583,6 +1593,9 @@ proc readValue*[BlockType: ForkedBlindedBeaconBlock](
exc.formatMsg("BlindedBlock") & "]")
value = ForkedBlindedBeaconBlock(kind: ConsensusFork.Deneb,
denebData: res)
of ConsensusFork.Electra:
debugRaiseAssert "electra, REST reading"
reader.raiseUnexpectedValue("Incorrect electra block format")
proc readValue*[BlockType: Web3SignerForkedBeaconBlock](
reader: var JsonReader[RestJson],
@ -1885,6 +1898,8 @@ proc readValue*(reader: var JsonReader[RestJson],
assign(
value.denebBody.execution_payload.excess_blob_gas,
ep_src.excess_blob_gas.get())
of ConsensusFork.Electra:
debugRaiseAssert "electra support missing"
## RestPublishedBeaconBlock
proc readValue*(reader: var JsonReader[RestJson],
@ -1991,6 +2006,9 @@ proc readValue*(reader: var JsonReader[RestJson],
body: body.denebBody
)
)
of ConsensusFork.Electra:
debugRaiseAssert "electra missing"
default(ForkedBeaconBlock)
)
## RestPublishedSignedBeaconBlock
@ -2104,7 +2122,9 @@ proc readValue*(reader: var JsonReader[RestJson],
reader.raiseUnexpectedValue("Length mismatch of `kzg_proofs` and `blobs`")
withBlck(distinctBase(signed_message.get)):
when consensusFork >= ConsensusFork.Deneb:
when consensusFork >= ConsensusFork.Electra:
debugRaiseAssert "electra support missing"
elif consensusFork >= ConsensusFork.Deneb:
template kzg_commitments: untyped =
forkyBlck.message.body.blob_kzg_commitments
if kzg_proofs.get().len != kzg_commitments.len:
@ -2232,6 +2252,8 @@ proc readValue*(reader: var JsonReader[RestJson],
reader.raiseUnexpectedValue("Incorrect deneb block format")
value = ForkedSignedBeaconBlock.init(res)
of ConsensusFork.Electra:
debugRaiseAssert "electra support missing"
withBlck(value):
forkyBlck.root = hash_tree_root(forkyBlck.message)
@ -2255,6 +2277,8 @@ proc writeValue*(
of ConsensusFork.Deneb:
writer.writeField("version", "deneb")
writer.writeField("data", value.denebData)
of ConsensusFork.Electra:
debugRaiseAssert "writeValue RestJson Electra ForkedSignedBaconBlock"
writer.endRecord()
# ForkedHashedBeaconState is used where a `ForkedBeaconState` normally would
@ -2358,6 +2382,9 @@ proc readValue*(reader: var JsonReader[RestJson],
except SerializationError:
reader.raiseUnexpectedValue("Incorrect deneb beacon state format")
toValue(denebData)
of ConsensusFork.Electra:
debugRaiseAssert "electra missing"
reader.raiseUnexpectedValue("electra missing")
proc writeValue*(
writer: var JsonWriter[RestJson], value: ForkedHashedBeaconState
@ -2379,6 +2406,8 @@ proc writeValue*(
of ConsensusFork.Deneb:
writer.writeField("version", "deneb")
writer.writeField("data", value.denebData.data)
of ConsensusFork.Electra:
debugRaiseAssert "writeValue RestJson ForkedHashedBeaconState Electra missing"
writer.endRecord()
## SomeForkedLightClientObject
@ -3302,7 +3331,10 @@ proc writeValue*(writer: var JsonWriter[RestJson],
if value.consensusValue.isSome():
writer.writeField("consensus_block_value",
$(value.consensusValue.get()))
writer.writeField("data", forkyMaybeBlindedBlck)
when consensusFork == ConsensusFork.Electra:
debugRaiseAssert "electra JsonWriter ProduceBlockV3 missing"
else:
writer.writeField("data", forkyMaybeBlindedBlck)
writer.endRecord()
proc readValue*(reader: var JsonReader[RestJson],
@ -3328,7 +3360,9 @@ proc readValue*(reader: var JsonReader[RestJson],
reader.raiseUnexpectedValue("Field `data` is missing")
withConsensusFork(version.get):
when consensusFork >= ConsensusFork.Deneb:
when consensusFork >= ConsensusFork.Electra:
debugRaiseAssert "electra missing"
elif consensusFork >= ConsensusFork.Deneb:
if blinded.get:
value = ForkedMaybeBlindedBeaconBlock.init(
RestJson.decode(
@ -3458,6 +3492,9 @@ proc decodeBody*(
return err(RestErrorMessage.init(Http400, UnexpectedDecodeError,
[version, $exc.msg]))
ok(RestPublishedSignedBeaconBlock(ForkedSignedBeaconBlock.init(blck)))
of ConsensusFork.Electra:
debugRaiseAssert "electra"
return err(RestErrorMessage.init(Http400, UnexpectedDecodeError))
else:
err(RestErrorMessage.init(Http415, "Invalid content type",
[version, $body.contentType]))
@ -3548,6 +3585,9 @@ proc decodeBody*(
[version, $exc.msg]))
ok(RestPublishedSignedBlockContents(
kind: ConsensusFork.Deneb, denebData: blckContents))
of ConsensusFork.Electra:
debugRaiseAssert "electra"
return err(RestErrorMessage.init(Http400, UnexpectedDecodeError))
else:
err(RestErrorMessage.init(Http415, "Invalid content type",
[version, $body.contentType]))
@ -3677,6 +3717,10 @@ proc decodeBodyJsonOrSsz*(
[version, $exc.msg]))
ok(RestPublishedSignedBlockContents(
kind: ConsensusFork.Deneb, denebData: blckContents))
of ConsensusFork.Electra:
debugRaiseAssert "electra"
return err(
RestErrorMessage.init(Http400, UnexpectedDecodeError))
else:
err(RestErrorMessage.init(Http415, "Invalid content type",
[version, $body.contentType]))
@ -3820,6 +3864,9 @@ proc decodeBytes*[T: DecodeConsensysTypes](
let fork = ConsensusFork.decodeString(consensusVersion).valueOr:
return err("Invalid or Unsupported consensus version")
case fork
of ConsensusFork.Electra:
debugRaiseAssert "electra in REST decodeBytes"
return err("Invalid or Unsupported consensus version")
of ConsensusFork.Deneb:
let blckContents = ? readSszResBytes(deneb.BlockContents, value)
ok(ProduceBlockResponseV2(kind: ConsensusFork.Deneb,
@ -3844,6 +3891,9 @@ proc decodeBytes*[T: DecodeConsensysTypes](
let fork = ConsensusFork.decodeString(consensusVersion).valueOr:
return err("Invalid or Unsupported consensus version")
case fork
of ConsensusFork.Electra:
debugRaiseAssert "rest decoding blinded"
err("electra missing")
of ConsensusFork.Deneb:
let
blck = ? readSszResBytes(deneb_mev.BlindedBeaconBlock, value)
@ -3916,7 +3966,10 @@ proc decodeBytes*[T: ProduceBlockResponseV3](
except ValueError:
return err("Incorrect `Eth-Consensus-Block-Value` header value")
withConsensusFork(fork):
when consensusFork >= ConsensusFork.Deneb:
when consensusFork >= ConsensusFork.Electra:
debugRaiseAssert "eth2 rest serialization"
return err("electra missing")
elif consensusFork >= ConsensusFork.Deneb:
if blinded:
let contents =
? readSszResBytes(consensusFork.BlindedBlockContents, value)

View File

@ -341,6 +341,7 @@ type
of ConsensusFork.Bellatrix: bellatrixData*: bellatrix.SignedBeaconBlock
of ConsensusFork.Capella: capellaData*: capella.SignedBeaconBlock
of ConsensusFork.Deneb: denebData*: DenebSignedBlockContents
of ConsensusFork.Electra: electraData*: ElectraSignedBlockContents
RestPublishedBeaconBlock* = distinct ForkedBeaconBlock
@ -351,6 +352,7 @@ type
of ConsensusFork.Bellatrix: bellatrixBody*: bellatrix.BeaconBlockBody
of ConsensusFork.Capella: capellaBody*: capella.BeaconBlockBody
of ConsensusFork.Deneb: denebBody*: deneb.BeaconBlockBody
of ConsensusFork.Electra: electraBody*: electra.BeaconBlockBody
ProduceBlockResponseV2* = object
case kind*: ConsensusFork
@ -359,6 +361,7 @@ type
of ConsensusFork.Bellatrix: bellatrixData*: bellatrix.BeaconBlock
of ConsensusFork.Capella: capellaData*: capella.BeaconBlock
of ConsensusFork.Deneb: denebData*: deneb.BlockContents
of ConsensusFork.Electra: electraData*: electra.BlockContents
ProduceBlockResponseV3* = ForkedMaybeBlindedBeaconBlock
@ -615,6 +618,12 @@ func `==`*(a, b: RestValidatorIndex): bool =
template withForkyBlck*(
x: RestPublishedSignedBlockContents, body: untyped): untyped =
case x.kind
of ConsensusFork.Electra:
const consensusFork {.inject, used.} = ConsensusFork.Electra
template forkyBlck: untyped {.inject, used.} = x.electraData.signed_block
template kzg_proofs: untyped {.inject, used.} = x.electraData.kzg_proofs
template blobs: untyped {.inject, used.} = x.electraData.blobs
body
of ConsensusFork.Deneb:
const consensusFork {.inject, used.} = ConsensusFork.Deneb
template forkyBlck: untyped {.inject, used.} = x.denebData.signed_block
@ -652,6 +661,9 @@ func init*(T: type ForkedSignedBeaconBlock,
ForkedSignedBeaconBlock.init(contents.capellaData)
of ConsensusFork.Deneb:
ForkedSignedBeaconBlock.init(contents.denebData.signed_block)
of ConsensusFork.Electra:
debugRaiseAssert "electra init ForkedSignedBeaconBlock from RestPublished*"
default(ForkedSignedBeaconBlock)
func init*(t: typedesc[RestPublishedSignedBlockContents],
blck: phase0.BeaconBlock, root: Eth2Digest,

View File

@ -46,7 +46,8 @@ type
Altair,
Bellatrix,
Capella,
Deneb
Deneb,
Electra
ForkyBeaconState* =
phase0.BeaconState |
@ -71,6 +72,7 @@ type
of ConsensusFork.Bellatrix: bellatrixData*: bellatrix.HashedBeaconState
of ConsensusFork.Capella: capellaData*: capella.HashedBeaconState
of ConsensusFork.Deneb: denebData*: deneb.HashedBeaconState
of ConsensusFork.Electra: electraData*: electra.HashedBeaconState
ForkyExecutionPayload* =
bellatrix.ExecutionPayload |
@ -156,6 +158,7 @@ type
of ConsensusFork.Bellatrix: bellatrixData*: bellatrix.BeaconBlock
of ConsensusFork.Capella: capellaData*: capella.BeaconBlock
of ConsensusFork.Deneb: denebData*: deneb.BeaconBlock
of ConsensusFork.Electra: electraData*: electra.BeaconBlock
ForkedMaybeBlindedBeaconBlock* = object
case kind*: ConsensusFork
@ -169,6 +172,8 @@ type
capellaData*: capella.BeaconBlock
of ConsensusFork.Deneb:
denebData*: deneb_mev.MaybeBlindedBeaconBlock
of ConsensusFork.Electra:
electraData*: electra.BeaconBlock
consensusValue*: Opt[UInt256]
executionValue*: Opt[UInt256]
@ -183,6 +188,7 @@ type
of ConsensusFork.Bellatrix: bellatrixData*: bellatrix_mev.BlindedBeaconBlock
of ConsensusFork.Capella: capellaData*: capella_mev.BlindedBeaconBlock
of ConsensusFork.Deneb: denebData*: deneb_mev.BlindedBeaconBlock
of ConsensusFork.Electra: electraData*: electra.BeaconBlock
ForkySignedBeaconBlock* =
phase0.SignedBeaconBlock |
@ -199,6 +205,7 @@ type
of ConsensusFork.Bellatrix: bellatrixData*: bellatrix.SignedBeaconBlock
of ConsensusFork.Capella: capellaData*: capella.SignedBeaconBlock
of ConsensusFork.Deneb: denebData*: deneb.SignedBeaconBlock
of ConsensusFork.Electra: electraData*: electra.SignedBeaconBlock
ForkySignedBlindedBeaconBlock* =
phase0.SignedBeaconBlock |
@ -214,6 +221,7 @@ type
of ConsensusFork.Bellatrix: bellatrixData*: bellatrix_mev.SignedBlindedBeaconBlock
of ConsensusFork.Capella: capellaData*: capella_mev.SignedBlindedBeaconBlock
of ConsensusFork.Deneb: denebData*: deneb_mev.SignedBlindedBeaconBlock
of ConsensusFork.Electra: electraData*: electra.SignedBeaconBlock
ForkySigVerifiedSignedBeaconBlock* =
phase0.SigVerifiedSignedBeaconBlock |
@ -246,6 +254,7 @@ type
of ConsensusFork.Bellatrix: bellatrixData*: bellatrix.MsgTrustedSignedBeaconBlock
of ConsensusFork.Capella: capellaData*: capella.MsgTrustedSignedBeaconBlock
of ConsensusFork.Deneb: denebData*: deneb.MsgTrustedSignedBeaconBlock
of ConsensusFork.Electra: electraData*: electra.MsgTrustedSignedBeaconBlock
ForkedTrustedSignedBeaconBlock* = object
case kind*: ConsensusFork
@ -254,6 +263,7 @@ type
of ConsensusFork.Bellatrix: bellatrixData*: bellatrix.TrustedSignedBeaconBlock
of ConsensusFork.Capella: capellaData*: capella.TrustedSignedBeaconBlock
of ConsensusFork.Deneb: denebData*: deneb.TrustedSignedBeaconBlock
of ConsensusFork.Electra: electraData*: electra.TrustedSignedBeaconBlock
SomeForkySignedBeaconBlock* =
ForkySignedBeaconBlock |
@ -367,8 +377,28 @@ template kind*(
deneb_mev.SignedBlindedBeaconBlock]): ConsensusFork =
ConsensusFork.Deneb
template kind*(
x: typedesc[
electra.BeaconState |
electra.HashedBeaconState |
electra.ExecutionPayload |
electra.ExecutionPayloadForSigning |
electra.ExecutionPayloadHeader |
electra.BeaconBlock |
electra.SignedBeaconBlock |
electra.TrustedBeaconBlock |
electra.BeaconBlockBody |
electra.SigVerifiedBeaconBlockBody |
electra.TrustedBeaconBlockBody |
electra.SigVerifiedSignedBeaconBlock |
electra.MsgTrustedSignedBeaconBlock |
electra.TrustedSignedBeaconBlock]): ConsensusFork =
ConsensusFork.Electra
template BeaconState*(kind: static ConsensusFork): auto =
when kind == ConsensusFork.Deneb:
when kind == ConsensusFork.Electra:
typedesc[electra.BeaconState]
elif kind == ConsensusFork.Deneb:
typedesc[deneb.BeaconState]
elif kind == ConsensusFork.Capella:
typedesc[capella.BeaconState]
@ -396,7 +426,9 @@ template BeaconBlock*(kind: static ConsensusFork): auto =
static: raiseAssert "Unreachable"
template BeaconBlockBody*(kind: static ConsensusFork): auto =
when kind == ConsensusFork.Deneb:
when kind == ConsensusFork.Electra:
typedesc[electra.BeaconBlockBody]
elif kind == ConsensusFork.Deneb:
typedesc[deneb.BeaconBlockBody]
elif kind == ConsensusFork.Capella:
typedesc[capella.BeaconBlockBody]
@ -410,7 +442,9 @@ template BeaconBlockBody*(kind: static ConsensusFork): auto =
static: raiseAssert "Unreachable"
template SignedBeaconBlock*(kind: static ConsensusFork): auto =
when kind == ConsensusFork.Deneb:
when kind == ConsensusFork.Electra:
typedesc[electra.SignedBeaconBlock]
elif kind == ConsensusFork.Deneb:
typedesc[deneb.SignedBeaconBlock]
elif kind == ConsensusFork.Capella:
typedesc[capella.SignedBeaconBlock]
@ -424,7 +458,9 @@ template SignedBeaconBlock*(kind: static ConsensusFork): auto =
static: raiseAssert "Unreachable"
template TrustedSignedBeaconBlock*(kind: static ConsensusFork): auto =
when kind == ConsensusFork.Deneb:
when kind == ConsensusFork.Electra:
typedesc[electra.TrustedSignedBeaconBlock]
elif kind == ConsensusFork.Deneb:
typedesc[deneb.TrustedSignedBeaconBlock]
elif kind == ConsensusFork.Capella:
typedesc[capella.TrustedSignedBeaconBlock]
@ -438,7 +474,9 @@ template TrustedSignedBeaconBlock*(kind: static ConsensusFork): auto =
static: raiseAssert "Unreachable"
template ExecutionPayloadForSigning*(kind: static ConsensusFork): auto =
when kind == ConsensusFork.Deneb:
when kind == ConsensusFork.Electra:
typedesc[electra.ExecutionPayloadForSigning]
elif kind == ConsensusFork.Deneb:
typedesc[deneb.ExecutionPayloadForSigning]
elif kind == ConsensusFork.Capella:
typedesc[capella.ExecutionPayloadForSigning]
@ -478,7 +516,11 @@ template Forky*(
template withAll*(
x: typedesc[ConsensusFork], body: untyped): untyped =
static: doAssert ConsensusFork.high == ConsensusFork.Deneb
static: doAssert ConsensusFork.high == ConsensusFork.Electra
debugRaiseAssert "don't turn on electra here yet"
#block:
# const consensusFork {.inject, used.} = ConsensusFork.Electra
# body
block:
const consensusFork {.inject, used.} = ConsensusFork.Deneb
body
@ -498,6 +540,9 @@ template withAll*(
template withConsensusFork*(
x: ConsensusFork, body: untyped): untyped =
case x
of ConsensusFork.Electra:
const consensusFork {.inject, used.} = ConsensusFork.Electra
body
of ConsensusFork.Deneb:
const consensusFork {.inject, used.} = ConsensusFork.Deneb
body
@ -516,7 +561,9 @@ template withConsensusFork*(
template BlockContents*(
kind: static ConsensusFork): auto =
when kind == ConsensusFork.Deneb:
when kind == ConsensusFork.Electra:
typedesc[electra.BlockContents]
elif kind == ConsensusFork.Deneb:
typedesc[deneb.BlockContents]
elif kind == ConsensusFork.Capella:
typedesc[capella.BeaconBlock]
@ -554,8 +601,9 @@ template PayloadAttributes*(
{.error: "PayloadAttributes does not support " & $kind.}
# `eth2_merkleization` cannot import `forks` (circular), so the check is here
static: doAssert ConsensusFork.high == ConsensusFork.Deneb,
static: doAssert ConsensusFork.high == ConsensusFork.Electra,
"eth2_merkleization has been checked and `hash_tree_root` is up to date"
debugRaiseAssert("this has not actually been checked for Electra, but it doesn't matter unless the electra fork is entered")
# TODO when https://github.com/nim-lang/Nim/issues/21086 fixed, use return type
# `ref T`
@ -601,6 +649,8 @@ template init*(T: type ForkedSignedBeaconBlock, blck: capella.SignedBeaconBlock)
T(kind: ConsensusFork.Capella, capellaData: blck)
template init*(T: type ForkedSignedBeaconBlock, blck: deneb.SignedBeaconBlock): T =
T(kind: ConsensusFork.Deneb, denebData: blck)
template init*(T: type ForkedSignedBeaconBlock, blck: electra.SignedBeaconBlock): T =
T(kind: ConsensusFork.Electra, electraData: blck)
func init*(T: type ForkedSignedBeaconBlock, forked: ForkedBeaconBlock,
blockRoot: Eth2Digest, signature: ValidatorSig): T =
@ -630,6 +680,11 @@ func init*(T: type ForkedSignedBeaconBlock, forked: ForkedBeaconBlock,
denebData: deneb.SignedBeaconBlock(message: forked.denebData,
root: blockRoot,
signature: signature))
of ConsensusFork.Electra:
T(kind: ConsensusFork.Electra,
electraData: electra.SignedBeaconBlock(message: forked.electraData,
root: blockRoot,
signature: signature))
func init*(T: type ForkedSignedBlindedBeaconBlock,
forked: ForkedBlindedBeaconBlock, blockRoot: Eth2Digest,
@ -656,6 +711,11 @@ func init*(T: type ForkedSignedBlindedBeaconBlock,
T(kind: ConsensusFork.Deneb,
denebData: deneb_mev.SignedBlindedBeaconBlock(message: forked.denebData,
signature: signature))
of ConsensusFork.Electra:
T(kind: ConsensusFork.Electra,
electraData: electra.SignedBeaconBlock(message: forked.electraData,
root: blockRoot,
signature: signature))
template init*(T: type ForkedSignedBlindedBeaconBlock,
blck: capella_mev.BlindedBeaconBlock, blockRoot: Eth2Digest,
@ -692,6 +752,8 @@ template init*(T: type ForkedTrustedSignedBeaconBlock, blck: capella.TrustedSign
T(kind: ConsensusFork.Capella, capellaData: blck)
template init*(T: type ForkedTrustedSignedBeaconBlock, blck: deneb.TrustedSignedBeaconBlock): T =
T(kind: ConsensusFork.Deneb, denebData: blck)
template init*(T: type ForkedTrustedSignedBeaconBlock, blck: electra.TrustedSignedBeaconBlock): T =
T(kind: ConsensusFork.Electra, electraData: blck)
template toString*(kind: ConsensusFork): string =
case kind
@ -705,9 +767,13 @@ template toString*(kind: ConsensusFork): string =
"capella"
of ConsensusFork.Deneb:
"deneb"
of ConsensusFork.Electra:
"electra"
template init*(T: typedesc[ConsensusFork], value: string): Opt[ConsensusFork] =
case value
of "electra":
Opt.some ConsensusFork.Electra
of "deneb":
Opt.some ConsensusFork.Deneb
of "capella":
@ -732,6 +798,10 @@ template init*(T: type ForkedEpochInfo, info: altair.EpochInfo): T =
template withState*(x: ForkedHashedBeaconState, body: untyped): untyped =
case x.kind
of ConsensusFork.Electra:
const consensusFork {.inject, used.} = ConsensusFork.Electra
template forkyState: untyped {.inject, used.} = x.electraData
body
of ConsensusFork.Deneb:
const consensusFork {.inject, used.} = ConsensusFork.Deneb
template forkyState: untyped {.inject, used.} = x.denebData
@ -758,7 +828,9 @@ template forky*(
ForkedBeaconBlock |
ForkedHashedBeaconState,
kind: static ConsensusFork): untyped =
when kind == ConsensusFork.Deneb:
when kind == ConsensusFork.Electra:
x.electraData
elif kind == ConsensusFork.Deneb:
x.denebData
elif kind == ConsensusFork.Capella:
x.capellaData
@ -830,6 +902,8 @@ func setStateRoot*(x: var ForkedHashedBeaconState, root: Eth2Digest) =
func consensusForkEpoch*(
cfg: RuntimeConfig, consensusFork: ConsensusFork): Epoch =
case consensusFork
of ConsensusFork.Electra:
cfg.ELECTRA_FORK_EPOCH
of ConsensusFork.Deneb:
cfg.DENEB_FORK_EPOCH
of ConsensusFork.Capella:
@ -844,14 +918,16 @@ func consensusForkEpoch*(
func consensusForkAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): ConsensusFork =
## Return the current fork for the given epoch.
static:
doAssert high(ConsensusFork) == ConsensusFork.Deneb
doAssert high(ConsensusFork) == ConsensusFork.Electra
doAssert ConsensusFork.Electra > ConsensusFork.Deneb
doAssert ConsensusFork.Deneb > ConsensusFork.Capella
doAssert ConsensusFork.Capella > ConsensusFork.Bellatrix
doAssert ConsensusFork.Bellatrix > ConsensusFork.Altair
doAssert ConsensusFork.Altair > ConsensusFork.Phase0
doAssert GENESIS_EPOCH == 0
if epoch >= cfg.DENEB_FORK_EPOCH: ConsensusFork.Deneb
if epoch >= cfg.ELECTRA_FORK_EPOCH: ConsensusFork.Electra
elif epoch >= cfg.DENEB_FORK_EPOCH: ConsensusFork.Deneb
elif epoch >= cfg.CAPELLA_FORK_EPOCH: ConsensusFork.Capella
elif epoch >= cfg.BELLATRIX_FORK_EPOCH: ConsensusFork.Bellatrix
elif epoch >= cfg.ALTAIR_FORK_EPOCH: ConsensusFork.Altair
@ -859,8 +935,10 @@ func consensusForkAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): ConsensusFork =
func consensusForkForDigest*(
forkDigests: ForkDigests, forkDigest: ForkDigest): Opt[ConsensusFork] =
static: doAssert high(ConsensusFork) == ConsensusFork.Deneb
if forkDigest == forkDigests.deneb:
static: doAssert high(ConsensusFork) == ConsensusFork.Electra
if forkDigest == forkDigests.electra:
ok ConsensusFork.Electra
elif forkDigest == forkDigests.deneb:
ok ConsensusFork.Deneb
elif forkDigest == forkDigests.capella:
ok ConsensusFork.Capella
@ -876,6 +954,8 @@ func consensusForkForDigest*(
func atConsensusFork*(
forkDigests: ForkDigests, consensusFork: ConsensusFork): ForkDigest =
case consensusFork
of ConsensusFork.Electra:
forkDigests.electra
of ConsensusFork.Deneb:
forkDigests.deneb
of ConsensusFork.Capella:
@ -954,6 +1034,10 @@ template withBlck*(
const consensusFork {.inject, used.} = ConsensusFork.Deneb
template forkyBlck: untyped {.inject, used.} = x.denebData
body
of ConsensusFork.Electra:
const consensusFork {.inject, used.} = ConsensusFork.Electra
template forkyBlck: untyped {.inject, used.} = x.electraData
body
func proposer_index*(x: ForkedBeaconBlock): uint64 =
withBlck(x): forkyBlck.proposer_index
@ -977,7 +1061,8 @@ template getForkedBlockField*(
of ConsensusFork.Altair: unsafeAddr x.altairData.message.y
of ConsensusFork.Bellatrix: unsafeAddr x.bellatrixData.message.y
of ConsensusFork.Capella: unsafeAddr x.capellaData.message.y
of ConsensusFork.Deneb: unsafeAddr x.denebData.message.y)[]
of ConsensusFork.Deneb: unsafeAddr x.denebData.message.y
of ConsensusFork.Electra: unsafeAddr x.electraData.message.y)[]
template signature*(x: ForkedSignedBeaconBlock |
ForkedMsgTrustedSignedBeaconBlock |
@ -1015,6 +1100,12 @@ template withForkyMaybeBlindedBlck*(
b: ForkedMaybeBlindedBeaconBlock,
body: untyped): untyped =
case b.kind
of ConsensusFork.Electra:
const
consensusFork {.inject, used.} = ConsensusFork.Electra
isBlinded {.inject, used.} = false
template forkyMaybeBlindedBlck: untyped {.inject, used.} = b.electraData
body
of ConsensusFork.Deneb:
const consensusFork {.inject, used.} = ConsensusFork.Deneb
template d: untyped = b.denebData
@ -1059,6 +1150,11 @@ template withStateAndBlck*(
ForkedTrustedSignedBeaconBlock,
body: untyped): untyped =
case s.kind
of ConsensusFork.Electra:
const consensusFork {.inject, used.} = ConsensusFork.Electra
template forkyState: untyped {.inject.} = s.electraData
template forkyBlck: untyped {.inject.} = b.electraData
body
of ConsensusFork.Deneb:
const consensusFork {.inject, used.} = ConsensusFork.Deneb
template forkyState: untyped {.inject.} = s.denebData
@ -1153,6 +1249,7 @@ func electraFork*(cfg: RuntimeConfig): Fork =
func forkAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): Fork =
case cfg.consensusForkAtEpoch(epoch)
of ConsensusFork.Electra: cfg.electraFork
of ConsensusFork.Deneb: cfg.denebFork
of ConsensusFork.Capella: cfg.capellaFork
of ConsensusFork.Bellatrix: cfg.bellatrixFork
@ -1161,6 +1258,7 @@ func forkAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): Fork =
func forkVersionAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): Version =
case cfg.consensusForkAtEpoch(epoch)
of ConsensusFork.Electra: cfg.ELECTRA_FORK_VERSION
of ConsensusFork.Deneb: cfg.DENEB_FORK_VERSION
of ConsensusFork.Capella: cfg.CAPELLA_FORK_VERSION
of ConsensusFork.Bellatrix: cfg.BELLATRIX_FORK_VERSION
@ -1168,9 +1266,9 @@ func forkVersionAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): Version =
of ConsensusFork.Phase0: cfg.GENESIS_FORK_VERSION
func nextForkEpochAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): Epoch =
static: doAssert high(ConsensusFork) == ConsensusFork.Deneb
case cfg.consensusForkAtEpoch(epoch)
of ConsensusFork.Deneb: FAR_FUTURE_EPOCH
of ConsensusFork.Electra: FAR_FUTURE_EPOCH
of ConsensusFork.Deneb: cfg.ELECTRA_FORK_EPOCH
of ConsensusFork.Capella: cfg.DENEB_FORK_EPOCH
of ConsensusFork.Bellatrix: cfg.CAPELLA_FORK_EPOCH
of ConsensusFork.Altair: cfg.BELLATRIX_FORK_EPOCH
@ -1183,6 +1281,7 @@ func forkVersion*(cfg: RuntimeConfig, consensusFork: ConsensusFork): Version =
of ConsensusFork.Bellatrix: cfg.BELLATRIX_FORK_VERSION
of ConsensusFork.Capella: cfg.CAPELLA_FORK_VERSION
of ConsensusFork.Deneb: cfg.DENEB_FORK_VERSION
of ConsensusFork.Electra: cfg.ELECTRA_FORK_VERSION
func lcDataForkAtConsensusFork*(
consensusFork: ConsensusFork): LightClientDataFork =
@ -1290,7 +1389,7 @@ func compute_fork_digest*(current_version: Version,
func init*(T: type ForkDigests,
cfg: RuntimeConfig,
genesis_validators_root: Eth2Digest): T =
static: doAssert high(ConsensusFork) == ConsensusFork.Deneb
static: doAssert high(ConsensusFork) == ConsensusFork.Electra
T(
phase0:
compute_fork_digest(cfg.GENESIS_FORK_VERSION, genesis_validators_root),

View File

@ -8,7 +8,7 @@
{.push raises: [].}
import
./datatypes/[phase0, altair, bellatrix, capella, deneb],
./datatypes/[phase0, altair, bellatrix, capella, deneb, electra],
./eth2_merkleization
type
@ -957,9 +957,13 @@ func toLightClientHeader*(
altair.SignedBeaconBlock | altair.TrustedSignedBeaconBlock |
bellatrix.SignedBeaconBlock | bellatrix.TrustedSignedBeaconBlock |
capella.SignedBeaconBlock | capella.TrustedSignedBeaconBlock |
deneb.SignedBeaconBlock | deneb.TrustedSignedBeaconBlock,
deneb.SignedBeaconBlock | deneb.TrustedSignedBeaconBlock |
electra.SignedBeaconBlock | electra.TrustedSignedBeaconBlock,
kind: static LightClientDataFork): auto =
when kind == LightClientDataFork.Deneb:
when blck is electra.SignedBeaconBlock or blck is electra.TrustedSignedBeaconBlock:
debugRaiseAssert "toLightClientHeader electra missing"
default(deneb.LightClientHeader)
elif kind == LightClientDataFork.Deneb:
blck.toDenebLightClientHeader()
elif kind == LightClientDataFork.Capella:
blck.toCapellaLightClientHeader()

View File

@ -295,7 +295,10 @@ proc state_transition_block*(
doAssert not rollback.isNil, "use noRollback if it's ok to mess up state"
let res = withState(state):
when consensusFork == type(signedBlock).kind:
when consensusFork == ConsensusFork.Electra:
debugRaiseAssert "electra state_transition_block"
err("no")
elif consensusFork == type(signedBlock).kind:
state_transition_block_aux(cfg, forkyState, signedBlock, cache, flags)
else:
err("State/block fork mismatch")
@ -457,6 +460,8 @@ proc makeBeaconBlockWithRewards*(
])
else:
raiseAssert "Attempt to use non-Deneb payload with post-Deneb state"
elif consensusFork == ConsensusFork.Electra:
debugRaiseAssert "makeBeaconBlock doesn't support Electra"
else:
static: raiseAssert "Unreachable"
@ -480,6 +485,8 @@ proc makeBeaconBlockWithRewards*(
case state.kind
of ConsensusFork.Deneb: makeBeaconBlock(deneb)
else: raiseAssert "Attempt to use Deneb payload with non-Deneb state"
elif payloadFork == ConsensusFork.Electra:
debugRaiseAssert "Electra block production missing"
else:
{.error: "Unsupported fork".}

View File

@ -2259,6 +2259,9 @@ proc publishBlock*(
publishBlock(it, data.capellaData)
of ConsensusFork.Deneb:
publishBlock(it, data.denebData)
of ConsensusFork.Electra:
debugRaiseAssert "electra missing"
publishBlock(it, data.denebData)
do:
if apiResponse.isErr():
handleCommunicationError()
@ -2305,6 +2308,9 @@ proc publishBlock*(
publishBlock(it, data.capellaData)
of ConsensusFork.Deneb:
publishBlock(it, data.denebData)
of ConsensusFork.Electra:
debugRaiseAssert "electra in vc"
publishBlock(it, data.denebData)
do:
if apiResponse.isErr():
@ -2461,6 +2467,9 @@ proc publishBlindedBlock*(
publishBlindedBlock(it, data.capellaData)
of ConsensusFork.Deneb:
publishBlindedBlock(it, data.denebData)
of ConsensusFork.Electra:
debugRaiseAssert "vc part something"
publishBlindedBlock(it, data.denebData)
do:
if apiResponse.isErr():
handleCommunicationError()
@ -2506,6 +2515,9 @@ proc publishBlindedBlock*(
publishBlindedBlock(it, data.capellaData)
of ConsensusFork.Deneb:
publishBlindedBlock(it, data.denebData)
of ConsensusFork.Electra:
debugRaiseAssert "more electra vc"
publishBlindedBlock(it, data.denebData)
do:
if apiResponse.isErr():
handleCommunicationError()

View File

@ -38,7 +38,10 @@ func shortLog(v: Opt[UInt256]): auto =
func shortLog(v: ForkedMaybeBlindedBeaconBlock): auto =
withForkyMaybeBlindedBlck(v):
when consensusFork < ConsensusFork.Deneb:
when consensusFork == ConsensusFork.Electra:
debugRaiseAssert ""
shortLog(default(phase0.BeaconBlock))
elif consensusFork < ConsensusFork.Deneb:
shortLog(forkyMaybeBlindedBlck)
else:
when isBlinded:
@ -109,6 +112,9 @@ proc produceBlock(
data: ForkedBeaconBlock.init(blck),
kzgProofsOpt: Opt.some(kzgProofs),
blobsOpt: Opt.some(blobs)))
of ConsensusFork.Electra:
debugRaiseAssert ""
return Opt.none(PreparedBeaconBlock)
proc produceBlindedBlock(
vc: ValidatorClientRef,
@ -323,9 +329,12 @@ proc publishBlockV3(vc: ValidatorClientRef, currentSlot, slot: Slot,
warn "Blinded block was not accepted by beacon node"
false
else:
debugRaiseAssert "electra htr"
let
blockRoot = hash_tree_root(
when consensusFork < ConsensusFork.Deneb:
when consensusFork == ConsensusFork.Electra:
default(Attestation)
elif consensusFork < ConsensusFork.Deneb:
forkyMaybeBlindedBlck
else:
forkyMaybeBlindedBlck.`block`
@ -345,9 +354,12 @@ proc publishBlockV3(vc: ValidatorClientRef, currentSlot, slot: Slot,
.slashingProtection
.registerBlock(vindex, validator.pubkey, slot, signingRoot)
debugRaiseAssert "electra logging"
logScope:
blck = shortLog(
when consensusFork < ConsensusFork.Deneb:
when consensusFork == ConsensusFork.Electra:
default(phase0.BeaconBlock)
elif consensusFork < ConsensusFork.Deneb:
forkyMaybeBlindedBlck
else:
forkyMaybeBlindedBlck.`block`
@ -599,6 +611,9 @@ proc publishBlockV2(vc: ValidatorClientRef, currentSlot, slot: Slot,
signature: signature),
kzg_proofs: preparedBlock.kzgProofsOpt.get,
blobs: preparedBlock.blobsOpt.get))
of ConsensusFork.Electra:
debugRaiseAssert ""
default(RestPublishedSignedBlockContents)
res =
try:

View File

@ -421,6 +421,9 @@ proc getExecutionPayload(
PayloadType, beaconHead.blck.bid.root, executionHead, latestSafe,
latestFinalized, timestamp, random, feeRecipient, withdrawals)
# BlockRewards has issues resolving somehow otherwise
import ".."/spec/state_transition_block
proc makeBeaconBlockForHeadAndSlot*(
PayloadType: type ForkyExecutionPayloadForSigning,
node: BeaconNode, randao_reveal: ValidatorSig,
@ -1195,7 +1198,10 @@ proc proposeBlock(node: BeaconNode,
genesis_validators_root, node.config.localBlockValueBoost)
return withConsensusFork(node.dag.cfg.consensusForkAtEpoch(slot.epoch)):
when consensusFork >= ConsensusFork.Deneb:
when consensusFork >= ConsensusFork.Electra:
debugRaiseAssert "can't propose electra block"
return default(BlockRef)
elif consensusFork >= ConsensusFork.Deneb:
proposeBlockContinuation(
consensusFork.SignedBlindedBeaconBlock,
consensusFork.ExecutionPayloadForSigning)

View File

@ -535,7 +535,8 @@ proc getBlockSignature*(v: AttachedValidator, fork: Fork,
let web3signerRequest =
when blck is ForkedBlindedBeaconBlock:
case blck.kind
of ConsensusFork.Phase0 .. ConsensusFork.Capella:
of ConsensusFork.Phase0 .. ConsensusFork.Capella, ConsensusFork.Electra:
debugRaiseAssert "move electra case out"
return SignatureResult.err("Invalid blinded beacon block fork")
of ConsensusFork.Deneb:
case v.data.remoteType
@ -613,6 +614,9 @@ proc getBlockSignature*(v: AttachedValidator, fork: Fork,
Web3SignerForkedBeaconBlock(kind: ConsensusFork.Deneb,
data: forkyMaybeBlindedBlck.`block`.toBeaconBlockHeader),
proofs)
elif consensusFork == ConsensusFork.Electra:
debugRaiseAssert ""
default(Web3SignerRequest)
else:
case blck.kind
of ConsensusFork.Phase0 .. ConsensusFork.Bellatrix:
@ -643,6 +647,9 @@ proc getBlockSignature*(v: AttachedValidator, fork: Fork,
Web3SignerForkedBeaconBlock(kind: ConsensusFork.Deneb,
data: blck.denebData.toBeaconBlockHeader),
proofs)
of ConsensusFork.Electra:
debugRaiseAssert "validator pool"
return SignatureResult.err("Invalid beacon block fork: electra")
await v.signData(web3signerRequest)
# https://github.com/ethereum/consensus-specs/blob/v1.4.0/specs/phase0/validator.md#aggregate-signature

View File

@ -98,6 +98,9 @@ template saveSSZFile(filename: string, value: ForkedHashedBeaconState) =
of ConsensusFork.Bellatrix: SSZ.saveFile(filename, value.bellatrixData.data)
of ConsensusFork.Capella: SSZ.saveFile(filename, value.capellaData.data)
of ConsensusFork.Deneb: SSZ.saveFile(filename, value.denebData.data)
of ConsensusFork.Electra:
debugRaiseAssert ""
let x = 5
except IOError:
raiseAssert "error saving SSZ file"
@ -268,4 +271,4 @@ when isMainModule:
of hash_tree_root: doSSZ(conf)
of pretty: doSSZ(conf)
of transition: doTransition(conf)
of slots: doSlots(conf)
of slots: doSlots(conf)

View File

@ -266,6 +266,9 @@ proc cmdBench(conf: DbConf, cfg: RuntimeConfig) =
of ConsensusFork.Deneb:
blocks[4].add dag.db.getBlock(
blck.root, deneb.TrustedSignedBeaconBlock).get()
of ConsensusFork.Electra:
debugRaiseAssert ""
let x = 5
let stateData = newClone(dag.headState)
@ -338,6 +341,9 @@ proc cmdBench(conf: DbConf, cfg: RuntimeConfig) =
of ConsensusFork.Deneb:
doAssert dbBenchmark.getState(
forkyState.root, loadedState[4][].data, noRollback)
of ConsensusFork.Electra:
debugRaiseAssert ""
let x = 5
if forkyState.data.slot.epoch mod 16 == 0:
let loadedRoot = case consensusFork
@ -346,6 +352,9 @@ proc cmdBench(conf: DbConf, cfg: RuntimeConfig) =
of ConsensusFork.Bellatrix: hash_tree_root(loadedState[2][].data)
of ConsensusFork.Capella: hash_tree_root(loadedState[3][].data)
of ConsensusFork.Deneb: hash_tree_root(loadedState[4][].data)
of ConsensusFork.Electra:
debugRaiseAssert ""
ZERO_HASH
doAssert hash_tree_root(forkyState.data) == loadedRoot
processBlocks(blocks[0])
@ -1169,4 +1178,4 @@ when isMainModule:
of DbCmd.validatorPerf:
cmdValidatorPerf(conf, cfg)
of DbCmd.validatorDb:
cmdValidatorDb(conf, cfg)
cmdValidatorDb(conf, cfg)

View File

@ -472,6 +472,9 @@ cli do(slots = SLOTS_PER_EPOCH * 7,
if blockRatio > 0.0:
withTimer(timers[t]):
case dag.cfg.consensusForkAtEpoch(slot.epoch)
of ConsensusFork.Electra:
echo "no electra here"
debugRaiseAssert "no electra"
of ConsensusFork.Deneb: proposeDenebBlock(slot)
of ConsensusFork.Capella: proposeCapellaBlock(slot)
of ConsensusFork.Bellatrix, ConsensusFork.Altair, ConsensusFork.Phase0:
@ -507,4 +510,4 @@ cli do(slots = SLOTS_PER_EPOCH * 7,
echo "Done!"
printTimers(dag.headState, attesters, true, timers)
printTimers(dag.headState, attesters, true, timers)

View File

@ -221,6 +221,9 @@ cli do(validatorsDir: string, secretsDir: string,
fork, genesis_validators_root, slot, blockRoot,
validators[proposer]).toValidatorSig())
dump(".", signedBlock)
of ConsensusFork.Electra:
debugRaiseAssert ""
let x =5
except CatchableError:
raiseAssert "unreachable"
notice "Block proposed", message, blockRoot
@ -291,4 +294,4 @@ cli do(validatorsDir: string, secretsDir: string,
syncAggregate.sync_committee_bits.setBit(i)
if inited:
syncAggregate.sync_committee_signature = finish(agg).toValidatorSig()
syncAggregate.sync_committee_signature = finish(agg).toValidatorSig()

View File

@ -47,6 +47,12 @@ func readValue*(r: var JsonReader, a: var seq[byte]) =
func genesisTestRuntimeConfig*(consensusFork: ConsensusFork): RuntimeConfig =
var res = defaultRuntimeConfig
case consensusFork
of ConsensusFork.Electra:
res.ELECTRA_FORK_EPOCH = GENESIS_EPOCH
res.DENEB_FORK_EPOCH = GENESIS_EPOCH
res.CAPELLA_FORK_EPOCH = GENESIS_EPOCH
res.BELLATRIX_FORK_EPOCH = GENESIS_EPOCH
res.ALTAIR_FORK_EPOCH = GENESIS_EPOCH
of ConsensusFork.Deneb:
res.DENEB_FORK_EPOCH = GENESIS_EPOCH
res.CAPELLA_FORK_EPOCH = GENESIS_EPOCH
@ -160,4 +166,4 @@ proc loadForkedState*(
withState(state[]):
forkyState.data = parseTest(path, SSZ, consensusFork.BeaconState)
forkyState.root = hash_tree_root(forkyState.data)
state
state

View File

@ -123,29 +123,32 @@ proc loadOps(
let filename = step["block"].getStr()
doAssert step.hasKey"blobs" == step.hasKey"proofs"
withConsensusFork(fork):
let
blck = parseTest(
path/filename & ".ssz_snappy",
SSZ, consensusFork.SignedBeaconBlock)
when consensusFork != ConsensusFork.Electra:
let
blck = parseTest(
path/filename & ".ssz_snappy",
SSZ, consensusFork.SignedBeaconBlock)
blobData =
when consensusFork >= ConsensusFork.Deneb:
if step.hasKey"blobs":
numExtraFields += 2
Opt.some BlobData(
blobs: distinctBase(parseTest(
path/(step["blobs"].getStr()) & ".ssz_snappy",
SSZ, List[KzgBlob, Limit MAX_BLOBS_PER_BLOCK])),
proofs: step["proofs"].mapIt(KzgProof.fromHex(it.getStr())))
blobData =
when consensusFork >= ConsensusFork.Electra:
debugRaiseAssert "no electra support in fc test"
elif consensusFork >= ConsensusFork.Deneb:
if step.hasKey"blobs":
numExtraFields += 2
Opt.some BlobData(
blobs: distinctBase(parseTest(
path/(step["blobs"].getStr()) & ".ssz_snappy",
SSZ, List[KzgBlob, Limit MAX_BLOBS_PER_BLOCK])),
proofs: step["proofs"].mapIt(KzgProof.fromHex(it.getStr())))
else:
Opt.none(BlobData)
else:
doAssert not step.hasKey"blobs"
Opt.none(BlobData)
else:
doAssert not step.hasKey"blobs"
Opt.none(BlobData)
result.add Operation(kind: opOnBlock,
blck: ForkedSignedBeaconBlock.init(blck),
blobData: blobData)
result.add Operation(kind: opOnBlock,
blck: ForkedSignedBeaconBlock.init(blck),
blobData: blobData)
elif step.hasKey"attester_slashing":
let filename = step["attester_slashing"].getStr()
let attesterSlashing = parseTest(
@ -302,8 +305,13 @@ proc doRunTest(
let
stores = withConsensusFork(fork):
initialLoad(
path, db, consensusFork.BeaconState, consensusFork.BeaconBlock)
when consensusFork != ConsensusFork.Electra:
# another withFoo when it statically knows, sure, ok, so this means another place it has to be disabled
initialLoad(
path, db, consensusFork.BeaconState, consensusFork.BeaconBlock)
else:
debugRaiseAssert "electra etc"
default(tuple[dag: ChainDAGRef, fkChoice: ref ForkChoice])
rng = HmacDrbgContext.new()
taskpool =
@ -335,11 +343,13 @@ proc doRunTest(
doAssert status.isOk == step.valid
of opOnBlock:
withBlck(step.blck):
let status = stepOnBlock(
stores.dag, stores.fkChoice,
verifier, state[], stateCache,
forkyBlck, step.blobData, time, invalidatedHashes)
doAssert status.isOk == step.valid
debugRaiseAssert "electra etc"
when typeof(forkyBlck).kind != ConsensusFork.Electra:
let status = stepOnBlock(
stores.dag, stores.fkChoice,
verifier, state[], stateCache,
forkyBlck, step.blobData, time, invalidatedHashes)
doAssert status.isOk == step.valid
of opOnAttesterSlashing:
let indices =
check_attester_slashing(state[], step.attesterSlashing, flags = {})
@ -396,15 +406,17 @@ template fcSuite(suiteName: static[string], testPathElem: static[string]) =
continue
let fork = forkForPathComponent(path).valueOr:
raiseAssert "Unknown test fork: " & testsPath
for kind, path in walkDir(testsPath, relative = true, checkDir = true):
let basePath = testsPath/path/"pyspec_tests"
if kind != pcDir:
continue
for kind, path in walkDir(basePath, relative = true, checkDir = true):
runTest(suiteName, basePath/path, fork)
if true:
debugRaiseAssert "no electra in fc tests"
for kind, path in walkDir(testsPath, relative = true, checkDir = true):
let basePath = testsPath/path/"pyspec_tests"
if kind != pcDir:
continue
for kind, path in walkDir(basePath, relative = true, checkDir = true):
runTest(suiteName, basePath/path, fork)
from ../../beacon_chain/conf import loadKzgTrustedSetup
discard loadKzgTrustedSetup() # Required for Deneb tests
fcSuite("ForkChoice", "fork_choice")
fcSuite("Sync", "sync")
fcSuite("Sync", "sync")

View File

@ -68,11 +68,13 @@ suite "EF - Light client - Single merkle proof" & preset():
continue
let objName = path
withConsensusFork(fork):
for kind, path in walkDir(suitePath, relative = true, checkDir = true):
case objName
of "BeaconBlockBody":
runTest(suiteName, suitePath/path, consensusFork.BeaconBlockBody)
of "BeaconState":
runTest(suiteName, suitePath/path, consensusFork.BeaconState)
else:
raiseAssert "Unknown test object: " & suitePath/path
debugRaiseAssert ""
when consensusFork != ConsensusFork.Electra:
for kind, path in walkDir(suitePath, relative = true, checkDir = true):
case objName
of "BeaconBlockBody":
runTest(suiteName, suitePath/path, consensusFork.BeaconBlockBody)
of "BeaconState":
runTest(suiteName, suitePath/path, consensusFork.BeaconState)
else:
raiseAssert "Unknown test object: " & suitePath/path

View File

@ -25,12 +25,13 @@ suite "Light client" & preset():
headPeriod = 3.SyncCommitteePeriod
let
cfg = block: # Fork schedule so that each `LightClientDataFork` is covered
static: doAssert ConsensusFork.high == ConsensusFork.Deneb
static: doAssert ConsensusFork.high == ConsensusFork.Electra
var res = defaultRuntimeConfig
res.ALTAIR_FORK_EPOCH = 1.Epoch
res.BELLATRIX_FORK_EPOCH = 2.Epoch
res.CAPELLA_FORK_EPOCH = (EPOCHS_PER_SYNC_COMMITTEE_PERIOD * 1).Epoch
res.DENEB_FORK_EPOCH = (EPOCHS_PER_SYNC_COMMITTEE_PERIOD * 2).Epoch
debugRaiseAssert "don't use FAR_FUTURE_EPOCH"
res.ELECTRA_FORK_EPOCH = FAR_FUTURE_EPOCH
res
altairStartSlot = cfg.ALTAIR_FORK_EPOCH.start_slot
@ -246,4 +247,4 @@ suite "Light client" & preset():
let headSlot = (finalizedSlot.epoch + i).start_slot
cpDag.advanceToSlot(headSlot, verifier, quarantine[])
check true
check true

View File

@ -28,12 +28,13 @@ suite "Light client processor" & preset():
highPeriod = 5.SyncCommitteePeriod
let
cfg = block: # Fork schedule so that each `LightClientDataFork` is covered
static: doAssert ConsensusFork.high == ConsensusFork.Deneb
static: doAssert ConsensusFork.high == ConsensusFork.Electra
var res = defaultRuntimeConfig
res.ALTAIR_FORK_EPOCH = 1.Epoch
res.BELLATRIX_FORK_EPOCH = 2.Epoch
res.CAPELLA_FORK_EPOCH = (EPOCHS_PER_SYNC_COMMITTEE_PERIOD * 1).Epoch
res.DENEB_FORK_EPOCH = (EPOCHS_PER_SYNC_COMMITTEE_PERIOD * 2).Epoch
debugRaiseAssert "presumably FAR_FUTURE_EPOCH is less than optimal"
res.ELECTRA_FORK_EPOCH = FAR_FUTURE_EPOCH
res
@ -387,4 +388,4 @@ suite "Light client processor" & preset():
check:
res.isErr
res.error == VerifierError.MissingParent
numOnStoreInitializedCalls == 0
numOnStoreInitializedCalls == 0

View File

@ -92,6 +92,9 @@ func init(T: type ForkedBeaconBlock, contents: ProduceBlockResponseV2): T =
return ForkedBeaconBlock.init(contents.capellaData)
of ConsensusFork.Deneb:
return ForkedBeaconBlock.init(contents.denebData.`block`)
of ConsensusFork.Electra:
debugRaiseAssert "probably like the deneb case"
return default(T)
proc getBlock(
fork: ConsensusFork,
@ -104,6 +107,9 @@ proc getBlock(
of ConsensusFork.Phase0 .. ConsensusFork.Bellatrix: raiseAssert "Unsupported fork"
of ConsensusFork.Capella: CapellaBlock % [feeRecipient]
of ConsensusFork.Deneb: DenebBlockContents % [feeRecipient]
of ConsensusFork.Electra:
debugRaiseAssert "electra test signing node getblock"
raiseAssert "electra unsupported"
except ValueError:
# https://github.com/nim-lang/Nim/pull/23356
raiseAssert "Arguments match the format string"
@ -129,6 +135,9 @@ func init(t: typedesc[Web3SignerForkedBeaconBlock],
Web3SignerForkedBeaconBlock(
kind: ConsensusFork.Deneb,
data: forked.denebData.toBeaconBlockHeader)
of ConsensusFork.Electra:
debugRaiseAssert "electra missing"
raiseAssert "electra missing"
proc createKeystore(dataDir, pubkey,
store, password: string): Result[void, string] =

View File

@ -48,7 +48,9 @@ proc makeTestDB*(
# Upgrade genesis state to later fork, if required by fork schedule
cfg.maybeUpgradeState(genState[])
withState(genState[]):
when consensusFork > ConsensusFork.Phase0:
when consensusFork >= ConsensusFork.Electra:
debugRaiseAssert "makeTestDB electra missing"
elif consensusFork > ConsensusFork.Phase0:
forkyState.data.fork.previous_version =
forkyState.data.fork.current_version
forkyState.data.latest_block_header.body_root =
@ -95,4 +97,4 @@ proc getEarliestInvalidBlockRoot*(
break
curBlck = curBlck.parent
curBlck.root
curBlck.root

View File

@ -73,7 +73,7 @@ proc getTestStates*(
info = ForkedEpochInfo()
cfg = defaultRuntimeConfig
static: doAssert high(ConsensusFork) == ConsensusFork.Deneb
static: doAssert high(ConsensusFork) == ConsensusFork.Electra
if consensusFork >= ConsensusFork.Altair:
cfg.ALTAIR_FORK_EPOCH = 1.Epoch
if consensusFork >= ConsensusFork.Bellatrix:
@ -83,6 +83,8 @@ proc getTestStates*(
if consensusFork >= ConsensusFork.Deneb:
cfg.DENEB_FORK_EPOCH = 4.Epoch
debugRaiseAssert "ELECTRA_FORK_EPOCH"
for i, epoch in stateEpochs:
let slot = epoch.Epoch.start_slot
if getStateField(tmpState[], slot) < slot:
@ -95,4 +97,4 @@ proc getTestStates*(
doAssert getStateField(tmpState[], slot) == slot
if tmpState[].kind == consensusFork:
result.add assignClone(tmpState[])
result.add assignClone(tmpState[])