فهرست منبع

script/research/nodes-tool: use new src/consensus structs

aggstam 4 سال پیش
والد
کامیت
4589153852
2فایلهای تغییر یافته به همراه36 افزوده شده و 26 حذف شده
  1. 1 0
      script/research/nodes-tool/Cargo.toml
  2. 35 26
      script/research/nodes-tool/src/main.rs

+ 1 - 0
script/research/nodes-tool/Cargo.toml

@@ -9,6 +9,7 @@ features = ["blockchain"]
 
 
 [dependencies]
 [dependencies]
 
 
+async-std = "1.11.0"
 blake3 = "1.3.1"
 blake3 = "1.3.1"
 sled = "0.34.7"
 sled = "0.34.7"
 
 

+ 35 - 26
script/research/nodes-tool/src/main.rs

@@ -1,15 +1,21 @@
 use std::{fs::File, io::Write};
 use std::{fs::File, io::Write};
 
 
 use darkfi::{
 use darkfi::{
+    blockchain::{
+        Blockchain,
+        blockstore::{BlockOrderStore, BlockStore},
+        metadatastore::StreamletMetadataStore,
+        txstore::TxStore,
+    },
     consensus::{
     consensus::{
-        block::{Block, BlockOrderStore, BlockProposal, BlockStore},
-        blockchain::{Blockchain, ProposalsChain},
-        metadata::{Metadata, OuroborosMetadata, StreamletMetadata, StreamletMetadataStore},
+        block::{Block, BlockProposal, ProposalChain},
+        metadata::{Metadata, OuroborosMetadata, StreamletMetadata},
         participant::Participant,
         participant::Participant,
         state::{ConsensusState, ValidatorState},
         state::{ConsensusState, ValidatorState},
-        tx::{Tx, TxStore},
+        tx::Tx,
         util::Timestamp,
         util::Timestamp,
         vote::Vote,
         vote::Vote,
+        TESTNET_GENESIS_HASH_BYTES,
     },
     },
     util::expand_path,
     util::expand_path,
     Result,
     Result,
@@ -114,44 +120,44 @@ struct ProposalInfo {
 impl ProposalInfo {
 impl ProposalInfo {
     pub fn new(proposal: &BlockProposal) -> ProposalInfo {
     pub fn new(proposal: &BlockProposal) -> ProposalInfo {
         let _id = proposal.id;
         let _id = proposal.id;
-        let _st = proposal.st;
-        let _sl = proposal.sl;
-        let _txs = proposal.txs.clone();
-        let _metadata = MetadataInfo::new(&proposal.metadata);
-        let _sm = StreamletMetadataInfo::new(&proposal.sm);
+        let _st = proposal.block.st;
+        let _sl = proposal.block.sl;
+        let _txs = proposal.block.txs.clone();
+        let _metadata = MetadataInfo::new(&proposal.block.metadata);
+        let _sm = StreamletMetadataInfo::new(&proposal.block.sm);
         ProposalInfo { _id, _st, _sl, _txs, _metadata, _sm }
         ProposalInfo { _id, _st, _sl, _txs, _metadata, _sm }
     }
     }
 }
 }
 
 
 #[derive(Debug)]
 #[derive(Debug)]
-struct ProposalsInfoChain {
+struct ProposalInfoChain {
     _proposals: Vec<ProposalInfo>,
     _proposals: Vec<ProposalInfo>,
 }
 }
 
 
-impl ProposalsInfoChain {
-    pub fn new(proposals: &ProposalsChain) -> ProposalsInfoChain {
+impl ProposalInfoChain {
+    pub fn new(proposals: &ProposalChain) -> ProposalInfoChain {
         let mut _proposals = Vec::new();
         let mut _proposals = Vec::new();
         for proposal in &proposals.proposals {
         for proposal in &proposals.proposals {
             _proposals.push(ProposalInfo::new(&proposal));
             _proposals.push(ProposalInfo::new(&proposal));
         }
         }
-        ProposalsInfoChain { _proposals }
+        ProposalInfoChain { _proposals }
     }
     }
 }
 }
 
 
 #[derive(Debug)]
 #[derive(Debug)]
 struct ConsensusInfo {
 struct ConsensusInfo {
-    _genesis: Timestamp,
-    _proposals: Vec<ProposalsInfoChain>,
+    _genesis_ts: Timestamp,
+    _proposals: Vec<ProposalInfoChain>,
 }
 }
 
 
 impl ConsensusInfo {
 impl ConsensusInfo {
     pub fn new(consensus: &ConsensusState) -> ConsensusInfo {
     pub fn new(consensus: &ConsensusState) -> ConsensusInfo {
-        let _genesis = consensus.genesis.clone();
+        let _genesis_ts = consensus.genesis_ts.clone();
         let mut _proposals = Vec::new();
         let mut _proposals = Vec::new();
         for proposal in &consensus.proposals {
         for proposal in &consensus.proposals {
-            _proposals.push(ProposalsInfoChain::new(&proposal));
+            _proposals.push(ProposalInfoChain::new(&proposal));
         }
         }
-        ConsensusInfo { _genesis, _proposals }
+        ConsensusInfo { _genesis_ts, _proposals }
     }
     }
 }
 }
 
 
@@ -237,12 +243,12 @@ impl BlockOrderStoreInfo {
 #[derive(Debug)]
 #[derive(Debug)]
 struct TxInfo {
 struct TxInfo {
     _hash: blake3::Hash,
     _hash: blake3::Hash,
-    _payload: String,
+    _payload: Tx,
 }
 }
 
 
 impl TxInfo {
 impl TxInfo {
     pub fn new(_hash: blake3::Hash, tx: &Tx) -> TxInfo {
     pub fn new(_hash: blake3::Hash, tx: &Tx) -> TxInfo {
-        let _payload = tx.payload.clone();
+        let _payload = tx.clone();
         TxInfo { _hash, _payload }
         TxInfo { _hash, _payload }
     }
     }
 }
 }
@@ -344,15 +350,18 @@ impl StateInfo {
     }
     }
 }
 }
 
 
-fn main() -> Result<()> {
+#[async_std::main]
+async fn main() -> Result<()> {
     let nodes = 4;
     let nodes = 4;
-    let genesis = 1648383795;
+    let genesis_ts = Timestamp(1648383795);
+    let genesis_data = *TESTNET_GENESIS_HASH_BYTES;
     for i in 0..nodes {
     for i in 0..nodes {
         let path = format!("~/.config/darkfi/validatord_db_{:?}", i);
         let path = format!("~/.config/darkfi/validatord_db_{:?}", i);
-        let database_path = expand_path(&path).unwrap();
-        println!("Export data from sled database: {:?}", database_path);
-        let state = ValidatorState::new(database_path, i, genesis).unwrap();
-        let info = StateInfo::new(&*state.read().unwrap());
+        let db_path = expand_path(&path).unwrap();
+        let sled_db = sled::open(&db_path)?;
+        println!("Export data from sled database: {:?}", db_path);
+        let state = ValidatorState::new(&sled_db, i, genesis_ts, genesis_data)?;
+        let info = StateInfo::new(&*state.read().await);
         let info_string = format!("{:#?}", info);
         let info_string = format!("{:#?}", info);
         let path = format!("validatord_state_{:?}", i);
         let path = format!("validatord_state_{:?}", i);
         let mut file = File::create(path)?;
         let mut file = File::create(path)?;