瀏覽代碼

[crypsinous]organize epoch consensus

mohab metwally 3 年之前
父節點
當前提交
964e2dce48
共有 6 個文件被更改,包括 64 次插入54 次删除
  1. 4 0
      db/conf
  2. 二進制
      db/db
  3. 1 1
      example/lead.rs
  4. 2 52
      src/stakeholder/epoch.rs
  5. 51 0
      src/stakeholder/epochconsensus.rs
  6. 6 1
      src/stakeholder/mod.rs

+ 4 - 0
db/conf

@@ -0,0 +1,4 @@
+segment_size: 524288
+use_compression: false
+version: 0.34
+vQÁ

二進制
db/db


+ 1 - 1
example/lead.rs

@@ -7,7 +7,7 @@ use url::Url;
 use darkfi::{
     crypto::leadcoin::{LeadCoin, LEAD_PUBLIC_INPUT_LEN},
     net::Settings,
-    stakeholder::{Stakeholder, epoch::{Epoch, {EpochConsensus}}},
+    stakeholder::{Stakeholder, Epoch, EpochConsensus},
 };
 
 

+ 2 - 52
src/stakeholder/epoch.rs

@@ -24,6 +24,8 @@ use crate::crypto::{
     util::{mod_r_p, pedersen_commitment_base, pedersen_commitment_u64},
 
 };
+
+use crate::stakeholder::EpochConsensus;
 use crate::stakeholder::utils::{fbig2ibig, base2ibig};
 use crate::stakeholder::Float10;
 use crate::stakeholder::consts::{RADIX_BITS};
@@ -33,58 +35,6 @@ const PRF_NULLIFIER_PREFIX: u64 = 0;
 const MERKLE_DEPTH: u8 = MERKLE_DEPTH_ORCHARD as u8;
 
 
-/// epoch configuration
-/// this struct need be a singleton,
-/// TODO should be populated from configuration file.
-#[derive(Copy, Debug, Default, Clone)]
-pub struct EpochConsensus {
-    pub sl_len: u64, // length of slot in terms of ticks
-    // number of slots per epoch
-    pub e_len: u64, // length of epoch in terms of slots
-    pub tick_len: u64, // length of tick in terms of seconds
-    pub reward: u64, // constant reward value for the slot leader
-}
-
-impl EpochConsensus {
-    pub fn new(
-        sl_len: Option<u64>,
-        e_len: Option<u64>,
-        tick_len: Option<u64>,
-        reward: Option<u64>,
-    ) -> Self {
-        Self {
-            sl_len: sl_len.unwrap_or(22),
-            e_len: e_len.unwrap_or(3),
-            tick_len: tick_len.unwrap_or(22),
-            reward: reward.unwrap_or(1),
-        }
-    }
-
-    pub fn total_stake(&self, e: u64, sl: u64) -> u64 {
-        (e*self.e_len +  sl+ 1) * self.reward
-    }
-    /// getter for constant stakeholder reward
-    /// used for configuring the stakeholder reward value
-    pub fn get_reward(&self) -> u64 {
-        self.reward
-    }
-
-    /// getter for the slot length in terms of ticks
-    pub fn get_slot_len(&self) -> u64 {
-        self.sl_len
-    }
-
-    /// getter for the epoch length in terms of slots
-    pub fn get_epoch_len(&self) -> u64 {
-        self.e_len
-    }
-
-    /// getter for the ticks length in terms of seconds
-    pub fn get_tick_len(&self) -> u64 {
-        self.tick_len
-    }
-}
-
 #[derive(Debug, Default, Clone)]
 pub struct Epoch {
     pub consensus: EpochConsensus,

+ 51 - 0
src/stakeholder/epochconsensus.rs

@@ -0,0 +1,51 @@
+/// epoch configuration
+/// this struct need be a singleton,
+/// TODO should be populated from configuration file.
+#[derive(Copy, Debug, Default, Clone)]
+pub struct EpochConsensus {
+    pub sl_len: u64, // length of slot in terms of ticks
+    // number of slots per epoch
+    pub e_len: u64, // length of epoch in terms of slots
+    pub tick_len: u64, // length of tick in terms of seconds
+    pub reward: u64, // constant reward value for the slot leader
+}
+
+impl EpochConsensus {
+    pub fn new(
+        sl_len: Option<u64>,
+        e_len: Option<u64>,
+        tick_len: Option<u64>,
+        reward: Option<u64>,
+    ) -> Self {
+        Self {
+            sl_len: sl_len.unwrap_or(22),
+            e_len: e_len.unwrap_or(3),
+            tick_len: tick_len.unwrap_or(22),
+            reward: reward.unwrap_or(1),
+        }
+    }
+
+    pub fn total_stake(&self, e: u64, sl: u64) -> u64 {
+        (e*self.e_len +  sl+ 1) * self.reward
+    }
+    /// getter for constant stakeholder reward
+    /// used for configuring the stakeholder reward value
+    pub fn get_reward(&self) -> u64 {
+        self.reward
+    }
+
+    /// getter for the slot length in terms of ticks
+    pub fn get_slot_len(&self) -> u64 {
+        self.sl_len
+    }
+
+    /// getter for the epoch length in terms of slots
+    pub fn get_epoch_len(&self) -> u64 {
+        self.e_len
+    }
+
+    /// getter for the ticks length in terms of seconds
+    pub fn get_tick_len(&self) -> u64 {
+        self.tick_len
+    }
+}

+ 6 - 1
src/stakeholder/mod.rs

@@ -54,8 +54,13 @@ use pasta_curves::pallas;
 
 use group::ff::PrimeField;
 
+
+pub mod epochconsensus;
+pub use epochconsensus::EpochConsensus;
+
+
 pub mod epoch;
-pub use epoch::{Epoch, EpochConsensus};
+pub use epoch::Epoch;
 
 pub(crate) mod workspace;
 pub(crate) use workspace::SlotWorkspace;