Преглед изворни кода

drk: add scan_cache_log!() which makes filling msgs buffer optional to avoid string formatting in tight loops when not needed.

x пре 1 дан
родитељ
комит
835ccbc10a
4 измењених фајлова са 87 додато и 58 уклоњено
  1. 15 10
      bin/drk/src/dao.rs
  2. 4 3
      bin/drk/src/deploy.rs
  3. 29 21
      bin/drk/src/money.rs
  4. 39 24
      bin/drk/src/rpc.rs

+ 15 - 10
bin/drk/src/dao.rs

@@ -82,6 +82,7 @@ use crate::{
     money::BALANCE_BASE10_DECIMALS,
     money::BALANCE_BASE10_DECIMALS,
     params,
     params,
     rpc::ScanCache,
     rpc::ScanCache,
+    scan_cache_log,
     walletdb::Value,
     walletdb::Value,
     Drk,
     Drk,
 };
 };
@@ -1200,9 +1201,10 @@ impl Drk {
         }
         }
 
 
         // Confirm it
         // Confirm it
-        scan_cache.log(format!(
+        scan_cache_log!(
+            scan_cache,
             "[apply_dao_mint_data] Found minted DAO {new_bulla}, noting down for wallet update"
             "[apply_dao_mint_data] Found minted DAO {new_bulla}, noting down for wallet update"
-        ));
+        );
         if let Err(e) = self
         if let Err(e) = self
             .confirm_dao(
             .confirm_dao(
                 new_bulla,
                 new_bulla,
@@ -1249,9 +1251,10 @@ impl Drk {
             };
             };
 
 
             // We managed to decrypt it. Let's place this in a proper ProposalRecord object
             // We managed to decrypt it. Let's place this in a proper ProposalRecord object
-            scan_cache.messages_buffer.push(format!(
+            scan_cache_log!(
+                scan_cache,
                 "[apply_dao_propose_data] Managed to decrypt proposal note for DAO: {dao}"
                 "[apply_dao_propose_data] Managed to decrypt proposal note for DAO: {dao}"
-            ));
+            );
 
 
             // Check if we already got the record
             // Check if we already got the record
             let our_proposal = if scan_cache.own_proposals.contains_key(&params.proposal_bulla) {
             let our_proposal = if scan_cache.own_proposals.contains_key(&params.proposal_bulla) {
@@ -1426,7 +1429,7 @@ impl Drk {
         // Run through the transaction call data and see what we got:
         // Run through the transaction call data and see what we got:
         match DaoFunction::try_from(data[0])? {
         match DaoFunction::try_from(data[0])? {
             DaoFunction::Mint => {
             DaoFunction::Mint => {
-                scan_cache.log(String::from("[apply_tx_dao_data] Found Dao::Mint call"));
+                scan_cache_log!(scan_cache, "[apply_tx_dao_data] Found Dao::Mint call");
                 let params: DaoMintParams = deserialize_async(&data[1..]).await?;
                 let params: DaoMintParams = deserialize_async(&data[1..]).await?;
                 self.apply_dao_mint_data(
                 self.apply_dao_mint_data(
                     scan_cache,
                     scan_cache,
@@ -1438,24 +1441,26 @@ impl Drk {
                 .await
                 .await
             }
             }
             DaoFunction::Propose => {
             DaoFunction::Propose => {
-                scan_cache.log(String::from("[apply_tx_dao_data] Found Dao::Propose call"));
+                scan_cache_log!(scan_cache, "[apply_tx_dao_data] Found Dao::Propose call");
                 let params: DaoProposeParams = deserialize_async(&data[1..]).await?;
                 let params: DaoProposeParams = deserialize_async(&data[1..]).await?;
                 self.apply_dao_propose_data(scan_cache, &params, tx_hash, call_idx, block_height)
                 self.apply_dao_propose_data(scan_cache, &params, tx_hash, call_idx, block_height)
                     .await
                     .await
             }
             }
             DaoFunction::Vote => {
             DaoFunction::Vote => {
-                scan_cache.log(String::from("[apply_tx_dao_data] Found Dao::Vote call"));
+                scan_cache_log!(scan_cache, "[apply_tx_dao_data] Found Dao::Vote call");
                 let params: DaoVoteParams = deserialize_async(&data[1..]).await?;
                 let params: DaoVoteParams = deserialize_async(&data[1..]).await?;
                 self.apply_dao_vote_data(scan_cache, &params, tx_hash, call_idx, block_height).await
                 self.apply_dao_vote_data(scan_cache, &params, tx_hash, call_idx, block_height).await
             }
             }
             DaoFunction::Exec => {
             DaoFunction::Exec => {
-                scan_cache.log(String::from("[apply_tx_dao_data] Found Dao::Exec call"));
+                scan_cache_log!(scan_cache, "[apply_tx_dao_data] Found Dao::Exec call");
                 let params: DaoExecParams = deserialize_async(&data[1..]).await?;
                 let params: DaoExecParams = deserialize_async(&data[1..]).await?;
                 self.apply_dao_exec_data(scan_cache, &params, tx_hash, block_height).await
                 self.apply_dao_exec_data(scan_cache, &params, tx_hash, block_height).await
             }
             }
             DaoFunction::AuthMoneyTransfer => {
             DaoFunction::AuthMoneyTransfer => {
-                scan_cache
-                    .log(String::from("[apply_tx_dao_data] Found Dao::AuthMoneyTransfer call"));
+                scan_cache_log!(
+                    scan_cache,
+                    "[apply_tx_dao_data] Found Dao::AuthMoneyTransfer call"
+                );
                 // Does nothing, just verifies the other calls are correct
                 // Does nothing, just verifies the other calls are correct
                 Ok(false)
                 Ok(false)
             }
             }

+ 4 - 3
bin/drk/src/deploy.rs

@@ -44,7 +44,8 @@ use darkfi_sdk::{
 use darkfi_serial::{deserialize_async, serialize, serialize_async, AsyncEncodable};
 use darkfi_serial::{deserialize_async, serialize, serialize_async, AsyncEncodable};
 
 
 use crate::{
 use crate::{
-    convert_named_params, error::WalletDbResult, params, rpc::ScanCache, walletdb::Value, Drk,
+    convert_named_params, error::WalletDbResult, params, rpc::ScanCache, scan_cache_log,
+    walletdb::Value, Drk,
 };
 };
 
 
 // Wallet SQL table constant names. These have to represent the `wallet.sql`
 // Wallet SQL table constant names. These have to represent the `wallet.sql`
@@ -516,12 +517,12 @@ impl Drk {
         // Run through the transaction call data and see what we got:
         // Run through the transaction call data and see what we got:
         match DeployFunction::try_from(data[0])? {
         match DeployFunction::try_from(data[0])? {
             DeployFunction::DeployV1 => {
             DeployFunction::DeployV1 => {
-                scan_cache.log(String::from("[apply_tx_deploy_data] Found Deploy::DeployV1 call"));
+                scan_cache_log!(scan_cache, "[apply_tx_deploy_data] Found Deploy::DeployV1 call");
                 let params: DeployParamsV1 = deserialize_async(&data[1..]).await?;
                 let params: DeployParamsV1 = deserialize_async(&data[1..]).await?;
                 self.apply_deploy_deploy_data(scan_cache, &params, tx_hash, block_height).await
                 self.apply_deploy_deploy_data(scan_cache, &params, tx_hash, block_height).await
             }
             }
             DeployFunction::LockV1 => {
             DeployFunction::LockV1 => {
-                scan_cache.log(String::from("[apply_tx_deploy_data] Found Deploy::LockV1 call"));
+                scan_cache_log!(scan_cache, "[apply_tx_deploy_data] Found Deploy::LockV1 call");
                 let params: LockParamsV1 = deserialize_async(&data[1..]).await?;
                 let params: LockParamsV1 = deserialize_async(&data[1..]).await?;
                 self.apply_deploy_lock_data(scan_cache, &params.public_key, tx_hash, block_height)
                 self.apply_deploy_lock_data(scan_cache, &params.public_key, tx_hash, block_height)
                     .await
                     .await

+ 29 - 21
bin/drk/src/money.rs

@@ -66,6 +66,7 @@ use crate::{
     error::{WalletDbError, WalletDbResult},
     error::{WalletDbError, WalletDbResult},
     params,
     params,
     rpc::ScanCache,
     rpc::ScanCache,
+    scan_cache_log,
     walletdb::Value,
     walletdb::Value,
     Drk,
     Drk,
 };
 };
@@ -771,7 +772,7 @@ impl Drk {
         let data = &call.data.data;
         let data = &call.data.data;
         match MoneyFunction::try_from(data[0])? {
         match MoneyFunction::try_from(data[0])? {
             MoneyFunction::FeeV1 => {
             MoneyFunction::FeeV1 => {
-                scan_cache.log(String::from("[parse_money_call] Found Money::FeeV1 call"));
+                scan_cache_log!(scan_cache, "[parse_money_call] Found Money::FeeV1 call");
                 let params: MoneyFeeParamsV1 = deserialize_async(&data[9..]).await?;
                 let params: MoneyFeeParamsV1 = deserialize_async(&data[9..]).await?;
                 nullifiers.push(params.input.nullifier);
                 nullifiers.push(params.input.nullifier);
                 if !params.output.tx_local {
                 if !params.output.tx_local {
@@ -779,7 +780,7 @@ impl Drk {
                 }
                 }
             }
             }
             MoneyFunction::GenesisMintV1 => {
             MoneyFunction::GenesisMintV1 => {
-                scan_cache.log(String::from("[parse_money_call] Found Money::GenesisMintV1 call"));
+                scan_cache_log!(scan_cache, "[parse_money_call] Found Money::GenesisMintV1 call");
                 let params: MoneyGenesisMintParamsV1 = deserialize_async(&data[1..]).await?;
                 let params: MoneyGenesisMintParamsV1 = deserialize_async(&data[1..]).await?;
                 for output in params.outputs {
                 for output in params.outputs {
                     if !output.tx_local {
                     if !output.tx_local {
@@ -788,14 +789,14 @@ impl Drk {
                 }
                 }
             }
             }
             MoneyFunction::PoWRewardV1 => {
             MoneyFunction::PoWRewardV1 => {
-                scan_cache.log(String::from("[parse_money_call] Found Money::PoWRewardV1 call"));
+                scan_cache_log!(scan_cache, "[parse_money_call] Found Money::PoWRewardV1 call");
                 let params: MoneyPoWRewardParamsV1 = deserialize_async(&data[1..]).await?;
                 let params: MoneyPoWRewardParamsV1 = deserialize_async(&data[1..]).await?;
                 if !params.output.tx_local {
                 if !params.output.tx_local {
                     coins.push((params.output.coin, params.output.note, true));
                     coins.push((params.output.coin, params.output.note, true));
                 }
                 }
             }
             }
             MoneyFunction::TransferV1 => {
             MoneyFunction::TransferV1 => {
-                scan_cache.log(String::from("[parse_money_call] Found Money::TransferV1 call"));
+                scan_cache_log!(scan_cache, "[parse_money_call] Found Money::TransferV1 call");
                 let params: MoneyTransferParamsV1 = deserialize_async(&data[1..]).await?;
                 let params: MoneyTransferParamsV1 = deserialize_async(&data[1..]).await?;
 
 
                 for input in params.inputs {
                 for input in params.inputs {
@@ -809,23 +810,24 @@ impl Drk {
                 }
                 }
             }
             }
             MoneyFunction::AuthTokenMintV1 => {
             MoneyFunction::AuthTokenMintV1 => {
-                scan_cache
-                    .log(String::from("[parse_money_call] Found Money::AuthTokenMintV1 call"));
+                scan_cache_log!(scan_cache, "[parse_money_call] Found Money::AuthTokenMintV1 call");
                 // Handled in TokenMint
                 // Handled in TokenMint
             }
             }
             MoneyFunction::AuthTokenFreezeV1 => {
             MoneyFunction::AuthTokenFreezeV1 => {
-                scan_cache
-                    .log(String::from("[parse_money_call] Found Money::AuthTokenFreezeV1 call"));
+                scan_cache_log!(
+                    scan_cache,
+                    "[parse_money_call] Found Money::AuthTokenFreezeV1 call"
+                );
                 let params: MoneyAuthTokenFreezeParamsV1 = deserialize_async(&data[1..]).await?;
                 let params: MoneyAuthTokenFreezeParamsV1 = deserialize_async(&data[1..]).await?;
                 freezes.push(params.token_id);
                 freezes.push(params.token_id);
             }
             }
             MoneyFunction::TokenMintV1 => {
             MoneyFunction::TokenMintV1 => {
-                scan_cache.log(String::from("[parse_money_call] Found Money::TokenMintV1 call"));
+                scan_cache_log!(scan_cache, "[parse_money_call] Found Money::TokenMintV1 call");
                 let params: MoneyTokenMintParamsV1 = deserialize_async(&data[1..]).await?;
                 let params: MoneyTokenMintParamsV1 = deserialize_async(&data[1..]).await?;
                 coins.push((params.coin, params.enc_note, false))
                 coins.push((params.coin, params.enc_note, false))
             }
             }
             MoneyFunction::BurnV1 => {
             MoneyFunction::BurnV1 => {
-                scan_cache.log(String::from("[parse_money_call] Found Money::BurnV1 call"));
+                scan_cache_log!(scan_cache, "[parse_money_call] Found Money::BurnV1 call");
                 let params: MoneyBurnParamsV1 = deserialize_async(&data[1..]).await?;
                 let params: MoneyBurnParamsV1 = deserialize_async(&data[1..]).await?;
                 for input in params.inputs {
                 for input in params.inputs {
                     nullifiers.push(input.nullifier);
                     nullifiers.push(input.nullifier);
@@ -844,7 +846,7 @@ impl Drk {
         &self,
         &self,
         tree: &mut MerkleTree,
         tree: &mut MerkleTree,
         secrets: &[SecretKey],
         secrets: &[SecretKey],
-        messages_buffer: &mut Vec<String>,
+        mut messages_buffer: Option<&mut Vec<String>>,
         coins: &[(Coin, AeadEncryptedNote, bool)],
         coins: &[(Coin, AeadEncryptedNote, bool)],
     ) -> Result<(Vec<OwnCoin>, Option<SecretKey>)> {
     ) -> Result<(Vec<OwnCoin>, Option<SecretKey>)> {
         // Keep track of our own coins found in the vec
         // Keep track of our own coins found in the vec
@@ -868,15 +870,21 @@ impl Drk {
             // Attempt to decrypt the note
             // Attempt to decrypt the note
             for secret in secrets {
             for secret in secrets {
                 let Ok(note) = note.decrypt::<MoneyNote>(secret) else { continue };
                 let Ok(note) = note.decrypt::<MoneyNote>(secret) else { continue };
-                messages_buffer.push(String::from(
-                    "[handle_money_call_coins] Successfully decrypted a Money Note",
-                ));
-                messages_buffer
-                    .push(String::from("[handle_money_call_coins] Witnessing coin in Merkle tree"));
+                if let Some(buffer) = messages_buffer.as_deref_mut() {
+                    buffer.push(String::from(
+                        "[handle_money_call_coins] Successfully decrypted a Money Note",
+                    ));
+                    buffer.push(String::from(
+                        "[handle_money_call_coins] Witnessing coin in Merkle tree",
+                    ));
+                }
                 let leaf_position = tree.mark().unwrap();
                 let leaf_position = tree.mark().unwrap();
                 if *is_block_reward {
                 if *is_block_reward {
-                    messages_buffer
-                        .push(String::from("[handle_money_call_coins] Grabing block signing key"));
+                    if let Some(buffer) = messages_buffer.as_deref_mut() {
+                        buffer.push(String::from(
+                            "[handle_money_call_coins] Grabing block signing key",
+                        ));
+                    }
                     block_signing_key = Some(deserialize(&note.memo)?);
                     block_signing_key = Some(deserialize(&note.memo)?);
                 }
                 }
                 let owncoin = OwnCoin { coin: *coin, note, secret: *secret, leaf_position };
                 let owncoin = OwnCoin { coin: *coin, note, secret: *secret, leaf_position };
@@ -896,7 +904,7 @@ impl Drk {
         coins: &[OwnCoin],
         coins: &[OwnCoin],
         creation_height: &u32,
         creation_height: &u32,
     ) -> Result<()> {
     ) -> Result<()> {
-        scan_cache.log(format!("Found {} OwnCoin(s) in transaction", coins.len()));
+        scan_cache_log!(scan_cache, "Found {} OwnCoin(s) in transaction", coins.len());
 
 
         // Check if we have any owncoins to process
         // Check if we have any owncoins to process
         if coins.is_empty() {
         if coins.is_empty() {
@@ -926,7 +934,7 @@ impl Drk {
         // Handle our own coins
         // Handle our own coins
         let spent_height: Option<u32> = None;
         let spent_height: Option<u32> = None;
         for coin in coins {
         for coin in coins {
-            scan_cache.log(format!("OwnCoin: {:?}", coin.coin));
+            scan_cache_log!(scan_cache, "OwnCoin: {:?}", coin.coin);
             // Grab coin record key
             // Grab coin record key
             let key = coin.coin.to_bytes();
             let key = coin.coin.to_bytes();
 
 
@@ -1035,7 +1043,7 @@ impl Drk {
         let (owncoins, block_signing_key) = self.handle_money_call_coins(
         let (owncoins, block_signing_key) = self.handle_money_call_coins(
             &mut scan_cache.money_tree,
             &mut scan_cache.money_tree,
             &scan_cache.notes_secrets,
             &scan_cache.notes_secrets,
-            &mut scan_cache.messages_buffer,
+            scan_cache.messages_buffer.as_mut(),
             &coins,
             &coins,
         )?;
         )?;
 
 

+ 39 - 24
bin/drk/src/rpc.rs

@@ -103,26 +103,35 @@ pub struct ScanCache {
     pub own_proposals: HashMap<DaoProposalBulla, DaoBulla>,
     pub own_proposals: HashMap<DaoProposalBulla, DaoBulla>,
     /// Our own deploy authorities
     /// Our own deploy authorities
     pub own_deploy_auths: HashMap<[u8; 32], SecretKey>,
     pub own_deploy_auths: HashMap<[u8; 32], SecretKey>,
-    /// Messages buffer for better downstream prints handling
-    pub messages_buffer: Vec<String>,
+    /// Optional messages buffer for better downstream prints handling
+    pub messages_buffer: Option<Vec<String>>,
 }
 }
 
 
 impl ScanCache {
 impl ScanCache {
-    /// Auxiliary function to append messages to the buffer.
-    pub fn log(&mut self, msg: String) {
-        self.messages_buffer.push(msg);
-    }
-
     /// Auxiliary function to consume the messages buffer.
     /// Auxiliary function to consume the messages buffer.
     pub fn flush_messages(&mut self) -> Vec<String> {
     pub fn flush_messages(&mut self) -> Vec<String> {
-        self.messages_buffer.drain(..).collect()
+        self.messages_buffer.as_mut().map_or(vec![], std::mem::take)
     }
     }
 }
 }
 
 
+/// Guard to push a message into the provided [`ScanCache`] optional
+/// messages buffer. The format arguments are only evaluated when the
+/// buffer is enabled, so no string formatting happens when logging
+/// is disabled.
+#[macro_export]
+macro_rules! scan_cache_log {
+    ($cache:expr, $($arg:tt)*) => {
+        if let Some(ref mut buffer) = $cache.messages_buffer {
+            buffer.push(format!($($arg)*));
+        }
+    };
+}
+
 impl Drk {
 impl Drk {
     /// Auxiliary function to generate a new [`ScanCache`] for the
     /// Auxiliary function to generate a new [`ScanCache`] for the
-    /// wallet.
-    pub async fn scan_cache(&self) -> Result<ScanCache> {
+    /// wallet. The provided flag controls whether the messages
+    /// buffer is enabled.
+    pub async fn scan_cache(&self, verbose: bool) -> Result<ScanCache> {
         let money_tree = self.get_money_tree().await?;
         let money_tree = self.get_money_tree().await?;
         let smt_store = CacheSmtStorage::new(CacheOverlay::new(&self.cache)?, KVDB_MONEY_SMT_TREE);
         let smt_store = CacheSmtStorage::new(CacheOverlay::new(&self.cache)?, KVDB_MONEY_SMT_TREE);
         let money_smt = CacheSmt::new(smt_store, PoseidonFp::new(), &EMPTY_NODES_FP);
         let money_smt = CacheSmt::new(smt_store, PoseidonFp::new(), &EMPTY_NODES_FP);
@@ -155,6 +164,7 @@ impl Drk {
             own_proposals.insert(proposal.bulla(), proposal.proposal.dao_bulla);
             own_proposals.insert(proposal.bulla(), proposal.proposal.dao_bulla);
         }
         }
         let own_deploy_auths = self.get_deploy_auths_keys_map().await?;
         let own_deploy_auths = self.get_deploy_auths_keys_map().await?;
+        let messages_buffer = if verbose { Some(vec![]) } else { None };
 
 
         Ok(ScanCache {
         Ok(ScanCache {
             money_tree,
             money_tree,
@@ -167,7 +177,7 @@ impl Drk {
             own_daos,
             own_daos,
             own_proposals,
             own_proposals,
             own_deploy_auths,
             own_deploy_auths,
-            messages_buffer: vec![],
+            messages_buffer,
         })
         })
     }
     }
 
 
@@ -183,19 +193,19 @@ impl Drk {
         scan_cache.dao_proposals_tree.checkpoint(block.header.height as usize);
         scan_cache.dao_proposals_tree.checkpoint(block.header.height as usize);
 
 
         // Scan the block
         // Scan the block
-        scan_cache.log(String::from("======================================="));
-        scan_cache.log(format!("{}", block.header));
-        scan_cache.log(String::from("======================================="));
-        scan_cache.log(format!("[scan_block] Iterating over {} transactions", block.txs.len()));
+        scan_cache_log!(scan_cache, "=======================================");
+        scan_cache_log!(scan_cache, "{}", block.header);
+        scan_cache_log!(scan_cache, "=======================================");
+        scan_cache_log!(scan_cache, "[scan_block] Iterating over {} transactions", block.txs.len());
         let mut block_signing_key = None;
         let mut block_signing_key = None;
         for tx in block.txs.iter() {
         for tx in block.txs.iter() {
             let tx_hash = tx.hash();
             let tx_hash = tx.hash();
             let tx_hash_string = tx_hash.to_string();
             let tx_hash_string = tx_hash.to_string();
             let mut wallet_tx = false;
             let mut wallet_tx = false;
-            scan_cache.log(format!("[scan_block] Processing transaction: {tx_hash_string}"));
+            scan_cache_log!(scan_cache, "[scan_block] Processing transaction: {tx_hash_string}");
             for (i, call) in tx.calls.iter().enumerate() {
             for (i, call) in tx.calls.iter().enumerate() {
                 if call.data.contract_id == *MONEY_CONTRACT_ID {
                 if call.data.contract_id == *MONEY_CONTRACT_ID {
-                    scan_cache.log(format!("[scan_block] Found Money contract in call {i}"));
+                    scan_cache_log!(scan_cache, "[scan_block] Found Money contract in call {i}");
                     let (is_wallet_tx, signing_key) = self
                     let (is_wallet_tx, signing_key) = self
                         .apply_tx_money_data(
                         .apply_tx_money_data(
                             scan_cache,
                             scan_cache,
@@ -216,7 +226,7 @@ impl Drk {
                 }
                 }
 
 
                 if call.data.contract_id == *DAO_CONTRACT_ID {
                 if call.data.contract_id == *DAO_CONTRACT_ID {
-                    scan_cache.log(format!("[scan_block] Found DAO contract in call {i}"));
+                    scan_cache_log!(scan_cache, "[scan_block] Found DAO contract in call {i}");
                     if self
                     if self
                         .apply_tx_dao_data(
                         .apply_tx_dao_data(
                             scan_cache,
                             scan_cache,
@@ -233,7 +243,10 @@ impl Drk {
                 }
                 }
 
 
                 if call.data.contract_id == *DEPLOYOOOR_CONTRACT_ID {
                 if call.data.contract_id == *DEPLOYOOOR_CONTRACT_ID {
-                    scan_cache.log(format!("[scan_block] Found DeployoOor contract in call {i}"));
+                    scan_cache_log!(
+                        scan_cache,
+                        "[scan_block] Found DeployoOor contract in call {i}"
+                    );
                     if self
                     if self
                         .apply_tx_deploy_data(
                         .apply_tx_deploy_data(
                             scan_cache,
                             scan_cache,
@@ -249,8 +262,10 @@ impl Drk {
                 }
                 }
 
 
                 // TODO: For now we skip non-native contract calls
                 // TODO: For now we skip non-native contract calls
-                scan_cache
-                    .log(format!("[scan_block] Found non-native contract in call {i}, skipping."));
+                scan_cache_log!(
+                    scan_cache,
+                    "[scan_block] Found non-native contract in call {i}, skipping."
+                );
             }
             }
 
 
             // If this is our wallet tx we mark it for update
             // If this is our wallet tx we mark it for update
@@ -374,7 +389,7 @@ impl Drk {
         }
         }
 
 
         // Generate a new scan cache
         // Generate a new scan cache
-        let mut scan_cache = match self.scan_cache().await {
+        let mut scan_cache = match self.scan_cache(true).await {
             Ok(c) => c,
             Ok(c) => c,
             Err(e) => {
             Err(e) => {
                 append_or_print(
                 append_or_print(
@@ -775,7 +790,7 @@ pub async fn subscribe_blocks(
                                     ))
                                     ))
                                 }
                                 }
                             };
                             };
-                            let mut scan_cache = lock.scan_cache().await?;
+                            let mut scan_cache = lock.scan_cache(true).await?;
                             if let Err(e) = lock.scan_block(&mut scan_cache, &genesis).await {
                             if let Err(e) = lock.scan_block(&mut scan_cache, &genesis).await {
                                 shell_sender.send(shell_message).await?;
                                 shell_sender.send(shell_message).await?;
                                 break 'outer Error::Custom(format!(
                                 break 'outer Error::Custom(format!(
@@ -788,7 +803,7 @@ pub async fn subscribe_blocks(
                         }
                         }
                     }
                     }
 
 
-                    let mut scan_cache = lock.scan_cache().await?;
+                    let mut scan_cache = lock.scan_cache(true).await?;
                     if let Err(e) = lock.scan_block(&mut scan_cache, &block).await {
                     if let Err(e) = lock.scan_block(&mut scan_cache, &block).await {
                         shell_sender.send(shell_message).await?;
                         shell_sender.send(shell_message).await?;
                         break 'outer Error::Custom(format!(
                         break 'outer Error::Custom(format!(