[Temp Commit] Implements more basic skeleton code.

This commit is contained in:
Age Manning
2019-03-04 16:39:37 +11:00
parent 2e020a3efa
commit 3b8f29a914
19 changed files with 195 additions and 93 deletions

View File

@@ -1,68 +1,10 @@
// /// Syncing for lighthouse.
/// Syncing for lighthouse.
///
/// Stores the various syncing methods for the beacon chain.
mod simple_sync;
/*
// for initial testing and setup, to be replaced.
pub fn sync_server(config: Config) {
// Set up database
let db = match config.db_type {
_ => Arc::new(MemoryDB::open()),
//TODO: Box db
//DBType::Memory => Arc::new(Box::new(MemoryDB::open())),
//DBType::RocksDB => Arc::new(Box::new(DiskDB::open(&config.db_name, None))),
};
pub use crate::SimpleSync;
// build block
let block_store = Arc::new(BeaconBlockStore::new(db.clone()));
let state_store = Arc::new(BeaconStateStore::new(db.clone()));
// Slot clock
let genesis_time = 1_549_935_547; // 12th Feb 2018 (arbitrary value in the past).
let slot_clock = SystemTimeSlotClock::new(genesis_time, spec.slot_duration)
.expect("Unable to load SystemTimeSlotClock");
// Choose the fork choice
let fork_choice = BitwiseLMDGhost::new(block_store.clone(), state_store.clone());
/*
* Generate some random data to start a chain with.
*
* This is will need to be replace for production usage.
*/
let latest_eth1_data = Eth1Data {
deposit_root: Hash256::zero(),
block_hash: Hash256::zero(),
};
let keypairs: Vec<Keypair> = (0..10)
.collect::<Vec<usize>>()
.iter()
.map(|_| Keypair::random())
.collect();
let initial_validator_deposits = keypairs
.iter()
.map(|keypair| Deposit {
branch: vec![], // branch verification is not specified.
index: 0, // index verification is not specified.
deposit_data: DepositData {
amount: 32_000_000_000, // 32 ETH (in Gwei)
timestamp: genesis_time - 1,
deposit_input: DepositInput {
pubkey: keypair.pk.clone(),
withdrawal_credentials: Hash256::zero(), // Withdrawal not possible.
proof_of_possession: create_proof_of_possession(&keypair),
},
},
})
.collect();
// Genesis chain
let _chain_result = BeaconChain::genesis(
state_store.clone(),
block_store.clone(),
slot_clock,
genesis_time,
latest_eth1_data,
initial_validator_deposits,
spec,
fork_choice,
);
pub enum SyncMethod {
SimpleSync,
}
*/

View File

@@ -0,0 +1,22 @@
use std::collections::HashMap;
use types::{Slot, H256};
/// Keeps track of syncing information for known connected peers.
pub struct PeerSyncInfo {
best_slot: Slot,
best_slot_hash: H256,
}
/// The current syncing state.
pub enum SyncState {
Idle,
Downloading,
Stopped,
}
/// Simple Syncing protocol.
pub struct SimpleSync {
genesis_hash: H256,
known_peers: HashMap<PeerId, PeerSyncInfo>,
state: SyncState,
}