Skip to content

Commit

Permalink
Basic shard node running via clap tools
Browse files Browse the repository at this point in the history
  • Loading branch information
villanuevawill committed Sep 25, 2019
1 parent b89d650 commit d4292b8
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ members = [
"beacon_node/rpc",
"beacon_node/version",
"beacon_node/beacon_chain",
"shard_node",
"shard_node/shard_store",
"shard_node/shard_chain",
"tests/ef_tests",
Expand Down
30 changes: 30 additions & 0 deletions shard_node/cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "shard_node"
version = "0.1.0"
authors = ["Will Villanueva"]
edition = "2018"

[dependencies]
shard_chain = { path = "./shard_chain" }
types = { path = "../eth2/types" }
toml = "^0.5"
store = { path = "../beacon_node/store" }
shard_store = { path = "./shard_store" }
clap = "2.32.0"
serde = "1.0"
shard_operation_pool = { path = "../eth2/shard_operation_pool" }
slog = { version = "^2.2.3" , features = ["max_level_trace"] }
slog-term = "^2.4.0"
slog-async = "^2.3.0"
slot_clock = { path = "../eth2/utils/slot_clock" }
ctrlc = { version = "3.1.1", features = ["termination"] }
tokio = "0.1.15"
tokio-timer = "0.2.10"
futures = "0.1.25"
exit-future = "0.1.3"
shard_state_processing = { path = "../eth2/shard_state_processing" }
env_logger = "0.6.1"
dirs = "2.0.1"
shard_lmd_ghost = { path = "../eth2/shard_lmd_ghost" }
lmd_ghost = { path = "../eth2/lmd_ghost" }
rand = "0.5.5"
1 change: 1 addition & 0 deletions shard_node/shard_chain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ pub mod shard_chain;
pub use self::checkpoint::CheckPoint;
pub use self::errors::{BlockProductionError, ShardChainError};
pub use self::shard_chain::{ShardChain, ShardChainTypes};
pub use self::harness::ShardChainHarness;
25 changes: 25 additions & 0 deletions shard_node/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
mod run;

extern crate clap;
use shard_chain::ShardChainHarness;
use clap::{Arg, App, SubCommand};

fn main() {
let matches = App::new("My Super Program")
.version("0.1.0")
.author("Will Villanueva")
.about("Simulates Shard Chains")
.arg(Arg::with_name("shards")
.short("s")
.long("shards")
.value_name("FILE")
.help("Sets a custom config file")
.takes_value(true))
.get_matches();

// Matches number of shards to run
let shards = matches.value_of("shards").unwrap_or("1");
run::run_harness();
}


36 changes: 36 additions & 0 deletions shard_node/src/run.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use shard_chain::ShardChainHarness;
use lmd_ghost::ThreadSafeReducedTree;
use rand::Rng;
use shard_lmd_ghost::ThreadSafeReducedTree as ShardThreadSafeReducedTree;
use shard_store::{MemoryStore as ShardMemoryStore, Store as ShardStore};
use store::{MemoryStore, Store};
use types::test_utils::{SeedableRng, TestRandom, XorShiftRng};
use types::{EthSpec, MinimalEthSpec, MinimalShardSpec, Slot};

pub const VALIDATOR_COUNT: usize = 24;

pub type TestBeaconForkChoice = ThreadSafeReducedTree<MemoryStore, MinimalEthSpec>;
pub type TestShardForkChoice = ShardThreadSafeReducedTree<ShardMemoryStore, MinimalShardSpec>;

fn get_harness(
validator_count: usize,
) -> ShardChainHarness<TestBeaconForkChoice, MinimalEthSpec, TestShardForkChoice, MinimalShardSpec>
{
let harness = ShardChainHarness::new(validator_count);

// Move past the zero slot
harness.advance_beacon_slot();
harness.advance_shard_slot();

harness
}

pub fn run_harness() -> () {
let harness = get_harness(VALIDATOR_COUNT);
let num_blocks_produced =
MinimalEthSpec::slots_per_epoch() * harness.beacon_spec.phase_1_fork_epoch;

harness.extend_beacon_chain((num_blocks_produced + 1) as usize);
harness.extend_shard_chain(1, vec![]);
println!("{:?}", harness.shard_chain.current_state().clone());
}

0 comments on commit d4292b8

Please sign in to comment.