Skip to content

Commit

Permalink
Merge branch 'dev' into cleanup_implblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
fluidvanadium authored Nov 13, 2023
2 parents 1263c60 + 9349ee0 commit ed85901
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 47 deletions.
6 changes: 3 additions & 3 deletions zingolib/src/blaze/fetch_full_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,9 @@ impl TransactionContext {

Err(e) => log::error!(
"Could not decode wallet internal memo: {e}.\n\
Have you recently used a more up-to-date version of\
this software?\nIf not, this may mean you are being sent\
malicious data.\nSome information may not display correctly"
Have you recently used a more up-to-date version of \
this software?\nIf not, this may mean you are being sent \
malicious data.\nSome information may not display correctly."
),
}
}
Expand Down
48 changes: 4 additions & 44 deletions zingolib/src/lightclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,27 +417,6 @@ impl LightClient {
}
}

async fn ensure_witness_tree_not_above_wallet_blocks(&self) {
let last_synced_height = self.wallet.last_synced_height().await;
let mut txmds_writelock = self
.wallet
.transaction_context
.transaction_metadata_set
.write()
.await;
if let Some(ref mut trees) = txmds_writelock.witness_trees {
trees
.witness_tree_sapling
.truncate_removing_checkpoint(&BlockHeight::from(last_synced_height as u32))
.expect("Infallible");
trees
.witness_tree_orchard
.truncate_removing_checkpoint(&BlockHeight::from(last_synced_height as u32))
.expect("Infallible");
trees.add_checkpoint(BlockHeight::from(last_synced_height as u32));
}
}

pub async fn clear_state(&self) {
// First, clear the state from the wallet
self.wallet.clear_all().await;
Expand Down Expand Up @@ -1165,27 +1144,6 @@ impl LightClient {
*lc.mempool_monitor.write().unwrap() = Some(h);
}

async fn wallet_has_any_empty_commitment_trees(&self) -> bool {
self.wallet
.transaction_context
.transaction_metadata_set
.read()
.await
.witness_trees
.as_ref()
.is_some_and(|trees| {
trees
.witness_tree_orchard
.max_leaf_position(0)
.unwrap()
.is_none()
|| trees
.witness_tree_sapling
.max_leaf_position(0)
.unwrap()
.is_none()
})
}
/// Start syncing in batches with the max size, to manage memory consumption.
async fn start_sync(&self) -> Result<SyncResult, String> {
// We can only do one sync at a time because we sync blocks in serial order
Expand All @@ -1201,10 +1159,12 @@ impl LightClient {
// If our internal state gets damaged somehow (for example,
// a resync that gets interrupted partway through) we need to make sure
// our witness trees are aligned with our blockchain data
self.ensure_witness_tree_not_above_wallet_blocks().await;
self.wallet
.ensure_witness_tree_not_above_wallet_blocks()
.await;

// This is a fresh wallet. We need to get the initial trees
if self.wallet_has_any_empty_commitment_trees().await
if self.wallet.has_any_empty_commitment_trees().await
&& last_synced_height >= self.config.sapling_activation_height()
{
let trees = crate::grpc_connector::GrpcConnector::get_trees(
Expand Down
40 changes: 40 additions & 0 deletions zingolib/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,46 @@ impl LightWallet {

Ok(())
}
pub async fn ensure_witness_tree_not_above_wallet_blocks(&self) {
let last_synced_height = self.last_synced_height().await;
let mut txmds_writelock = self
.transaction_context
.transaction_metadata_set
.write()
.await;
if let Some(ref mut trees) = txmds_writelock.witness_trees {
trees
.witness_tree_sapling
.truncate_removing_checkpoint(&BlockHeight::from(last_synced_height as u32))
.expect("Infallible");
trees
.witness_tree_orchard
.truncate_removing_checkpoint(&BlockHeight::from(last_synced_height as u32))
.expect("Infallible");
trees.add_checkpoint(BlockHeight::from(last_synced_height as u32));
}
}

pub async fn has_any_empty_commitment_trees(&self) -> bool {
self.transaction_context
.transaction_metadata_set
.read()
.await
.witness_trees
.as_ref()
.is_some_and(|trees| {
trees
.witness_tree_orchard
.max_leaf_position(0)
.unwrap()
.is_none()
|| trees
.witness_tree_sapling
.max_leaf_position(0)
.unwrap()
.is_none()
})
}
}

//This function will likely be used again if/when we re-implement key import
Expand Down

0 comments on commit ed85901

Please sign in to comment.