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

consensus: removed douplicate sigmas generation on proposal

aggstam 3 лет назад
Родитель
Сommit
9f43a66011
2 измененных файлов с 10 добавлено и 7 удалено
  1. 8 4
      src/consensus/state.rs
  2. 2 3
      src/consensus/task/proposal.rs

+ 8 - 4
src/consensus/state.rs

@@ -599,7 +599,7 @@ impl ValidatorState {
     /// * `slot` - slot relative index
     /// * `epoch_coins` - stakeholder's epoch coins
     /// Returns: (check: bool, idx: usize) where idx is the winning coin's index
-    pub fn is_slot_leader(&mut self) -> (bool, usize) {
+    pub fn is_slot_leader(&mut self) -> (bool, usize, pallas::Base, pallas::Base) {
         // Slot relative index
         let slot = self.relative_slot(self.current_slot());
         let (sigma1, sigma2) = self.sigmas(slot, self.consensus.epoch);
@@ -628,15 +628,19 @@ impl ValidatorState {
             }
         }
 
-        (won, highest_stake_idx)
+        (won, highest_stake_idx, sigma1, sigma2)
     }
 
     /// Generate a block proposal for the current slot, containing all
     /// unconfirmed transactions. Proposal extends the longest fork
     /// chain the node is holding.
-    pub fn propose(&mut self, idx: usize) -> Result<Option<BlockProposal>> {
+    pub fn propose(
+        &mut self,
+        idx: usize,
+        sigma1: pallas::Base,
+        sigma2: pallas::Base,
+    ) -> Result<Option<BlockProposal>> {
         let slot = self.current_slot();
-        let (sigma1, sigma2) = self.sigmas(slot, self.consensus.epoch);
         let (prev_hash, index) = self.longest_chain_last_hash().unwrap();
         let unproposed_txs = self.unproposed_txs(index);
 

+ 2 - 3
src/consensus/task/proposal.rs

@@ -115,9 +115,8 @@ pub async fn proposal_task(consensus_p2p: P2pPtr, sync_p2p: P2pPtr, state: Valid
 
         // Node checks if it's the slot leader to generate a new proposal
         // for that slot.
-
-        let (won, idx) = state.write().await.is_slot_leader();
-        let result = if won { state.write().await.propose(idx) } else { Ok(None) };
+        let (won, idx, sigma1, sigma2) = state.write().await.is_slot_leader();
+        let result = if won { state.write().await.propose(idx, sigma1, sigma2) } else { Ok(None) };
         let proposal = match result {
             Ok(prop) => {
                 if prop.is_none() {