wallet: Add assertions during Orchard wallet bundle appends
`Wallet::append_bundle_commitments` should never be called twice on the same bundle, as that breaks sequentiality requirements (which we already check for), so it is safe to assert that the inserted values do not overwrite any existing data.
This commit is contained in:
parent
838f1cccec
commit
b3b5429956
|
@ -584,13 +584,16 @@ impl Wallet {
|
||||||
let my_notes_for_tx = self.wallet_received_notes.get(txid);
|
let my_notes_for_tx = self.wallet_received_notes.get(txid);
|
||||||
if my_notes_for_tx.is_some() {
|
if my_notes_for_tx.is_some() {
|
||||||
tracing::trace!("Tx is ours, marking as mined");
|
tracing::trace!("Tx is ours, marking as mined");
|
||||||
self.wallet_note_positions.insert(
|
assert!(self
|
||||||
*txid,
|
.wallet_note_positions
|
||||||
NotePositions {
|
.insert(
|
||||||
tx_height: block_height,
|
*txid,
|
||||||
note_positions: BTreeMap::default(),
|
NotePositions {
|
||||||
},
|
tx_height: block_height,
|
||||||
);
|
note_positions: BTreeMap::default(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (action_idx, action) in bundle.actions().iter().enumerate() {
|
for (action_idx, action) in bundle.actions().iter().enumerate() {
|
||||||
|
@ -610,23 +613,28 @@ impl Wallet {
|
||||||
{
|
{
|
||||||
tracing::trace!("Witnessing Orchard note ({}, {})", txid, action_idx);
|
tracing::trace!("Witnessing Orchard note ({}, {})", txid, action_idx);
|
||||||
let pos = self.witness_tree.witness().expect("tree is not empty");
|
let pos = self.witness_tree.witness().expect("tree is not empty");
|
||||||
self.wallet_note_positions
|
assert!(self
|
||||||
|
.wallet_note_positions
|
||||||
.get_mut(txid)
|
.get_mut(txid)
|
||||||
.expect("We created this above")
|
.expect("We created this above")
|
||||||
.note_positions
|
.note_positions
|
||||||
.insert(action_idx, pos);
|
.insert(action_idx, pos)
|
||||||
|
.is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
// For nullifiers that are ours that we detect as spent by this action,
|
// For nullifiers that are ours that we detect as spent by this action,
|
||||||
// we will record that input as being mined.
|
// we will record that input as being mined.
|
||||||
if let Some(outpoint) = self.nullifiers.get(action.nullifier()) {
|
if let Some(outpoint) = self.nullifiers.get(action.nullifier()) {
|
||||||
self.mined_notes.insert(
|
assert!(self
|
||||||
*outpoint,
|
.mined_notes
|
||||||
InPoint {
|
.insert(
|
||||||
txid: *txid,
|
*outpoint,
|
||||||
action_idx,
|
InPoint {
|
||||||
},
|
txid: *txid,
|
||||||
);
|
action_idx,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.is_none());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue