shift block_sim fork epochs; allow VC to work with non-multiple-of-3 SECONDS_PER_SLOT (#3244)

This commit is contained in:
tersec 2022-01-05 13:41:39 +00:00 committed by GitHub
parent 7594fa660d
commit 66c9b7fbce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 19 deletions

View File

@ -1,4 +1,4 @@
# Copyright (c) 2021 Status Research & Development GmbH
# Copyright (c) 2021-2022 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@ -6,7 +6,7 @@
import std/[tables, os, strutils]
import chronos, chronicles, confutils,
stew/[base10, results, byteutils, io2], bearssl, blscurve
stew/[base10, results, io2], bearssl, blscurve
import ".."/validators/slashing_protection
import ".."/[conf, version, filepath, beacon_node]
import ".."/spec/[keystore, crypto]

View File

@ -13,7 +13,7 @@ import
# Standard lib
std/[algorithm, math, sequtils, sets, tables],
# Status libraries
stew/[byteutils, endians2, bitops2],
stew/[bitops2, byteutils, endians2],
chronicles,
# Internal
./datatypes/[phase0, altair, merge],
@ -299,7 +299,7 @@ func is_valid_merkle_branch*(leaf: Eth2Digest, branch: openArray[Eth2Digest],
value = eth2digest(buf)
value == root
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/tests/core/pyspec/eth2spec/test/helpers/merkle.py#L4-L21
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/tests/core/pyspec/eth2spec/test/helpers/merkle.py#L4-L21
func build_proof_impl(anchor: object, leaf_index: uint64,
proof: var openArray[Eth2Digest]) =
let
@ -513,11 +513,11 @@ func get_subtree_index*(idx: GeneralizedIndex): uint64 =
doAssert idx > 0
uint64(idx mod (type(idx)(1) shl log2trunc(idx)))
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/merge/beacon-chain.md#is_merge_transition_complete
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/bellatrix/beacon-chain.md#is_merge_transition_complete
func is_merge_transition_complete*(state: merge.BeaconState): bool =
state.latest_execution_payload_header != default(ExecutionPayloadHeader)
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/merge/beacon-chain.md#is_merge_transition_block
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/bellatrix/beacon-chain.md#is_merge_transition_block
func is_merge_transition_block(
state: merge.BeaconState,
body: merge.BeaconBlockBody | merge.TrustedBeaconBlockBody |
@ -525,14 +525,14 @@ func is_merge_transition_block(
not is_merge_transition_complete(state) and
body.execution_payload != default(merge.ExecutionPayload)
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/merge/beacon-chain.md#is_execution_enabled
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/bellatrix/beacon-chain.md#is_execution_enabled
func is_execution_enabled*(
state: merge.BeaconState,
body: merge.BeaconBlockBody | merge.TrustedBeaconBlockBody |
merge.SigVerifiedBeaconBlockBody): bool =
is_merge_transition_block(state, body) or is_merge_transition_complete(state)
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/merge/beacon-chain.md#compute_timestamp_at_slot
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/bellatrix/beacon-chain.md#compute_timestamp_at_slot
func compute_timestamp_at_slot*(state: ForkyBeaconState, slot: Slot): uint64 =
# Note: This function is unsafe with respect to overflows and underflows.
let slots_since_genesis = slot - GENESIS_SLOT

View File

@ -1,5 +1,4 @@
import
std/sets,
stew/[bitops2, objects],
datatypes/altair,
helpers
@ -9,12 +8,12 @@ func get_active_header(update: LightClientUpdate): BeaconBlockHeader =
# The "active header" is the header that the update is trying to convince
# us to accept. If a finalized header is present, it's the finalized
# header, otherwise it's the attested header
if update.finalized_header != BeaconBlockHeader():
if not update.finalized_header.isZeroMemory:
update.finalized_header
else:
update.attested_header
# https://github.com/ethereum/consensus-specs/blob/v1.1.7/specs/altair/sync-protocol.md#validate_light_client_update
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/sync-protocol.md#validate_light_client_update
proc validate_light_client_update*(store: LightClientStore,
update: LightClientUpdate,
current_slot: Slot,
@ -86,7 +85,7 @@ proc validate_light_client_update*(store: LightClientStore,
blsFastAggregateVerify(
participant_pubkeys, signing_root.data, sync_aggregate.sync_committee_signature)
# https://github.com/ethereum/consensus-specs/blob/v1.1.7/specs/altair/sync-protocol.md#apply_light_client_update
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/sync-protocol.md#apply_light_client_update
func apply_light_client_update(
store: var LightClientStore, update: LightClientUpdate) =
let
@ -102,14 +101,14 @@ func apply_light_client_update(
store.next_sync_committee = update.next_sync_committee
store.finalized_header = active_header
# https://github.com/ethereum/consensus-specs/blob/v1.1.7/specs/altair/sync-protocol.md#get_safety_threshold
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/sync-protocol.md#get_safety_threshold
func get_safety_threshold(store: LightClientStore): uint64 =
max(
store.previous_max_active_participants,
store.current_max_active_participants
) div 2
# https://github.com/ethereum/consensus-specs/blob/v1.1.7/specs/altair/sync-protocol.md#process_light_client_update
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/sync-protocol.md#process_light_client_update
proc process_light_client_update*(store: var LightClientStore,
update: LightClientUpdate,
current_slot: Slot,
@ -142,7 +141,7 @@ proc process_light_client_update*(store: var LightClientStore,
# Update finalized header
if sum_sync_committee_bits * 3 >= len(sync_committee_bits) * 2 and
update.finalized_header != default(BeaconBlockHeader):
not update.finalized_header.isZeroMemory:
# Normal update through 2/3 threshold
apply_light_client_update(store, update)
store.best_valid_update = none(LightClientUpdate)

View File

@ -114,7 +114,7 @@ const
DefaultDutyAndProof* = DutyAndProof(epoch: Epoch(0xFFFF_FFFF_FFFF_FFFF'u64))
SlotDuration* = int64(SECONDS_PER_SLOT).seconds
EpochDuration* = int64(SLOTS_PER_EPOCH * SECONDS_PER_SLOT).seconds
OneThirdDuration* = int64(SECONDS_PER_SLOT div INTERVALS_PER_SLOT).seconds
OneThirdDuration* = int64(SECONDS_PER_SLOT).seconds div INTERVALS_PER_SLOT
proc `$`*(bn: BeaconNodeServerRef): string =
if bn.ident.isSome():

View File

@ -71,8 +71,8 @@ cli do(slots = SLOTS_PER_EPOCH * 6,
var
cfg = defaultRuntimeConfig
cfg.ALTAIR_FORK_EPOCH = 64.Slot.epoch
cfg.MERGE_FORK_EPOCH = 128.Slot.epoch
cfg.ALTAIR_FORK_EPOCH = 32.Slot.epoch
cfg.MERGE_FORK_EPOCH = 96.Slot.epoch
echo "Starting simulation..."

View File

@ -50,7 +50,7 @@ type
const
FixturesDir* =
currentSourcePath.rsplit(DirSep, 1)[0] / ".." / ".." / "vendor" / "nim-eth2-scenarios"
SszTestsDir* = FixturesDir / "tests-v1.1.8"
SszTestsDir* = FixturesDir / "tests-v" & SPEC_VERSION
MaxObjectSize* = 3_000_000
proc parseTest*(path: string, Format: typedesc[Json], T: typedesc): T =