Skip to content

Commit 524e842

Browse files
author
Antoine Riard
committed
Assert on correct registeration of outputs index
1 parent 720c796 commit 524e842

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,6 +1772,20 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
17721772
let idx_and_scripts = txouts.iter().map(|o| (o.0, o.1.script_pubkey.clone())).collect();
17731773
self.outputs_to_watch.insert(txid.clone(), idx_and_scripts).is_none()
17741774
});
1775+
#[cfg(test)]
1776+
{
1777+
// If we see a transaction for which we registered outputs previously,
1778+
// make sure the registered scriptpubkey at the expected index match
1779+
// the actual transaction output one. We failed this case before #653.
1780+
for tx in &txn_matched {
1781+
if let Some(outputs) = self.get_outputs_to_watch().get(&tx.txid()) {
1782+
for (idx, idx_and_script) in outputs.iter().enumerate() {
1783+
assert!(idx < tx.output.len());
1784+
assert_eq!(tx.output[idx].script_pubkey, idx_and_script.1);
1785+
}
1786+
}
1787+
}
1788+
}
17751789
watch_outputs
17761790
}
17771791

0 commit comments

Comments
 (0)