From d43856aa76b55e239ac380ad42308b9acb19a401 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Sun, 6 Oct 2019 11:38:20 -0700 Subject: [PATCH] Unroll witnesses during rollbacks properly --- src/lightwallet.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/lightwallet.rs b/src/lightwallet.rs index 3813a00..04ebc0e 100644 --- a/src/lightwallet.rs +++ b/src/lightwallet.rs @@ -791,7 +791,7 @@ impl LightWallet { } } - // Next, remove transactions + // Next, remove entire transactions { let mut txs = self.txs.write().unwrap(); let txids_to_remove = txs.values() @@ -818,8 +818,21 @@ impl LightWallet { }) }) } + + // Of the notes that still remain, unroll the witness. + // Remove `num_invalidated` items from the witness + { + let mut txs = self.txs.write().unwrap(); + + // Trim all witnesses for the invalidated blocks + for tx in txs.values_mut() { + for nd in tx.notes.iter_mut() { + nd.witnesses.split_off(nd.witnesses.len().saturating_sub(num_invalidated)); + } + } + } - num_invalidated + num_invalidated as u64 } // Scan a block. Will return an error with the block height that failed to scan