Sfoglia il codice sorgente

consensus: verify proposer eligibility via coin age

aggstam 3 anni fa
parent
commit
f2da17ea1e
3 ha cambiato i file con 22 aggiunte e 4 eliminazioni
  1. 4 2
      src/consensus/task/proposal.rs
  2. 12 0
      src/consensus/validator.rs
  3. 6 2
      src/error.rs

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

@@ -100,8 +100,10 @@ async fn consensus_loop(
     // Note: when a node can start produce proposals is only enforced in code,
     // Note: when a node can start produce proposals is only enforced in code,
     // where we verify if the hardware can keep up with the consensus, by
     // where we verify if the hardware can keep up with the consensus, by
     // counting how many consecutive slots node successfully listened and process
     // counting how many consecutive slots node successfully listened and process
-    // everything. Later, this will be enforced via contract, where it will be explicit
-    // when a node can produce proposals, and after which slot they can be considered as valid.
+    // everything. Aditionally, we check each proposer coin creation slot to be
+    // greater than an epoch length. Later, this will be enforced via contract,
+    // where it will be explicit when a node can produce proposals,
+    // and after which slot they can be considered as valid.
     let mut listened_slots = 0;
     let mut listened_slots = 0;
     let mut changed_status = false;
     let mut changed_status = false;
     loop {
     loop {

+ 12 - 0
src/consensus/validator.rs

@@ -379,6 +379,18 @@ impl ValidatorState {
             return Err(Error::ProposalNotForCurrentSlotError)
             return Err(Error::ProposalNotForCurrentSlotError)
         }
         }
 
 
+        // Verify that proposer can produce proposals.
+        // NOTE: Later, this will be enforced via contract, where it will be explicit
+        // when a node can produce proposals, and after which slot they can be considered as valid.
+        let elapsed_slots = current - lf.coin_slot;
+        if elapsed_slots <= (constants::EPOCH_LENGTH as u64) {
+            warn!(
+                "receive_proposal(): Proposer {} is not eligible to produce proposals",
+                lf.public_key
+            );
+            return Err(Error::ProposalProposerNotEligible)
+        }
+
         // Check if proposal extends any existing fork chains
         // Check if proposal extends any existing fork chains
         let index = self.consensus.find_extended_chain_index(proposal)?;
         let index = self.consensus.find_extended_chain_index(proposal)?;
         if index == -2 {
         if index == -2 {

+ 6 - 2
src/error.rs

@@ -262,11 +262,15 @@ pub enum Error {
     #[error("Proposal contains more transactions than configured cap")]
     #[error("Proposal contains more transactions than configured cap")]
     ProposalTxsExceedCapError,
     ProposalTxsExceedCapError,
 
 
-    #[error("unable to verify transfer transaction")]
+    #[error("Unable to verify transfer transaction")]
     TransferTxVerification,
     TransferTxVerification,
 
 
-    #[error("unable to verify proposed mu values")]
+    #[error("Unable to verify proposed mu values")]
     ProposalPublicValuesMismatched,
     ProposalPublicValuesMismatched,
+
+    #[error("Proposer is not eligible to produce proposals")]
+    ProposalProposerNotEligible,
+
     // ===============
     // ===============
     // Database errors
     // Database errors
     // ===============
     // ===============