Explorar el Código

src/validator: get TimeKeeper from upstream

aggstam hace 3 años
padre
commit
a980612ce8
Se han modificado 2 ficheros con 9 adiciones y 14 borrados
  1. 2 7
      src/validator/consensus/consensus.rs
  2. 7 7
      src/validator/validator.rs

+ 2 - 7
src/validator/consensus/consensus.rs

@@ -16,11 +16,7 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-use crate::{
-    blockchain::Blockchain,
-    consensus::constants::{EPOCH_LENGTH, SLOT_TIME},
-    util::time::{TimeKeeper, Timestamp},
-};
+use crate::{blockchain::Blockchain, util::time::TimeKeeper};
 
 /// This struct represents the information required by the consensus algorithm
 pub struct Consensus {
@@ -31,8 +27,7 @@ pub struct Consensus {
 }
 
 impl Consensus {
-    pub fn new(blockchain: Blockchain, genesis_ts: Timestamp) -> Self {
-        let time_keeper = TimeKeeper::new(genesis_ts, EPOCH_LENGTH as u64, SLOT_TIME, 0);
+    pub fn new(blockchain: Blockchain, time_keeper: TimeKeeper) -> Self {
         Self { blockchain, time_keeper }
     }
 }

+ 7 - 7
src/validator/validator.rs

@@ -24,7 +24,7 @@ use log::info;
 use crate::{
     blockchain::{Blockchain, BlockchainOverlay},
     runtime::vm_runtime::Runtime,
-    util::time::Timestamp,
+    util::time::TimeKeeper,
     Result,
 };
 
@@ -43,10 +43,10 @@ pub struct Validator {
 
 /// Configuration for initializing [`Validator`]
 pub struct ValidatorConfig {
-    /// Genesis timestamp
-    pub genesis_ts: Timestamp,
-    /// Genesis data
-    pub genesis_data: blake3::Hash,
+    /// Helper structure to calculate time related operations
+    pub time_keeper: TimeKeeper,
+    /// Genesis block
+    pub genesis_block: blake3::Hash,
     /// Whitelisted faucet pubkeys (testnet stuff)
     pub faucet_pubkeys: Vec<PublicKey>,
 }
@@ -58,10 +58,10 @@ impl Validator {
         info!(target: "consensus::validator", "Initializing Blockchain");
         // TODO: Initialize chain, then check if its empty, so we can execute
         // the transactions of the genesis block
-        let blockchain = Blockchain::new(db, config.genesis_ts, config.genesis_data)?;
+        let blockchain = Blockchain::new(db, config.time_keeper.genesis_ts, config.genesis_block)?;
 
         info!(target: "consensus::validator", "Initializing Consensus");
-        let consensus = Consensus::new(blockchain.clone(), config.genesis_ts);
+        let consensus = Consensus::new(blockchain.clone(), config.time_keeper);
 
         // =====================
         // NATIVE WASM CONTRACTS