Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions lightning/src/ln/chanmon_update_fail_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

use crate::chain::chaininterface::LowerBoundedFeeEstimator;
use crate::chain::chainmonitor::ChainMonitor;
use crate::chain::channelmonitor::{ChannelMonitor, MonitorEvent, ANTI_REORG_DELAY};
use crate::chain::channelmonitor::{
ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, MonitorEvent, ANTI_REORG_DELAY,
};
use crate::chain::transaction::OutPoint;
use crate::chain::{ChannelMonitorUpdateStatus, Listen, Watch};
use crate::events::{ClosureReason, Event, HTLCHandlingFailureType, PaymentPurpose};
Expand Down Expand Up @@ -2710,6 +2712,7 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
check_added_monitors!(nodes[0], 1);

nodes[1].node.handle_update_add_htlc(node_a_id, &send.msgs[0]);
assert_eq!(send.msgs[0].payment_hash, payment_hash_1);
nodes[1].node.handle_commitment_signed_batch_test(node_a_id, &send.commitment_msg);
check_added_monitors!(nodes[1], 1);

Expand Down Expand Up @@ -2773,6 +2776,28 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
if reload_a {
// The two pending monitor updates were replayed (but are still pending).
check_added_monitors(&nodes[0], 2);
check_latest_n_monitor_updates(
&nodes[0],
chan_id,
2,
|upd_idx, upd: &ChannelMonitorUpdate| {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it simpler to just return the updates, and do this matching afterwards instead of using the closure?

assert_eq!(upd.updates.len(), 1);
match upd_idx {
0 => {
matches!(upd.updates[0],
ChannelMonitorUpdateStep::PaymentPreimage { payment_preimage, .. }
if payment_preimage == payment_preimage_0)
},
1 => {
matches!(
upd.updates[0],
ChannelMonitorUpdateStep::CommitmentSecret { .. }
)
},
_ => panic!(),
}
},
);
} else {
// There should be no monitor updates as we are still pending awaiting a failed one.
check_added_monitors(&nodes[0], 0);
Expand Down Expand Up @@ -2810,6 +2835,7 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
expect_payment_sent(&nodes[1], payment_preimage_0, None, false, false);
assert_eq!(updates.update_add_htlcs.len(), 1);
nodes[1].node.handle_update_add_htlc(node_a_id, &updates.update_add_htlcs[0]);
assert_eq!(updates.update_add_htlcs[0].payment_hash, payment_hash_2);
updates.commitment_signed
},
_ => panic!("Unexpected event type!"),
Expand All @@ -2829,7 +2855,9 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
let events = nodes[1].node.get_and_clear_pending_events();
assert_eq!(events.len(), 1);
match events[0] {
Event::PaymentPathSuccessful { .. } => {},
Event::PaymentPathSuccessful { payment_hash, .. } => {
assert_eq!(payment_hash.unwrap(), payment_hash_0);
},
_ => panic!("Unexpected event"),
};

Expand Down
22 changes: 20 additions & 2 deletions lightning/src/ln/functional_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! A bunch of useful utilities for building networks of nodes and exchanging messages between
//! nodes for functional tests.

use crate::chain::channelmonitor::ChannelMonitor;
use crate::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate};
use crate::chain::transaction::OutPoint;
use crate::chain::{BestBlock, ChannelMonitorUpdateStatus, Confirm, Listen, Watch};
use crate::events::bump_transaction::sync::{
Expand Down Expand Up @@ -1285,6 +1285,24 @@ pub fn check_added_monitors<CM: AChannelManager, H: NodeHolder<CM = CM>>(node: &
}
}

// Check whether the latest monitor updates added are as-expected.
pub fn check_latest_n_monitor_updates<CM: AChannelManager, H: NodeHolder<CM = CM>, F>(
node: &H, channel_id: ChannelId, n: usize, matches: F,
) where
F: Fn(usize, &ChannelMonitorUpdate) -> bool,
{
if let Some(chain_monitor) = node.chain_monitor() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let chain_monitor = node.chain_monitor().expect("Missing chain monitor"); ?

let updates = chain_monitor.monitor_updates.lock().unwrap();
let chan_updates = updates.get(&channel_id).unwrap();
assert!(chan_updates.len() >= n, "Expected at least {n} updates, got {}", updates.len());
for (idx, update) in chan_updates.iter().rev().take(n).rev().enumerate() {
assert!(matches(idx, update));
}
} else {
panic!()
}
}

/// Check whether N channel monitor(s) have been added.
///
/// Don't use this, use the identically-named function instead.
Expand Down Expand Up @@ -3042,7 +3060,7 @@ pub fn expect_payment_sent<CM: AChannelManager, H: NodeHolder<CM = CM>>(
bitcoin::hashes::sha256::Hash::hash(&expected_payment_preimage.0).to_byte_array(),
);
if expect_per_path_claims {
assert!(events.len() > 1);
assert!(events.len() > 1, "Expected more than 1 event for per-path claims, got {events:?}");
} else {
assert_eq!(events.len(), 1);
}
Expand Down