diff --git a/lib/core/conf/src/lib.rs b/lib/core/conf/src/lib.rs index 9141d2184b5ef1b33c0a19297d137fb027651457..eb214d9952cbcd7c2a92fcd58aa33e6e219a0c3e 100644 --- a/lib/core/conf/src/lib.rs +++ b/lib/core/conf/src/lib.rs @@ -456,7 +456,7 @@ pub fn get_datas_path(profile_path: PathBuf) -> PathBuf { if !datas_path.as_path().exists() { if let Err(io_error) = fs::create_dir(datas_path.as_path()) { if io_error.kind() != std::io::ErrorKind::AlreadyExists { - fatal_error!("Impossible to create currency dir !"); + fatal_error!("Impossible to create modules datas folder !"); } } } diff --git a/lib/core/message/src/events.rs b/lib/core/message/src/events.rs index 88385edfd55dac3bd49a07db705e6dedb45a407a..ea1675b1fe9884edcab112fcdc9a742c524f631c 100644 --- a/lib/core/message/src/events.rs +++ b/lib/core/message/src/events.rs @@ -20,7 +20,7 @@ use dubp_user_docs::documents::UserDocumentDUBP; use durs_network::events::NetworkEvent; /// The DURS event message. -#[derive(Debug, Clone)] +#[derive(Clone, Debug, PartialEq)] pub enum DursEvent { /// Arbitrary datas. ArbitraryDatas(ArbitraryDatas), @@ -34,7 +34,7 @@ pub enum DursEvent { ReceiveValidDocsFromClient(Vec<UserDocumentDUBP>), } -#[derive(Debug, Clone)] +#[derive(Clone, Debug, PartialEq)] /// MemPool module events pub enum MemPoolEvent { /// FindNextBlock (local node find next block) @@ -43,7 +43,7 @@ pub enum MemPoolEvent { StoreNewDocInPool(Box<UserDocumentDUBP>), } -#[derive(Debug, Clone)] +#[derive(Clone, Debug, PartialEq)] /// Blockchain module events pub enum BlockchainEvent { /// Currency parameters diff --git a/lib/core/message/src/lib.rs b/lib/core/message/src/lib.rs index 35340e3af1ba8aac517edd5b7b9f69260cd34d02..2106ca6383f307d49d832ee16e2f050792971896 100644 --- a/lib/core/message/src/lib.rs +++ b/lib/core/message/src/lib.rs @@ -45,7 +45,7 @@ use crate::requests::*; use crate::responses::*; /// Message exchanged between Dunitrust modules -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub enum DursMsg { /// Dunitrust module event Event { @@ -89,7 +89,7 @@ pub enum DursMsg { impl ModuleMessage for DursMsg {} /// Arbitrary datas -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub enum ArbitraryDatas { /// Arbitrary text message Text(String), diff --git a/lib/core/message/src/requests.rs b/lib/core/message/src/requests.rs index c598dc39361e6fd301bf3f1a0c984b40ebd47391..13cbf098ae205ea696cddbcb14194255ca95f2e8 100644 --- a/lib/core/message/src/requests.rs +++ b/lib/core/message/src/requests.rs @@ -19,7 +19,7 @@ use dup_crypto::hashs::Hash; use dup_crypto::keys::*; use durs_network::requests::OldNetworkRequest; -#[derive(Debug, Clone)] +#[derive(Clone, Debug, PartialEq)] /// Modules request content pub enum DursReqContent { /// Request to the old network module @@ -59,7 +59,7 @@ pub enum BlockchainRequest { UIDs(Vec<PubKey>), } -#[derive(Debug, Copy, Clone)] +#[derive(Copy, Clone, Debug, PartialEq)] /// Inter-module request for mem pool data pub enum MemPoolRequest { /// All pending identities with their pending certifications diff --git a/lib/core/message/src/responses.rs b/lib/core/message/src/responses.rs index ee7dfbde9b964162df5c0937fdeabd3526b79125..ffd44eb1b7bf5209d7e0cc5d459dec881ac6600f 100644 --- a/lib/core/message/src/responses.rs +++ b/lib/core/message/src/responses.rs @@ -27,7 +27,7 @@ use durs_network::requests::NetworkResponse; use std::collections::HashMap; /// Dunitrust request response message -#[derive(Debug, Clone)] +#[derive(Clone, Debug, PartialEq)] pub enum DursResContent { /// BlockchainResponse BlockchainResponse(BlockchainResponse), @@ -39,7 +39,7 @@ pub enum DursResContent { ProverResponse(BlockNumber, Sig, u64), } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] /// Pending identity datas pub struct PendingIdtyDatas { /// Identity document @@ -54,7 +54,7 @@ pub struct PendingIdtyDatas { pub revocation: Option<RevocationDocumentV10>, } -#[derive(Debug, Clone)] +#[derive(Clone, Debug, PartialEq)] /// Response to a BlockchainReqBlockchain request pub enum BlockchainResponse { /// Current blockstamp @@ -71,7 +71,7 @@ pub enum BlockchainResponse { Identities(Vec<IdentityDocument>), } -#[derive(Debug, Clone)] +#[derive(Clone, Debug, PartialEq)] /// Response to a MemPoolRequest request pub enum MemPoolResponse { /// All pending identities with their pending certifications diff --git a/lib/core/module/src/lib.rs b/lib/core/module/src/lib.rs index 2d10c83f3c2c1ea789644cfea61848ebff7dc6e5..9460a625587fd30e2ed5d264a5a7512444c4cec0 100644 --- a/lib/core/module/src/lib.rs +++ b/lib/core/module/src/lib.rs @@ -164,7 +164,7 @@ pub struct SoftwareMetaDatas<DC: DursConfTrait> { /// The different modules of Duniter-rs can exchange messages with the type of their choice, /// provided that this type implements the ModuleMessage trait. -pub trait ModuleMessage: Clone + Debug {} +pub trait ModuleMessage: Clone + Debug + PartialEq {} /// List of the different roles that can be assigned to a module. /// This role list allows a module to send a message to all modules playing a specific role without knowing their name. @@ -227,7 +227,7 @@ pub enum ModuleEvent { SyncEvent, } -#[derive(Debug, Clone)] +#[derive(Clone, Debug)] /// Type sent by each module to the router during initialization pub enum RouterThreadMessage<M: ModuleMessage> { /// Number of expected modules diff --git a/lib/core/network/events.rs b/lib/core/network/events.rs index 12df524923965a5ae34c0d7a854ada87966201bb..cf3a07957b8eaf9b130d66ff99adfab5bccef3a3 100644 --- a/lib/core/network/events.rs +++ b/lib/core/network/events.rs @@ -23,7 +23,7 @@ use dubp_common_doc::blockstamp::Blockstamp; use dubp_user_docs::documents::UserDocumentDUBP; use durs_common_tools::Percent; -#[derive(Debug, Clone)] +#[derive(Clone, Debug, PartialEq)] /// Type containing a network event, each time a network event occurs it's relayed to all modules pub enum NetworkEvent { /// A connection has changed state(`u32` is the new state, `Option<String>` est l'uid du noeud) diff --git a/lib/core/network/requests.rs b/lib/core/network/requests.rs index ac7b1c878dfb941a75496cfe54e2eaeb1d850be3..d880afbe4e2085300b021edbd6ee23de1abeec5e 100644 --- a/lib/core/network/requests.rs +++ b/lib/core/network/requests.rs @@ -20,7 +20,7 @@ use dubp_block_doc::BlockDocument; use dubp_common_doc::blockstamp::Blockstamp; use dubp_user_docs::documents::UserDocumentDUBP; -#[derive(Debug, Copy, Clone)] +#[derive(Clone, Copy, Debug, Eq, PartialEq)] /// Type containing a request addressed to the network module pub enum OldNetworkRequest { /// Get a current block of a specific node @@ -69,7 +69,7 @@ pub enum OldNetworkRequestError { ReceiverUnreachable(), } -#[derive(Debug, Clone)] +#[derive(Clone, Debug, PartialEq)] /// Type containing the response to a network request pub enum NetworkResponse { /// CurrentBlock diff --git a/lib/dubp/currency-params/src/lib.rs b/lib/dubp/currency-params/src/lib.rs index 1eeb05b0692d6f429a1e7cf3ae0dbfa3ec7abdd9..dc5cceef6e0b497c944a1c6ca060900fdefb78e4 100644 --- a/lib/dubp/currency-params/src/lib.rs +++ b/lib/dubp/currency-params/src/lib.rs @@ -34,7 +34,7 @@ use crate::constants::*; pub use dubp_common_doc::CurrencyName; use genesis_block_params::v10::BlockV10Parameters; -#[derive(Debug, Copy, Clone)] +#[derive(Copy, Clone, Debug, PartialEq)] /// Currency parameters pub struct CurrencyParameters { /// Protocol version diff --git a/lib/dubp/user-docs/src/documents/mod.rs b/lib/dubp/user-docs/src/documents/mod.rs index ac5cb1a2258bdc83a01c00fff1e2339b23c9a4bc..d502e94877e843136439451eabd3073b470cd556 100644 --- a/lib/dubp/user-docs/src/documents/mod.rs +++ b/lib/dubp/user-docs/src/documents/mod.rs @@ -33,7 +33,7 @@ pub mod revocation; pub mod transaction; /// User document of DUBP (DUniter Blockhain Protocol) -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub enum UserDocumentDUBP { /// Transaction document. Transaction(Box<TransactionDocument>), diff --git a/lib/dubp/user-docs/src/documents/transaction.rs b/lib/dubp/user-docs/src/documents/transaction.rs index 923550d7a6392269cb8b77d0c3f69ed6b8638502..015bb6969fef52ed598d2bd160462d929bd25a6f 100644 --- a/lib/dubp/user-docs/src/documents/transaction.rs +++ b/lib/dubp/user-docs/src/documents/transaction.rs @@ -628,7 +628,7 @@ impl TransactionDocument { hash } else { self.hash = Some(self.compute_hash()); - self.hash.expect("Try to get hash of a reduce tx !") + self.hash.expect("unreach") } } /// Get transaction inputs @@ -642,6 +642,7 @@ impl TransactionDocument { /// Lightens the transaction (for example to store it while minimizing the space required) /// WARNING: do not remove the hash as it's necessary to reverse the transaction ! pub fn reduce(&mut self) { + self.hash = Some(self.compute_hash()); self.text = None; for output in &mut self.outputs { output.reduce() @@ -799,7 +800,7 @@ impl TextDocument for TransactionDocument { if let Some(ref text) = self.text { text } else { - fatal_error!("Try to get text of tx whti None text !") + fatal_error!("Try to get text of tx with None text !") } } diff --git a/lib/dunp/network-documents/src/network_endpoint.rs b/lib/dunp/network-documents/src/network_endpoint.rs index bb67e5f4f831564026222398e56f4452a3f75e57..767f0122b0d820e55726f90613a2ebed2c205dbd 100644 --- a/lib/dunp/network-documents/src/network_endpoint.rs +++ b/lib/dunp/network-documents/src/network_endpoint.rs @@ -71,7 +71,7 @@ pub struct ApiName(pub String); pub struct ApiVersion(pub usize); /// Api parts -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] pub struct ApiPart { pub name: ApiName, pub versions: HashSet<ApiVersion>, diff --git a/lib/modules-lib/bc-db-reader/src/blocks.rs b/lib/modules-lib/bc-db-reader/src/blocks.rs index f5d62ad4efad79be3f7194f25ef6487cf1772e40..3281d0f18822c2d8991f1ad0bb00eeb19e62dc06 100644 --- a/lib/modules-lib/bc-db-reader/src/blocks.rs +++ b/lib/modules-lib/bc-db-reader/src/blocks.rs @@ -100,7 +100,7 @@ pub fn get_block<DB: DbReadable, R: DbReader>( r: &R, blockstamp: Blockstamp, ) -> Result<Option<DbBlock>, DbError> { - let opt_dal_block = get_dal_block_in_local_blockchain(db, r, blockstamp.id)?; + let opt_dal_block = get_db_block_in_local_blockchain(db, r, blockstamp.id)?; if opt_dal_block.is_none() { get_fork_block(db, r, blockstamp) } else { @@ -184,6 +184,7 @@ pub fn get_blocks_in_local_blockchain<DB: DbReadable, R: DbReader>( } /// Get several blocks in local blockchain by their number +#[cfg(feature = "client-indexer")] pub fn get_blocks_in_local_blockchain_by_numbers<DB: DbReadable, R: DbReader>( db: &DB, r: &R, diff --git a/lib/modules-lib/bc-db-reader/src/trait.rs b/lib/modules-lib/bc-db-reader/src/trait.rs index 96e4b88ee56ebec8dd63bf8edf468d1ebaae153a..eba22403aa956c3c2b5632c4f541fa6b0c24552c 100644 --- a/lib/modules-lib/bc-db-reader/src/trait.rs +++ b/lib/modules-lib/bc-db-reader/src/trait.rs @@ -65,6 +65,7 @@ impl<'r, 'db: 'r> BcDbRoTrait for BcDbRoWithReader<'r, 'db> { ) -> Result<Option<DbBlock>, DbError> { crate::blocks::get_db_block_in_local_blockchain(self.db, self.r, block_number) } + #[cfg(feature = "client-indexer")] fn get_db_blocks_in_local_blockchain( &self, numbers: Vec<BlockNumber>, diff --git a/lib/modules/blockchain/bc-db-writer/src/blocks/fork_tree.rs b/lib/modules/blockchain/bc-db-writer/src/blocks/fork_tree.rs index 174eb82285016341216953ee71f1d186ce19bd19..8f3bae818336b79970dfa79829e43ca168c31e45 100644 --- a/lib/modules/blockchain/bc-db-writer/src/blocks/fork_tree.rs +++ b/lib/modules/blockchain/bc-db-writer/src/blocks/fork_tree.rs @@ -56,6 +56,11 @@ pub fn insert_new_fork_block( blockstamp: Blockstamp, previous_hash: Hash, ) -> Result<bool, DbError> { + trace!( + "insert_new_fork_block #{} (previous_hash={})", + blockstamp, + previous_hash + ); let previous_blockstamp = Blockstamp { id: BlockNumber(blockstamp.id.0 - 1), hash: BlockHash(previous_hash), diff --git a/lib/modules/blockchain/bc-db-writer/src/writers/requests.rs b/lib/modules/blockchain/bc-db-writer/src/writers/requests.rs index 045dac7777a40e71a8a076e98c012437df0f4895..07865a248a6b86417c7ee8bf0d58fd043ae38434 100644 --- a/lib/modules/blockchain/bc-db-writer/src/writers/requests.rs +++ b/lib/modules/blockchain/bc-db-writer/src/writers/requests.rs @@ -64,22 +64,22 @@ impl BlocksDBsWriteQuery { sync_target: Option<Blockstamp>, ) -> Result<(), DbError> { match self { - BlocksDBsWriteQuery::WriteBlock(dal_block) => { - let dal_block: DbBlock = dal_block; + BlocksDBsWriteQuery::WriteBlock(mut block_db) => { trace!("BlocksDBsWriteQuery::WriteBlock..."); - crate::current_meta_datas::update_current_meta_datas(db, w, &dal_block.block)?; + block_db.block.reduce(); + crate::current_meta_datas::update_current_meta_datas(db, w, &block_db.block)?; if sync_target.is_none() - || dal_block.blockstamp().id.0 + fork_window_size as u32 + || block_db.blockstamp().id.0 + fork_window_size as u32 >= sync_target.expect("safe unwrap").id.0 { - crate::blocks::insert_new_head_block(db, w, Some(fork_tree), dal_block)?; + crate::blocks::insert_new_head_block(db, w, Some(fork_tree), block_db)?; } else { - crate::blocks::insert_new_head_block(db, w, None, dal_block)?; + crate::blocks::insert_new_head_block(db, w, None, block_db)?; } } - BlocksDBsWriteQuery::RevertBlock(dal_block) => { + BlocksDBsWriteQuery::RevertBlock(block_db) => { trace!("BlocksDBsWriteQuery::WriteBlock..."); - crate::blocks::remove_block(db, w, dal_block.block.number())?; + crate::blocks::remove_block(db, w, block_db.block.number())?; trace!("BlocksDBsWriteQuery::WriteBlock...finish"); } } diff --git a/lib/modules/blockchain/blockchain/Cargo.toml b/lib/modules/blockchain/blockchain/Cargo.toml index 77c33b6bf37cf388550fcce007246f18f25bf368..dd0a21d593afe7f195b462afeac4a742a41e7b48 100644 --- a/lib/modules/blockchain/blockchain/Cargo.toml +++ b/lib/modules/blockchain/blockchain/Cargo.toml @@ -41,4 +41,6 @@ unwrap = "1.2.1" dup-crypto-tests-tools = { path = "../../../tests-tools/crypto-tests-tools" } dubp-user-docs-tests-tools = { path = "../../../tests-tools/user-docs-tests-tools" } dubp-blocks-tests-tools = { path = "../../../tests-tools/blocks-tests-tools" } +durs-common-tests-tools = { path = "../../../tests-tools/common-tests-tools" } +pretty_assertions = "0.5.1" tempfile = "3.1.0" diff --git a/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs b/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs index dd5f853bea365c960169f66d478d2addf82bd7b0..2aee3b68bac247b77c1bd0a4114e7a22300fe1a7 100644 --- a/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs +++ b/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs @@ -15,7 +15,7 @@ //! Sub-module that applies the content of a block to the indexes of the local blockchain. -use dubp_block_doc::block::{BlockDocument, BlockDocumentTrait, BlockDocumentV10}; +use dubp_block_doc::block::{BlockDocument, BlockDocumentV10}; use dubp_common_doc::traits::Document; use dubp_common_doc::BlockNumber; use dubp_user_docs::documents::transaction::{TxAmount, TxBase}; @@ -65,7 +65,7 @@ pub fn apply_valid_block<W: WebOfTrust>( pub fn apply_valid_block_v10<W: WebOfTrust>( db: &Db, w: &mut DbWriter, - mut block: BlockDocumentV10, + block: BlockDocumentV10, wot_index: &mut HashMap<PubKey, WotId>, wot_db: &BinFreeStructDb<W>, expire_certs: &HashMap<(WotId, WotId), BlockNumber>, @@ -282,14 +282,13 @@ pub fn apply_valid_block_v10<W: WebOfTrust>( ); }*/ // Create DbBlock - block.reduce(); - let dal_block = DbBlock { + let block_db = DbBlock { block: BlockDocument::V10(block), expire_certs: Some(expire_certs.clone()), }; // Return DBs requests Ok(ValidBlockApplyReqs( - BlocksDBsWriteQuery::WriteBlock(dal_block), + BlocksDBsWriteQuery::WriteBlock(block_db), wot_dbs_requests, currency_dbs_requests, )) diff --git a/lib/modules/blockchain/blockchain/src/lib.rs b/lib/modules/blockchain/blockchain/src/lib.rs index 812f15d00c12ae3ac418de1237af89a476f6724d..3c6137f3ad2315ef11c8eed371fff8ab16c7ab79 100644 --- a/lib/modules/blockchain/blockchain/src/lib.rs +++ b/lib/modules/blockchain/blockchain/src/lib.rs @@ -170,6 +170,44 @@ pub enum SyncVerificationLevel { } impl BlockchainModule { + /// Instantiate blockchain module + pub fn new( + router_sender: Sender<RouterThreadMessage<DursMsg>>, + profile_path: PathBuf, + currency_name: Option<CurrencyName>, + currency_params: Option<CurrencyParameters>, + db: Db, + wot_databases: WotsV10DBs, + ) -> Result<BlockchainModule, DbError> { + // Get current blockstamp + let current_blockstamp = + durs_bc_db_reader::current_meta_datas::get_current_blockstamp(&db)?.unwrap_or_default(); + + // Get fork tree + let fork_tree = durs_bc_db_reader::current_meta_datas::get_fork_tree(&db)?; + + // Get wot index + let wot_index: HashMap<PubKey, WotId> = + durs_bc_db_reader::indexes::identities::get_wot_index(&db)?; + + Ok(BlockchainModule { + router_sender, + profile_path, + currency: currency_name, + currency_params, + current_blockstamp, + consensus: Blockstamp::default(), + db: Some(db), + fork_tree, + wot_index, + wot_databases, + pending_block: None, + invalid_forks: HashSet::new(), + pending_network_requests: HashMap::new(), + last_request_blocks: UNIX_EPOCH, + last_request_fork_blocks: UNIX_EPOCH, + }) + } /// Return module identifier pub fn name() -> ModuleStaticName { ModuleStaticName(MODULE_NAME) @@ -184,16 +222,9 @@ impl BlockchainModule { // Get db path let dbs_path = durs_conf::get_blockchain_db_path(profile_path.clone()); - // Open databases - let fork_tree = durs_bc_db_reader::current_meta_datas::get_fork_tree(&db) - .unwrap_or_else(|_| fatal_error!("Fail to get fork tree.")); + // Open wot let wot_databases = WotsV10DBs::open(Some(&dbs_path)); - // Get current blockstamp - let current_blockstamp = durs_bc_db_reader::current_meta_datas::get_current_blockstamp(&db) - .expect("Fatal error : fail to read Blockchain DB !") - .unwrap_or_default(); - // Get currency parameters let (currency_name, currency_params) = if let Some((currency_name, currency_params)) = dubp_currency_params::db::get_currency_params(durs_conf::get_datas_path( @@ -206,29 +237,17 @@ impl BlockchainModule { (None, None) }; - // Get wot index - let wot_index: HashMap<PubKey, WotId> = - durs_bc_db_reader::indexes::identities::get_wot_index(&db) - .expect("Fatal eror : get_wot_index : Fail to read blockchain databases"); - // Instanciate BlockchainModule - BlockchainModule { + // TODO ESZ + BlockchainModule::new( router_sender, profile_path, - currency: currency_name, + currency_name, currency_params, - current_blockstamp, - consensus: Blockstamp::default(), - db: Some(db), - fork_tree, - wot_index, + db, wot_databases, - pending_block: None, - invalid_forks: HashSet::new(), - pending_network_requests: HashMap::new(), - last_request_blocks: UNIX_EPOCH, - last_request_fork_blocks: UNIX_EPOCH, - } + ) + .unwrap_or_else(|e| fatal_error!("Fail to instantiate BlockchainModule: {:?}", e)) } /// Databases explorer pub fn dbex(profile_path: PathBuf, csv: bool, req: &DbExQuery) { @@ -293,14 +312,14 @@ impl BlockchainModule { loop { let now = SystemTime::now(); // Request Consensus - requests::sent::request_network_consensus(self); + //requests::sent::request_network_consensus(self); // Request next main blocks requests::sent::request_next_main_blocks(self, now); // Request fork blocks requests::sent::request_fork_blocks(self, now); // Listen received messages - match blockchain_receiver.recv_timeout(Duration::from_millis(1000)) { + match blockchain_receiver.recv_timeout(Duration::from_millis(2000)) { Ok(durs_message) => { match durs_message { DursMsg::Request { @@ -321,7 +340,10 @@ impl BlockchainModule { res_content, .. } => responses::received::receive_response(self, req_id, res_content), - DursMsg::Stop => break, + DursMsg::Stop => { + debug!("Receive Stop message."); + break; + } _ => {} // Others DursMsg variants } } diff --git a/lib/modules/blockchain/blockchain/src/requests/sent.rs b/lib/modules/blockchain/blockchain/src/requests/sent.rs index ef3584c3ba4c1eaf2436345a01c85ea433b14520..788255751661baf9e8f36717e0b5a441eb650bd3 100644 --- a/lib/modules/blockchain/blockchain/src/requests/sent.rs +++ b/lib/modules/blockchain/blockchain/src/requests/sent.rs @@ -17,20 +17,25 @@ use crate::*; use dubp_common_doc::{BlockNumber, Blockstamp}; -use durs_network::requests::OldNetworkRequest; -pub fn request_network_consensus(bc: &mut BlockchainModule) { - let req = OldNetworkRequest::GetConsensus(ModuleReqFullId( - BlockchainModule::name(), - ModuleReqId(bc.pending_network_requests.len() as u32), - )); - let req_id = dunp::queries::request_network( - bc, - ModuleReqId(bc.pending_network_requests.len() as u32), - &req, - ); - bc.pending_network_requests.insert(req_id, req); -} +/*pub fn request_network_consensus(bc: &mut BlockchainModule) { + if now + .duration_since(bc.last_request_consensus) + .expect("duration_since error") + > Duration::from_secs(*REQUEST_CONSENSUS_FREQUENCY_IN_SEC) + { + let req = OldNetworkRequest::GetConsensus(ModuleReqFullId( + BlockchainModule::name(), + ModuleReqId(bc.pending_network_requests.len() as u32), + )); + let req_id = dunp::queries::request_network( + bc, + ModuleReqId(bc.pending_network_requests.len() as u32), + &req, + ); + bc.pending_network_requests.insert(req_id, req); + } +}*/ pub fn request_orphan_previous(bc: &mut BlockchainModule, orphan_blockstamp: Blockstamp) { let new_pending_network_requests = diff --git a/lib/tests-tools/blocks-tests-tools/src/mocks.rs b/lib/tests-tools/blocks-tests-tools/src/mocks.rs index 5b3fe2f155c83d0dcb93e8ca742fa595de58457b..7a1fba293191a19bfd8399006c0cf96f925b9796 100644 --- a/lib/tests-tools/blocks-tests-tools/src/mocks.rs +++ b/lib/tests-tools/blocks-tests-tools/src/mocks.rs @@ -67,7 +67,7 @@ pub fn gen_empty_timed_issued_hashed_block_v10( signator: &dup_crypto::keys::SignatorEnum, ) -> BlockDocumentV10 { let mut block = gen_empty_block_v10(block_number); - block.time = time; + block.median_time = time; block.issuers = vec![signator.public_key()]; block.previous_issuer = Some(previous_issuer); block.previous_hash = Some(previous_hash);