Skip to content

Commit

Permalink
remove some debugRaiseAsserts and fill in Electra functionality (#6179)
Browse files Browse the repository at this point in the history
  • Loading branch information
tersec authored Apr 6, 2024
1 parent 0d53422 commit 2792140
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 22 deletions.
7 changes: 5 additions & 2 deletions beacon_chain/consensus_object_pools/blockchain_dag.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1005,8 +1005,11 @@ proc applyBlock(
dag.cfg, state, data, cache, info,
dag.updateFlags + {slotProcessed}, noRollback)
of ConsensusFork.Electra:
debugRaiseAssert "electra applyblock missing"
return ok()
let data = getBlock(dag, bid, electra.TrustedSignedBeaconBlock).valueOr:
return err("Block load failed")
? state_transition(
dag.cfg, state, data, cache, info,
dag.updateFlags + {slotProcessed}, noRollback)

ok()

Expand Down
6 changes: 3 additions & 3 deletions beacon_chain/consensus_object_pools/consensus_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,9 @@ proc runProposalForkchoiceUpdated*(
debug "Fork-choice updated for proposal", status

static: doAssert high(ConsensusFork) == ConsensusFork.Electra
when consensusFork >= ConsensusFork.Electra:
debugRaiseAssert "foobar"
elif consensusFork >= ConsensusFork.Deneb:
when consensusFork >= ConsensusFork.Deneb:
# https://github.com/ethereum/execution-apis/blob/90a46e9137c89d58e818e62fa33a0347bba50085/src/engine/prague.md
# does not define any new forkchoiceUpdated, so reuse V3 from Dencun
callForkchoiceUpdated(PayloadAttributesV3(
timestamp: Quantity timestamp,
prevRandao: FixedBytes[32] randomData,
Expand Down
8 changes: 4 additions & 4 deletions beacon_chain/el/el_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,10 @@ proc getPayloadFromSingleEL(
prevRandao: FixedBytes[32] randomData.data,
suggestedFeeRecipient: suggestedFeeRecipient,
withdrawals: withdrawals))
elif GetPayloadResponseType is engine_api.GetPayloadV3Response:
elif GetPayloadResponseType is engine_api.GetPayloadV3Response or
GetPayloadResponseType is engine_api.GetPayloadV4Response:
# https://github.com/ethereum/execution-apis/blob/90a46e9137c89d58e818e62fa33a0347bba50085/src/engine/prague.md
# does not define any new forkchoiceUpdated, so reuse V3 from Dencun
let response = await rpcClient.forkchoiceUpdated(
ForkchoiceStateV1(
headBlockHash: headBlock.asBlockHash,
Expand All @@ -806,9 +809,6 @@ 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

Expand Down
3 changes: 1 addition & 2 deletions beacon_chain/nimbus_signing_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ proc installApiHandlers*(node: SigningNodeRef) =
of ConsensusFork.Deneb:
(GeneralizedIndex(801), request.beaconBlockHeader.data)
of ConsensusFork.Electra:
debugRaiseAssert "electra signing node missing"
(GeneralizedIndex(801*42), request.beaconBlockHeader.data)
(GeneralizedIndex(801), request.beaconBlockHeader.data)

if request.proofs.isNone() or len(request.proofs.get()) == 0:
return errorResponse(Http400, MissingMerkleProofError)
Expand Down
12 changes: 10 additions & 2 deletions beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3525,8 +3525,16 @@ proc decodeBody*(
[version, $exc.msg]))
ok(RestPublishedSignedBeaconBlock(ForkedSignedBeaconBlock.init(blck)))
of ConsensusFork.Electra:
debugRaiseAssert "electra"
return err(RestErrorMessage.init(Http400, UnexpectedDecodeError))
let blck =
try:
SSZ.decode(body.data, electra.SignedBeaconBlock)
except SerializationError as exc:
return err(RestErrorMessage.init(Http400, UnableDecodeError,
[version, exc.formatMsg("<data>")]))
except CatchableError as exc:
return err(RestErrorMessage.init(Http400, UnexpectedDecodeError,
[version, $exc.msg]))
ok(RestPublishedSignedBeaconBlock(ForkedSignedBeaconBlock.init(blck)))
else:
err(RestErrorMessage.init(Http415, "Invalid content type",
[version, $body.contentType]))
Expand Down
4 changes: 3 additions & 1 deletion beacon_chain/spec/forks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,9 @@ template BeaconState*(kind: static ConsensusFork): auto =
static: raiseAssert "Unreachable"

template BeaconBlock*(kind: static ConsensusFork): auto =
when kind == ConsensusFork.Deneb:
when kind == ConsensusFork.Electra:
typedesc[electra.BeaconBlock]
elif kind == ConsensusFork.Deneb:
typedesc[deneb.BeaconBlock]
elif kind == ConsensusFork.Capella:
typedesc[capella.BeaconBlock]
Expand Down
11 changes: 6 additions & 5 deletions beacon_chain/spec/state_transition.nim
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,7 @@ proc state_transition_block*(
doAssert not rollback.isNil, "use noRollback if it's ok to mess up state"

let res = withState(state):
when consensusFork == ConsensusFork.Electra:
debugRaiseAssert "electra state_transition_block"
err("no")
elif consensusFork == type(signedBlock).kind:
when consensusFork == type(signedBlock).kind:
state_transition_block_aux(cfg, forkyState, signedBlock, cache, flags)
else:
err("State/block fork mismatch")
Expand Down Expand Up @@ -383,6 +380,8 @@ func partialBeaconBlock*(
when consensusFork >= ConsensusFork.Deneb:
res.body.blob_kzg_commitments = execution_payload.blobsBundle.commitments

debugRaiseAssert "check for new fields or conditions to ensure in electra"

res

proc makeBeaconBlockWithRewards*(
Expand Down Expand Up @@ -486,7 +485,9 @@ proc makeBeaconBlockWithRewards*(
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"
case state.kind
of ConsensusFork.Electra: makeBeaconBlock(electra)
else: raiseAssert "Attempt to use Electra payload with non-Electra state"
else:
{.error: "Unsupported fork".}

Expand Down
6 changes: 3 additions & 3 deletions beacon_chain/spec/state_transition_block.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1025,9 +1025,9 @@ proc process_block*(
total_active_balance = get_total_active_balance(state, cache)
base_reward_per_increment =
get_base_reward_per_increment(total_active_balance)
operations_rewards = ? process_operations(
cfg, state, blck.body, base_reward_per_increment, flags, cache)
? process_sync_aggregate(
var operations_rewards = ? process_operations(
cfg, state, blck.body, base_reward_per_increment, flags, cache)
operations_rewards.sync_aggregate = ? process_sync_aggregate(
state, blck.body.sync_aggregate, total_active_balance, flags, cache)

ok(operations_rewards)

0 comments on commit 2792140

Please sign in to comment.