mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-10 22:36:01 +00:00
abe0d7b4ae
Instead of keeping a validator key list per EpochRef, this PR introduces a single shared validator key list in ChainDAG, and cleans up some other ChainDAG and key-related issues. The PR does not introduce the validator key list in the state transition - this is because we batch-check all signatures before entering the spec code, thus the spec code never hits the cache. A future refactor should _probably_ remove the threadvar altogether. There's a few other small fixes in here that make the flow easier to read: * fix `var ChainDAGRef` -> `ChainDAGRef` * fix `var QuarantineRef` -> `QuarantineRef` * consistent `dag` variable name * avoid using threadvar pubkey cache in most cases * better error messages in batch signature checking
58 lines
2.3 KiB
Nim
58 lines
2.3 KiB
Nim
# beacon_chain
|
|
# Copyright (c) 2020 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).
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
{.used.}
|
|
|
|
import chronicles, chronos
|
|
import eth/keys
|
|
import ../beacon_chain/spec/[datatypes, presets]
|
|
import ../beacon_chain/consensus_object_pools/[block_quarantine, blockchain_dag, exit_pool]
|
|
import "."/[testutil, testdbutil]
|
|
|
|
proc getExitPool(): auto =
|
|
let dag =
|
|
init(ChainDAGRef, defaultRuntimePreset, makeTestDB(SLOTS_PER_EPOCH * 3))
|
|
newClone(ExitPool.init(dag, QuarantineRef.init(keys.newRng())))
|
|
|
|
suite "Exit pool testing suite":
|
|
setup:
|
|
let pool = getExitPool()
|
|
test "addExitMessage/getProposerSlashingMessage":
|
|
for i in 0'u64 .. MAX_PROPOSER_SLASHINGS + 5:
|
|
for j in 0'u64 .. i:
|
|
pool.proposer_slashings.addExitMessage(
|
|
ProposerSlashing(), MAX_PROPOSER_SLASHINGS)
|
|
check:
|
|
pool[].getProposerSlashingsForBlock().lenu64 ==
|
|
min(i + 1, MAX_PROPOSER_SLASHINGS)
|
|
pool[].getProposerSlashingsForBlock().len == 0
|
|
|
|
test "addExitMessage/getAttesterSlashingMessage":
|
|
for i in 0'u64 .. MAX_ATTESTER_SLASHINGS + 5:
|
|
for j in 0'u64 .. i:
|
|
pool.attester_slashings.addExitMessage(
|
|
AttesterSlashing(
|
|
attestation_1: IndexedAttestation(attesting_indices:
|
|
List[uint64, Limit MAX_VALIDATORS_PER_COMMITTEE](@[0'u64])),
|
|
attestation_2: IndexedAttestation(attesting_indices:
|
|
List[uint64, Limit MAX_VALIDATORS_PER_COMMITTEE](@[0'u64]))),
|
|
MAX_ATTESTER_SLASHINGS)
|
|
check:
|
|
pool[].getAttesterSlashingsForBlock().lenu64 ==
|
|
min(i + 1, MAX_ATTESTER_SLASHINGS)
|
|
pool[].getAttesterSlashingsForBlock().len == 0
|
|
|
|
test "addExitMessage/getVoluntaryExitMessage":
|
|
for i in 0'u64 .. MAX_VOLUNTARY_EXITS + 5:
|
|
for j in 0'u64 .. i:
|
|
pool.voluntary_exits.addExitMessage(
|
|
SignedVoluntaryExit(), MAX_VOLUNTARY_EXITS)
|
|
check:
|
|
pool[].getVoluntaryExitsForBlock().lenu64 ==
|
|
min(i + 1, MAX_VOLUNTARY_EXITS)
|
|
pool[].getProposerSlashingsForBlock().len == 0
|