From 490d8964aad7e45662060fa81ac75f2c25bf5ec1 Mon Sep 17 00:00:00 2001 From: Agnish Ghosh Date: Thu, 31 Oct 2024 02:44:01 +0530 Subject: [PATCH] attempt to fix ci --- .../block_pools_types.nim | 2 +- beacon_chain/nimbus_signing_node.nim | 2 + beacon_chain/spec/state_transition.nim | 3 + research/block_sim.nim | 73 +++++++++++++++++++ .../test_fixture_ssz_consensus_objects.nim | 2 +- tests/consensus_spec/fixtures_utils.nim | 7 ++ tests/test_eip7594_helpers.nim | 2 +- tests/testblockutil.nim | 5 +- tests/teststateutil.nim | 7 +- 9 files changed, 96 insertions(+), 7 deletions(-) diff --git a/beacon_chain/consensus_object_pools/block_pools_types.nim b/beacon_chain/consensus_object_pools/block_pools_types.nim index 35d4a7938..d7f4c34d5 100644 --- a/beacon_chain/consensus_object_pools/block_pools_types.nim +++ b/beacon_chain/consensus_object_pools/block_pools_types.nim @@ -344,7 +344,7 @@ type template OnBlockAddedCallback*(kind: static ConsensusFork): auto = when kind == ConsensusFork.Fulu: typedesc[OnFuluBlockAdded] - when kind == ConsensusFork.Electra: + elif kind == ConsensusFork.Electra: typedesc[OnElectraBlockAdded] elif kind == ConsensusFork.Deneb: typedesc[OnDenebBlockAdded] diff --git a/beacon_chain/nimbus_signing_node.nim b/beacon_chain/nimbus_signing_node.nim index 503a5506c..0c0cfca2a 100644 --- a/beacon_chain/nimbus_signing_node.nim +++ b/beacon_chain/nimbus_signing_node.nim @@ -248,6 +248,8 @@ proc installApiHandlers*(node: SigningNodeRef) = (GeneralizedIndex(801), request.beaconBlockHeader.data) of ConsensusFork.Electra: (GeneralizedIndex(801), request.beaconBlockHeader.data) + of ConsensusFork.Fulu: + (GeneralizedIndex(801), request.beaconBlockHeader.data) if request.proofs.isNone() or len(request.proofs.get()) == 0: return errorResponse(Http400, MissingMerkleProofError) diff --git a/beacon_chain/spec/state_transition.nim b/beacon_chain/spec/state_transition.nim index f2b84feca..876379bbd 100644 --- a/beacon_chain/spec/state_transition.nim +++ b/beacon_chain/spec/state_transition.nim @@ -168,6 +168,9 @@ func noRollback*(state: var deneb.HashedBeaconState) = func noRollback*(state: var electra.HashedBeaconState) = trace "Skipping rollback of broken Electra state" +func noRollback*(state: var fulu.HashedBeaconState) = + trace "Skipping rollback of broken Fulu state" + func maybeUpgradeStateToAltair( cfg: RuntimeConfig, state: var ForkedHashedBeaconState) = # Both process_slots() and state_transition_block() call this, so only run it diff --git a/research/block_sim.nim b/research/block_sim.nim index 6662a9849..af9ae5b7e 100644 --- a/research/block_sim.nim +++ b/research/block_sim.nim @@ -144,6 +144,50 @@ proc makeSimulationBlock( ok(blck) +proc makeSimulationBlock( + cfg: RuntimeConfig, + state: var fulu.HashedBeaconState, + proposer_index: ValidatorIndex, + randao_reveal: ValidatorSig, + eth1_data: Eth1Data, + graffiti: GraffitiBytes, + attestations: seq[electra.Attestation], + deposits: seq[Deposit], + exits: BeaconBlockValidatorChanges, + sync_aggregate: SyncAggregate, + execution_payload: fulu.ExecutionPayloadForSigning, + bls_to_execution_changes: SignedBLSToExecutionChangeList, + rollback: RollbackHashedProc[fulu.HashedBeaconState], + cache: var StateCache, + # TODO: + # `verificationFlags` is needed only in tests and can be + # removed if we don't use invalid signatures there + verificationFlags: UpdateFlags = {}): Result[fulu.BeaconBlock, cstring] = + ## Create a block for the given state. The latest block applied to it will + ## be used for the parent_root value, and the slot will be take from + ## state.slot meaning process_slots must be called up to the slot for which + ## the block is to be created. + + # To create a block, we'll first apply a partial block to the state, skipping + # some validations. + + var blck = partialBeaconBlock( + cfg, state, proposer_index, randao_reveal, eth1_data, graffiti, + attestations, deposits, exits, sync_aggregate, execution_payload, + default(ExecutionRequests)) + + let res = process_block( + cfg, state.data, blck.asSigVerified(), verificationFlags, cache) + + if res.isErr: + rollback(state) + return err(res.error()) + + state.root = hash_tree_root(state.data) + blck.state_root = state.root + + ok(blck) + # TODO confutils is an impenetrable black box. how can a help text be added here? cli do(slots = SLOTS_PER_EPOCH * 7, validators = SLOTS_PER_EPOCH * 500, @@ -369,6 +413,8 @@ cli do(slots = SLOTS_PER_EPOCH * 7, addr state.denebData elif T is electra.SignedBeaconBlock: addr state.electraData + elif T is fulu.SignedBeaconBlock: + addr state.fuluData else: static: doAssert false message = makeSimulationBlock( @@ -383,6 +429,8 @@ cli do(slots = SLOTS_PER_EPOCH * 7, default(GraffitiBytes), when T is electra.SignedBeaconBlock: attPool.getElectraAttestationsForBlock(state, cache) + elif T is fulu.SignedBeaconBlock: + attPool.getElectraAttestationsForBlock(state, cache) else: attPool.getAttestationsForBlock(state, cache), eth1ProposalData.deposits, @@ -390,6 +438,8 @@ cli do(slots = SLOTS_PER_EPOCH * 7, sync_aggregate, (when T is electra.SignedBeaconBlock: default(electra.ExecutionPayloadForSigning) + elif T is fulu.SignedBeaconBlock: + default(fulu.ExecutionPayloadForSigning) elif T is deneb.SignedBeaconBlock: default(deneb.ExecutionPayloadForSigning) else: @@ -461,6 +511,28 @@ cli do(slots = SLOTS_PER_EPOCH * 7, do: raiseAssert "withUpdatedState failed" + proc proposeFuluBlock(slot: Slot) = + if rand(r, 1.0) > blockRatio: + return + + dag.withUpdatedState(tmpState[], dag.getBlockIdAtSlot(slot).expect("block")) do: + let + newBlock = getNewBlock[fulu.SignedBeaconBlock](updatedState, slot, cache) + added = dag.addHeadBlock(verifier, newBlock) do ( + blckRef: BlockRef, signedBlock: fulu.TrustedSignedBeaconBlock, + epochRef: EpochRef, unrealized: FinalityCheckpoints): + # Callback add to fork choice if valid + attPool.addForkChoice( + epochRef, blckRef, unrealized, signedBlock.message, + blckRef.slot.start_beacon_time) + + dag.updateHead(added[], quarantine[], []) + if dag.needStateCachesAndForkChoicePruning(): + dag.pruneStateCachesDAG() + attPool.prune() + do: + raiseAssert "withUpdatedState failed" + var lastEth1BlockAt = genesisTime eth1BlockNum = 1000 @@ -501,6 +573,7 @@ cli do(slots = SLOTS_PER_EPOCH * 7, if blockRatio > 0.0: withTimer(timers[t]): case dag.cfg.consensusForkAtEpoch(slot.epoch) + of ConsensusFork.Fulu: proposeFuluBlock(slot) of ConsensusFork.Electra: proposeElectraBlock(slot) of ConsensusFork.Deneb: proposeDenebBlock(slot) of ConsensusFork.Phase0 .. ConsensusFork.Capella: diff --git a/tests/consensus_spec/eip7594/test_fixture_ssz_consensus_objects.nim b/tests/consensus_spec/eip7594/test_fixture_ssz_consensus_objects.nim index 3451ee5ef..03fae0ca2 100644 --- a/tests/consensus_spec/eip7594/test_fixture_ssz_consensus_objects.nim +++ b/tests/consensus_spec/eip7594/test_fixture_ssz_consensus_objects.nim @@ -19,7 +19,7 @@ import ../../../beacon_chain/spec/datatypes/[ altair, deneb, - eip7594], + fulu], # Status libraries snappy, # Test utilities diff --git a/tests/consensus_spec/fixtures_utils.nim b/tests/consensus_spec/fixtures_utils.nim index 98ee03203..fbd999568 100644 --- a/tests/consensus_spec/fixtures_utils.nim +++ b/tests/consensus_spec/fixtures_utils.nim @@ -47,6 +47,13 @@ func readValue*(r: var JsonReader, a: var seq[byte]) = func genesisTestRuntimeConfig*(consensusFork: ConsensusFork): RuntimeConfig = var res = defaultRuntimeConfig case consensusFork + of ConsensusFork.Fulu: + res.FULU_FORK_EPOCH = GENESIS_EPOCH + 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.Electra: res.ELECTRA_FORK_EPOCH = GENESIS_EPOCH res.DENEB_FORK_EPOCH = GENESIS_EPOCH diff --git a/tests/test_eip7594_helpers.nim b/tests/test_eip7594_helpers.nim index 6fa26d16c..e535e663e 100644 --- a/tests/test_eip7594_helpers.nim +++ b/tests/test_eip7594_helpers.nim @@ -15,7 +15,7 @@ import kzg4844/[kzg_abi, kzg], ./consensus_spec/[os_ops, fixtures_utils], ../beacon_chain/spec/[helpers, eip7594_helpers], - ../beacon_chain/spec/datatypes/[eip7594, deneb] + ../beacon_chain/spec/datatypes/[fulu, deneb] from std/strutils import rsplit diff --git a/tests/testblockutil.nim b/tests/testblockutil.nim index 11c939e95..21108bf8f 100644 --- a/tests/testblockutil.nim +++ b/tests/testblockutil.nim @@ -217,8 +217,9 @@ proc addTestBlock*( deposit_count: forkyState.data.eth1_deposit_index + deposits.lenu64, block_hash: eth1_data.block_hash), graffiti, - when consensusFork == ConsensusFork.Electra or - consensusFork == ConsensusFork.Fulu: + when consensusFork == ConsensusFork.Electra: + electraAttestations + elif consensusFork == ConsensusFork.Fulu: electraAttestations else: attestations, diff --git a/tests/teststateutil.nim b/tests/teststateutil.nim index 520da1a00..e97b284be 100644 --- a/tests/teststateutil.nim +++ b/tests/teststateutil.nim @@ -79,7 +79,7 @@ proc getTestStates*( info = ForkedEpochInfo() cfg = defaultRuntimeConfig - static: doAssert high(ConsensusFork) == ConsensusFork.Electra + static: doAssert high(ConsensusFork) == ConsensusFork.Fulu if consensusFork >= ConsensusFork.Altair: cfg.ALTAIR_FORK_EPOCH = 1.Epoch if consensusFork >= ConsensusFork.Bellatrix: @@ -90,6 +90,8 @@ proc getTestStates*( cfg.DENEB_FORK_EPOCH = 4.Epoch if consensusFork >= ConsensusFork.Electra: cfg.ELECTRA_FORK_EPOCH = 5.Epoch + if consensusFork >= ConsensusFork.Fulu: + cfg.ELECTRA_FORK_EPOCH = 6.Epoch for i, epoch in stateEpochs: let slot = epoch.Epoch.start_slot @@ -109,7 +111,8 @@ from std/sequtils import allIt from ".."/beacon_chain/spec/beaconstate import get_expected_withdrawals proc checkPerValidatorBalanceCalc*( - state: deneb.BeaconState | electra.BeaconState): bool = + state: deneb.BeaconState | electra.BeaconState | + fulu.BeaconState): bool = var info: altair.EpochInfo cache: StateCache