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

+ 2 - 0
src/consensus/constants.rs

@@ -46,6 +46,7 @@ lazy_static! {
     pub static ref  TD: Float10 = FLOAT10_ONE.clone() / FLOAT10_TEN.clone();
 
     pub static ref PID_OUT_STEP: Float10  = Float10::from_str_native("0.1").unwrap().with_precision(RADIX_BITS).value();
+
 }
 
 /// Block version number
@@ -82,3 +83,4 @@ pub const PI_MU_Y_INDEX: usize = 8;
 pub const PI_MU_RHO_INDEX: usize = 10;
 pub const PI_SIGMA1_INDEX: usize = 12;
 pub const PI_SIGMA2_INDEX: usize = 13;
+pub const GENESIS_TOTAL_STAKE: i64 = 1;

+ 7 - 1
src/consensus/state.rs

@@ -431,7 +431,13 @@ impl ValidatorState {
         let f = self.win_prob_with_full_stake();
 
         // Generate sigmas
-        let total_stake = self.total_stake_plus(); // Only used for fine-tuning
+        let mut total_stake = self.total_stake_plus(); // Only used for fine-tuning
+        // at genesis epoch first slot, of absolute index 0,
+        // the total stake would be 0, to avoid division by zero,
+        // we asume total stake at first division is GENESIS_TOTAL_STAKE.
+        if total_stake == 0 {
+            total_stake = constants::GENESIS_TOTAL_STAKE;
+        }
         debug!("consensus::sigmas(): f: {}", f);
         debug!("consensus::sigmas(): stake: {}", total_stake);
         let one = constants::FLOAT10_ONE.clone();