diff --git a/config/sample.toml b/config/sample.toml index 883bab8c..ada0d902 100644 --- a/config/sample.toml +++ b/config/sample.toml @@ -1,8 +1,11 @@ log_format = "json" -id = 1 [fnames] disable = false stop_at = 9999999999 start_from = 0 url = "https://fnames.farcaster.xyz/transfers" + +[consensus] +num_shards = 1 +shard_ids = [1] diff --git a/src/consensus/consensus.rs b/src/consensus/consensus.rs index d103b5cc..2ee55545 100644 --- a/src/consensus/consensus.rs +++ b/src/consensus/consensus.rs @@ -47,7 +47,8 @@ impl From> for Consensu #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Config { pub private_key: String, - pub shard_ids: String, + pub num_shards: u32, + pub shard_ids: Vec, #[serde(with = "humantime_serde")] pub propose_value_delay: Duration, @@ -62,25 +63,11 @@ impl Config { Keypair::from(secret_key.unwrap()) } - pub fn shard_ids(&self) -> Vec { - self.shard_ids - .split(',') - .map(|s| s.parse().unwrap()) - .collect() - } - - pub fn num_shards(&self) -> u32 { - self.shard_ids().len() as u32 - } - pub fn with_shard_ids(&self, shard_ids: Vec) -> Self { Self { private_key: self.private_key.clone(), - shard_ids: shard_ids - .iter() - .map(|i| i.to_string()) - .collect::>() - .join(","), + num_shards: shard_ids.len() as u32, + shard_ids, propose_value_delay: self.propose_value_delay, max_messages_per_block: self.max_messages_per_block, } @@ -91,7 +78,8 @@ impl Default for Config { fn default() -> Self { Self { private_key: hex::encode(SecretKey::generate()), - shard_ids: "1".to_string(), + shard_ids: vec![1], + num_shards: 1, propose_value_delay: Duration::from_millis(250), max_messages_per_block: 250, //TODO } diff --git a/src/main.rs b/src/main.rs index eb7f6b8e..5b50b8e4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -206,7 +206,15 @@ async fn main() -> Result<(), Box> { // Every 5 ticks, re-register the validators so that new nodes can discover each other if tick_count % 5 == 0 { let nonce = tick_count as u64; - for i in 0..=app_config.consensus.num_shards() { + + let ids = { + // prepend 0 to shard_ids for the following loop + let mut ids = vec![0u32]; + ids.extend(&app_config.consensus.shard_ids); + ids + }; + + for i in ids { let current_height = if i == 0 { block_store.max_block_number().unwrap_or_else(|_| 0) diff --git a/src/node/snapchain_node.rs b/src/node/snapchain_node.rs index b921a599..7d76c121 100644 --- a/src/node/snapchain_node.rs +++ b/src/node/snapchain_node.rs @@ -54,7 +54,7 @@ impl SnapchainNode { let mut shard_stores: HashMap = HashMap::new(); // Create the shard validators - for shard_id in config.shard_ids() { + for shard_id in config.shard_ids { if shard_id == 0 { panic!("Shard ID 0 is reserved for the block shard, created automaticaly"); } else if shard_id > MAX_SHARDS { @@ -155,7 +155,7 @@ impl SnapchainNode { validator_address.clone(), block_shard.clone(), shard_decision_rx, - config.num_shards(), + config.num_shards, block_tx, engine, );