From 9750cd3a38e3f971541affb2c52ff7a8baeeeaae Mon Sep 17 00:00:00 2001 From: tersec Date: Mon, 26 Sep 2022 19:13:50 +0000 Subject: [PATCH] update state diffs to Bellatrix (#4177) --- beacon_chain/conf.nim | 4 ++-- beacon_chain/consensus_object_pools/spec_cache.nim | 2 +- beacon_chain/spec/helpers.nim | 4 ++-- beacon_chain/spec/light_client_sync.nim | 2 +- beacon_chain/statediff.nim | 8 ++++---- beacon_chain/validators/validator_duties.nim | 2 +- tests/test_statediff.nim | 10 +++++----- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/beacon_chain/conf.nim b/beacon_chain/conf.nim index 938e61e56..48beb9e4f 100644 --- a/beacon_chain/conf.nim +++ b/beacon_chain/conf.nim @@ -538,11 +538,11 @@ type defaultValue: false name: "validator-monitor-totals" .}: bool - # https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.3/sync/optimistic.md#fork-choice-poisoning + # https://github.com/ethereum/consensus-specs/blob/v1.2.0/sync/optimistic.md#fork-choice-poisoning safeSlotsToImportOptimistically* {. hidden desc: "Modify SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY" - # https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.3/sync/optimistic.md#constants + # https://github.com/ethereum/consensus-specs/blob/v1.2.0/sync/optimistic.md#constants defaultValue: 128 name: "safe-slots-to-import-optimistically" .}: uint16 diff --git a/beacon_chain/consensus_object_pools/spec_cache.nim b/beacon_chain/consensus_object_pools/spec_cache.nim index c351c7af4..5b8cd56d2 100644 --- a/beacon_chain/consensus_object_pools/spec_cache.nim +++ b/beacon_chain/consensus_object_pools/spec_cache.nim @@ -217,7 +217,7 @@ func makeAttestationData*( epoch: current_epoch, root: epoch_boundary_block.blck.root)) -# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/validator.md#validator-assignments +# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#validator-assignments iterator get_committee_assignments*( shufflingRef: ShufflingRef, validator_indices: HashSet[ValidatorIndex]): tuple[committee_index: CommitteeIndex, diff --git a/beacon_chain/spec/helpers.nim b/beacon_chain/spec/helpers.nim index cb7e2a443..88b4394dd 100644 --- a/beacon_chain/spec/helpers.nim +++ b/beacon_chain/spec/helpers.nim @@ -200,7 +200,7 @@ func has_flag*(flags: ParticipationFlags, flag_index: int): bool = let flag = ParticipationFlags(1'u8 shl flag_index) (flags and flag) == flag -# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.3/specs/altair/light-client/sync-protocol.md#is_sync_committee_update +# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/light-client/sync-protocol.md#is_sync_committee_update template is_sync_committee_update*(update: SomeLightClientUpdate): bool = when update is SomeLightClientUpdateWithSyncCommittee: not isZeroMemory(update.next_sync_committee_branch) @@ -218,7 +218,7 @@ template is_finality_update*(update: SomeLightClientUpdate): bool = template is_next_sync_committee_known*(store: LightClientStore): bool = not isZeroMemory(store.next_sync_committee) -# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.3/specs/altair/light-client/sync-protocol.md#get_safety_threshold +# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/light-client/sync-protocol.md#get_safety_threshold func get_safety_threshold*(store: LightClientStore): uint64 = max( store.previous_max_active_participants, diff --git a/beacon_chain/spec/light_client_sync.nim b/beacon_chain/spec/light_client_sync.nim index 347f49ec0..7137f9cc0 100644 --- a/beacon_chain/spec/light_client_sync.nim +++ b/beacon_chain/spec/light_client_sync.nim @@ -148,7 +148,7 @@ proc validate_light_client_update*( ok() -# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.3/specs/altair/light-client/sync-protocol.md#apply_light_client_update +# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/light-client/sync-protocol.md#apply_light_client_update func apply_light_client_update( store: var LightClientStore, update: SomeLightClientUpdate): bool = diff --git a/beacon_chain/statediff.nim b/beacon_chain/statediff.nim index 49df82b8d..a170ad232 100644 --- a/beacon_chain/statediff.nim +++ b/beacon_chain/statediff.nim @@ -12,7 +12,7 @@ else: import stew/assign2, - ./spec/datatypes/altair, + ./spec/datatypes/bellatrix, ./spec/helpers func diffModIncEpoch[T, U](hl: HashArray[U, T], startSlot: uint64): @@ -85,7 +85,7 @@ func replaceOrAddDecodeEth1Votes[T, U]( if not votes0.add item: raiseAssert "same limit" -func getMutableValidatorStatuses(state: altair.BeaconState): +func getMutableValidatorStatuses(state: bellatrix.BeaconState): List[ValidatorStatus, Limit VALIDATOR_REGISTRY_LIMIT] = if not result.setLen(state.validators.len): raiseAssert "same limt as validators" @@ -100,7 +100,7 @@ func getMutableValidatorStatuses(state: altair.BeaconState): assign(result[i].exit_epoch, validator.exit_epoch) assign(result[i].withdrawable_epoch, validator.withdrawable_epoch) -func diffStates*(state0, state1: altair.BeaconState): BeaconStateDiff = +func diffStates*(state0, state1: bellatrix.BeaconState): BeaconStateDiff = doAssert state1.slot > state0.slot doAssert state0.slot.is_epoch doAssert state1.slot == state0.slot + SLOTS_PER_EPOCH @@ -158,7 +158,7 @@ func diffStates*(state0, state1: altair.BeaconState): BeaconStateDiff = ) func applyDiff*( - state: var altair.BeaconState, + state: var bellatrix.BeaconState, immutableValidators: openArray[ImmutableValidatorData2], stateDiff: BeaconStateDiff) = template assign[T, U](tgt: var HashList[T, U], src: List[T, U]) = diff --git a/beacon_chain/validators/validator_duties.nim b/beacon_chain/validators/validator_duties.nim index 5f3472685..1bddce0cc 100644 --- a/beacon_chain/validators/validator_duties.nim +++ b/beacon_chain/validators/validator_duties.nim @@ -564,7 +564,7 @@ proc getBlindedExecutionPayload( pubkey: ValidatorPubKey): Future[Result[ExecutionPayloadHeader, cstring]] {.async.} = if node.payloadBuilderRestClient.isNil: - return err "getBlindedBeaconBlock: nil REST client" + return err "getBlindedExecutionPayload: nil REST client" let blindedHeader = awaitWithTimeout( node.payloadBuilderRestClient.getHeader(slot, executionBlockRoot, pubkey), diff --git a/tests/test_statediff.nim b/tests/test_statediff.nim index dcaf52cbc..3c65a7eab 100644 --- a/tests/test_statediff.nim +++ b/tests/test_statediff.nim @@ -11,7 +11,7 @@ import options, sequtils, unittest2, ./testutil, ./testdbutil, ./teststateutil, - ../beacon_chain/spec/datatypes/altair, + ../beacon_chain/spec/datatypes/bellatrix, ../beacon_chain/spec/[forks, helpers], ../beacon_chain/statediff, ../beacon_chain/consensus_object_pools/[blockchain_dag, block_quarantine] @@ -27,7 +27,7 @@ suite "state diff tests" & preset(): dag = init(ChainDAGRef, defaultRuntimeConfig, db, validatorMonitor, {}) test "random slot differences" & preset(): - let testStates = getTestStates(dag.headState, BeaconStateFork.Altair) + let testStates = getTestStates(dag.headState, BeaconStateFork.Bellatrix) for i in 0 ..< testStates.len: for j in (i+1) ..< testStates.len: @@ -35,9 +35,9 @@ suite "state diff tests" & preset(): getStateField(testStates[j][], slot) if getStateField(testStates[i][], slot) + SLOTS_PER_EPOCH != getStateField(testStates[j][], slot): continue - let tmpStateApplyBase = assignClone(testStates[i].altairData.data) + let tmpStateApplyBase = assignClone(testStates[i].bellatrixData.data) let diff = diffStates( - testStates[i].altairData.data, testStates[j].altairData.data) + testStates[i].bellatrixData.data, testStates[j].bellatrixData.data) # Immutable parts of validators stored separately, so aren't part of # the state diff. Synthesize required portion here for testing. applyDiff( @@ -48,5 +48,5 @@ suite "state diff tests" & preset(): getStateField(testStates[j][], validators).len - 1], it.getImmutableValidatorData), diff) - check hash_tree_root(testStates[j][].altairData.data) == + check hash_tree_root(testStates[j][].bellatrixData.data) == hash_tree_root(tmpStateApplyBase[])