update to Altair as of v1.1.0-alpha.7 (#2649)

* update to Altair as of v1.1.0-alpha.7

* introduce Altair types into attestation pool

* avoid allocating/copying pubkeys excessively in get_next_sync_committee()
This commit is contained in:
tersec 2021-06-14 17:42:46 +00:00 committed by GitHub
parent 146fa48454
commit 1c3314f08b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 91 additions and 138 deletions

View File

@ -308,12 +308,12 @@ OK: 7/7 Fail: 0/7 Skip: 0/7
OK: 9/9 Fail: 0/9 Skip: 0/9
## Official - Altair - Epoch Processing - Participation flag updates [Preset: mainnet]
```diff
+ Participation flag updates - all_zeroed [Preset: mainnet] OK
+ Participation flag updates - current_epoch_zeroed [Preset: mainnet] OK
+ Participation flag updates - filled [Preset: mainnet] OK
+ Participation flag updates - prev_zeroed [Preset: mainnet] OK
+ Participation flag updates - previous_epoch_zeroed [Preset: mainnet] OK
+ Participation flag updates - random [Preset: mainnet] OK
+ Participation flag updates - random_genesis [Preset: mainnet] OK
+ Participation flag updates - zeroed [Preset: mainnet] OK
+ Participation flag updates - zeroing [Preset: mainnet] OK
```
OK: 6/6 Fail: 0/6 Skip: 0/6
## Official - Altair - Epoch Processing - RANDAO mixes reset [Preset: mainnet]
@ -381,7 +381,7 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
+ Testing SyncAggregatorSelectionData OK
+ Testing SyncCommittee OK
+ Testing SyncCommitteeContribution OK
+ Testing SyncCommitteeSignature OK
+ Testing SyncCommitteeMessage OK
+ Testing Validator OK
+ Testing VoluntaryExit OK
```

View File

@ -235,7 +235,7 @@ OK: 196/196 Fail: 0/196 Skip: 0/196
+ Testing SyncAggregatorSelectionData OK
+ Testing SyncCommittee OK
+ Testing SyncCommitteeContribution OK
+ Testing SyncCommitteeSignature OK
+ Testing SyncCommitteeMessage OK
+ Testing Validator OK
+ Testing VoluntaryExit OK
```

View File

@ -15,8 +15,9 @@ import
chronicles, stew/byteutils, json_serialization/std/sets as jsonSets,
# Internal
../spec/[
beaconstate, datatypes, crypto, digest, forkedbeaconstate_helpers,
beaconstate, crypto, digest, forkedbeaconstate_helpers,
validator],
../spec/datatypes/[phase0, altair],
../ssz/merkleization,
"."/[spec_cache, blockchain_dag, block_quarantine],
".."/[beacon_clock, beacon_node_types, extras],
@ -311,7 +312,7 @@ proc addAttestation*(pool: var AttestationPool,
proc addForkChoice*(pool: var AttestationPool,
epochRef: EpochRef,
blckRef: BlockRef,
blck: TrustedBeaconBlock,
blck: phase0.TrustedBeaconBlock,
wallSlot: Slot) =
## Add a verified block to the fork choice context
let state = pool.forkChoice.process_block(
@ -372,7 +373,7 @@ func add(
do:
attCache[key] = aggregation_bits
func init(T: type AttestationCache, state: HashedBeaconState): T =
func init(T: type AttestationCache, state: phase0.HashedBeaconState): T =
# Load attestations that are scheduled for being given rewards for
for i in 0..<state.data.previous_epoch_attestations.len():
result.add(
@ -405,7 +406,7 @@ proc score(
bitsScore
proc getAttestationsForBlock*(pool: var AttestationPool,
state: HashedBeaconState,
state: phase0.HashedBeaconState,
cache: var StateCache): seq[Attestation] =
## Retrieve attestations that may be added to a new block at the slot of the
## given state

View File

@ -604,7 +604,7 @@ func check_attestation_index(
ok()
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.6/specs/altair/beacon-chain.md#get_attestation_participation_flag_indices
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.7/specs/altair/beacon-chain.md#get_attestation_participation_flag_indices
func get_attestation_participation_flag_indices(state: altair.BeaconState,
data: AttestationData,
inclusion_delay: uint64): seq[int] =
@ -773,6 +773,8 @@ func get_next_sync_committee_indices(state: altair.BeaconState):
## duplicate indices) for the next sync committee, given a ``state`` at a
## sync committee period boundary.
# TODO this size is known statically, so return array[] if possible
# Note: Committee can contain duplicate indices for small validator sets
# (< SYNC_COMMITTEE_SIZE + 128)
let epoch = get_current_epoch(state) + 1
@ -799,42 +801,26 @@ func get_next_sync_committee_indices(state: altair.BeaconState):
i += 1'u64
sync_committee_indices
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.6/specs/altair/beacon-chain.md#get_next_sync_committee
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.7/specs/altair/beacon-chain.md#get_next_sync_committee
proc get_next_sync_committee*(state: altair.BeaconState): SyncCommittee =
## Return the *next* sync committee for a given ``state``.
#
# ``SyncCommittee`` contains an aggregate pubkey that enables
# resource-constrained clients to save some computation when verifying the
# sync committee's signature.
#
# ``SyncCommittee`` can also contain duplicate pubkeys, when
# ``get_next_sync_committee_indices`` returns duplicate indices.
# Implementations must take care when handling optimizations relating to
# aggregation and verification in the presence of duplicates.
#
# Note: This function should only be called at sync committee period
# boundaries by ``process_sync_committee_updates`` as
# ``get_next_sync_committee_indices`` is not stable within a given period.
let
indices = get_next_sync_committee_indices(state)
pubkeys = mapIt(indices, state.validators[it].pubkey)
let indices = get_next_sync_committee_indices(state)
# TODO not robust
doAssert pubkeys.len == SYNC_COMMITTEE_SIZE
doAssert indices.len == SYNC_COMMITTEE_SIZE
var res: SyncCommittee
for i, index in indices:
res.pubkeys.data[i] = state.validators[index].pubkey
res.pubkeys.resetCache()
# see signatures_batch, TODO shouldn't be here
# Deposit processing ensures all keys are valid
var
attestersAgg: AggregatePublicKey
attestersAgg.init(pubkeys[0].loadWithCache().get)
for i in 1 ..< pubkeys.len:
attestersAgg.aggregate(pubkeys[i].loadWithCache().get)
let aggregate_pubkey = finish(attestersAgg)
var attestersAgg: AggregatePublicKey
attestersAgg.init(res.pubkeys.data[0].loadWithCache().get)
for i in 1 ..< res.pubkeys.data.len:
attestersAgg.aggregate(res.pubkeys.data[i].loadWithCache().get)
var res = SyncCommittee(aggregate_pubkey: aggregate_pubkey.toPubKey())
for i in 0 ..< SYNC_COMMITTEE_SIZE:
# obviously ineffecient
res.pubkeys[i] = pubkeys[i]
res.aggregate_pubkey = finish(attestersAgg).toPubKey()
res
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.6/specs/altair/fork.md#upgrading-the-state
@ -862,7 +848,7 @@ func translate_participation(
proc upgrade_to_altair*(pre: phase0.BeaconState): ref altair.BeaconState =
let epoch = get_current_epoch(pre)
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.6/specs/altair/fork.md#configuration
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.7/specs/altair/fork.md#configuration
const ALTAIR_FORK_VERSION = Version [byte 1, 0, 0, 0]
var

View File

@ -38,11 +38,11 @@ import ./base, ./phase0
export base
const
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.6/specs/altair/beacon-chain.md#incentivization-weights
TIMELY_SOURCE_WEIGHT* = 12
TIMELY_TARGET_WEIGHT* = 24
TIMELY_HEAD_WEIGHT* = 12
SYNC_REWARD_WEIGHT* = 8
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.7/specs/altair/beacon-chain.md#incentivization-weights
TIMELY_SOURCE_WEIGHT* = 14
TIMELY_TARGET_WEIGHT* = 26
TIMELY_HEAD_WEIGHT* = 14
SYNC_REWARD_WEIGHT* = 2
PROPOSER_WEIGHT* = 8
WEIGHT_DENOMINATOR* = 64
@ -62,10 +62,15 @@ const
TIMELY_TARGET_FLAG_INDEX* = 1
TIMELY_HEAD_FLAG_INDEX* = 2
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.6/specs/altair/beacon-chain.md#inactivity-penalties
#INACTIVITY_SCORE_BIAS* = 4
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.7/specs/altair/beacon-chain.md#inactivity-penalties
INACTIVITY_SCORE_BIAS* = 4
INACTIVITY_SCORE_RECOVERY_RATE* = 16
# "Note: The sum of the weights equal WEIGHT_DENOMINATOR."
static: doAssert TIMELY_SOURCE_WEIGHT + TIMELY_TARGET_WEIGHT +
TIMELY_HEAD_WEIGHT + SYNC_REWARD_WEIGHT + PROPOSER_WEIGHT ==
WEIGHT_DENOMINATOR
let
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.6/specs/altair/beacon-chain.md#misc
# Cannot be computed at compile-time due to importc dependency
@ -79,11 +84,11 @@ let
type
### New types
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.6/specs/altair/beacon-chain.md#custom-types
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.7/specs/altair/beacon-chain.md#custom-types
# TODO could be distinct
ParticipationFlags* = uint8
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.6/specs/altair/beacon-chain.md#syncaggregate
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.7/specs/altair/beacon-chain.md#syncaggregate
SyncAggregate* = object
sync_committee_bits*: BitArray[SYNC_COMMITTEE_SIZE]
sync_committee_signature*: ValidatorSig
@ -93,8 +98,8 @@ type
pubkeys*: HashArray[Limit SYNC_COMMITTEE_SIZE, ValidatorPubKey]
aggregate_pubkey*: ValidatorPubKey
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.6/specs/altair/validator.md#synccommitteesignature
SyncCommitteeSignature* = object
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.7/specs/altair/validator.md#synccommitteemessage
SyncCommitteeMessage* = object
slot*: Slot ##\
## Slot to which this contribution pertains
@ -107,7 +112,7 @@ type
signature*: ValidatorSig ##\
## Signature by the validator over the block root of `slot`
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.6/specs/altair/validator.md#synccommitteecontribution
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.7/specs/altair/validator.md#synccommitteecontribution
SyncCommitteeContribution* = object
slot*: Slot ##\
## Slot to which this contribution pertains
@ -138,7 +143,7 @@ type
message*: ContributionAndProof
signature*: ValidatorSig
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.6/specs/altair/validator.md#syncaggregatorselectiondata
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.7/specs/altair/validator.md#syncaggregatorselectiondata
SyncAggregatorSelectionData* = object
slot*: Slot
subcommittee_index*: uint64
@ -177,7 +182,7 @@ type
fork_version*: Version ##\
## Fork version for the aggregate signature
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.5/specs/altair/beacon-chain.md#beaconstate
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.7/specs/altair/beacon-chain.md#beaconstate
BeaconState* = object
# Versioning
genesis_time*: uint64
@ -371,7 +376,7 @@ type
# [New in Altair]
sync_aggregate*: SyncAggregate
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.6/specs/phase0/beacon-chain.md#signedbeaconblock
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.7/specs/phase0/beacon-chain.md#signedbeaconblock
SignedBeaconBlock* = object
message*: BeaconBlock
signature*: ValidatorSig

View File

@ -121,9 +121,7 @@ type
DOMAIN_SELECTION_PROOF = 5
DOMAIN_AGGREGATE_AND_PROOF = 6
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.2/specs/altair/beacon-chain.md#domain-types
# Needs to be in same enum definition and is safe regardless of whether one
# only accesses phase 0 definitions
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.7/specs/altair/beacon-chain.md#domain-types
DOMAIN_SYNC_COMMITTEE = 7
DOMAIN_SYNC_COMMITTEE_SELECTION_PROOF = 8
DOMAIN_CONTRIBUTION_AND_PROOF = 9

View File

@ -180,12 +180,12 @@ func get_seed*(state: SomeBeaconState, epoch: Epoch, domain_type: DomainType):
epoch + EPOCHS_PER_HISTORICAL_VECTOR - MIN_SEED_LOOKAHEAD - 1).data
eth2digest(seed_input)
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.2/specs/altair/beacon-chain.md#add_flag
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.7/specs/altair/beacon-chain.md#add_flag
func add_flag*(flags: ParticipationFlags, flag_index: int): ParticipationFlags =
let flag = ParticipationFlags(1'u8 shl flag_index)
flags or flag
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.2/specs/altair/beacon-chain.md#has_flag
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.7/specs/altair/beacon-chain.md#has_flag
func has_flag*(flags: ParticipationFlags, flag_index: int): bool =
let flag = ParticipationFlags(1'u8 shl flag_index)
(flags and flag) == flag

View File

@ -11,7 +11,7 @@
const
# Updated penalty values
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.5/configs/mainnet/altair.yaml#L3
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.7/presets/mainnet/altair.yaml#L3
CONFIG_NAME* = "mainnet"
INACTIVITY_PENALTY_QUOTIENT_ALTAIR* = 50331648 ##\
@ -20,29 +20,15 @@ const
MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR* = 64
PROPORTIONAL_SLASHING_MULTIPLIER_ALTAIR* = 2
# Misc
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.2/configs/mainnet/altair.yaml#L15
SYNC_PUBKEYS_PER_AGGREGATE* = 64
INACTIVITY_SCORE_BIAS* = 4
# Sync Committee
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.5/configs/mainnet/altair.yaml#L13
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.7/presets/mainnet/altair.yaml#L13
SYNC_COMMITTEE_SIZE* = 512
EPOCHS_PER_SYNC_COMMITTEE_PERIOD* = 512
EPOCHS_PER_SYNC_COMMITTEE_PERIOD* = 256
# Signature domains (DOMAIN_SYNC_COMMITTEE) in spec/datatypes/base
# Fork
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.5/configs/mainnet/altair.yaml#L36
# ALTAIR_FORK_VERSION is a runtime preset
ALTAIR_FORK_EPOCH* = 18446744073709551615'u64
# Sync protocol
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.5/configs/mainnet/altair.yaml#L44
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.7/presets/mainnet/altair.yaml#L21
MIN_SYNC_COMMITTEE_PARTICIPANTS* = 1

View File

@ -11,7 +11,7 @@
const
# Updated penalty values
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.2/configs/minimal/altair.yaml#L5
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.7/presets/minimal/altair.yaml#L3
CONFIG_NAME* = "minimal"
INACTIVITY_PENALTY_QUOTIENT_ALTAIR* = 50331648 ##\
@ -20,31 +20,13 @@ const
MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR* = 64
PROPORTIONAL_SLASHING_MULTIPLIER_ALTAIR* = 2
# Misc
# Sync protocol
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.2/configs/minimal/altair.yaml#L15
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.7/presets/minimal/altair.yaml#L13
SYNC_COMMITTEE_SIZE* = 32
SYNC_PUBKEYS_PER_AGGREGATE* = 16
INACTIVITY_SCORE_BIAS* = 4
# Time parameters
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.2/configs/minimal/altair.yaml#L25
EPOCHS_PER_SYNC_COMMITTEE_PERIOD* = 8
# Signature domains (DOMAIN_SYNC_COMMITTEE) in spec/datatypes/base
# Fork
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.2/configs/minimal/altair.yaml#L36
# ALTAIR_FORK_VERSION is a runtime preset
ALTAIR_FORK_SLOT* = 0 # TBD
# Sync protocol
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.2/configs/minimal/altair.yaml#L43
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.7/presets/minimal/altair.yaml#L21
MIN_SYNC_COMMITTEE_PARTICIPANTS* = 1
MAX_VALID_LIGHT_CLIENT_UPDATES* = 32
LIGHT_CLIENT_UPDATE_TIMEOUT* = 32

View File

@ -168,8 +168,6 @@ func noRollback*(state: var phase0.HashedBeaconState) =
proc maybeUpgradeStateToAltair(
state: var ForkedHashedBeaconState, altairForkSlot: Slot) =
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.6/specs/altair/fork.md#upgrading-the-state
# Both process_slots() and state_transition_block() call this, so only run it
# once by checking for existing fork.
if getStateField(state, slot) == altairForkSlot and

View File

@ -337,7 +337,7 @@ proc process_operations(preset: RuntimePreset,
ok()
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.6/specs/altair/beacon-chain.md#sync-committee-processing
proc process_sync_committee*(
proc process_sync_aggregate*(
state: var altair.BeaconState, aggregate: SyncAggregate, cache: var StateCache):
Result[void, cstring] {.nbench.} =
# Verify sync committee aggregate signature signing over the previous slot
@ -356,7 +356,7 @@ proc process_sync_committee*(
# Empty participants allowed
if participant_pubkeys.len > 0 and not blsFastAggregateVerify(
participant_pubkeys, signing_root.data, aggregate.sync_committee_signature):
return err("process_sync_committee: invalid signature")
return err("process_sync_aggregate: invalid signature")
# Compute participant and proposer rewards
let
@ -377,18 +377,21 @@ proc process_sync_committee*(
if v.pubkey in s:
pubkeyIndices[v.pubkey] = i.ValidatorIndex
let committee_indices = mapIt(state.current_sync_committee.pubkeys, pubkeyIndices.getOrDefault(it))
var participant_indices: seq[ValidatorIndex]
for i, committee_index in committee_indices:
if aggregate.sync_committee_bits[i]:
participant_indices.add committee_index
for participant_index in participant_indices:
# TODO could use a sequtils2 zipIt
for i in 0 ..< min(
state.current_sync_committee.pubkeys.len,
aggregate.sync_committee_bits.len):
let proposer_index = get_beacon_proposer_index(state, cache)
if proposer_index.isSome:
increase_balance(state, participant_index, participant_reward)
increase_balance(state, proposer_index.get, proposer_reward)
let participant_index =
pubkeyIndices.getOrDefault(state.current_sync_committee.pubkeys[i])
if aggregate.sync_committee_bits[i]:
increase_balance(state, participant_index, participant_reward)
increase_balance(state, proposer_index.get, proposer_reward)
else:
decrease_balance(state, participant_index, participant_reward)
else:
warn "process_sync_committee: get_beacon_proposer_index failed"
warn "process_sync_aggregate: get_beacon_proposer_index failed"
ok()
@ -419,7 +422,7 @@ proc process_block*(
# The transition-triggering block creates, not acts on, an Altair state
err("process_block: Altair state with Phase 0 block")
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.6/specs/altair/beacon-chain.md#block-processing
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.7/specs/altair/beacon-chain.md#block-processing
# TODO workaround for https://github.com/nim-lang/Nim/issues/18095
# copy of datatypes/altair.nim
type SomeAltairBlock =
@ -436,7 +439,7 @@ proc process_block*(
? process_randao(state, blck.body, flags, cache)
? process_eth1_data(state, blck.body)
? process_operations(preset, state, blck.body, flags, cache)
? process_sync_committee(state, blck.body.sync_aggregate, cache) # [New in Altair]
? process_sync_aggregate(state, blck.body.sync_aggregate, cache) # [New in Altair]
ok()

View File

@ -277,8 +277,8 @@ proc process_justification_and_finalization*(state: var phase0.BeaconState,
current_epoch = current_epoch,
checkpoint = shortLog(state.finalized_checkpoint)
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.6/specs/altair/beacon-chain.md#justification-and-finalization
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.6/specs/phase0/beacon-chain.md#justification-and-finalization
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.7/specs/altair/beacon-chain.md#justification-and-finalization
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.7/specs/phase0/beacon-chain.md#justification-and-finalization
# TODO merge these things -- effectively, the phase0 process_justification_and_finalization is mostly a stub in this world
proc weigh_justification_and_finalization(state: var altair.BeaconState,
total_active_balance: Gwei,
@ -559,24 +559,19 @@ func get_attestation_deltas(state: phase0.BeaconState, rewards: var RewardInfo)
rewards.statuses[proposer_index].delta.add(
proposer_delta.get()[1])
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.6/specs/altair/beacon-chain.md#get_base_reward_per_increment
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.7/specs/altair/beacon-chain.md#get_base_reward_per_increment
func get_base_reward_per_increment(
state: altair.BeaconState, total_active_balance: Gwei): Gwei =
# TODO hoist this integer_squareroot, as with phase 0
EFFECTIVE_BALANCE_INCREMENT * BASE_REWARD_FACTOR div
integer_squareroot(total_active_balance)
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.6/specs/altair/beacon-chain.md#get_base_reward
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.7/specs/altair/beacon-chain.md#get_base_reward
func get_base_reward(
state: altair.BeaconState, index: ValidatorIndex, total_active_balance: Gwei):
Gwei =
## Return the base reward for the validator defined by ``index`` with respect
## to the current ``state``.
#
# Note: An optimally performing validator can earn one base reward per epoch
# over a long time horizon. This takes into account both per-epoch (e.g.
# attestation) and intermittent duties (e.g. block proposal and sync
# committees).
let increments =
state.validators[index].effective_balance div EFFECTIVE_BALANCE_INCREMENT
increments * get_base_reward_per_increment(state, total_active_balance)

View File

@ -21,7 +21,7 @@ import
./test_fixture_operations_block_header,
./test_fixture_operations_deposits,
./test_fixture_operations_proposer_slashings,
./test_fixture_operations_sync_committee,
./test_fixture_operations_sync_aggregate,
./test_fixture_operations_voluntary_exit,
./test_fixture_fork,
./test_fixture_transition

View File

@ -24,15 +24,15 @@ import
when isMainModule:
import chronicles # or some random compile error happens...
const OpSyncCommitteeDir = SszTestsDir/const_preset/"altair"/"operations"/"sync_committee"/"pyspec_tests"
const OpSyncAggregateDir = SszTestsDir/const_preset/"altair"/"operations"/"sync_aggregate"/"pyspec_tests"
proc runTest(identifier: string) =
proc runTest(dir, identifier: string) =
# We wrap the tests in a proc to avoid running out of globals
# in the future: Nim supports up to 3500 globals
# but unittest with the macro/templates put everything as globals
# https://github.com/nim-lang/Nim/issues/12084#issue-486866402
let testDir = OpSyncCommitteeDir / identifier
let testDir = dir / identifier
proc `testImpl_sync_committee _ identifier`() =
@ -54,17 +54,17 @@ proc runTest(identifier: string) =
let
postState =
newClone(parseTest(testDir/"post.ssz_snappy", SSZ, BeaconState))
done = process_sync_committee(
done = process_sync_aggregate(
preState[], syncAggregate, cache).isOk
doAssert done, "Valid sync aggregate not processed"
check: preState[].hash_tree_root() == postState[].hash_tree_root()
reportDiff(preState, postState)
else:
let done = process_sync_committee(preState[], syncAggregate, cache).isOk
let done = process_sync_aggregate(preState[], syncAggregate, cache).isOk
doAssert done == false, "We didn't expect this invalid proposer slashing to be processed."
`testImpl_sync_committee _ identifier`()
suite "Official - Altair - Operations - Sync Committee " & preset():
for kind, path in walkDir(OpSyncCommitteeDir, true):
runTest(path)
suite "Official - Altair - Operations - Sync Aggregate" & preset():
for kind, path in walkDir(OpSyncAggregateDir, true):
runTest(OpSyncAggregateDir, path)

View File

@ -140,8 +140,7 @@ suite "Official - Altair - SSZ consensus objects " & preset():
of "SyncCommittee": checkSSZ(SyncCommittee, path, hash)
of "SyncCommitteeContribution":
checkSSZ(SyncCommitteeContribution, path, hash)
of "SyncCommitteeSignature":
checkSSZ(SyncCommitteeSignature, path, hash)
of "SyncCommitteeMessage": checkSSZ(SyncCommitteeMessage, path, hash)
of "Validator": checkSSZ(Validator, path, hash)
of "VoluntaryExit": checkSSZ(VoluntaryExit, path, hash)
else:

View File

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

View File

@ -22,7 +22,7 @@ const
SpecDir = currentSourcePath.rsplit(DirSep, 1)[0] /
".."/".."/"beacon_chain"/"spec"
# v1.1.0-alpha.6 doesn't seem to have this file
# v1.1.0-alpha.7 doesn't seem to have this file
OldSszTestsDir* = FixturesDir / "tests-v1.1.0-alpha.5"
Config = OldSszTestsDir/const_preset/"config"/"phase0.yaml"

@ -1 +1 @@
Subproject commit e3c909505517f5e99311a03b44c64926110b9a94
Subproject commit 7e7d8988979dfad2d3f4a06121f22df94e5101e5