mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-10 14:26:26 +00:00
update state diffs to Bellatrix (#4177)
This commit is contained in:
parent
6c18e82506
commit
9750cd3a38
@ -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
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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 =
|
||||
|
@ -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]) =
|
||||
|
@ -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),
|
||||
|
@ -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[])
|
||||
|
Loading…
x
Reference in New Issue
Block a user