diff --git a/lib/modules/blockchain/blockchain-dal/src/writers/requests.rs b/lib/modules/blockchain/blockchain-dal/src/writers/requests.rs index c6c67ea4a4778255e3604a9c78f895538658816c..9cf73d9bdcf60a995dd957a3a958e7a82fe99b0d 100644 --- a/lib/modules/blockchain/blockchain-dal/src/writers/requests.rs +++ b/lib/modules/blockchain/blockchain-dal/src/writers/requests.rs @@ -123,8 +123,9 @@ impl WotsDBsWriteQuery { /// Apply WotsDBsWriteQuery pub fn apply( &self, - databases: &WotsV10DBs, + _blockstamp: &Blockstamp, currency_params: &CurrencyParameters, + databases: &WotsV10DBs, ) -> Result<(), DALError> { match *self { WotsDBsWriteQuery::CreateIdentity( @@ -284,13 +285,17 @@ pub enum CurrencyDBsWriteQuery { impl CurrencyDBsWriteQuery { /// Apply CurrencyDBsWriteQuery - pub fn apply(&self, databases: &CurrencyV10DBs) -> Result<(), DALError> { + pub fn apply( + &self, + blockstamp: &Blockstamp, + databases: &CurrencyV10DBs, + ) -> Result<(), DALError> { match *self { CurrencyDBsWriteQuery::WriteTx(ref tx_doc) => { - super::transaction::apply_and_write_tx(&databases, tx_doc.deref())?; + super::transaction::apply_and_write_tx(blockstamp, &databases, tx_doc.deref())?; } CurrencyDBsWriteQuery::RevertTx(ref dal_tx) => { - super::transaction::revert_tx(&databases, dal_tx.deref())?; + super::transaction::revert_tx(blockstamp, &databases, dal_tx.deref())?; } CurrencyDBsWriteQuery::CreateUD(ref du_amount, ref block_id, ref members) => { super::dividend::create_du( diff --git a/lib/modules/blockchain/blockchain-dal/src/writers/transaction.rs b/lib/modules/blockchain/blockchain-dal/src/writers/transaction.rs index 5a39904f44a17dbd5cef60fce351a7991c8226a6..6895fc83749d4ec21462fa2924a1c3580c216db8 100644 --- a/lib/modules/blockchain/blockchain-dal/src/writers/transaction.rs +++ b/lib/modules/blockchain/blockchain-dal/src/writers/transaction.rs @@ -44,7 +44,11 @@ pub struct DALTxV10 { } /// Apply transaction backwards -pub fn revert_tx(dbs: &CurrencyV10DBs, dal_tx: &DALTxV10) -> Result<(), DALError> { +pub fn revert_tx( + blockstamp: &Blockstamp, + dbs: &CurrencyV10DBs, + dal_tx: &DALTxV10, +) -> Result<(), DALError> { let mut tx_doc = dal_tx.tx_doc.clone(); let tx_hash = tx_doc.get_hash(); let sources_destroyed = &dal_tx.sources_destroyed; @@ -153,9 +157,13 @@ pub fn revert_tx(dbs: &CurrencyV10DBs, dal_tx: &DALTxV10) -> Result<(), DALError for (source_index, source_amount) in &recreated_sources { if let SourceIndexV10::UTXO(utxo_index) = source_index { // Get utxo - let utxo = db - .get(&utxo_index) - .expect("ApplyBLockError : unknow UTXO in inputs !"); + let utxo = db.get(&utxo_index).unwrap_or_else(|| { + fatal_error!( + "ApplyBLockError {} : unknow UTXO in inputs : {:?} !", + blockstamp, + utxo_index + ) + }); // Get utxo conditions(=address) let conditions = &utxo.conditions.conditions; // Calculate new balances datas for "conditions" address @@ -238,6 +246,7 @@ pub fn revert_tx(dbs: &CurrencyV10DBs, dal_tx: &DALTxV10) -> Result<(), DALError /// Apply and write transaction in databases pub fn apply_and_write_tx( + blockstamp: &Blockstamp, dbs: &CurrencyV10DBs, tx_doc: &TransactionDocument, ) -> Result<(), DALError> { @@ -272,7 +281,8 @@ pub fn apply_and_write_tx( let utxo = db.get(&utxo_index).unwrap_or_else(|| { debug!("apply_tx=\"{:#?}\"", tx_doc); fatal_error!( - "ApplyBLockError : unknow UTXO in inputs : {:?} !", + "ApplyBLockError {} : unknow UTXO in inputs : {:?} !", + blockstamp, utxo_index ) }); diff --git a/lib/modules/blockchain/blockchain/src/dunp/receiver.rs b/lib/modules/blockchain/blockchain/src/dunp/receiver.rs index a86aeaa18a4436072d59b7b8f5bfc55a3b2f4095..6ed74cd5cbe98609c036c094c25e07baab3cfa46 100644 --- a/lib/modules/blockchain/blockchain/src/dunp/receiver.rs +++ b/lib/modules/blockchain/blockchain/src/dunp/receiver.rs @@ -50,12 +50,12 @@ pub fn receive_blocks(bc: &mut BlockchainModule, blocks: Vec<BlockDocument>) { .expect("Fatal error : Fail to apply DBWriteRequest !"); for query in &wot_dbs_queries { query - .apply(&bc.wot_databases, &bc.currency_params) + .apply(&blockstamp, &bc.currency_params, &bc.wot_databases) .expect("Fatal error : Fail to apply WotsDBsWriteRequest !"); } for query in &tx_dbs_queries { query - .apply(&bc.currency_databases) + .apply(&blockstamp, &bc.currency_databases) .expect("Fatal error : Fail to apply CurrencyDBsWriteRequest !"); } save_blocks_dbs = true; diff --git a/lib/modules/blockchain/blockchain/src/fork/rollback.rs b/lib/modules/blockchain/blockchain/src/fork/rollback.rs index bdb7fc5b8e80b63b5cdacdbb9b7354556e98f25b..74d833eeaa7ddaa827bb0dd4045b2c399a313d32 100644 --- a/lib/modules/blockchain/blockchain/src/fork/rollback.rs +++ b/lib/modules/blockchain/blockchain/src/fork/rollback.rs @@ -46,18 +46,19 @@ pub fn apply_rollback(bc: &mut BlockchainModule, new_bc_branch: Vec<Blockstamp>) .unwrap_or_else(|_| { fatal_error!("revert block {} fail !", bc.current_blockstamp); }); + let blockstamp = dal_block.block.blockstamp(); // Apply db requests bc_db_query .apply(&bc.blocks_databases.blockchain_db, &bc.forks_dbs, None) .expect("Fatal error : Fail to apply DBWriteRequest !"); for query in &wot_dbs_queries { query - .apply(&bc.wot_databases, &bc.currency_params) + .apply(&blockstamp, &bc.currency_params, &bc.wot_databases) .expect("Fatal error : Fail to apply WotsDBsWriteRequest !"); } for query in &tx_dbs_queries { query - .apply(&bc.currency_databases) + .apply(&blockstamp, &bc.currency_databases) .expect("Fatal error : Fail to apply CurrencyDBsWriteRequest !"); } } else { @@ -86,12 +87,12 @@ pub fn apply_rollback(bc: &mut BlockchainModule, new_bc_branch: Vec<Blockstamp>) .expect("Fatal error : Fail to apply DBWriteRequest !"); for query in &wot_dbs_queries { query - .apply(&bc.wot_databases, &bc.currency_params) + .apply(&blockstamp, &bc.currency_params, &bc.wot_databases) .expect("Fatal error : Fail to apply WotsDBsWriteRequest !"); } for query in &tx_dbs_queries { query - .apply(&bc.currency_databases) + .apply(&blockstamp, &bc.currency_databases) .expect("Fatal error : Fail to apply CurrencyDBsWriteRequest !"); } } else { diff --git a/lib/modules/blockchain/blockchain/src/fork/stackable_blocks.rs b/lib/modules/blockchain/blockchain/src/fork/stackable_blocks.rs index b99b74d76a5c9f8f23427d7216dd98cc7c4b3eec..f04b80af5bb34f8058899598664e46aad34495d4 100644 --- a/lib/modules/blockchain/blockchain/src/fork/stackable_blocks.rs +++ b/lib/modules/blockchain/blockchain/src/fork/stackable_blocks.rs @@ -40,18 +40,19 @@ pub fn apply_stackable_blocks(bc: &mut BlockchainModule) { ))) = check_and_apply_block(bc, stackable_block.block) { let new_current_block = bc_db_query.get_block_doc_copy(); + let blockstamp = new_current_block.blockstamp(); // Apply db requests bc_db_query .apply(&bc.blocks_databases.blockchain_db, &bc.forks_dbs, None) .expect("Fatal error : Fail to apply DBWriteRequest !"); for query in &wot_dbs_queries { query - .apply(&bc.wot_databases, &bc.currency_params) + .apply(&blockstamp, &bc.currency_params, &bc.wot_databases) .expect("Fatal error : Fail to apply WotsDBsWriteRequest !"); } for query in &tx_dbs_queries { query - .apply(&bc.currency_databases) + .apply(&blockstamp, &bc.currency_databases) .expect("Fatal error : Fail to apply CurrencyDBsWriteRequest !"); } debug!("success to stackable_block({})", stackable_block_number); diff --git a/lib/modules/blockchain/blockchain/src/sync/apply/txs_worker.rs b/lib/modules/blockchain/blockchain/src/sync/apply/txs_worker.rs index a81a84c73a3043a41d644000b163e319bd13d4db..de0c7aaa12eeac81348089316b60d887dcbfd269 100644 --- a/lib/modules/blockchain/blockchain/src/sync/apply/txs_worker.rs +++ b/lib/modules/blockchain/blockchain/src/sync/apply/txs_worker.rs @@ -33,10 +33,10 @@ pub fn execute( // Listen db requets let mut all_wait_duration = Duration::from_millis(0); let mut wait_begin = SystemTime::now(); - while let Ok(SyncJobsMess::CurrencyDBsWriteQuery(req)) = recv.recv() { + while let Ok(SyncJobsMess::CurrencyDBsWriteQuery(blockstamp, req)) = recv.recv() { all_wait_duration += SystemTime::now().duration_since(wait_begin).unwrap(); // Apply db request - req.apply(&databases) + req.apply(&blockstamp, &databases) .expect("Fatal error : Fail to apply DBWriteRequest !"); wait_begin = SystemTime::now(); } diff --git a/lib/modules/blockchain/blockchain/src/sync/apply/wot_worker.rs b/lib/modules/blockchain/blockchain/src/sync/apply/wot_worker.rs index d266cff5f3792e886d2b1a8f0417e4e2e750e28e..b80db59039dbbc6787c1c81e502efe17c9bedd9a 100644 --- a/lib/modules/blockchain/blockchain/src/sync/apply/wot_worker.rs +++ b/lib/modules/blockchain/blockchain/src/sync/apply/wot_worker.rs @@ -37,8 +37,8 @@ pub fn execute( while let Ok(mess) = recv.recv() { all_wait_duration += SystemTime::now().duration_since(wait_begin).unwrap(); match mess { - SyncJobsMess::WotsDBsWriteQuery(req, currency_params) => req - .apply(&databases, ¤cy_params.deref()) + SyncJobsMess::WotsDBsWriteQuery(blockstamp, currency_params, req) => req + .apply(&blockstamp, ¤cy_params.deref(), &databases) .expect("Fatal error : Fail to apply DBWriteRequest !"), SyncJobsMess::End() => break, _ => {} diff --git a/lib/modules/blockchain/blockchain/src/sync/mod.rs b/lib/modules/blockchain/blockchain/src/sync/mod.rs index 8cf477750817103f2ff4e6378b283abe0adfdd14..93b4a208ba2753a1f5c65a468dc89454015f833b 100644 --- a/lib/modules/blockchain/blockchain/src/sync/mod.rs +++ b/lib/modules/blockchain/blockchain/src/sync/mod.rs @@ -56,8 +56,8 @@ pub enum MessForSyncThread { /// Message for a job thread pub enum SyncJobsMess { BlocksDBsWriteQuery(BlocksDBsWriteQuery), - WotsDBsWriteQuery(WotsDBsWriteQuery, Box<CurrencyParameters>), - CurrencyDBsWriteQuery(CurrencyDBsWriteQuery), + WotsDBsWriteQuery(Blockstamp, Box<CurrencyParameters>, WotsDBsWriteQuery), + CurrencyDBsWriteQuery(Blockstamp, CurrencyDBsWriteQuery), End(), } @@ -364,8 +364,9 @@ pub fn local_sync<DC: DursConfTrait>(profile_path: PathBuf, conf: &DC, sync_opts } sender_wot_thread .send(SyncJobsMess::WotsDBsWriteQuery( - req.clone(), + current_blockstamp, Box::new(currency_params), + req.clone(), )) .expect( "Fail to communicate with tx worker thread, please reset data & resync !", @@ -374,7 +375,10 @@ pub fn local_sync<DC: DursConfTrait>(profile_path: PathBuf, conf: &DC, sync_opts // Send blocks and wot requests to wot worker thread for req in currency_db_reqs { sender_tx_thread - .send(SyncJobsMess::CurrencyDBsWriteQuery(req.clone())) + .send(SyncJobsMess::CurrencyDBsWriteQuery( + current_blockstamp, + req.clone(), + )) .expect( "Fail to communicate with tx worker thread, please reset data & resync !", );