Просмотр исходного кода

increase proportional value to 0.4 stablizes pid

mohab metwally 3 лет назад
Родитель
Сommit
ab7f99dade
4 измененных файлов с 13 добавлено и 17 удалено
  1. 1 1
      src/consensus/constants.rs
  2. 6 6
      src/consensus/leadcoin.rs
  3. 3 7
      src/consensus/state.rs
  4. 3 3
      src/consensus/validator.rs

+ 1 - 1
src/consensus/constants.rs

@@ -45,7 +45,7 @@ lazy_static! {
     pub static ref  DT: Float10 =  Float10::from_str_native("0.1").unwrap().with_precision(RADIX_BITS).value();
     pub static ref  DT: Float10 =  Float10::from_str_native("0.1").unwrap().with_precision(RADIX_BITS).value();
     pub static ref  TI: Float10 = FLOAT10_ONE.clone();
     pub static ref  TI: Float10 = FLOAT10_ONE.clone();
     pub static ref  TD: Float10 = FLOAT10_ONE.clone();
     pub static ref  TD: Float10 = FLOAT10_ONE.clone();
-    pub static ref  KP: Float10 = Float10::from_str_native("0.3").unwrap().with_precision(RADIX_BITS).value();
+    pub static ref  KP: Float10 = Float10::from_str_native("0.4").unwrap().with_precision(RADIX_BITS).value();
     pub static ref  KI: Float10 = Float10::from_str_native("0.02").unwrap().with_precision(RADIX_BITS).value();
     pub static ref  KI: Float10 = Float10::from_str_native("0.02").unwrap().with_precision(RADIX_BITS).value();
     pub static ref  KD: Float10 = FLOAT10_ONE.clone();
     pub static ref  KD: Float10 = FLOAT10_ONE.clone();
     pub static ref PID_OUT_STEP: Float10  = Float10::from_str_native("0.1").unwrap().with_precision(RADIX_BITS).value();
     pub static ref PID_OUT_STEP: Float10  = Float10::from_str_native("0.1").unwrap().with_precision(RADIX_BITS).value();

+ 6 - 6
src/consensus/leadcoin.rs

@@ -27,7 +27,7 @@ use darkfi_sdk::{
 };
 };
 use halo2_proofs::{arithmetic::Field, circuit::Value};
 use halo2_proofs::{arithmetic::Field, circuit::Value};
 use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
 use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
-use log::{debug,info};
+use log::{debug};
 use rand::rngs::OsRng;
 use rand::rngs::OsRng;
 
 
 use super::constants::EPOCH_LENGTH;
 use super::constants::EPOCH_LENGTH;
