remove some skipBlsValidation usage/handling in tests (#2258)
This commit is contained in:
parent
7571e74dbd
commit
7f5a26002d
|
@ -1,5 +1,5 @@
|
|||
# beacon_chain
|
||||
# Copyright (c) 2018-2019 Status Research & Development GmbH
|
||||
# Copyright (c) 2018-2021 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).
|
||||
|
@ -84,8 +84,7 @@ proc signMockAttestation*(state: BeaconState, attestation: var Attestation) =
|
|||
|
||||
proc mockAttestationImpl(
|
||||
state: BeaconState,
|
||||
slot: Slot,
|
||||
flags: UpdateFlags): Attestation =
|
||||
slot: Slot): Attestation =
|
||||
|
||||
var cache = StateCache()
|
||||
|
||||
|
@ -105,19 +104,16 @@ proc mockAttestationImpl(
|
|||
for i in 0 ..< beacon_committee.len:
|
||||
result.aggregation_bits[i] = true
|
||||
|
||||
if skipBlsValidation notin flags:
|
||||
signMockAttestation(state, result)
|
||||
signMockAttestation(state, result)
|
||||
|
||||
proc mockAttestation*(
|
||||
state: BeaconState): Attestation =
|
||||
mockAttestationImpl(state, state.slot)
|
||||
|
||||
proc mockAttestation*(
|
||||
state: BeaconState,
|
||||
flags: UpdateFlags = {}): Attestation =
|
||||
mockAttestationImpl(state, state.slot, flags)
|
||||
|
||||
proc mockAttestation*(
|
||||
state: BeaconState,
|
||||
slot: Slot,
|
||||
flags: UpdateFlags = {}): Attestation =
|
||||
mockAttestationImpl(state, slot, flags)
|
||||
slot: Slot): Attestation =
|
||||
mockAttestationImpl(state, slot)
|
||||
|
||||
func fillAggregateAttestation*(state: BeaconState, attestation: var Attestation) =
|
||||
var cache = StateCache()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# beacon_chain
|
||||
# Copyright (c) 2018-2019 Status Research & Development GmbH
|
||||
# Copyright (c) 2018-2021 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).
|
||||
|
@ -10,7 +10,7 @@ import
|
|||
# Specs
|
||||
../../beacon_chain/spec/[datatypes, helpers, signatures, validator],
|
||||
# Internals
|
||||
../../beacon_chain/[ssz, extras],
|
||||
../../beacon_chain/ssz,
|
||||
# Mock helpers
|
||||
./mock_validator_keys
|
||||
|
||||
|
@ -39,11 +39,9 @@ proc signMockBlock*(state: BeaconState, signedBlock: var SignedBeaconBlock) =
|
|||
|
||||
proc mockBlock(
|
||||
state: BeaconState,
|
||||
slot: Slot,
|
||||
flags: UpdateFlags = {}): SignedBeaconBlock =
|
||||
slot: Slot): SignedBeaconBlock =
|
||||
## TODO don't do this gradual construction, for exception safety
|
||||
## Mock a BeaconBlock for the specific slot
|
||||
## Skip signature creation if block should not be signed (skipBlsValidation present)
|
||||
|
||||
var emptyCache = StateCache()
|
||||
let proposer_index = get_beacon_proposer_index(state, emptyCache)
|
||||
|
@ -56,9 +54,7 @@ proc mockBlock(
|
|||
previous_block_header.state_root = state.hash_tree_root()
|
||||
result.message.parent_root = previous_block_header.hash_tree_root()
|
||||
|
||||
if skipBlsValidation notin flags:
|
||||
signMockBlock(state, result)
|
||||
signMockBlock(state, result)
|
||||
|
||||
proc mockBlockForNextSlot*(state: BeaconState, flags: UpdateFlags = {}):
|
||||
SignedBeaconBlock =
|
||||
mockBlock(state, state.slot + 1, flags)
|
||||
proc mockBlockForNextSlot*(state: BeaconState): SignedBeaconBlock =
|
||||
mockBlock(state, state.slot + 1)
|
||||
|
|
|
@ -14,7 +14,7 @@ import
|
|||
stew/results,
|
||||
# Beacon chain internals
|
||||
../../beacon_chain/spec/[datatypes, beaconstate, presets],
|
||||
../../beacon_chain/[ssz, extras],
|
||||
../../beacon_chain/ssz,
|
||||
# Test utilities
|
||||
../testutil,
|
||||
./fixtures_utils,
|
||||
|
@ -32,10 +32,7 @@ proc runTest(identifier: string) =
|
|||
|
||||
proc `testImpl _ operations_deposits _ identifier`() =
|
||||
|
||||
var flags: UpdateFlags
|
||||
var prefix: string
|
||||
if not existsFile(testDir/"meta.yaml"):
|
||||
flags.incl skipBlsValidation
|
||||
if existsFile(testDir/"post.ssz"):
|
||||
prefix = "[Valid] "
|
||||
else:
|
||||
|
@ -47,10 +44,10 @@ proc runTest(identifier: string) =
|
|||
|
||||
if existsFile(testDir/"post.ssz"):
|
||||
let postState = newClone(parseTest(testDir/"post.ssz", SSZ, BeaconState))
|
||||
discard process_deposit(defaultRuntimePreset, preState[], deposit, flags)
|
||||
discard process_deposit(defaultRuntimePreset, preState[], deposit)
|
||||
reportDiff(preState, postState)
|
||||
else:
|
||||
check process_deposit(defaultRuntimePreset, preState[], deposit, flags).isErr
|
||||
check process_deposit(defaultRuntimePreset, preState[], deposit).isErr
|
||||
|
||||
`testImpl _ operations_deposits _ identifier`()
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# beacon_chain
|
||||
# Copyright (c) 2018-2020 Status Research & Development GmbH
|
||||
# Copyright (c) 2018-2021 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).
|
||||
|
@ -19,7 +19,7 @@ import
|
|||
../beacon_chain/fork_choice/[fork_choice_types, fork_choice],
|
||||
../beacon_chain/block_pools/[chain_dag, clearance]
|
||||
|
||||
func combine(tgt: var Attestation, src: Attestation, flags: UpdateFlags) =
|
||||
func combine(tgt: var Attestation, src: Attestation) =
|
||||
## Combine the signature and participation bitfield, with the assumption that
|
||||
## the same data is being signed - if the signatures overlap, they are not
|
||||
## combined.
|
||||
|
@ -32,11 +32,10 @@ func combine(tgt: var Attestation, src: Attestation, flags: UpdateFlags) =
|
|||
if not tgt.aggregation_bits.overlaps(src.aggregation_bits):
|
||||
tgt.aggregation_bits.combine(src.aggregation_bits)
|
||||
|
||||
if skipBlsValidation notin flags:
|
||||
var agg {.noInit.}: AggregateSignature
|
||||
agg.init(tgt.signature)
|
||||
agg.aggregate(src.signature)
|
||||
tgt.signature = agg.finish()
|
||||
var agg {.noInit.}: AggregateSignature
|
||||
agg.init(tgt.signature)
|
||||
agg.aggregate(src.signature)
|
||||
tgt.signature = agg.finish()
|
||||
|
||||
template wrappedTimedTest(name: string, body: untyped) =
|
||||
# `check` macro takes a copy of whatever it's checking, on the stack!
|
||||
|
@ -151,7 +150,7 @@ suiteReport "Attestation pool processing" & preset():
|
|||
attestation1 = makeAttestation(
|
||||
state.data.data, state.blck.root, bc0[1], cache)
|
||||
|
||||
attestation0.combine(attestation1, {})
|
||||
attestation0.combine(attestation1)
|
||||
|
||||
pool[].addAttestation(
|
||||
attestation0, [bc0[0]].toHashSet, attestation0.data.slot)
|
||||
|
@ -177,7 +176,7 @@ suiteReport "Attestation pool processing" & preset():
|
|||
attestation1 = makeAttestation(
|
||||
state.data.data, state.blck.root, bc0[1], cache)
|
||||
|
||||
attestation0.combine(attestation1, {})
|
||||
attestation0.combine(attestation1)
|
||||
|
||||
pool[].addAttestation(
|
||||
attestation1, [bc0[1]].toHashSet, attestation1.data.slot)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# beacon_chain
|
||||
# Copyright (c) 2018-2020 Status Research & Development GmbH
|
||||
# Copyright (c) 2018-2021 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).
|
||||
|
@ -57,10 +57,10 @@ proc makeInitialDeposits*(
|
|||
for i in 0..<n.int:
|
||||
result.add makeDeposit(i, flags)
|
||||
|
||||
func signBlock*(
|
||||
func signBlock(
|
||||
fork: Fork, genesis_validators_root: Eth2Digest, blck: BeaconBlock,
|
||||
privKey: ValidatorPrivKey, flags: UpdateFlags = {}): SignedBeaconBlock =
|
||||
var root = hash_tree_root(blck)
|
||||
let root = hash_tree_root(blck)
|
||||
SignedBeaconBlock(
|
||||
message: blck,
|
||||
root: root,
|
||||
|
@ -131,8 +131,7 @@ proc makeTestBlock*(
|
|||
eth1_data = Eth1Data(),
|
||||
attestations = newSeq[Attestation](),
|
||||
deposits = newSeq[Deposit](),
|
||||
graffiti = default(GraffitiBytes),
|
||||
flags: set[UpdateFlag] = {}): SignedBeaconBlock =
|
||||
graffiti = default(GraffitiBytes)): SignedBeaconBlock =
|
||||
# Create a block for `state.slot + 1` - like a block proposer would do!
|
||||
# It's a bit awkward - in order to produce a block for N+1, we need to
|
||||
# calculate what the state will look like after that block has been applied,
|
||||
|
@ -140,7 +139,7 @@ proc makeTestBlock*(
|
|||
var tmpState = assignClone(state)
|
||||
addTestBlock(
|
||||
tmpState[], parent_root, cache, eth1_data, attestations, deposits,
|
||||
graffiti, flags)
|
||||
graffiti)
|
||||
|
||||
proc makeAttestation*(
|
||||
state: BeaconState, beacon_block_root: Eth2Digest,
|
||||
|
@ -192,12 +191,11 @@ proc find_beacon_committee(
|
|||
|
||||
proc makeAttestation*(
|
||||
state: BeaconState, beacon_block_root: Eth2Digest,
|
||||
validator_index: ValidatorIndex, cache: var StateCache,
|
||||
flags: UpdateFlags = {}): Attestation =
|
||||
validator_index: ValidatorIndex, cache: var StateCache): Attestation =
|
||||
let (committee, slot, index) =
|
||||
find_beacon_committee(state, validator_index, cache)
|
||||
makeAttestation(state, beacon_block_root, committee, slot, index,
|
||||
validator_index, cache, flags)
|
||||
validator_index, cache)
|
||||
|
||||
proc makeFullAttestations*(
|
||||
state: BeaconState, beacon_block_root: Eth2Digest, slot: Slot,
|
||||
|
@ -244,9 +242,7 @@ iterator makeTestBlocks*(
|
|||
parent_root: Eth2Digest,
|
||||
cache: var StateCache,
|
||||
blocks: int,
|
||||
attested: bool,
|
||||
flags: set[UpdateFlag] = {}
|
||||
): SignedBeaconBlock =
|
||||
attested: bool): SignedBeaconBlock =
|
||||
var
|
||||
state = assignClone(state)
|
||||
parent_root = parent_root
|
||||
|
@ -254,11 +250,11 @@ iterator makeTestBlocks*(
|
|||
let attestations = if attested:
|
||||
makeFullAttestations(
|
||||
state[].data, parent_root,
|
||||
state[].data.slot, cache, flags)
|
||||
state[].data.slot, cache)
|
||||
else:
|
||||
@[]
|
||||
|
||||
let blck = addTestBlock(
|
||||
state[], parent_root, cache, attestations = attestations, flags = flags)
|
||||
state[], parent_root, cache, attestations = attestations)
|
||||
yield blck
|
||||
parent_root = blck.root
|
||||
|
|
Loading…
Reference in New Issue