Skip to content

Commit 20fdd86

Browse files
committed
Merge branch 'bat/dont-update-witness-maps-of-unowned-notes' (#4693)
* origin/bat/dont-update-witness-maps-of-unowned-notes: changelog Don't update witness maps of unowned notes
2 parents cc5ec95 + a7efe31 commit 20fdd86

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- When using the ledger client, we update witness maps manually. We now add notes to the witness map only if there were successfully trial decrypted. ([\#2693](https://github.com/anoma/namada/pull/4693))

crates/shielded_token/src/masp/shielded_sync/dispatcher.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,11 @@ where
409409
if needs_witness_map_update
410410
&& Some(&masp_indexed_tx) > last_witnessed_tx.as_ref()
411411
{
412-
self.ctx.update_witness_map(masp_indexed_tx, &stx_batch)?;
412+
self.ctx.update_witness_map(
413+
masp_indexed_tx,
414+
&stx_batch,
415+
&self.cache.trial_decrypted,
416+
)?;
413417
}
414418
let first_note_pos = self.ctx.note_index[&masp_indexed_tx];
415419
let mut vk_heights = BTreeMap::new();

crates/shielded_token/src/masp/shielded_sync/utils.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ impl TrialDecrypted {
233233
pub fn is_empty(&self) -> bool {
234234
self.inner.is_empty()
235235
}
236+
237+
/// Check if the tx with [`MaspIndexedTx`] was successfully decrypted
238+
pub fn has_indexed_tx(&self, ix: &MaspIndexedTx) -> bool {
239+
self.inner.contains_key(ix)
240+
}
236241
}
237242

238243
/// A cache of fetched indexed transactions.

crates/shielded_token/src/masp/shielded_wallet.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use namada_wallet::{DatedKeypair, DatedSpendingKey};
4747
use rand::prelude::StdRng;
4848
use rand_core::{OsRng, SeedableRng};
4949

50-
use super::utils::MaspIndexedTx;
50+
use super::utils::{MaspIndexedTx, TrialDecrypted};
5151
use crate::masp::utils::MaspClient;
5252
use crate::masp::{
5353
ContextSyncStatus, Conversions, MaspAmount, MaspDataLogEntry, MaspFeeData,
@@ -146,6 +146,7 @@ impl<U: ShieldedUtils + MaybeSend + MaybeSync> ShieldedWallet<U> {
146146
&mut self,
147147
masp_indexed_tx: MaspIndexedTx,
148148
shielded: &Transaction,
149+
trial_decrypted: &TrialDecrypted,
149150
) -> Result<(), eyre::Error> {
150151
let mut note_pos = self.tree.size();
151152
self.note_index.insert(masp_indexed_tx, note_pos);
@@ -166,10 +167,13 @@ impl<U: ShieldedUtils + MaybeSend + MaybeSync> ShieldedWallet<U> {
166167
self.tree.append(node).map_err(|()| {
167168
eyre!("note commitment tree is full".to_string())
168169
})?;
169-
// Finally, make it easier to construct merkle paths to this new
170-
// note
171-
let witness = IncrementalWitness::<Node>::from_tree(&self.tree);
172-
self.witness_map.insert(note_pos, witness);
170+
171+
if trial_decrypted.has_indexed_tx(&masp_indexed_tx) {
172+
// Finally, make it easier to construct merkle paths to this new
173+
// notes that we own
174+
let witness = IncrementalWitness::<Node>::from_tree(&self.tree);
175+
self.witness_map.insert(note_pos, witness);
176+
}
173177
note_pos = checked!(note_pos + 1).unwrap();
174178
}
175179
Ok(())

0 commit comments

Comments
 (0)