From 33e3744062d7ac791bdcb629f06b441926293099 Mon Sep 17 00:00:00 2001
From: librelois <elois@ifee.fr>
Date: Sun, 5 May 2019 00:00:36 +0200
Subject: [PATCH] [ref] blockchain: apply: add blockstamp to error message
---
.../blockchain-dal/src/writers/requests.rs | 13 ++++++++----
.../blockchain-dal/src/writers/transaction.rs | 20 ++++++++++++++-----
.../blockchain/src/dunp/receiver.rs | 4 ++--
.../blockchain/src/fork/rollback.rs | 9 +++++----
.../blockchain/src/fork/stackable_blocks.rs | 5 +++--
.../blockchain/src/sync/apply/txs_worker.rs | 4 ++--
.../blockchain/src/sync/apply/wot_worker.rs | 4 ++--
.../blockchain/blockchain/src/sync/mod.rs | 12 +++++++----
8 files changed, 46 insertions(+), 25 deletions(-)
diff --git a/lib/modules/blockchain/blockchain-dal/src/writers/requests.rs b/lib/modules/blockchain/blockchain-dal/src/writers/requests.rs
index c6c67ea4..9cf73d9b 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 5a39904f..6895fc83 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 a86aeaa1..6ed74cd5 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 bdb7fc5b..74d833ee 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 b99b74d7..f04b80af 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 a81a84c7..de0c7aaa 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 d266cff5..b80db590 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 8cf47775..93b4a208 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 !",
);
--
GitLab