From 56123ee754d4b2e0e646e926c92e8673c0e8c49a Mon Sep 17 00:00:00 2001 From: mithunshashidhara Date: Wed, 24 Oct 2018 13:11:51 +0530 Subject: [PATCH] Warnings and 80 column fix This PR fixes warnings messages during cargo build. code indentation has been improved and 80 colums width maintained. Signed-off-by: mithunshashidhara --- src/core/src/consensus_state.rs | 177 +++++++++++++------------- src/core/src/consensus_state_store.rs | 7 +- src/core/src/enclave_sgx.rs | 3 +- src/core/src/enclave_sim.rs | 5 +- src/core/src/engine.rs | 77 +++++------ src/core/src/fork_resolver.rs | 31 +++-- src/core/src/poet2_util.rs | 2 +- src/core/src/service.rs | 6 +- src/core/src/settings_view.rs | 125 +++++++++--------- 9 files changed, 224 insertions(+), 209 deletions(-) mode change 100644 => 100755 src/core/src/consensus_state_store.rs mode change 100644 => 100755 src/core/src/enclave_sgx.rs mode change 100644 => 100755 src/core/src/enclave_sim.rs mode change 100644 => 100755 src/core/src/engine.rs mode change 100644 => 100755 src/core/src/fork_resolver.rs mode change 100644 => 100755 src/core/src/poet2_util.rs mode change 100644 => 100755 src/core/src/settings_view.rs diff --git a/src/core/src/consensus_state.rs b/src/core/src/consensus_state.rs index 11b41cc..61f309d 100644 --- a/src/core/src/consensus_state.rs +++ b/src/core/src/consensus_state.rs @@ -3,20 +3,19 @@ use service::Poet2Service; use enclave_sgx::WaitCertificate; use std::collections::VecDeque; use std::collections::HashMap; -#[macro_use] -use serde_derive; use serde_json; /* * The validator state represents the state for a single * validator at a point in time. A validator state object contains: -* key_block_claim_count (int): The number of blocks that the validator has -* claimed using the current PoET public key -* poet_public_key (str): The current PoET public key for the validator -* total_block_claim_count (int): The total number of the blocks that the -* validator has claimed +* @param key_block_claim_count (int): The number of blocks that the validator +* has claimed using the current PoET public key. +* @param poet_public_key (str): The current PoET public key for the validator. +* @param total_block_claim_count (int): The total number of blocks that the +* validator has claimed. * */ + #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)] pub struct ValidatorState { key_block_claim_count : u64, @@ -28,8 +27,8 @@ pub struct ValidatorState { * The population sample represents the information * we need to create the population estimate, which in turn is used to compute * the local mean. A population sample object contains: -* wait_time (float): The duration from a wait certificate/timer -* local_mean (float): The local mean from a wait certificate/timer +* @param wait_time (float): The duration from a wait certificate/timer +* @param local_mean (float): The local mean from a wait certificate/timer */ #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)] @@ -40,23 +39,22 @@ pub struct PopulationSample { /* * -* The population estimate represents what we need -* to help in computing zTest results. A population estimate object contains: -* -* population_estimate (float): The population estimate for the corresponding -* block -* previous_block_id (str): The ID of the block previous to the one that this -* population estimate corresponds to -* validator_id (str): The ID of the validator that won the corresponding +* EstimateInfo represents what we need to help in computing zTest results. +* An Estimate Info object contains: +* @param population_estimate (float): The population estimate for the +* corresponding block +* @param previous_block_id (str): The ID of the block previous to the one that +* this population estimate corresponds to +* @param validator_id (str): The ID of the validator that won the corresponding * block * */ #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)] pub struct EstimateInfo { pub population_estimate : f64, - // Needs to be of type BlockId but encapsulating structure is required to + // Needs to be of type BlockId but encapsulating structure is required to // to be serializeable & BlockId is not at the sdk - pub previous_block_id: String,//BlockId, + pub previous_block_id: String, pub validator_id: String } @@ -73,43 +71,40 @@ pub struct ConsensusState { } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)] -pub struct ValidatorInfo{ - // Needs to be of type PeerId but encapsulating structure is required to +pub struct ValidatorInfo { + // Needs to be of type PeerId but encapsulating structure is required to // to be serializeable & PeerId is not at the sdk - id: String,//PeerId, + id: String, poet_public_key: String, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)] -pub struct PoetSettingsView{ +pub struct PoetSettingsView { population_estimate_sample_size: usize, } #[derive(Serialize, Deserialize, Clone, Debug, Default)] -struct BlockInfo{ +struct BlockInfo { wait_certificate: Option, validator_info: Option, poet_settings_view: Option, } -impl PartialEq for BlockInfo{ +impl PartialEq for BlockInfo { fn eq( &self, other: &BlockInfo) -> bool { let self_ = self.clone(); let other_ = other.clone(); - - - if (((self.wait_certificate.is_some() && other.wait_certificate.is_some()) + if (((self.wait_certificate.is_some() && other.wait_certificate.is_some()) && (self_.wait_certificate.unwrap() == other_.wait_certificate.unwrap())) - || (self.wait_certificate.is_none() && other.wait_certificate.is_none())) - && (((self.validator_info.is_some() && other.validator_info.is_some()) + || (self.wait_certificate.is_none() && other.wait_certificate.is_none())) + && (((self.validator_info.is_some() && other.validator_info.is_some()) && (self_.validator_info.unwrap() == other_.validator_info.unwrap())) - || (self.validator_info.is_none() && other.validator_info.is_none())) - && (((self.poet_settings_view.is_some() && other.poet_settings_view.is_some()) + || (self.validator_info.is_none() && other.validator_info.is_none())) + && (((self.poet_settings_view.is_some() && other.poet_settings_view.is_some()) && (self_.poet_settings_view.unwrap() == other_.poet_settings_view.unwrap())) - || (self.poet_settings_view.is_none() && other.poet_settings_view.is_none())) - + || (self.poet_settings_view.is_none() && other.poet_settings_view.is_none())) { true } - else + else { false } } } @@ -120,86 +115,94 @@ struct Entry{ value: BlockInfo, } -impl ConsensusState{ - - const MINIMUM_WAIT_TIME: f64 = 1.0; - pub fn consensus_state_for_block_id(&mut self, block_id: BlockId, svc: &mut Poet2Service) -> Option{ +impl ConsensusState { + pub fn consensus_state_for_block_id(&mut self, block_id: BlockId, + svc: &mut Poet2Service) -> Option { let mut previous_wait_certificate: Option = None; let mut consensus_state: Option = None; - let mut wait_certificate : Option = None; let mut blocks: Vec = Vec::new(); let mut current_id = block_id; - loop{ - let mut block_ = svc.get_block(current_id.clone()); + loop { + let block_ = svc.get_block(current_id.clone()); let block: Block; - if block_.is_ok(){ + if block_.is_ok() { block = block_.unwrap(); } - else{ + else { break; } - /*consensus_state = consensus_state_store.get(current_id.clone()); - if consensus_state != None{ - break - }*/ - let mut payload_vec = block.payload; - let mut payload_str = String::from_utf8(payload_vec).expect("Found Invalid UTF-8"); - let mut wait_certificate = Some(serde_json::from_str(&payload_str).unwrap()); + let payload_vec = block.payload; + let payload_str = String::from_utf8(payload_vec).expect("Found Invalid UTF-8"); + let wait_certificate = Some(serde_json::from_str(&payload_str).unwrap()); if wait_certificate.is_some() { //TODO } - else if blocks.is_empty() || previous_wait_certificate.is_some(){ - blocks.push(Entry{ key: current_id.clone(), value: BlockInfo{ wait_certificate: None, validator_info: None, poet_settings_view: None} }); + else if blocks.is_empty() || previous_wait_certificate.is_some() { + blocks.push(Entry{ key: current_id.clone(), value: + BlockInfo{ wait_certificate: None, validator_info: + None, poet_settings_view: None} }); } previous_wait_certificate = wait_certificate.clone(); current_id = block.previous_id; - //let mut consensus_state = consensus_state_store_.get(current_id.clone()); - if consensus_state.is_none(){ - consensus_state = Some(ConsensusState::default()); + if consensus_state.is_none() { + consensus_state = Some(ConsensusState::default()); } - for entry in blocks.iter().rev(){ + for entry in blocks.iter().rev() { let mut val = &entry.value; - if val.wait_certificate.is_none(){ - consensus_state = Some(ConsensusState::default()); - } - else{ - self.validator_did_claim_block(&(val.clone().validator_info.unwrap()), &(val.clone().wait_certificate.unwrap()), &(val.clone().poet_settings_view.unwrap())); - } + if val.wait_certificate.is_none() { + consensus_state = Some(ConsensusState::default()); + } + else { + self.validator_did_claim_block(&(val.clone().validator_info.unwrap()), + &(val.clone().wait_certificate.unwrap()), + &(val.clone().poet_settings_view.unwrap())); + } } } - consensus_state + consensus_state } - pub fn validator_did_claim_block(&mut self, validator_info: &ValidatorInfo, wait_certificate: &WaitCertificate, poet_settings_view: &PoetSettingsView ) -> (){ + pub fn validator_did_claim_block(&mut self, validator_info: &ValidatorInfo, + wait_certificate: &WaitCertificate, + poet_settings_view: &PoetSettingsView ) -> () { self.aggregate_local_mean += 5.5_f64; //wait_certificate.local_mean; self.total_block_claim_count += 1; - self.population_samples.push_back( PopulationSample{ wait_time: wait_certificate.wait_time , local_mean: 5.5_f64}); //wait_certificate.local_mean}); - while self.population_samples.len() > poet_settings_view.population_estimate_sample_size{ + self.population_samples.push_back( + PopulationSample{ wait_time: wait_certificate.wait_time , + local_mean: 5.5_f64}); + while self.population_samples.len() > + poet_settings_view.population_estimate_sample_size { self.population_samples.pop_front(); } - let mut validator_state = self.get_validator_state(validator_info.clone()); - let mut total_block_claim_count = validator_state.total_block_claim_count + 1; - let mut key_block_claim_count = if validator_info.poet_public_key == validator_state.poet_public_key { - validator_state.key_block_claim_count + 1 - } - else{ - 1 + let validator_state = self.get_validator_state(validator_info.clone()); + let total_block_claim_count = validator_state.total_block_claim_count + 1; + let key_block_claim_count = if validator_info.poet_public_key == + validator_state.poet_public_key { + validator_state.key_block_claim_count + 1 + } + else { + 1 }; let peerid_vec = Vec::from(validator_info.clone().id); let peerid_str = String::from_utf8(peerid_vec).expect("Found Invalid UTF-8"); - self.validators.insert(peerid_str, ValidatorState{ key_block_claim_count: key_block_claim_count, poet_public_key: validator_info.clone().poet_public_key, total_block_claim_count: total_block_claim_count}); - - } + self.validators.insert(peerid_str, + ValidatorState{ key_block_claim_count: key_block_claim_count, + poet_public_key: validator_info.clone().poet_public_key, + total_block_claim_count: total_block_claim_count}); + } - pub fn get_validator_state(&mut self, validator_info: ValidatorInfo) -> Box{ - let peerid_vec = Vec::from(validator_info.clone().id); - let peerid_str = String::from_utf8(peerid_vec).expect("Found Invalid UTF-8"); - let mut validator_state = self.validators.get(&peerid_str); - let mut val_state = ValidatorState{ key_block_claim_count: 0, poet_public_key: validator_info.clone().poet_public_key, total_block_claim_count: 0}; - if validator_state.is_none(){ - return Box::new(val_state); - } - Box::new(validator_state.unwrap().clone()) - } + pub fn get_validator_state(&mut self, validator_info: ValidatorInfo) -> + Box { + let peerid_vec = Vec::from(validator_info.clone().id); + let peerid_str = String::from_utf8(peerid_vec).expect("Found Invalid UTF-8"); + let validator_state = self.validators.get(&peerid_str); + let val_state = ValidatorState{ key_block_claim_count: 0, + poet_public_key: validator_info.clone().poet_public_key, + total_block_claim_count: 0}; + if validator_state.is_none() { + return Box::new(val_state); + } + Box::new(validator_state.unwrap().clone()) + } } diff --git a/src/core/src/consensus_state_store.rs b/src/core/src/consensus_state_store.rs old mode 100644 new mode 100755 index bba7f97..acf5489 --- a/src/core/src/consensus_state_store.rs +++ b/src/core/src/consensus_state_store.rs @@ -15,10 +15,9 @@ * ------------------------------------------------------------------------------ */ -use protobuf; use consensus_state::ConsensusState; use sawtooth_sdk::consensus::engine::BlockId; -use database::lmdb::{LmdbContext, LmdbDatabase}; +use database::lmdb::{LmdbDatabase}; use database::DatabaseError; use bincode::{serialize, deserialize}; @@ -57,11 +56,11 @@ impl<'a> ConsensusStateStore<'a> { pub fn delete(&mut self, block_id: BlockId) -> Result<(), DatabaseError>{ let mut writer = self.consensus_state_db.writer()?; writer.delete(&Vec::from(block_id))?; - Ok(()) } - pub fn put(&mut self, block_id: BlockId, consensus_state: ConsensusState) -> Result<(), DatabaseError>{ + pub fn put(&mut self, block_id: BlockId, consensus_state: ConsensusState) -> + Result<(), DatabaseError>{ let mut writer = self.consensus_state_db.writer()?; let serialized_state = serialize(&consensus_state).map_err(|err| { DatabaseError::WriterError(format!("Failed to serialize state: {}", err)) diff --git a/src/core/src/enclave_sgx.rs b/src/core/src/enclave_sgx.rs old mode 100644 new mode 100755 index c86e914..5420327 --- a/src/core/src/enclave_sgx.rs +++ b/src/core/src/enclave_sgx.rs @@ -165,7 +165,8 @@ impl EnclaveConfig { info!("wait certificate generated is {:?}", wait_cert); //release wait certificate - let status = ffi::release_wait_certificate(&mut eid, &mut wait_cert_info); + ffi::release_wait_certificate(&mut eid, &mut wait_cert_info) + .expect("failed to release wait certificate"); (wait_cert, wait_cert_sign) } diff --git a/src/core/src/enclave_sim.rs b/src/core/src/enclave_sim.rs old mode 100644 new mode 100755 index 55acf7f..0feea5b --- a/src/core/src/enclave_sim.rs +++ b/src/core/src/enclave_sim.rs @@ -61,7 +61,7 @@ impl Default for WaitCertificate { } } -static mut last_block_number : u64 = 0_u64; +// static mut last_block_number : u64 = 0_u64; pub struct PoetCertMap { poet_block_id : String, @@ -141,8 +141,7 @@ pub fn initialize_wait_certificate( if !in_serialized_prev_block_wait_certificate.is_empty() { let deserialized_prev_block_wait_certificate = serde_json::from_str(&in_serialized_prev_block_wait_certificate); - let mut prev_wait_certificate_obj : WaitCertificate = - WaitCertificate::default(); + let prev_wait_certificate_obj : WaitCertificate; if deserialized_prev_block_wait_certificate.is_ok() { prev_wait_certificate_obj = diff --git a/src/core/src/engine.rs b/src/core/src/engine.rs old mode 100644 new mode 100755 index c2c8d2c..6d53b65 --- a/src/core/src/engine.rs +++ b/src/core/src/engine.rs @@ -22,24 +22,25 @@ extern crate log4rs; use sawtooth_sdk::consensus::{engine::*, service::Service}; use service::Poet2Service; use std::sync::mpsc::{Receiver, RecvTimeoutError}; -use std::time; +// use std::time; use std::str::FromStr; use std::cmp; -use serde_json; +// use serde_json; use std::time::Duration; use std::time::Instant; -use std::collections::HashMap; -use enclave_sgx::*; -use consensus_state::*; +// use std::collections::HashMap; +// use enclave_sgx::*; +// use consensus_state::*; use consensus_state_store::ConsensusStateStore; use poet2_util; use database::config; use database::lmdb; -use database::{DatabaseError, CliError}; +// use database::{DatabaseError, CliError}; +use database::{CliError}; use settings_view::Poet2SettingsView; use fork_resolver; -const DEFAULT_BLOCK_CLAIM_LIMIT:i32 = 250; +// const DEFAULT_BLOCK_CLAIM_LIMIT:i32 = 250; pub struct Poet2Engine { } @@ -60,13 +61,13 @@ impl Engine for Poet2Engine { info!("Started PoET 2 Engine"); let mut service = Poet2Service::new(service); - let mut chain_head = startup_state.chain_head; + let chain_head = startup_state.chain_head; let mut published_at_height = false; let mut start = Instant::now(); let validator_id = Vec::from(startup_state.local_peer_info.peer_id); - let mut block_num_id_map:HashMap = HashMap::new(); - let mut block_num:u64 = 0; - let mut ctx = create_context().unwrap(); + // let block_num_id_map:HashMap = HashMap::new(); + // let block_num:u64 = 0; + let ctx = create_context().unwrap(); let mut state_store = open_statestore(&ctx).unwrap(); service.enclave.initialize_enclave(); @@ -274,33 +275,33 @@ fn verify_wait_certificate( _block: Block, service: &mut Poet2Service, poet_pub_ //k-test -fn validtor_has_claimed_block_limit( service: &mut Poet2Service ) -> bool { - - let mut block_claim_limit = DEFAULT_BLOCK_CLAIM_LIMIT; - let mut key_block_claim_count=9; - let mut poet_public_key="abcd"; - let mut validator_info_signup_info_poet_public_key="abcd"; - // let mut key_block_claim_limit = poet_settings_view.key_block_claim_limit ; //key - // need to use get_settings from service - let key_block_claim_limit = service.get_setting_from_head( - String::from("sawtooth.poet.key_block_claim_limit")); - - if key_block_claim_limit != "" { - block_claim_limit = key_block_claim_limit.parse::().unwrap(); - } - - // let mut validator_state = self.get_validator_state();// //stubbed - // if validator_state.poet_public_key == validator_info.signup_info.poet_public_key //stubbed - - if poet_public_key == validator_info_signup_info_poet_public_key //stubbed function replaced with dummy function - { - //if validator_state.key_block_claim_count >= block_claim_limit - if key_block_claim_count >= block_claim_limit{ - true } - else { false } - } - else{ false } -} +// fn validtor_has_claimed_block_limit( service: &mut Poet2Service ) -> bool { + +// let mut block_claim_limit = DEFAULT_BLOCK_CLAIM_LIMIT; +// let mut key_block_claim_count=9; +// let mut poet_public_key="abcd"; +// let mut validator_info_signup_info_poet_public_key="abcd"; +// // let mut key_block_claim_limit = poet_settings_view.key_block_claim_limit ; //key +// // need to use get_settings from service +// let key_block_claim_limit = service.get_setting_from_head( +// String::from("sawtooth.poet.key_block_claim_limit")); + +// if key_block_claim_limit != "" { +// block_claim_limit = key_block_claim_limit.parse::().unwrap(); +// } + +// // let mut validator_state = self.get_validator_state();// //stubbed +// // if validator_state.poet_public_key == validator_info.signup_info.poet_public_key //stubbed + +// if poet_public_key == validator_info_signup_info_poet_public_key //stubbed function replaced with dummy function +// { +// //if validator_state.key_block_claim_count >= block_claim_limit +// if key_block_claim_count >= block_claim_limit{ +// true } +// else { false } +// } +// else{ false } +// } //c-test diff --git a/src/core/src/fork_resolver.rs b/src/core/src/fork_resolver.rs old mode 100644 new mode 100755 index 8b93f7b..5e5792e --- a/src/core/src/fork_resolver.rs +++ b/src/core/src/fork_resolver.rs @@ -43,7 +43,7 @@ pub fn resolve_fork(service: &mut Poet2Service, state_store: &mut ConsensusState // Commiting or Resolving fork if one exists // Advance the chain if possible. - let mut claim_block_dur:u64 = 0_u64; + let claim_block_dur:u64; claim_block_dur = prev_wait_time; let new_block_dur = get_cert_from(&block).wait_time; @@ -68,13 +68,15 @@ pub fn resolve_fork(service: &mut Poet2Service, state_store: &mut ConsensusState state.aggregate_chain_clock = agg_chain_clock; state.estimate_info = EstimateInfo{ population_estimate : 0_f64, - previous_block_id : poet2_util::to_hex_string(Vec::from(block.previous_id.clone())), + previous_block_id : poet2_util::to_hex_string(Vec::from( + block.previous_id.clone())), validator_id : poet2_util::to_hex_string(Vec::from( block.signer_id.clone())), }; debug!("Storing cummulative cc = {} for blockId : {:?}", agg_chain_clock, block_id.clone()); - state_store.put(block_id.clone(), state); + state_store.put(block_id.clone(), state) + .expect("failed to put into state store"); service.set_chain_clock(agg_chain_clock); service.commit_block(block_id); } @@ -97,7 +99,7 @@ pub fn resolve_fork(service: &mut Poet2Service, state_store: &mut ConsensusState let mut fork_cc:u64 = new_block_dur; let mut fork_len:u64 = 1; let mut cc_upto_ancestor = 0_u64; - let mut ancestor_found:bool = false; + let ancestor_found:bool; info!("Looping over chain to find common ancestor."); loop { @@ -141,12 +143,12 @@ pub fn resolve_fork(service: &mut Poet2Service, state_store: &mut ConsensusState } } let mut fork_won = false; - let mut chain_cc:u64 = 0; + // let mut chain_cc:u64 = 0; if ancestor_found { info!("Found a common ancestor. Comparing length."); debug!("Chain clocks upto head = {}, upto common ancestor = {}", cc_upto_head, cc_upto_ancestor); - chain_cc = cc_upto_head - cc_upto_ancestor; + let chain_cc:u64 = cc_upto_head - cc_upto_ancestor; let chain_len:u64 = chain_head.block_num - cache_block.block_num; if chain_len > fork_len { fork_won = false; @@ -165,6 +167,8 @@ pub fn resolve_fork(service: &mut Poet2Service, state_store: &mut ConsensusState fork_won = if fork_cc < chain_cc { true } else { false }; } } + } else { + info!("Did not find a common ancestor."); } if fork_won { info!("Discarding the block in progress."); @@ -181,10 +185,13 @@ pub fn resolve_fork(service: &mut Poet2Service, state_store: &mut ConsensusState debug!("Storing cummulative cc = {}", agg_chain_clock); state.estimate_info = EstimateInfo{ population_estimate : 0_f64, - previous_block_id : poet2_util::to_hex_string(Vec::from(block.previous_id.clone())), - validator_id : poet2_util::to_hex_string(Vec::from(block.signer_id.clone())), + previous_block_id : poet2_util::to_hex_string( + Vec::from(block.previous_id.clone())), + validator_id : poet2_util::to_hex_string( + Vec::from(block.signer_id.clone())), }; - state_store.put(block_id.clone(), state); + state_store.put(block_id.clone(), state) + .expect("failed to put into state store"); service.set_chain_clock(agg_chain_clock); service.commit_block(block_id); // Mark all blocks upto common ancestor @@ -228,8 +235,10 @@ fn delete_states_upto( ancestor: BlockId, head: BlockId, delete_len: u64, } else { debug!("Deleting state for {:?}", next.clone()); - state_store.delete(next.clone()); - next = BlockId::from(state_.unwrap().estimate_info.previous_block_id.as_bytes().to_vec()); + state_store.delete(next.clone()) + .expect("failed to delete from state store"); + next = BlockId::from(state_.unwrap(). + estimate_info.previous_block_id.as_bytes().to_vec()); } } } diff --git a/src/core/src/poet2_util.rs b/src/core/src/poet2_util.rs old mode 100644 new mode 100755 index 330345f..106fca0 --- a/src/core/src/poet2_util.rs +++ b/src/core/src/poet2_util.rs @@ -10,7 +10,7 @@ pub fn to_hex_string(bytes: Vec) -> String { } pub fn blockid_to_hex_string(blockid: BlockId) -> String { - let mut blockid_vec = Vec::from(blockid); + let blockid_vec = Vec::from(blockid); to_hex_string(blockid_vec) } diff --git a/src/core/src/service.rs b/src/core/src/service.rs index ea58b1a..c896fb9 100755 --- a/src/core/src/service.rs +++ b/src/core/src/service.rs @@ -74,7 +74,9 @@ impl Poet2Service { match blocks { Err(err) => { warn!("Could not get a block with id {:?}", block_id.clone()); - Err(Error::UnknownBlock(format!("Block not found for id {:?}", block_id.clone()))) + Err(Error::UnknownBlock(format! + ("Block not found for id {:?} error code {:?}", + block_id.clone(), err))) } Ok(mut block_map) => { //remove from the returned hashmap to get value @@ -181,7 +183,7 @@ impl Poet2Service { pub fn get_wait_time(&mut self, pre_chain_head: Block, validator_id: &Vec, poet_pub_key: &String) -> u64 { - let mut duration64: u64 = 0_u64; + // let mut duration64: u64 = 0_u64; let mut prev_wait_certificate = String::new(); let mut prev_wait_certificate_sig = String::new(); diff --git a/src/core/src/settings_view.rs b/src/core/src/settings_view.rs old mode 100644 new mode 100755 index d83e756..94dd598 --- a/src/core/src/settings_view.rs +++ b/src/core/src/settings_view.rs @@ -16,7 +16,8 @@ */ use std::collections::HashMap; -use sawtooth_sdk::consensus::{engine::BlockId, service::Service}; +// use sawtooth_sdk::consensus::{engine::BlockId, service::Service}; +use sawtooth_sdk::consensus::{engine::BlockId}; use service::Poet2Service; #[derive(Clone, Debug, Default)] @@ -75,65 +76,65 @@ impl Poet2SettingsView { in_default_value } - fn block_claim_delay(&self) -> u64 { - let default_block_claim_delay = 1_u64; - self._get_config_value_as_u64( - "sawtooth.consensus.poet2.block_claim_delay", - default_block_claim_delay) - } - - fn initial_wait_time(&self) -> f64 { - let default_initial_wait_time = 3000.0_f64; - self._get_config_value_as_f64( - "sawtooth.consensus.poet2.initial_wait_time", - default_initial_wait_time) - } - - fn key_block_claim_limit(&self) -> u64 { - let default_key_block_claim_limit = 250_u64; - self._get_config_value_as_u64( - "sawtooth.consensus.poet2.key_block_claim_limit", - default_key_block_claim_limit) - } - - fn population_estimate_sample_size(&self) -> u64 { - let default_population_estimate_sample_size = 50_u64; - self._get_config_value_as_u64( - "sawtooth.consensus.poet2.population_estimate_sample_size", - default_population_estimate_sample_size) - } - - fn registration_retry_delay(&self) -> u64 { - let default_registration_retry_delay = 10_u64; - self._get_config_value_as_u64( - "sawtooth.consensus.poet2.registration_retry_delay", - default_registration_retry_delay) - } - - fn signup_commit_maximum_delay(&self) -> u64 { - let default_signup_commit_maximum_delay = 10_u64; - self._get_config_value_as_u64( - "sawtooth.consensus.poet2.signup_commit_maximum_delay", - default_signup_commit_maximum_delay) - } - - fn target_wait_time(&self) -> f64 { - let default_target_wait_time = 20.0_f64; - self._get_config_value_as_f64("sawtooth.consensus.poet2.target_wait_time", - default_target_wait_time) - } - - fn z_test_maximum_win_deviation(&self) -> f64 { - let default_z_test_maximum_win_deviation = 3.075_f64; - self._get_config_value_as_f64( - "sawtooth.consensus.poet2.z_test_maximum_win_deviation", - default_z_test_maximum_win_deviation) - } - - fn z_test_minimum_win_count(&self) -> u64 { - let default_z_test_minimum_win_count = 3_u64; - self._get_config_value_as_u64( - "sawtooth.consensus.poet2.z_test_minimum_win_count", - default_z_test_minimum_win_count) - } + // fn block_claim_delay(&self) -> u64 { + // let default_block_claim_delay = 1_u64; + // self._get_config_value_as_u64( + // "sawtooth.consensus.poet2.block_claim_delay", + // default_block_claim_delay) + // } + + // fn initial_wait_time(&self) -> f64 { + // let default_initial_wait_time = 3000.0_f64; + // self._get_config_value_as_f64( + // "sawtooth.consensus.poet2.initial_wait_time", + // default_initial_wait_time) + // } + + // fn key_block_claim_limit(&self) -> u64 { + // let default_key_block_claim_limit = 250_u64; + // self._get_config_value_as_u64( + // "sawtooth.consensus.poet2.key_block_claim_limit", + // default_key_block_claim_limit) + // } + + // fn population_estimate_sample_size(&self) -> u64 { + // let default_population_estimate_sample_size = 50_u64; + // self._get_config_value_as_u64( + // "sawtooth.consensus.poet2.population_estimate_sample_size", + // default_population_estimate_sample_size) + // } + + // fn registration_retry_delay(&self) -> u64 { + // let default_registration_retry_delay = 10_u64; + // self._get_config_value_as_u64( + // "sawtooth.consensus.poet2.registration_retry_delay", + // default_registration_retry_delay) + // } + + // fn signup_commit_maximum_delay(&self) -> u64 { + // let default_signup_commit_maximum_delay = 10_u64; + // self._get_config_value_as_u64( + // "sawtooth.consensus.poet2.signup_commit_maximum_delay", + // default_signup_commit_maximum_delay) + // } + + // fn target_wait_time(&self) -> f64 { + // let default_target_wait_time = 20.0_f64; + // self._get_config_value_as_f64("sawtooth.consensus.poet2.target_wait_time", + // default_target_wait_time) + // } + + // fn z_test_maximum_win_deviation(&self) -> f64 { + // let default_z_test_maximum_win_deviation = 3.075_f64; + // self._get_config_value_as_f64( + // "sawtooth.consensus.poet2.z_test_maximum_win_deviation", + // default_z_test_maximum_win_deviation) + // } + + // fn z_test_minimum_win_count(&self) -> u64 { + // let default_z_test_minimum_win_count = 3_u64; + // self._get_config_value_as_u64( + // "sawtooth.consensus.poet2.z_test_minimum_win_count", + // default_z_test_minimum_win_count) + // } }