@@ -128,7 +128,7 @@ impl LeadCoin {
         let pk = Self::util_pk(coin1_sk_root, tau);
         let pk = Self::util_pk(coin1_sk_root, tau);
         // Derive the nonce for coin2
         // Derive the nonce for coin2
         let coin2_seed = Self::util_derived_rho(coin1_sk_root, pallas::Base::from(seed));
         let coin2_seed = Self::util_derived_rho(coin1_sk_root, pallas::Base::from(seed));
-        info!("coin2_seed[{}]: {:?}", slot_index, coin2_seed);
+        debug!("coin2_seed[{}]: {:?}", slot_index, coin2_seed);
         let coin1_commitment =
         let coin1_commitment =
             Self::commitment(pk, pallas::Base::from(value), pallas::Base::from(seed), coin1_blind);
             Self::commitment(pk, pallas::Base::from(value), pallas::Base::from(seed), coin1_blind);
         // Hash its coordinates to get a base field element
         // Hash its coordinates to get a base field element
@@ -192,7 +192,7 @@ impl LeadCoin {
 
 
     /// Derive election seeds from given parameters
     /// Derive election seeds from given parameters
     pub fn election_seeds(eta: pallas::Base, slot: pallas::Base) -> (pallas::Base, pallas::Base) {
     pub fn election_seeds(eta: pallas::Base, slot: pallas::Base) -> (pallas::Base, pallas::Base) {
-        info!("election_seeds: eta: {:?}, slot: {:?}", eta, slot);
+        debug!("election_seeds: eta: {:?}, slot: {:?}", eta, slot);
         let election_seed_nonce = pallas::Base::from(3);
         let election_seed_nonce = pallas::Base::from(3);
         let election_seed_lead = pallas::Base::from(22);
         let election_seed_lead = pallas::Base::from(22);
 
 
@@ -286,8 +286,8 @@ impl LeadCoin {
         let value = pallas::Base::from(self.value);
         let value = pallas::Base::from(self.value);
         let target = sigma1 * value + sigma2 * value * value;
         let target = sigma1 * value + sigma2 * value * value;
 
 
-        info!("is_leader(): y = {:?}", y);
-        info!("is_leader(): T = {:?}", target);
+        debug!("is_leader(): y = {:?}", y);
+        debug!("is_leader(): T = {:?}", target);
 
 
         let first_winning = y < target;
         let first_winning = y < target;
         first_winning
         first_winning
@@ -317,7 +317,7 @@ impl LeadCoin {
         &self,
         &self,
         coin_commitment_tree: &mut BridgeTree<MerkleNode, MERKLE_DEPTH>,
         coin_commitment_tree: &mut BridgeTree<MerkleNode, MERKLE_DEPTH>,
     ) -> LeadCoin {
     ) -> LeadCoin {
-        info!("derive_coin(): Deriving new coin!");
+        debug!("derive_coin(): Deriving new coin!");
         let derived_c1_rho = self.derived_rho();
         let derived_c1_rho = self.derived_rho();
         let blind = pallas::Scalar::random(&mut OsRng);
         let blind = pallas::Scalar::random(&mut OsRng);
         let derived_c2_cm = Self::commitment(
         let derived_c2_cm = Self::commitment(

+ 3 - 7
src/consensus/state.rs

@@ -217,8 +217,8 @@ impl ConsensusState {
         if total_stake == 0 {
         if total_stake == 0 {
             total_stake = constants::GENESIS_TOTAL_STAKE;
             total_stake = constants::GENESIS_TOTAL_STAKE;
         }
         }
-        info!("sigmas(): f: {}", f);
-        info!("sigmas(): stake: {}", total_stake);
+        debug!("sigmas(): f: {}", f);
+        debug!("sigmas(): stake: {}", total_stake);
         let one = constants::FLOAT10_ONE.clone();
         let one = constants::FLOAT10_ONE.clone();
         let two = constants::FLOAT10_TWO.clone();
         let two = constants::FLOAT10_TWO.clone();
         let field_p = Float10::from_str_native(constants::P)
         let field_p = Float10::from_str_native(constants::P)
@@ -395,10 +395,6 @@ impl ConsensusState {
     }
     }
 
 
 
 
-    fn pid(p: Float10, i: Float10, d: Float10) -> Float10 {
-        constants::KP.clone() * p.abs() + constants::KI.clone() * i + constants::KD.clone() * d
-    }
-
     /// the probability inverse of winnig lottery having all the stake
     /// the probability inverse of winnig lottery having all the stake
     /// returns f
     /// returns f
     fn win_inv_prob_with_full_stake(&mut self) -> Float10 {
     fn win_inv_prob_with_full_stake(&mut self) -> Float10 {
@@ -408,7 +404,7 @@ impl ConsensusState {
         info!("win_inv_prob_with_full_stake(): PID P: {:?}", p);
         info!("win_inv_prob_with_full_stake(): PID P: {:?}", p);
         info!("win_inv_prob_with_full_stake(): PID I: {:?}", i);
         info!("win_inv_prob_with_full_stake(): PID I: {:?}", i);
         info!("win_inv_prob_with_full_stake(): PID D: {:?}", d);
         info!("win_inv_prob_with_full_stake(): PID D: {:?}", d);
-        let mut f = p+i+d;
+        let f = p+i+d;
         info!("win_inv_prob_with_full_stake(): PID f: {}", f);
         info!("win_inv_prob_with_full_stake(): PID f: {}", f);
         if f==constants::FLOAT10_ZERO.clone() {
         if f==constants::FLOAT10_ZERO.clone() {
             return constants::MIN_F.clone()
             return constants::MIN_F.clone()

+ 3 - 3
src/consensus/validator.rs

@@ -93,9 +93,9 @@ impl ValidatorState {
         faucet_pubkeys: Vec<PublicKey>,
         faucet_pubkeys: Vec<PublicKey>,
         enable_participation: bool,
         enable_participation: bool,
     ) -> Result<ValidatorStatePtr> {
     ) -> Result<ValidatorStatePtr> {
-        info!("Initializing ValidatorState");
+        debug!("Initializing ValidatorState");
 
 
-        info!("Initializing wallet tables for consensus");
+        debug!("Initializing wallet tables for consensus");
         // TODO: TESTNET: The stuff is kept entirely in memory for now, what should we write
         // TODO: TESTNET: The stuff is kept entirely in memory for now, what should we write
         //                to disk/wallet?
         //                to disk/wallet?
         //let consensus_tree_init_query = include_str!("../../script/sql/consensus_tree.sql");
         //let consensus_tree_init_query = include_str!("../../script/sql/consensus_tree.sql");
@@ -103,7 +103,7 @@ impl ValidatorState {
         //wallet.exec_sql(consensus_tree_init_query).await?;
         //wallet.exec_sql(consensus_tree_init_query).await?;
         //wallet.exec_sql(consensus_keys_init_query).await?;
         //wallet.exec_sql(consensus_keys_init_query).await?;
 
 
-        info!("Generating leader proof keys with k: {}", constants::LEADER_PROOF_K);
+        debug!("Generating leader proof keys with k: {}", constants::LEADER_PROOF_K);
         let bincode = include_bytes!("../../proof/lead.zk.bin");
         let bincode = include_bytes!("../../proof/lead.zk.bin");
         let zkbin = ZkBinary::decode(bincode)?;
         let zkbin = ZkBinary::decode(bincode)?;
         let witnesses = empty_witnesses(&zkbin);
         let witnesses = empty_witnesses(&zkbin);