Fix parallelism bug in exit processing (#1110)

* Fix parallelism bug in exit processing

Also:

* Remove parallelism for all other operations except deposit merkle proofs
* Improve exit tests
* Fix broken attestation test

Closes #1090

* Allow for generating block/pre/post states from some unit tests (#1123)

* Add post-state checks, comments

* Add state_transition_vectors crate

* Integrate new testing crate with CI

* Add readme

* Add additional valid tests

* Remove ExitTests (they were moved to new crate)

* Small test fixes

* Delete incorrect saturating_sub in slash_validator

And clean-up the balance increase/decrease functions to look more like the spec.

Co-authored-by: Paul Hauner <paul@paulhauner.com>
This commit is contained in:
Michael Sproul
2020-05-09 09:37:21 +10:00
committed by GitHub
parent ad5bd6412a
commit 338cb2fba7
27 changed files with 846 additions and 562 deletions

View File

@@ -35,7 +35,7 @@ impl_common!(Slot);
impl_common!(Epoch);
impl Slot {
pub fn new(slot: u64) -> Slot {
pub const fn new(slot: u64) -> Slot {
Slot(slot)
}
@@ -49,7 +49,7 @@ impl Slot {
}
impl Epoch {
pub fn new(slot: u64) -> Epoch {
pub const fn new(slot: u64) -> Epoch {
Epoch(slot)
}

View File

@@ -48,9 +48,6 @@ impl TestingAttestationDataBuilder {
let beacon_block_root = *state.get_block_root(slot).unwrap();
match test_task {
// FIXME: re-enable the shard-like tests
// AttestationTestTask::NoCommiteeForShard => index += 2,
// AttestationTestTask::BadShard => index = T::ShardCount::to_u64(),
AttestationTestTask::IncludedTooEarly => {
slot = state.slot - spec.min_attestation_inclusion_delay + 1
}

View File

@@ -28,25 +28,11 @@ pub enum DepositTestTask {
NoReset,
}
/// Enum used for passing test options to builder
#[derive(PartialEq, Clone, Copy)]
pub enum ExitTestTask {
AlreadyInitiated,
AlreadyExited,
BadSignature,
FutureEpoch,
NotActive,
Valid,
ValidatorUnknown,
}
/// Enum used for passing test options to builder
#[derive(PartialEq, Clone, Copy)]
pub enum AttestationTestTask {
Valid,
NoCommiteeForShard,
WrongJustifiedCheckpoint,
BadShard,
BadIndexedAttestationBadSignature,
BadAggregationBitfieldLen,
BadSignature,
@@ -348,39 +334,25 @@ impl<T: EthSpec> TestingBeaconBlockBuilder<T> {
}
}
/// Insert a `Valid` exit into the state.
/// Insert an exit for the given validator at the given epoch into the block.
pub fn insert_exit(
&mut self,
test_task: ExitTestTask,
state: &mut BeaconState<T>,
mut validator_index: u64,
validator_index: u64,
exit_epoch: Epoch,
secret_key: &SecretKey,
state: &BeaconState<T>,
spec: &ChainSpec,
) {
let sk = &mut secret_key.clone();
let mut exit_epoch = state.slot.epoch(T::slots_per_epoch());
match test_task {
ExitTestTask::BadSignature => *sk = SecretKey::random(),
ExitTestTask::ValidatorUnknown => validator_index = 4242,
ExitTestTask::AlreadyExited => {
state.validators[validator_index as usize].exit_epoch = Epoch::from(314_159 as u64)
}
// FIXME: disabled in v0.9
ExitTestTask::NotActive => {
state.validators[validator_index as usize].activation_epoch =
Epoch::from(314_159 as u64)
}
ExitTestTask::FutureEpoch => exit_epoch = spec.far_future_epoch,
_ => (),
}
let builder = TestingVoluntaryExitBuilder::new(exit_epoch, validator_index);
let exit = builder.build(sk, &state.fork, state.genesis_validators_root, spec);
let exit = builder.build(secret_key, &state.fork, state.genesis_validators_root, spec);
self.block.body.voluntary_exits.push(exit).unwrap();
}
/// Mutate the block before signing.
pub fn modify(&mut self, f: impl FnOnce(&mut BeaconBlock<T>)) {
f(&mut self.block)
}
/// Signs and returns the block, consuming the builder.
pub fn build(
self,

View File

@@ -164,9 +164,10 @@ impl<T: EthSpec> TestingBeaconStateBuilder<T> {
}
/// Sets the `BeaconState` to be in a slot, calling `teleport_to_epoch` to update the epoch.
pub fn teleport_to_slot(&mut self, slot: Slot) {
pub fn teleport_to_slot(&mut self, slot: Slot) -> &mut Self {
self.teleport_to_epoch(slot.epoch(T::slots_per_epoch()));
self.state.slot = slot;
self
}
/// Sets the `BeaconState` to be in the first slot of the given epoch.