Remove old chain maps and stores mods
This commit is contained in:
parent
ad91648f30
commit
62640ad691
@ -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;
|
||||
|
@ -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<Vec<ShardCommittee>>,
|
||||
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<Vec<ShardCommittee>> {
|
||||
let mut shard = 0;
|
||||
let mut validator = 0;
|
||||
let mut cycle = vec![];
|
||||
|
||||
for _ in 0..slot_count {
|
||||
let mut slot: Vec<ShardCommittee> = 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]);
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
use db::stores::{BeaconBlockStore, PoWChainStore, ValidatorStore};
|
||||
use db::ClientDB;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct BeaconChainStore<T: ClientDB + Sized> {
|
||||
pub block: Arc<BeaconBlockStore<T>>,
|
||||
pub pow_chain: Arc<PoWChainStore<T>>,
|
||||
pub validator: Arc<ValidatorStore<T>>,
|
||||
}
|
Loading…
Reference in New Issue
Block a user