Skip to content

Commit

Permalink
removed getset from nullifier map and wallet block
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscar-Pepper committed Feb 13, 2025
1 parent 74b4ca1 commit 22b050c
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 23 deletions.
36 changes: 29 additions & 7 deletions zingo-sync/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,10 @@ impl From<OutputId> for OutPoint {
}

/// Binary tree map of nullifiers from transaction spends or actions
#[derive(Debug, Getters, MutGetters)]
#[getset(get = "pub", get_mut = "pub")]
#[derive(Debug)]
pub struct NullifierMap {
sapling: BTreeMap<sapling_crypto::Nullifier, Locator>,
orchard: BTreeMap<orchard::note::Nullifier, Locator>,
pub(crate) sapling: BTreeMap<sapling_crypto::Nullifier, Locator>,
pub(crate) orchard: BTreeMap<orchard::note::Nullifier, Locator>,
}

impl NullifierMap {
Expand All @@ -272,6 +271,11 @@ impl NullifierMap {
orchard: BTreeMap::new(),
}
}

pub fn clear(&mut self) {
self.sapling.clear();
self.orchard.clear();
}
}

impl Default for NullifierMap {
Expand All @@ -281,14 +285,12 @@ impl Default for NullifierMap {
}

/// Wallet block data
#[derive(Debug, Clone, CopyGetters)]
#[getset(get_copy = "pub")]
#[derive(Debug, Clone)]
pub struct WalletBlock {
block_height: BlockHeight,
block_hash: BlockHash,
prev_hash: BlockHash,
time: u32,
#[getset(skip)]
txids: Vec<TxId>,
tree_boundaries: TreeBoundaries,
// TODO: optional price
Expand All @@ -313,9 +315,29 @@ impl WalletBlock {
}
}

pub fn block_height(&self) -> BlockHeight {
self.block_height
}

pub fn block_hash(&self) -> BlockHash {
self.block_hash
}

pub fn prev_hash(&self) -> BlockHash {
self.prev_hash
}

pub fn time(&self) -> u32 {
self.time
}

pub fn txids(&self) -> &[TxId] {
&self.txids
}

pub fn tree_boundaries(&self) -> TreeBoundaries {
self.tree_boundaries
}
}

/// Wallet transaction
Expand Down
4 changes: 2 additions & 2 deletions zingo-sync/src/scan/compact_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ fn collect_nullifiers(
.map(|spend| sapling_crypto::Nullifier::from_slice(spend.nf.as_slice()).unwrap())
.for_each(|nullifier| {
nullifier_map
.sapling_mut()
.sapling
.insert(nullifier, (block_height, transaction.txid()));
});
transaction
Expand All @@ -408,7 +408,7 @@ fn collect_nullifiers(
})
.for_each(|nullifier| {
nullifier_map
.orchard_mut()
.orchard
.insert(nullifier, (block_height, transaction.txid()));
});
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions zingo-sync/src/scan/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ fn collect_nullifiers(
.map(|spend| spend.nullifier())
.for_each(|nullifier| {
nullifier_map
.sapling_mut()
.sapling
.insert(*nullifier, (block_height, transaction.txid()));
});
}
Expand All @@ -504,7 +504,7 @@ fn collect_nullifiers(
.map(|action| action.nullifier())
.for_each(|nullifier| {
nullifier_map
.orchard_mut()
.orchard
.insert(*nullifier, (block_height, transaction.txid()));
});
}
Expand Down
4 changes: 2 additions & 2 deletions zingo-sync/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,12 +581,12 @@ where
wallet
.get_nullifiers_mut()
.unwrap()
.sapling_mut()
.sapling
.retain(|_, (height, _)| *height > fully_scanned_height);
wallet
.get_nullifiers_mut()
.unwrap()
.orchard_mut()
.orchard
.retain(|_, (height, _)| *height > fully_scanned_height);
wallet
.get_sync_state_mut()
Expand Down
4 changes: 2 additions & 2 deletions zingo-sync/src/sync/spend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ pub(super) fn detect_shielded_spends(
) {
let sapling_spend_locators = sapling_derived_nullifiers
.iter()
.flat_map(|nf| nullifier_map.sapling_mut().remove_entry(nf))
.flat_map(|nf| nullifier_map.sapling.remove_entry(nf))
.collect();
let orchard_spend_locators = orchard_derived_nullifiers
.iter()
.flat_map(|nf| nullifier_map.orchard_mut().remove_entry(nf))
.flat_map(|nf| nullifier_map.orchard.remove_entry(nf))
.collect();

(sapling_spend_locators, orchard_spend_locators)
Expand Down
12 changes: 6 additions & 6 deletions zingo-sync/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ pub trait SyncNullifiers: SyncWallet {
/// Append nullifiers to wallet nullifier map
fn append_nullifiers(&mut self, mut nullifiers: NullifierMap) -> Result<(), Self::Error> {
self.get_nullifiers_mut()?
.sapling_mut()
.append(nullifiers.sapling_mut());
.sapling
.append(&mut nullifiers.sapling);
self.get_nullifiers_mut()?
.orchard_mut()
.append(nullifiers.orchard_mut());
.orchard
.append(&mut nullifiers.orchard);

Ok(())
}
Expand All @@ -181,10 +181,10 @@ pub trait SyncNullifiers: SyncWallet {
fn truncate_nullifiers(&mut self, truncate_height: BlockHeight) -> Result<(), Self::Error> {
let nullifier_map = self.get_nullifiers_mut()?;
nullifier_map
.sapling_mut()
.sapling
.retain(|_, (block_height, _)| *block_height <= truncate_height);
nullifier_map
.orchard_mut()
.orchard
.retain(|_, (block_height, _)| *block_height <= truncate_height);

Ok(())
Expand Down
3 changes: 1 addition & 2 deletions zingolib/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ impl LightWallet {
pub fn clear_all(&mut self) {
self.wallet_blocks.clear();
self.wallet_transactions.clear();
self.nullifier_map.sapling_mut().clear();
self.nullifier_map.orchard_mut().clear();
self.nullifier_map.clear();
self.outpoint_map.clear();
self.sync_state = SyncState::new();
}
Expand Down

0 comments on commit 22b050c

Please sign in to comment.