Add timeouts to canonical head rwlock (#759)

* Add TimeoutRwLock to BeaconChain

* Update network crate

* Update rest api

* Fix beacon chain tests

* Fix rest api tests

* Set test back to !debug_assertions
This commit is contained in:
Paul Hauner
2020-01-06 17:30:37 +11:00
committed by GitHub
parent b0c8b2b700
commit f04c55075e
21 changed files with 391 additions and 156 deletions
@@ -59,7 +59,14 @@ fn finalizes_after_resuming_from_db() {
);
assert!(
harness.chain.head().beacon_state.finalized_checkpoint.epoch > 0,
harness
.chain
.head()
.expect("should read head")
.beacon_state
.finalized_checkpoint
.epoch
> 0,
"the chain should have already finalized"
);
@@ -95,7 +102,11 @@ fn finalizes_after_resuming_from_db() {
AttestationStrategy::AllValidators,
);
let state = &resumed_harness.chain.head().beacon_state;
let state = &resumed_harness
.chain
.head()
.expect("should read head")
.beacon_state;
assert_eq!(
state.slot, num_blocks_produced,
"head should be at the current slot"
+10 -4
View File
@@ -96,7 +96,7 @@ fn randomised_skips() {
}
}
let state = &harness.chain.head().beacon_state;
let state = &harness.chain.head().expect("should get head").beacon_state;
assert_eq!(state.slot, num_slots, "head should be at the current slot");
@@ -166,6 +166,7 @@ fn randao_genesis_storage() {
let genesis_value = *harness
.chain
.head()
.expect("should get head")
.beacon_state
.get_randao_mix(Epoch::new(0))
.expect("randao mix ok");
@@ -181,6 +182,7 @@ fn randao_genesis_storage() {
assert!(harness
.chain
.head()
.expect("should get head")
.beacon_state
.randao_mixes
.iter()
@@ -197,6 +199,7 @@ fn randao_genesis_storage() {
assert!(harness
.chain
.head()
.expect("should get head")
.beacon_state
.randao_mixes
.iter()
@@ -238,7 +241,7 @@ fn split_slot_restore() {
/// Check that the head state's slot matches `expected_slot`.
fn check_slot(harness: &TestHarness, expected_slot: u64) {
let state = &harness.chain.head().beacon_state;
let state = &harness.chain.head().expect("should get head").beacon_state;
assert_eq!(
state.slot, expected_slot,
@@ -248,7 +251,7 @@ fn check_slot(harness: &TestHarness, expected_slot: u64) {
/// Check that the chain has finalized under best-case assumptions, and check the head slot.
fn check_finalization(harness: &TestHarness, expected_slot: u64) {
let state = &harness.chain.head().beacon_state;
let state = &harness.chain.head().expect("should get head").beacon_state;
check_slot(harness, expected_slot);
@@ -271,6 +274,7 @@ fn check_split_slot(harness: &TestHarness, store: Arc<DiskStore<E>>) {
harness
.chain
.head()
.expect("should get head")
.beacon_state
.finalized_checkpoint
.epoch
@@ -314,7 +318,7 @@ fn check_chain_dump(harness: &TestHarness, expected_len: u64) {
.map(|checkpoint| (checkpoint.beacon_block_root, checkpoint.beacon_block.slot))
.collect::<Vec<_>>();
let head = harness.chain.head();
let head = harness.chain.head().expect("should get head");
let mut forward_block_roots = Store::forwards_block_roots_iterator(
harness.chain.store.clone(),
Slot::new(0),
@@ -343,6 +347,7 @@ fn check_iterators(harness: &TestHarness) {
harness
.chain
.rev_iter_state_roots()
.expect("should get iter")
.last()
.map(|(_, slot)| slot),
Some(Slot::new(0))
@@ -351,6 +356,7 @@ fn check_iterators(harness: &TestHarness) {
harness
.chain
.rev_iter_block_roots()
.expect("should get iter")
.last()
.map(|(_, slot)| slot),
Some(Slot::new(0))
+74 -24
View File
@@ -37,7 +37,7 @@ fn get_harness(validator_count: usize) -> BeaconChainHarness<HarnessType<Minimal
fn massive_skips() {
let harness = get_harness(8);
let spec = &MinimalEthSpec::default_spec();
let mut state = harness.chain.head().beacon_state;
let mut state = harness.chain.head().expect("should get head").beacon_state;
// Run per_slot_processing until it returns an error.
let error = loop {
@@ -70,8 +70,16 @@ fn iterators() {
AttestationStrategy::SomeValidators(vec![]),
);
let block_roots: Vec<(Hash256, Slot)> = harness.chain.rev_iter_block_roots().collect();
let state_roots: Vec<(Hash256, Slot)> = harness.chain.rev_iter_state_roots().collect();
let block_roots: Vec<(Hash256, Slot)> = harness
.chain
.rev_iter_block_roots()
.expect("should get iter")
.collect();
let state_roots: Vec<(Hash256, Slot)> = harness
.chain
.rev_iter_state_roots()
.expect("should get iter")
.collect();
assert_eq!(
block_roots.len(),
@@ -109,7 +117,7 @@ fn iterators() {
)
});
let head = &harness.chain.head();
let head = &harness.chain.head().expect("should get head");
assert_eq!(
*block_roots.first().expect("should have some block roots"),
@@ -154,7 +162,7 @@ fn chooses_fork() {
assert!(honest_head != faulty_head, "forks should be distinct");
let state = &harness.chain.head().beacon_state;
let state = &harness.chain.head().expect("should get head").beacon_state;
assert_eq!(
state.slot,
@@ -163,7 +171,11 @@ fn chooses_fork() {
);
assert_eq!(
harness.chain.head().beacon_block_root,
harness
.chain
.head()
.expect("should get head")
.beacon_block_root,
honest_head,
"the honest chain should be the canonical chain"
);
@@ -181,7 +193,7 @@ fn finalizes_with_full_participation() {
AttestationStrategy::AllValidators,
);
let state = &harness.chain.head().beacon_state;
let state = &harness.chain.head().expect("should get head").beacon_state;
assert_eq!(
state.slot, num_blocks_produced,
@@ -219,7 +231,7 @@ fn finalizes_with_two_thirds_participation() {
AttestationStrategy::SomeValidators(attesters),
);
let state = &harness.chain.head().beacon_state;
let state = &harness.chain.head().expect("should get head").beacon_state;
assert_eq!(
state.slot, num_blocks_produced,
@@ -263,7 +275,7 @@ fn does_not_finalize_with_less_than_two_thirds_participation() {
AttestationStrategy::SomeValidators(attesters),
);
let state = &harness.chain.head().beacon_state;
let state = &harness.chain.head().expect("should get head").beacon_state;
assert_eq!(
state.slot, num_blocks_produced,
@@ -296,7 +308,7 @@ fn does_not_finalize_without_attestation() {
AttestationStrategy::SomeValidators(vec![]),
);
let state = &harness.chain.head().beacon_state;
let state = &harness.chain.head().expect("should get head").beacon_state;
assert_eq!(
state.slot, num_blocks_produced,
@@ -357,7 +369,7 @@ fn free_attestations_added_to_fork_choice_some_none() {
AttestationStrategy::AllValidators,
);
let state = &harness.chain.head().beacon_state;
let state = &harness.chain.head().expect("should get head").beacon_state;
let fork_choice = &harness.chain.fork_choice;
let validator_slots: Vec<(usize, Slot)> = (0..VALIDATOR_COUNT)
@@ -409,12 +421,23 @@ fn attestations_with_increasing_slots() {
AttestationStrategy::SomeValidators(vec![]),
);
attestations.append(&mut harness.get_free_attestations(
&AttestationStrategy::AllValidators,
&harness.chain.head().beacon_state,
harness.chain.head().beacon_block_root,
harness.chain.head().beacon_block.slot,
));
attestations.append(
&mut harness.get_free_attestations(
&AttestationStrategy::AllValidators,
&harness.chain.head().expect("should get head").beacon_state,
harness
.chain
.head()
.expect("should get head")
.beacon_block_root,
harness
.chain
.head()
.expect("should get head")
.beacon_block
.slot,
),
);
harness.advance_slot();
}
@@ -439,7 +462,7 @@ fn free_attestations_added_to_fork_choice_all_updated() {
AttestationStrategy::AllValidators,
);
let state = &harness.chain.head().beacon_state;
let state = &harness.chain.head().expect("should get head").beacon_state;
let fork_choice = &harness.chain.fork_choice;
let validators: Vec<usize> = (0..VALIDATOR_COUNT).collect();
@@ -496,17 +519,39 @@ fn run_skip_slot_test(skip_slots: u64) {
);
assert_eq!(
harness_a.chain.head().beacon_block.slot,
harness_a
.chain
.head()
.expect("should get head")
.beacon_block
.slot,
Slot::new(skip_slots + 1)
);
assert_eq!(harness_b.chain.head().beacon_block.slot, Slot::new(0));
assert_eq!(
harness_b
.chain
.process_block(harness_a.chain.head().beacon_block.clone()),
.head()
.expect("should get head")
.beacon_block
.slot,
Slot::new(0)
);
assert_eq!(
harness_b.chain.process_block(
harness_a
.chain
.head()
.expect("should get head")
.beacon_block
.clone()
),
Ok(BlockProcessingOutcome::Processed {
block_root: harness_a.chain.head().beacon_block_root
block_root: harness_a
.chain
.head()
.expect("should get head")
.beacon_block_root
})
);
@@ -516,7 +561,12 @@ fn run_skip_slot_test(skip_slots: u64) {
.expect("should run fork choice");
assert_eq!(
harness_b.chain.head().beacon_block.slot,
harness_b
.chain
.head()
.expect("should get head")
.beacon_block
.slot,
Slot::new(skip_slots + 1)
);
}