From 9d3bda9bce5bb03f502a9a7b46d7145aab7d31b1 Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Fri, 30 May 2025 08:50:35 +0300 Subject: [PATCH] fix: fmt --- node_core/src/chain_storage/block_store.rs | 13 ++-- node_core/src/chain_storage/mod.rs | 71 +++++++++------------- 2 files changed, 37 insertions(+), 47 deletions(-) diff --git a/node_core/src/chain_storage/block_store.rs b/node_core/src/chain_storage/block_store.rs index 38c185e..553594e 100644 --- a/node_core/src/chain_storage/block_store.rs +++ b/node_core/src/chain_storage/block_store.rs @@ -2,7 +2,7 @@ use std::path::Path; use anyhow::{anyhow, Result}; use common::block::Block; -use log::warn; +use log::{error, warn}; use storage::sc_db_utils::{DataBlob, DataBlobChangeVariant}; use storage::RocksDBIO; @@ -66,23 +66,24 @@ impl NodeBlockStore { txs_ser: Vec, nullifiers_ser: Vec, ) -> Result<()> { + //Error notification for writing into DB error self.dbio .put_snapshot_block_id_db(id) - .inspect_err(|err| warn!("Failed to store snapshot block id with error {err:#?}"))?; + .inspect_err(|err| error!("Failed to store snapshot block id with error {err:#?}"))?; self.dbio .put_snapshot_account_db(accounts_ser) - .inspect_err(|err| warn!("Failed to store snapshot accounts with error {err:#?}"))?; + .inspect_err(|err| error!("Failed to store snapshot accounts with error {err:#?}"))?; self.dbio .put_snapshot_commitement_db(comm_ser) - .inspect_err(|err| warn!("Failed to store snapshot commitments with error {err:#?}"))?; + .inspect_err(|err| error!("Failed to store snapshot commitments with error {err:#?}"))?; self.dbio .put_snapshot_transaction_db(txs_ser) .inspect_err(|err| { - warn!("Failed to store snapshot transactions with error {err:#?}") + error!("Failed to store snapshot transactions with error {err:#?}") })?; self.dbio .put_snapshot_account_db(nullifiers_ser) - .inspect_err(|err| warn!("Failed to store snapshot nullifiers with error {err:#?}"))?; + .inspect_err(|err| error!("Failed to store snapshot nullifiers with error {err:#?}"))?; Ok(()) } diff --git a/node_core/src/chain_storage/mod.rs b/node_core/src/chain_storage/mod.rs index f166a10..1fbe284 100644 --- a/node_core/src/chain_storage/mod.rs +++ b/node_core/src/chain_storage/mod.rs @@ -1,7 +1,4 @@ -use std::{ - collections::{BTreeMap, HashMap, HashSet}, - path::Path, -}; +use std::collections::{BTreeMap, HashMap, HashSet}; use accounts::account_core::{Account, AccountAddress}; use anyhow::Result; @@ -145,48 +142,40 @@ impl NodeChainStore { if block_id % self.node_config.shapshot_frequency_in_blocks == 0 { //Serializing all important data structures - //If we fail snapshot, it is not the reason to stop running + //If we fail serialization, it is not the reason to stop running //Logging on warn level in this cases - let accounts_ser = serde_json::to_vec(&self.acc_map).inspect_err(|err| { + if let Ok(accounts_ser) = serde_json::to_vec(&self.acc_map).inspect_err(|err| { warn!("Failed to serialize accounts data {err:#?}"); - }); + }) { + if let Ok(comm_ser) = + serde_json::to_vec(&self.utxo_commitments_store).inspect_err(|err| { + warn!("Failed to serialize commitments {err:#?}"); + }) + { + if let Ok(txs_ser) = serde_json::to_vec(&self.pub_tx_store).inspect_err(|err| { + warn!("Failed to serialize transactions {err:#?}"); + }) { + if let Ok(nullifiers_ser) = serde_json::to_vec(&self.nullifier_store) + .inspect_err(|err| { + warn!("Failed to serialize nullifiers {err:#?}"); + }) + { + let snapshot_trace = self.block_store.put_snapshot_at_block_id( + block_id, + accounts_ser, + comm_ser, + txs_ser, + nullifiers_ser, + ); - let comm_tree_serialized = serde_json::to_vec(&self.utxo_commitments_store) - .inspect_err(|err| { - warn!("Failed to serialize commitments {err:#?}"); - }); - - let tx_tree_serialized = serde_json::to_vec(&self.pub_tx_store).inspect_err(|err| { - warn!("Failed to serialize transactions {err:#?}"); - }); - - let nullifiers_serialized = - serde_json::to_vec(&self.nullifier_store).inspect_err(|err| { - warn!("Failed to serialize nullifiers {err:#?}"); - }); - - match ( - accounts_ser, - comm_tree_serialized, - tx_tree_serialized, - nullifiers_serialized, - ) { - (Ok(accounts_ser), Ok(comm_ser), Ok(txs_ser), Ok(nullifiers_ser)) => { - let snapshot_trace = self.block_store.put_snapshot_at_block_id( - block_id, - accounts_ser, - comm_ser, - txs_ser, - nullifiers_ser, - ); - - info!( - "Snapshot executed at {:?} with results {snapshot_trace:#?}", - block_id - ); + info!( + "Snapshot executed at {:?} with results {snapshot_trace:#?}", + block_id + ); + } + } } - _ => warn!("Failed to serialize node data for snapshot"), } }