fix(lite-backend): keep witnesses current for notes in a pending send
Notes spent by a send still in the mempool stopped getting witness updates. After a restart (pending flags are not saved), or a reorg that un-mined the send, those notes were spendable again but with stale witnesses, so the next send from them used an anchor that is not on chain and failed until a rescan. Deterministic note selection made this sticky: the stale note was picked every time it was the best fit. Witnesses now advance for every note that is not spent on chain, pending or not. Witness clearing still keys on the mined spend only, so pending notes are never cleared. The wallet file format is unchanged; an old build reading a file written while a send was pending can now spend from it (verified offline). The oracle reloads and reorgs inside the pending window and compares every unspent note's witnesses byte for byte; reverting the fix fails 9 tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+4
-3
@@ -424,8 +424,9 @@ impl Chain {
|
||||
}
|
||||
}
|
||||
|
||||
/// T0: for every live note (L entries, B retained blocks) assert L <= 100, L <= B and, for k in
|
||||
/// {0, 1, L-1}, witnesses[L-1-k].root() == blocks[B-1-k].tree.root(): the anchor at offset k.
|
||||
/// T0: for every unspent note, pending ones included (L entries, B retained blocks) assert L <= 100,
|
||||
/// L <= B and, for k in {0, 1, L-1}, witnesses[L-1-k].root() == blocks[B-1-k].tree.root(): the
|
||||
/// anchor at offset k.
|
||||
fn check_anchor_alignment(w: &LightWallet, ctx: &str) -> usize {
|
||||
let blocks = w.blocks.read().unwrap();
|
||||
let b = blocks.len();
|
||||
@@ -433,7 +434,7 @@ fn check_anchor_alignment(w: &LightWallet, ctx: &str) -> usize {
|
||||
let mut checked = 0;
|
||||
for tx in txs.values() {
|
||||
for nd in tx.notes.iter() {
|
||||
if nd.spent.is_some() || nd.unconfirmed_spent.is_some() {
|
||||
if nd.spent.is_some() {
|
||||
continue;
|
||||
}
|
||||
let l = nd.witnesses.len();
|
||||
|
||||
Reference in New Issue
Block a user