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

fix sl index in election_seeds

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

+ 6 - 6
src/consensus/leadcoin.rs

@@ -183,6 +183,10 @@ impl LeadCoin {
         poseidon_hash(sn_msg)
     }
 
+    pub fn election_seeds_u64(eta: pallas::Base, slotu64: u64) -> (pallas::Base, pallas::Base) {
+        Self::election_seeds(eta, pallas::Base::from(slotu64))
+    }
+
     /// Derive election seeds from given parameters
     pub fn election_seeds(eta: pallas::Base, slot: pallas::Base) -> (pallas::Base, pallas::Base) {
         info!("LeadCoin::election_seeds(): eta: {:?}, slot: {:?}", eta, slot);
@@ -303,8 +307,8 @@ impl LeadCoin {
 
     /// the new coin to be minted after the current coin is spent
     /// in lottery.
-    pub fn derive_coin(&self, eta: pallas::Base, slot: u64) -> LeadCoin {
-        let tau = pallas::Base::from(slot);
+    pub fn derive_coin(&self) -> LeadCoin {
+        info!("LeadCoin::derive_coin()");
         let mut derived = self.clone();
         let rho = self.derived_rho();
         let blind = pallas::Scalar::random(&mut OsRng);
@@ -314,10 +318,6 @@ impl LeadCoin {
         derived.coin2_commitment = cm;
         derived.coin1_blind = derived.coin2_blind;
         derived.coin2_blind = blind;
-        // update random mau_y, mau_rho in case epoch is changed
-        let (y_mu, rho_mu) = Self::election_seeds(eta, tau);
-        derived.y_mu = y_mu;
-        derived.rho_mu = rho_mu;
         derived
     }
 

+ 7 - 5
src/consensus/state.rs

@@ -478,8 +478,8 @@ impl ValidatorState {
         for i in 0..constants::EPOCH_LENGTH {
             let coin = LeadCoin::new(
                 eta,
-                constants::LOTTERY_HEAD_START, // TODO: TESTNET: Why is this constant being used?
-                slot as u64,
+                LOTTERY_HEAD_START, // TODO: TESTNET: Why is this constant being used?
+                slot+i as u64,
                 epoch_secrets.secret_keys[i].inner(),
                 epoch_secrets.merkle_roots[i],
                 i,
@@ -705,7 +705,7 @@ impl ValidatorState {
         // Replacing old coin with the derived coin
         // TODO: do we need that? on next epoch we replace everything
         // how is this going to get reused?
-        self.consensus.coins[relative_slot][idx] = coin.derive_coin(eta, relative_slot as u64);
+        self.consensus.coins[relative_slot][idx] = coin.derive_coin();
 
         Ok(Some(BlockProposal::new(header, unproposed_txs, lead_info)))
     }
@@ -764,9 +764,11 @@ impl ValidatorState {
     /// it extends. If the proposal extends the canonical blockchain, a new fork chain is created.
     pub async fn receive_proposal(&mut self, proposal: &BlockProposal) -> Result<()> {
         let current = self.current_slot();
-
+        let coin_slot = &proposal.block.header.slot;
         let eta = self.consensus.epoch_eta;
-        let (mu_y, mu_rho) = LeadCoin::election_seeds(eta, pallas::Base::from(current));
+        info!("Consensus::receive_proposal(): current slot: {}", current);
+        info!("Consensus::receive_proposal(): proposed slot: {}", coin_slot);
+        let (mu_y, mu_rho) = LeadCoin::election_seeds_u64(eta, *coin_slot);
         // Node hasn't started participating
         match self.consensus.participating {
             Some(start) => {