Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
41 changes: 38 additions & 3 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 All @@ -2839,10 +2867,17 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_1);
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage_2);
}

#[test]
fn channel_holding_cell_serialize() {
fn channel_holding_cell_serialize_with_disconnect_and_reload() {
do_channel_holding_cell_serialize(true, true);
}
#[test]
fn channel_holding_cell_serialize_with_disconnect() {
do_channel_holding_cell_serialize(true, false);
}
#[test]
fn channel_holding_cell_serialize() {
do_channel_holding_cell_serialize(false, true); // last arg doesn't matter
}

Expand Down
27 changes: 26 additions & 1 deletion lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use crate::ln::channel_state::{
};
use crate::ln::channelmanager::{
self, ChannelReadyOrder, FundingConfirmedMessage, HTLCFailureMsg, HTLCSource,
OpenChannelMessage, PaymentClaimDetails, PendingHTLCInfo, PendingHTLCStatus,
OpenChannelMessage, PaymentClaimDetails, PaymentId, PendingHTLCInfo, PendingHTLCStatus,
RAACommitmentOrder, SentHTLCId, BREAKDOWN_TIMEOUT, MAX_LOCAL_BREAKDOWN_TIMEOUT,
MIN_CLTV_EXPIRY_DELTA,
};
Expand All @@ -72,6 +72,7 @@ use crate::ln::types::ChannelId;
use crate::ln::LN_MAX_MSG_LEN;
use crate::offers::static_invoice::StaticInvoice;
use crate::routing::gossip::NodeId;
use crate::routing::router::Path;
use crate::sign::ecdsa::EcdsaChannelSigner;
use crate::sign::tx_builder::{HTLCAmountDirection, NextCommitmentStats, SpecTxBuilder, TxBuilder};
use crate::sign::{ChannelSigner, EntropySource, NodeSigner, Recipient, SignerProvider};
Expand Down Expand Up @@ -12616,6 +12617,30 @@ where
Ok(true)
}

pub(super) fn get_all_outbound_holding_cell_htlcs(
&self,
) -> Vec<(PaymentId, PaymentHash, [u8; 32], Path)> {
let mut htlcs = Vec::new();
for htlc in self.context.holding_cell_htlc_updates.iter() {
match htlc {
HTLCUpdateAwaitingACK::AddHTLC {
payment_hash,
source: HTLCSource::OutboundRoute { path, session_priv, payment_id, .. },
..
} => {
htlcs.push((
*payment_id,
*payment_hash,
session_priv.secret_bytes(),
path.clone(),
));
},
_ => {},
}
}
htlcs

Choose a reason for hiding this comment

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

Any reason to worry about inefficiency of the copy? I don't know if this could be references too.

}

#[rustfmt::skip]
pub(super) fn get_available_balances<F: Deref>(
&self, fee_estimator: &LowerBoundedFeeEstimator<F>,
Expand Down
Loading
Loading