Răsfoiți Sursa

util/time/TimeKeeper: changed slot epoch calculation(increment by 1)

aggstam 3 ani în urmă
părinte
comite
9054780c28
2 a modificat fișierele cu 12 adăugiri și 4 ștergeri
  1. 2 2
      src/contract/consensus/tests/stake_unstake.rs
  2. 10 2
      src/util/time.rs

+ 2 - 2
src/contract/consensus/tests/stake_unstake.rs

@@ -42,7 +42,7 @@ async fn consensus_contract_stake_unstake() -> Result<()> {
     const ALICE_AIRDROP: u64 = 1000;
 
     // Slot to verify against
-    let mut current_slot = 11;
+    let mut current_slot = 1;
     let mut current_epoch = 1;
 
     // Initialize harness
@@ -105,7 +105,7 @@ async fn consensus_contract_stake_unstake() -> Result<()> {
     info!(target: "consensus", "[Alice] ====================");
     info!(target: "consensus", "[Alice] Building proposal tx");
     info!(target: "consensus", "[Alice] ====================");
-    let (proposal_tx, proposal_params, proposal_secret_key) =
+    let (proposal_tx, _, _) =
         th.proposal(Holder::Alice, slot_checkpoint, alice_staked_oc.clone())?;
 
     info!(target: "consensus", "[Malicious] =====================================");

+ 10 - 2
src/util/time.rs

@@ -55,9 +55,17 @@ impl TimeKeeper {
         self.slot_epoch(self.current_slot())
     }
 
-    /// Calculates the epoch of the provided slot.    
+    /// Calculates the epoch of the provided slot.
+    /// Only slot 0 exists in epoch 0, everything
+    /// else is incremented by one. This practically
+    /// means that epoch 0 has 1 slot(the genesis slot),
+    /// epoch 1 has one less slot(the genesis slot) and
+    /// rest epoch have the normal amount of slots.
     pub fn slot_epoch(&self, slot: u64) -> u64 {
-        slot / self.epoch_length
+        if slot == 0 {
+            return 0
+        }
+        (slot / self.epoch_length) + 1
     }
 
     /// Calculates current slot, based on elapsed time from the genesis block.