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

consensus: leaders history sync fix, fmt

aggstam 3 лет назад
Родитель
Сommit
ae24fd7674

+ 1 - 1
src/consensus/leadcoin.rs

@@ -27,7 +27,7 @@ use darkfi_sdk::{
 };
 use halo2_proofs::{arithmetic::Field, circuit::Value};
 use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
-use log::{debug};
+use log::debug;
 use rand::rngs::OsRng;
 
 use super::constants::EPOCH_LENGTH;

+ 9 - 2
src/consensus/proto/protocol_sync_consensus.rs

@@ -81,9 +81,16 @@ impl ProtocolSyncConsensus {
             }
             let unconfirmed_txs = lock.unconfirmed_txs.clone();
             let slot_checkpoints = lock.consensus.slot_checkpoints.clone();
+            let leaders_history = lock.consensus.leaders_history.clone();
             let nullifiers = lock.consensus.nullifiers.clone();
-            let response =
-                ConsensusResponse { offset, forks, unconfirmed_txs, slot_checkpoints, nullifiers };
+            let response = ConsensusResponse {
+                offset,
+                forks,
+                unconfirmed_txs,
+                slot_checkpoints,
+                leaders_history,
+                nullifiers,
+            };
             if let Err(e) = self.channel.send(response).await {
                 error!("ProtocolSyncConsensus::handle_receive_request() channel send fail: {}", e);
             };

+ 4 - 3
src/consensus/state.rs

@@ -394,7 +394,6 @@ impl ConsensusState {
         constants::KI.clone() * self.f_int()
     }
 
-
     /// the probability inverse of winnig lottery having all the stake
     /// returns f
     fn win_inv_prob_with_full_stake(&mut self) -> Float10 {
@@ -404,9 +403,9 @@ impl ConsensusState {
         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 D: {:?}", d);
-        let f = p+i+d;
+        let f = p + i + d;
         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()
         }
         info!("win_inv_prob_with_full_stake(): PID clipped f: {}", f);
@@ -625,6 +624,8 @@ pub struct ConsensusResponse {
     pub unconfirmed_txs: Vec<Transaction>,
     /// Hot/live slot checkpoints
     pub slot_checkpoints: Vec<SlotCheckpoint>,
+    /// Leaders count history
+    pub leaders_history: Vec<u64>,
     /// Seen nullifiers from proposals
     pub nullifiers: Vec<pallas::Base>,
 }

+ 1 - 0
src/consensus/task/consensus_sync.rs

@@ -64,6 +64,7 @@ pub async fn consensus_sync_task(p2p: P2pPtr, state: ValidatorStatePtr) -> Resul
             lock.consensus.forks = forks;
             lock.unconfirmed_txs = response.unconfirmed_txs.clone();
             lock.consensus.slot_checkpoints = response.slot_checkpoints.clone();
+            lock.consensus.leaders_history = response.leaders_history.clone();
             lock.consensus.nullifiers = response.nullifiers.clone();
 
             break