From 62640ad6919268a12360a423991ff5c4265a91de Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Fri, 4 Jan 2019 18:12:32 +1100 Subject: [PATCH] Remove old chain maps and stores mods --- lighthouse/beacon_chain/src/lib.rs | 4 +- lighthouse/beacon_chain/src/maps.rs | 127 -------------------------- lighthouse/beacon_chain/src/stores.rs | 9 -- 3 files changed, 1 insertion(+), 139 deletions(-) delete mode 100644 lighthouse/beacon_chain/src/maps.rs delete mode 100644 lighthouse/beacon_chain/src/stores.rs diff --git a/lighthouse/beacon_chain/src/lib.rs b/lighthouse/beacon_chain/src/lib.rs index 632aa2c85..6acdc3ef6 100644 --- a/lighthouse/beacon_chain/src/lib.rs +++ b/lighthouse/beacon_chain/src/lib.rs @@ -1,14 +1,12 @@ mod block_processing; mod block_production; -mod maps; -mod stores; use db::{ stores::{BeaconBlockStore, BeaconStateStore}, ClientDB, DBError, }; use genesis::{genesis_beacon_block, genesis_beacon_state, GenesisError}; -use slot_clock::{SlotClock, TestingSlotClockError}; +use slot_clock::SlotClock; use spec::ChainSpec; use ssz::ssz_encode; use std::collections::HashSet; diff --git a/lighthouse/beacon_chain/src/maps.rs b/lighthouse/beacon_chain/src/maps.rs deleted file mode 100644 index 4c737cb44..000000000 --- a/lighthouse/beacon_chain/src/maps.rs +++ /dev/null @@ -1,127 +0,0 @@ -use types::{AttesterMap, ProposerMap, ShardCommittee}; - -#[derive(Debug, PartialEq)] -pub enum AttesterAndProposerMapError { - NoShardCommitteeForSlot, - NoAvailableProposer, -} - -/// Generate a map of `(slot, shard) |--> committee`. -/// -/// The attester map is used to optimise the lookup of a committee. -pub fn generate_attester_and_proposer_maps( - shard_and_committee_for_slots: &Vec>, - start_slot: u64, -) -> Result<(AttesterMap, ProposerMap), AttesterAndProposerMapError> { - let mut attester_map = AttesterMap::new(); - let mut proposer_map = ProposerMap::new(); - for (i, slot) in shard_and_committee_for_slots.iter().enumerate() { - /* - * Store the proposer for the block. - */ - let slot_number = (i as u64).saturating_add(start_slot); - let first_committee = &slot - .get(0) - .ok_or(AttesterAndProposerMapError::NoShardCommitteeForSlot)? - .committee; - let proposer_index = (slot_number as usize) - .checked_rem(first_committee.len()) - .ok_or(AttesterAndProposerMapError::NoAvailableProposer)?; - proposer_map.insert(slot_number, first_committee[proposer_index]); - - /* - * Loop through the shards and extend the attester map. - */ - for shard_and_committee in slot { - let committee = shard_and_committee.committee.clone(); - attester_map.insert((slot_number, shard_and_committee.shard), committee); - } - } - Ok((attester_map, proposer_map)) -} - -#[cfg(test)] -mod tests { - use super::*; - - fn sac_generator( - shard_count: u64, - slot_count: usize, - sac_per_slot: usize, - committee_size: usize, - ) -> Vec> { - let mut shard = 0; - let mut validator = 0; - let mut cycle = vec![]; - - for _ in 0..slot_count { - let mut slot: Vec = vec![]; - for _ in 0..sac_per_slot { - let mut sac = ShardCommittee { - shard: shard % shard_count, - committee: vec![], - }; - for _ in 0..committee_size { - sac.committee.push(validator); - validator += 1; - } - slot.push(sac); - shard += 1; - } - cycle.push(slot); - } - cycle - } - - #[test] - fn test_attester_proposer_maps_empty_slots() { - let sac = sac_generator(4, 4, 0, 1); - let result = generate_attester_and_proposer_maps(&sac, 0); - assert_eq!( - result, - Err(AttesterAndProposerMapError::NoShardCommitteeForSlot) - ); - } - - #[test] - fn test_attester_proposer_maps_empty_committees() { - let sac = sac_generator(4, 4, 1, 0); - let result = generate_attester_and_proposer_maps(&sac, 0); - assert_eq!( - result, - Err(AttesterAndProposerMapError::NoAvailableProposer) - ); - } - - #[test] - fn test_attester_proposer_maps_scenario_a() { - let sac = sac_generator(4, 4, 1, 1); - let (a, p) = generate_attester_and_proposer_maps(&sac, 0).unwrap(); - - assert_eq!(*p.get(&0).unwrap(), 0); - assert_eq!(*p.get(&1).unwrap(), 1); - assert_eq!(*p.get(&2).unwrap(), 2); - assert_eq!(*p.get(&3).unwrap(), 3); - - assert_eq!(*a.get(&(0, 0)).unwrap(), vec![0]); - assert_eq!(*a.get(&(1, 1)).unwrap(), vec![1]); - assert_eq!(*a.get(&(2, 2)).unwrap(), vec![2]); - assert_eq!(*a.get(&(3, 3)).unwrap(), vec![3]); - } - - #[test] - fn test_attester_proposer_maps_scenario_b() { - let sac = sac_generator(4, 4, 1, 4); - let (a, p) = generate_attester_and_proposer_maps(&sac, 0).unwrap(); - - assert_eq!(*p.get(&0).unwrap(), 0); - assert_eq!(*p.get(&1).unwrap(), 5); - assert_eq!(*p.get(&2).unwrap(), 10); - assert_eq!(*p.get(&3).unwrap(), 15); - - assert_eq!(*a.get(&(0, 0)).unwrap(), vec![0, 1, 2, 3]); - assert_eq!(*a.get(&(1, 1)).unwrap(), vec![4, 5, 6, 7]); - assert_eq!(*a.get(&(2, 2)).unwrap(), vec![8, 9, 10, 11]); - assert_eq!(*a.get(&(3, 3)).unwrap(), vec![12, 13, 14, 15]); - } -} diff --git a/lighthouse/beacon_chain/src/stores.rs b/lighthouse/beacon_chain/src/stores.rs deleted file mode 100644 index fae097899..000000000 --- a/lighthouse/beacon_chain/src/stores.rs +++ /dev/null @@ -1,9 +0,0 @@ -use db::stores::{BeaconBlockStore, PoWChainStore, ValidatorStore}; -use db::ClientDB; -use std::sync::Arc; - -pub struct BeaconChainStore { - pub block: Arc>, - pub pow_chain: Arc>, - pub validator: Arc>, -}