Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zingo sync retain relevant blocks #1339

Merged
merged 5 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions zingo-sync/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ where

fn remove_irrelevant_data<W>(wallet: &mut W, scan_range: &ScanRange) -> Result<(), ()>
where
W: SyncWallet + SyncBlocks + SyncNullifiers,
W: SyncWallet + SyncBlocks + SyncNullifiers + SyncTransactions,
{
if scan_range.priority() != ScanPriority::Historic {
return Ok(());
Expand All @@ -254,9 +254,16 @@ where
.block_range()
.end;

// TODO: also retain blocks that contain transactions relevant to the wallet
let wallet_transaction_heights = wallet
.get_wallet_transactions()
.unwrap()
.values()
.map(|tx| tx.block_height())
.collect::<Vec<_>>();
wallet.get_wallet_blocks_mut().unwrap().retain(|height, _| {
*height >= scan_range.block_range().end || *height >= wallet_height.saturating_sub(100)
*height >= scan_range.block_range().end
|| *height >= wallet_height.saturating_sub(100)
|| wallet_transaction_heights.contains(height)
});
wallet
.get_nullifiers_mut()
Expand Down
3 changes: 3 additions & 0 deletions zingo-sync/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ pub trait SyncBlocks: SyncWallet {

/// Trait for interfacing [`crate::primitives::WalletTransaction`]s with wallet data
pub trait SyncTransactions: SyncWallet {
/// Get reference to wallet transactions
fn get_wallet_transactions(&self) -> Result<&HashMap<TxId, WalletTransaction>, Self::Error>;

/// Get mutable reference to wallet transactions
fn get_wallet_transactions_mut(
&mut self,
Expand Down
9 changes: 9 additions & 0 deletions zingolib/src/wallet/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ impl SyncBlocks for LightWallet {
}

impl SyncTransactions for LightWallet {
fn get_wallet_transactions(
&self,
) -> Result<
&HashMap<zcash_primitives::transaction::TxId, zingo_sync::primitives::WalletTransaction>,
Self::Error,
> {
Ok(self.wallet_transactions())
}

fn get_wallet_transactions_mut(
&mut self,
) -> Result<
Expand Down