Merged
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
5 changes: 2 additions & 3 deletions lightning-persister/src/test_utils.rs
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
use lightning::check_closed_broadcast;
use lightning::events::ClosureReason;
use lightning::ln::functional_test_utils::*;
use lightning::util::persist::{
Expand DownExpand Up@@ -188,7 +187,7 @@ pub(crate) fn do_test_store<K: KVStoreSync + Sync>(store_0: &K, store_1: &K) {
.unwrap();
let reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true), message };
check_closed_event(&nodes[0], 1, reason, &[node_b_id], 100000);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);
check_added_monitors(&nodes[0], 1);

let node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
Expand All@@ -202,7 +201,7 @@ pub(crate) fn do_test_store<K: KVStoreSync + Sync>(store_0: &K, store_1: &K) {
vec![node_txn[0].clone(), node_txn[0].clone()],
),
);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
let reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, reason, &[nodes[0].node.get_our_node_id()], 100000);
check_added_monitors(&nodes[1], 1);
Expand Down
3 changes: 2 additions & 1 deletion lightning/src/ln/accountable_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,7 +26,8 @@ fn test_accountable_forwarding_with_override(
let _chan_ab = create_announced_chan_between_nodes(&nodes, 0, 1);
let _chan_bc = create_announced_chan_between_nodes(&nodes, 1, 2);

let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);
let (payment_preimage, payment_hash, payment_secret) =
get_payment_preimage_hash(&nodes[2], None, None);
let route_params = RouteParameters::from_payment_params_and_value(
PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV),
100_000,
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/async_signer_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1308,9 +1308,9 @@ fn do_test_closing_signed(extra_closing_signed: bool, reconnect: bool) {
}

nodes[0].node.signer_unblocked(None);
let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast!(nodes[0].node, node_b_id);
let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast(&nodes[0], node_b_id);
nodes[1].node.handle_closing_signed(node_a_id, &node_0_2nd_closing_signed.unwrap());
let (_, node_1_closing_signed) = get_closing_signed_broadcast!(nodes[1].node, node_a_id);
let (_, node_1_closing_signed) = get_closing_signed_broadcast(&nodes[1], node_a_id);
assert!(node_1_closing_signed.is_none());

assert!(nodes[0].node.list_channels().is_empty());
Expand Down
29 changes: 15 additions & 14 deletions lightning/src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -277,7 +277,7 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool) {
};
nodes[0].node.force_close_broadcasting_latest_txn(&channel_id, &node_b_id, message).unwrap();
check_added_monitors(&nodes[0], 1);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);

// TODO: Once we hit the chain with the failure transaction we should check that we get a
// PaymentPathFailed event
Expand DownExpand Up@@ -1382,9 +1382,9 @@ fn raa_no_response_awaiting_raa_state() {
let (route, payment_hash_1, payment_preimage_1, payment_secret_1) =
get_route_and_payment_hash!(nodes[0], nodes[1], 1000000);
let (payment_preimage_2, payment_hash_2, payment_secret_2) =
get_payment_preimage_hash!(nodes[1]);
get_payment_preimage_hash(&nodes[1], None, None);
let (payment_preimage_3, payment_hash_3, payment_secret_3) =
get_payment_preimage_hash!(nodes[1]);
get_payment_preimage_hash(&nodes[1], None, None);

// Queue up two payments - one will be delivered right away, one immediately goes into the
// holding cell as nodes[0] is AwaitingRAA. Ultimately this allows us to deliver an RAA
Expand DownExpand Up@@ -1872,7 +1872,7 @@ fn test_monitor_update_fail_claim() {
do_commitment_signed_dance(&nodes[1], &nodes[2], &payment_event.commitment_msg, false, true);
expect_htlc_failure_conditions(nodes[1].node.get_and_clear_pending_events(), &[]);

let (_, payment_hash_3, payment_secret_3) = get_payment_preimage_hash!(nodes[0]);
let (_, payment_hash_3, payment_secret_3) = get_payment_preimage_hash(&nodes[0], None, None);
let id_3 = PaymentId(payment_hash_3.0);
let onion_3 = RecipientOnionFields::secret_only(payment_secret_3);
nodes[2].node.send_payment_with_route(route, payment_hash_3, onion_3, id_3).unwrap();
Expand DownExpand Up@@ -2509,7 +2509,7 @@ fn test_fail_htlc_on_broadcast_after_claim() {
mine_transaction(&nodes[1], &bs_txn[0]);
let reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, reason, &[node_c_id], 100000);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1);
check_added_monitors(&nodes[1], 1);
expect_and_process_pending_htlcs_and_htlc_handling_failed(
Expand DownExpand Up@@ -2663,7 +2663,7 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
let (route, payment_hash_1, payment_preimage_1, payment_secret_1) =
get_route_and_payment_hash!(&nodes[0], nodes[1], 100000);
let (payment_preimage_2, payment_hash_2, payment_secret_2) =
get_payment_preimage_hash!(&nodes[1]);
get_payment_preimage_hash(&nodes[1], None, None);

// Do a really complicated dance to get an HTLC into the holding cell, with
// MonitorUpdateInProgress set but AwaitingRemoteRevoke unset. When this test was written, any
Expand DownExpand Up@@ -3048,11 +3048,11 @@ fn test_temporary_error_during_shutdown() {
node_b_id,
&get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, node_a_id),
);
let (_, closing_signed_a) = get_closing_signed_broadcast!(nodes[0].node, node_b_id);
let (_, closing_signed_a) = get_closing_signed_broadcast(&nodes[0], node_b_id);
let txn_a = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);

nodes[1].node.handle_closing_signed(node_a_id, &closing_signed_a.unwrap());
let (_, none_b) = get_closing_signed_broadcast!(nodes[1].node, node_a_id);
let (_, none_b) = get_closing_signed_broadcast(&nodes[1], node_a_id);
assert!(none_b.is_none());
let txn_b = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);

Expand DownExpand Up@@ -4043,7 +4043,7 @@ fn do_test_reload_mon_update_completion_actions(close_during_reload: bool) {
};
nodes[0].node.force_close_broadcasting_latest_txn(&chan_id_ab, &node_b_id, msg).unwrap();
check_added_monitors(&nodes[0], 1);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);
check_closed_event(&nodes[0], 1, reason, &[node_b_id], 100_000);
let as_closing_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
mine_transaction_without_consistency_checks(&nodes[1], &as_closing_tx[0]);
Expand DownExpand Up@@ -4494,13 +4494,13 @@ fn test_claim_to_closed_channel_blocks_forwarded_preimage_removal() {
check_added_monitors(&nodes[0], 1);
let a_reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true), message };
check_closed_event(&nodes[0], 1, a_reason, &[node_b_id], 1000000);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);

let as_commit_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
assert_eq!(as_commit_tx.len(), 1);

mine_transaction(&nodes[1], &as_commit_tx[0]);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
check_added_monitors(&nodes[1], 1);
let b_reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, b_reason, &[node_a_id], 1000000);
Expand DownExpand Up@@ -4572,13 +4572,13 @@ fn test_claim_to_closed_channel_blocks_claimed_event() {
check_added_monitors(&nodes[0], 1);
let a_reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true), message };
check_closed_event(&nodes[0], 1, a_reason, &[node_b_id], 1000000);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);

let as_commit_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
assert_eq!(as_commit_tx.len(), 1);

mine_transaction(&nodes[1], &as_commit_tx[0]);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
check_added_monitors(&nodes[1], 1);
let b_reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, b_reason, &[node_a_id], 1000000);
Expand DownExpand Up@@ -5099,7 +5099,8 @@ fn test_mpp_claim_to_holding_cell() {
send_along_route_with_secret(&nodes[0], route, paths, 500_000, paymnt_hash_1, payment_secret);

// Put the C <-> D channel into AwaitingRaa
let (preimage_2, paymnt_hash_2, payment_secret_2) = get_payment_preimage_hash!(nodes[3]);
let (preimage_2, paymnt_hash_2, payment_secret_2) =
get_payment_preimage_hash(&nodes[3], None, None);
let onion = RecipientOnionFields::secret_only(payment_secret_2);
let id = PaymentId([42; 32]);
let pay_params = PaymentParameters::from_node_id(node_d_id, TEST_FINAL_CLTV);
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -20522,7 +20522,7 @@ mod tests {
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);

let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(&nodes[0]);
let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[0], None, None);
let payment_data = msgs::FinalOnionHopData {
payment_secret,
total_msat: 100_000,
Expand Down
87 changes: 28 additions & 59 deletions lightning/src/ln/functional_test_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2210,31 +2210,31 @@ macro_rules! check_spends {
}
}

macro_rules! get_closing_signed_broadcast {
($node: expr, $dest_pubkey: expr) => {{
let events = $node.get_and_clear_pending_msg_events();
assert!(events.len() == 1 || events.len() == 2);
(
match events[events.len() - 1] {
MessageSendEvent::BroadcastChannelUpdate { ref msg, .. } => {
assert_eq!(msg.contents.channel_flags & 2, 2);
msg.clone()
pub fn get_closing_signed_broadcast(
node: &Node, dest_pubkey: PublicKey,
) -> (msgs::ChannelUpdate, Option<msgs::ClosingSigned>) {
let events = node.node.get_and_clear_pending_msg_events();
assert!(events.len() == 1 || events.len() == 2);
(
match events[events.len() - 1] {
MessageSendEvent::BroadcastChannelUpdate { ref msg, .. } => {
assert_eq!(msg.contents.channel_flags & 2, 2);
msg.clone()
},
_ => panic!("Unexpected event"),
},
if events.len() == 2 {
match events[0] {
MessageSendEvent::SendClosingSigned { ref node_id, ref msg } => {
assert_eq!(*node_id, dest_pubkey);
Some(msg.clone())
},
_ => panic!("Unexpected event"),
},
if events.len() == 2 {
match events[0] {
MessageSendEvent::SendClosingSigned { ref node_id, ref msg } => {
assert_eq!(*node_id, $dest_pubkey);
Some(msg.clone())
},
_ => panic!("Unexpected event"),
}
} else {
None
},
)
}};
}
} else {
None
},
)
}

#[cfg(test)]
Expand DownExpand Up@@ -2313,17 +2313,6 @@ pub fn check_closed_broadcast(
.collect()
}

/// Check that a channel's closing channel update has been broadcasted, and optionally
/// check whether an error message event has occurred.
///
/// Don't use this, use the identically-named function instead.
#[macro_export]
macro_rules! check_closed_broadcast {
($node: expr, $with_error_msg: expr) => {
$crate::ln::functional_test_utils::check_closed_broadcast(&$node, 1, $with_error_msg).pop()
};
}

#[derive(Default)]
pub struct ExpectedCloseEvent {
pub channel_capacity_sats: Option<u64>,
Expand DownExpand Up@@ -2530,10 +2519,10 @@ pub fn close_channel<'a, 'b, 'c>(
assert_eq!(broadcaster_b.txn_broadcasted.lock().unwrap().len(), 1);
tx_b = broadcaster_b.txn_broadcasted.lock().unwrap().remove(0);
let (bs_update, closing_signed_b) =
get_closing_signed_broadcast!(node_b, node_a.get_our_node_id());
get_closing_signed_broadcast(struct_b, node_a.get_our_node_id());

node_a.handle_closing_signed(node_b.get_our_node_id(), &closing_signed_b.unwrap());
let (as_update, none_a) = get_closing_signed_broadcast!(node_a, node_b.get_our_node_id());
let (as_update, none_a) = get_closing_signed_broadcast(struct_a, node_b.get_our_node_id());
assert!(none_a.is_none());
assert_eq!(broadcaster_a.txn_broadcasted.lock().unwrap().len(), 1);
tx_a = broadcaster_a.txn_broadcasted.lock().unwrap().remove(0);
Expand All@@ -2550,10 +2539,10 @@ pub fn close_channel<'a, 'b, 'c>(
assert_eq!(broadcaster_a.txn_broadcasted.lock().unwrap().len(), 1);
tx_a = broadcaster_a.txn_broadcasted.lock().unwrap().remove(0);
let (as_update, closing_signed_a) =
get_closing_signed_broadcast!(node_a, node_b.get_our_node_id());
get_closing_signed_broadcast(struct_a, node_b.get_our_node_id());

node_b.handle_closing_signed(node_a.get_our_node_id(), &closing_signed_a.unwrap());
let (bs_update, none_b) = get_closing_signed_broadcast!(node_b, node_a.get_our_node_id());
let (bs_update, none_b) = get_closing_signed_broadcast(struct_b, node_a.get_our_node_id());
assert!(none_b.is_none());
assert_eq!(broadcaster_b.txn_broadcasted.lock().unwrap().len(), 1);
tx_b = broadcaster_b.txn_broadcasted.lock().unwrap().remove(0);
Expand DownExpand Up@@ -2829,26 +2818,6 @@ pub fn get_payment_preimage_hash(
(payment_preimage, payment_hash, payment_secret)
}

/// Get a payment preimage and hash.
///
/// Don't use this, use the identically-named function instead.
#[macro_export]
macro_rules! get_payment_preimage_hash {
($dest_node: expr) => {
get_payment_preimage_hash!($dest_node, None)
};
($dest_node: expr, $min_value_msat: expr) => {
$crate::get_payment_preimage_hash!($dest_node, $min_value_msat, None)
};
($dest_node: expr, $min_value_msat: expr, $min_final_cltv_expiry_delta: expr) => {
$crate::ln::functional_test_utils::get_payment_preimage_hash(
&$dest_node,
$min_value_msat,
$min_final_cltv_expiry_delta,
)
};
}

/// Gets a route from the given sender to the node described in `payment_params`.
pub fn get_route(send_node: &Node, route_params: &RouteParameters) -> Result<Route, &'static str> {
let scorer = TestScorer::new();
Expand DownExpand Up@@ -3820,7 +3789,7 @@ pub fn send_along_route<'a, 'b, 'c>(
recv_value: u64,
) -> (PaymentPreimage, PaymentHash, PaymentSecret, PaymentId) {
let (our_payment_preimage, our_payment_hash, our_payment_secret) =
get_payment_preimage_hash!(expected_route.last().unwrap());
get_payment_preimage_hash(expected_route.last().unwrap(), None, None);
let payment_id = send_along_route_with_secret(
origin_node,
route,
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
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
5 changes: 2 additions & 3 deletions lightning-persister/src/test_utils.rs
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
use lightning::check_closed_broadcast;
use lightning::events::ClosureReason;
use lightning::ln::functional_test_utils::*;
use lightning::util::persist::{
Expand DownExpand Up@@ -188,7 +187,7 @@ pub(crate) fn do_test_store<K: KVStoreSync + Sync>(store_0: &K, store_1: &K) {
.unwrap();
let reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true), message };
check_closed_event(&nodes[0], 1, reason, &[node_b_id], 100000);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);
check_added_monitors(&nodes[0], 1);

let node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
Expand All@@ -202,7 +201,7 @@ pub(crate) fn do_test_store<K: KVStoreSync + Sync>(store_0: &K, store_1: &K) {
vec![node_txn[0].clone(), node_txn[0].clone()],
),
);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
let reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, reason, &[nodes[0].node.get_our_node_id()], 100000);
check_added_monitors(&nodes[1], 1);
Expand Down
3 changes: 2 additions & 1 deletion lightning/src/ln/accountable_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,7 +26,8 @@ fn test_accountable_forwarding_with_override(
let _chan_ab = create_announced_chan_between_nodes(&nodes, 0, 1);
let _chan_bc = create_announced_chan_between_nodes(&nodes, 1, 2);

let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);
let (payment_preimage, payment_hash, payment_secret) =
get_payment_preimage_hash(&nodes[2], None, None);
let route_params = RouteParameters::from_payment_params_and_value(
PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV),
100_000,
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/async_signer_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1308,9 +1308,9 @@ fn do_test_closing_signed(extra_closing_signed: bool, reconnect: bool) {
}

nodes[0].node.signer_unblocked(None);
let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast!(nodes[0].node, node_b_id);
let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast(&nodes[0], node_b_id);
nodes[1].node.handle_closing_signed(node_a_id, &node_0_2nd_closing_signed.unwrap());
let (_, node_1_closing_signed) = get_closing_signed_broadcast!(nodes[1].node, node_a_id);
let (_, node_1_closing_signed) = get_closing_signed_broadcast(&nodes[1], node_a_id);
assert!(node_1_closing_signed.is_none());

assert!(nodes[0].node.list_channels().is_empty());
Expand Down
29 changes: 15 additions & 14 deletions lightning/src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -277,7 +277,7 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool) {
};
nodes[0].node.force_close_broadcasting_latest_txn(&channel_id, &node_b_id, message).unwrap();
check_added_monitors(&nodes[0], 1);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);

// TODO: Once we hit the chain with the failure transaction we should check that we get a
// PaymentPathFailed event
Expand DownExpand Up@@ -1382,9 +1382,9 @@ fn raa_no_response_awaiting_raa_state() {
let (route, payment_hash_1, payment_preimage_1, payment_secret_1) =
get_route_and_payment_hash!(nodes[0], nodes[1], 1000000);
let (payment_preimage_2, payment_hash_2, payment_secret_2) =
get_payment_preimage_hash!(nodes[1]);
get_payment_preimage_hash(&nodes[1], None, None);
let (payment_preimage_3, payment_hash_3, payment_secret_3) =
get_payment_preimage_hash!(nodes[1]);
get_payment_preimage_hash(&nodes[1], None, None);

// Queue up two payments - one will be delivered right away, one immediately goes into the
// holding cell as nodes[0] is AwaitingRAA. Ultimately this allows us to deliver an RAA
Expand DownExpand Up@@ -1872,7 +1872,7 @@ fn test_monitor_update_fail_claim() {
do_commitment_signed_dance(&nodes[1], &nodes[2], &payment_event.commitment_msg, false, true);
expect_htlc_failure_conditions(nodes[1].node.get_and_clear_pending_events(), &[]);

let (_, payment_hash_3, payment_secret_3) = get_payment_preimage_hash!(nodes[0]);
let (_, payment_hash_3, payment_secret_3) = get_payment_preimage_hash(&nodes[0], None, None);
let id_3 = PaymentId(payment_hash_3.0);
let onion_3 = RecipientOnionFields::secret_only(payment_secret_3);
nodes[2].node.send_payment_with_route(route, payment_hash_3, onion_3, id_3).unwrap();
Expand DownExpand Up@@ -2509,7 +2509,7 @@ fn test_fail_htlc_on_broadcast_after_claim() {
mine_transaction(&nodes[1], &bs_txn[0]);
let reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, reason, &[node_c_id], 100000);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1);
check_added_monitors(&nodes[1], 1);
expect_and_process_pending_htlcs_and_htlc_handling_failed(
Expand DownExpand Up@@ -2663,7 +2663,7 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
let (route, payment_hash_1, payment_preimage_1, payment_secret_1) =
get_route_and_payment_hash!(&nodes[0], nodes[1], 100000);
let (payment_preimage_2, payment_hash_2, payment_secret_2) =
get_payment_preimage_hash!(&nodes[1]);
get_payment_preimage_hash(&nodes[1], None, None);

// Do a really complicated dance to get an HTLC into the holding cell, with
// MonitorUpdateInProgress set but AwaitingRemoteRevoke unset. When this test was written, any
Expand DownExpand Up@@ -3048,11 +3048,11 @@ fn test_temporary_error_during_shutdown() {
node_b_id,
&get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, node_a_id),
);
let (_, closing_signed_a) = get_closing_signed_broadcast!(nodes[0].node, node_b_id);
let (_, closing_signed_a) = get_closing_signed_broadcast(&nodes[0], node_b_id);
let txn_a = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);

nodes[1].node.handle_closing_signed(node_a_id, &closing_signed_a.unwrap());
let (_, none_b) = get_closing_signed_broadcast!(nodes[1].node, node_a_id);
let (_, none_b) = get_closing_signed_broadcast(&nodes[1], node_a_id);
assert!(none_b.is_none());
let txn_b = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);

Expand DownExpand Up@@ -4043,7 +4043,7 @@ fn do_test_reload_mon_update_completion_actions(close_during_reload: bool) {
};
nodes[0].node.force_close_broadcasting_latest_txn(&chan_id_ab, &node_b_id, msg).unwrap();
check_added_monitors(&nodes[0], 1);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);
check_closed_event(&nodes[0], 1, reason, &[node_b_id], 100_000);
let as_closing_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
mine_transaction_without_consistency_checks(&nodes[1], &as_closing_tx[0]);
Expand DownExpand Up@@ -4494,13 +4494,13 @@ fn test_claim_to_closed_channel_blocks_forwarded_preimage_removal() {
check_added_monitors(&nodes[0], 1);
let a_reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true), message };
check_closed_event(&nodes[0], 1, a_reason, &[node_b_id], 1000000);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);

let as_commit_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
assert_eq!(as_commit_tx.len(), 1);

mine_transaction(&nodes[1], &as_commit_tx[0]);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
check_added_monitors(&nodes[1], 1);
let b_reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, b_reason, &[node_a_id], 1000000);
Expand DownExpand Up@@ -4572,13 +4572,13 @@ fn test_claim_to_closed_channel_blocks_claimed_event() {
check_added_monitors(&nodes[0], 1);
let a_reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true), message };
check_closed_event(&nodes[0], 1, a_reason, &[node_b_id], 1000000);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);

let as_commit_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
assert_eq!(as_commit_tx.len(), 1);

mine_transaction(&nodes[1], &as_commit_tx[0]);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
check_added_monitors(&nodes[1], 1);
let b_reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, b_reason, &[node_a_id], 1000000);
Expand DownExpand Up@@ -5099,7 +5099,8 @@ fn test_mpp_claim_to_holding_cell() {
send_along_route_with_secret(&nodes[0], route, paths, 500_000, paymnt_hash_1, payment_secret);

// Put the C <-> D channel into AwaitingRaa
let (preimage_2, paymnt_hash_2, payment_secret_2) = get_payment_preimage_hash!(nodes[3]);
let (preimage_2, paymnt_hash_2, payment_secret_2) =
get_payment_preimage_hash(&nodes[3], None, None);
let onion = RecipientOnionFields::secret_only(payment_secret_2);
let id = PaymentId([42; 32]);
let pay_params = PaymentParameters::from_node_id(node_d_id, TEST_FINAL_CLTV);
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -20522,7 +20522,7 @@ mod tests {
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);

let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(&nodes[0]);
let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[0], None, None);
let payment_data = msgs::FinalOnionHopData {
payment_secret,
total_msat: 100_000,
Expand Down
87 changes: 28 additions & 59 deletions lightning/src/ln/functional_test_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2210,31 +2210,31 @@ macro_rules! check_spends {
}
}

macro_rules! get_closing_signed_broadcast {
($node: expr, $dest_pubkey: expr) => {{
let events = $node.get_and_clear_pending_msg_events();
assert!(events.len() == 1 || events.len() == 2);
(
match events[events.len() - 1] {
MessageSendEvent::BroadcastChannelUpdate { ref msg, .. } => {
assert_eq!(msg.contents.channel_flags & 2, 2);
msg.clone()
pub fn get_closing_signed_broadcast(
node: &Node, dest_pubkey: PublicKey,
) -> (msgs::ChannelUpdate, Option<msgs::ClosingSigned>) {
let events = node.node.get_and_clear_pending_msg_events();
assert!(events.len() == 1 || events.len() == 2);
(
match events[events.len() - 1] {
MessageSendEvent::BroadcastChannelUpdate { ref msg, .. } => {
assert_eq!(msg.contents.channel_flags & 2, 2);
msg.clone()
},
_ => panic!("Unexpected event"),
},
if events.len() == 2 {
match events[0] {
MessageSendEvent::SendClosingSigned { ref node_id, ref msg } => {
assert_eq!(*node_id, dest_pubkey);
Some(msg.clone())
},
_ => panic!("Unexpected event"),
},
if events.len() == 2 {
match events[0] {
MessageSendEvent::SendClosingSigned { ref node_id, ref msg } => {
assert_eq!(*node_id, $dest_pubkey);
Some(msg.clone())
},
_ => panic!("Unexpected event"),
}
} else {
None
},
)
}};
}
} else {
None
},
)
}

#[cfg(test)]
Expand DownExpand Up@@ -2313,17 +2313,6 @@ pub fn check_closed_broadcast(
.collect()
}

/// Check that a channel's closing channel update has been broadcasted, and optionally
/// check whether an error message event has occurred.
///
/// Don't use this, use the identically-named function instead.
#[macro_export]
macro_rules! check_closed_broadcast {
($node: expr, $with_error_msg: expr) => {
$crate::ln::functional_test_utils::check_closed_broadcast(&$node, 1, $with_error_msg).pop()
};
}

#[derive(Default)]
pub struct ExpectedCloseEvent {
pub channel_capacity_sats: Option<u64>,
Expand DownExpand Up@@ -2530,10 +2519,10 @@ pub fn close_channel<'a, 'b, 'c>(
assert_eq!(broadcaster_b.txn_broadcasted.lock().unwrap().len(), 1);
tx_b = broadcaster_b.txn_broadcasted.lock().unwrap().remove(0);
let (bs_update, closing_signed_b) =
get_closing_signed_broadcast!(node_b, node_a.get_our_node_id());
get_closing_signed_broadcast(struct_b, node_a.get_our_node_id());

node_a.handle_closing_signed(node_b.get_our_node_id(), &closing_signed_b.unwrap());
let (as_update, none_a) = get_closing_signed_broadcast!(node_a, node_b.get_our_node_id());
let (as_update, none_a) = get_closing_signed_broadcast(struct_a, node_b.get_our_node_id());
assert!(none_a.is_none());
assert_eq!(broadcaster_a.txn_broadcasted.lock().unwrap().len(), 1);
tx_a = broadcaster_a.txn_broadcasted.lock().unwrap().remove(0);
Expand All@@ -2550,10 +2539,10 @@ pub fn close_channel<'a, 'b, 'c>(
assert_eq!(broadcaster_a.txn_broadcasted.lock().unwrap().len(), 1);
tx_a = broadcaster_a.txn_broadcasted.lock().unwrap().remove(0);
let (as_update, closing_signed_a) =
get_closing_signed_broadcast!(node_a, node_b.get_our_node_id());
get_closing_signed_broadcast(struct_a, node_b.get_our_node_id());

node_b.handle_closing_signed(node_a.get_our_node_id(), &closing_signed_a.unwrap());
let (bs_update, none_b) = get_closing_signed_broadcast!(node_b, node_a.get_our_node_id());
let (bs_update, none_b) = get_closing_signed_broadcast(struct_b, node_a.get_our_node_id());
assert!(none_b.is_none());
assert_eq!(broadcaster_b.txn_broadcasted.lock().unwrap().len(), 1);
tx_b = broadcaster_b.txn_broadcasted.lock().unwrap().remove(0);
Expand DownExpand Up@@ -2829,26 +2818,6 @@ pub fn get_payment_preimage_hash(
(payment_preimage, payment_hash, payment_secret)
}

/// Get a payment preimage and hash.
///
/// Don't use this, use the identically-named function instead.
#[macro_export]
macro_rules! get_payment_preimage_hash {
($dest_node: expr) => {
get_payment_preimage_hash!($dest_node, None)
};
($dest_node: expr, $min_value_msat: expr) => {
$crate::get_payment_preimage_hash!($dest_node, $min_value_msat, None)
};
($dest_node: expr, $min_value_msat: expr, $min_final_cltv_expiry_delta: expr) => {
$crate::ln::functional_test_utils::get_payment_preimage_hash(
&$dest_node,
$min_value_msat,
$min_final_cltv_expiry_delta,
)
};
}

/// Gets a route from the given sender to the node described in `payment_params`.
pub fn get_route(send_node: &Node, route_params: &RouteParameters) -> Result<Route, &'static str> {
let scorer = TestScorer::new();
Expand DownExpand Up@@ -3820,7 +3789,7 @@ pub fn send_along_route<'a, 'b, 'c>(
recv_value: u64,
) -> (PaymentPreimage, PaymentHash, PaymentSecret, PaymentId) {
let (our_payment_preimage, our_payment_hash, our_payment_secret) =
get_payment_preimage_hash!(expected_route.last().unwrap());
get_payment_preimage_hash(expected_route.last().unwrap(), None, None);
let payment_id = send_along_route_with_secret(
origin_node,
route,
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
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
5 changes: 2 additions & 3 deletions lightning-persister/src/test_utils.rs
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
use lightning::check_closed_broadcast;
use lightning::events::ClosureReason;
use lightning::ln::functional_test_utils::*;
use lightning::util::persist::{
Expand DownExpand Up@@ -188,7 +187,7 @@ pub(crate) fn do_test_store<K: KVStoreSync + Sync>(store_0: &K, store_1: &K) {
.unwrap();
let reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true), message };
check_closed_event(&nodes[0], 1, reason, &[node_b_id], 100000);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);
check_added_monitors(&nodes[0], 1);

let node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
Expand All@@ -202,7 +201,7 @@ pub(crate) fn do_test_store<K: KVStoreSync + Sync>(store_0: &K, store_1: &K) {
vec![node_txn[0].clone(), node_txn[0].clone()],
),
);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
let reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, reason, &[nodes[0].node.get_our_node_id()], 100000);
check_added_monitors(&nodes[1], 1);
Expand Down
3 changes: 2 additions & 1 deletion lightning/src/ln/accountable_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,7 +26,8 @@ fn test_accountable_forwarding_with_override(
let _chan_ab = create_announced_chan_between_nodes(&nodes, 0, 1);
let _chan_bc = create_announced_chan_between_nodes(&nodes, 1, 2);

let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);
let (payment_preimage, payment_hash, payment_secret) =
get_payment_preimage_hash(&nodes[2], None, None);
let route_params = RouteParameters::from_payment_params_and_value(
PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV),
100_000,
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/async_signer_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1308,9 +1308,9 @@ fn do_test_closing_signed(extra_closing_signed: bool, reconnect: bool) {
}

nodes[0].node.signer_unblocked(None);
let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast!(nodes[0].node, node_b_id);
let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast(&nodes[0], node_b_id);
nodes[1].node.handle_closing_signed(node_a_id, &node_0_2nd_closing_signed.unwrap());
let (_, node_1_closing_signed) = get_closing_signed_broadcast!(nodes[1].node, node_a_id);
let (_, node_1_closing_signed) = get_closing_signed_broadcast(&nodes[1], node_a_id);
assert!(node_1_closing_signed.is_none());

assert!(nodes[0].node.list_channels().is_empty());
Expand Down
29 changes: 15 additions & 14 deletions lightning/src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -277,7 +277,7 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool) {
};
nodes[0].node.force_close_broadcasting_latest_txn(&channel_id, &node_b_id, message).unwrap();
check_added_monitors(&nodes[0], 1);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);

// TODO: Once we hit the chain with the failure transaction we should check that we get a
// PaymentPathFailed event
Expand DownExpand Up@@ -1382,9 +1382,9 @@ fn raa_no_response_awaiting_raa_state() {
let (route, payment_hash_1, payment_preimage_1, payment_secret_1) =
get_route_and_payment_hash!(nodes[0], nodes[1], 1000000);
let (payment_preimage_2, payment_hash_2, payment_secret_2) =
get_payment_preimage_hash!(nodes[1]);
get_payment_preimage_hash(&nodes[1], None, None);
let (payment_preimage_3, payment_hash_3, payment_secret_3) =
get_payment_preimage_hash!(nodes[1]);
get_payment_preimage_hash(&nodes[1], None, None);

// Queue up two payments - one will be delivered right away, one immediately goes into the
// holding cell as nodes[0] is AwaitingRAA. Ultimately this allows us to deliver an RAA
Expand DownExpand Up@@ -1872,7 +1872,7 @@ fn test_monitor_update_fail_claim() {
do_commitment_signed_dance(&nodes[1], &nodes[2], &payment_event.commitment_msg, false, true);
expect_htlc_failure_conditions(nodes[1].node.get_and_clear_pending_events(), &[]);

let (_, payment_hash_3, payment_secret_3) = get_payment_preimage_hash!(nodes[0]);
let (_, payment_hash_3, payment_secret_3) = get_payment_preimage_hash(&nodes[0], None, None);
let id_3 = PaymentId(payment_hash_3.0);
let onion_3 = RecipientOnionFields::secret_only(payment_secret_3);
nodes[2].node.send_payment_with_route(route, payment_hash_3, onion_3, id_3).unwrap();
Expand DownExpand Up@@ -2509,7 +2509,7 @@ fn test_fail_htlc_on_broadcast_after_claim() {
mine_transaction(&nodes[1], &bs_txn[0]);
let reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, reason, &[node_c_id], 100000);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1);
check_added_monitors(&nodes[1], 1);
expect_and_process_pending_htlcs_and_htlc_handling_failed(
Expand DownExpand Up@@ -2663,7 +2663,7 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
let (route, payment_hash_1, payment_preimage_1, payment_secret_1) =
get_route_and_payment_hash!(&nodes[0], nodes[1], 100000);
let (payment_preimage_2, payment_hash_2, payment_secret_2) =
get_payment_preimage_hash!(&nodes[1]);
get_payment_preimage_hash(&nodes[1], None, None);

// Do a really complicated dance to get an HTLC into the holding cell, with
// MonitorUpdateInProgress set but AwaitingRemoteRevoke unset. When this test was written, any
Expand DownExpand Up@@ -3048,11 +3048,11 @@ fn test_temporary_error_during_shutdown() {
node_b_id,
&get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, node_a_id),
);
let (_, closing_signed_a) = get_closing_signed_broadcast!(nodes[0].node, node_b_id);
let (_, closing_signed_a) = get_closing_signed_broadcast(&nodes[0], node_b_id);
let txn_a = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);

nodes[1].node.handle_closing_signed(node_a_id, &closing_signed_a.unwrap());
let (_, none_b) = get_closing_signed_broadcast!(nodes[1].node, node_a_id);
let (_, none_b) = get_closing_signed_broadcast(&nodes[1], node_a_id);
assert!(none_b.is_none());
let txn_b = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);

Expand DownExpand Up@@ -4043,7 +4043,7 @@ fn do_test_reload_mon_update_completion_actions(close_during_reload: bool) {
};
nodes[0].node.force_close_broadcasting_latest_txn(&chan_id_ab, &node_b_id, msg).unwrap();
check_added_monitors(&nodes[0], 1);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);
check_closed_event(&nodes[0], 1, reason, &[node_b_id], 100_000);
let as_closing_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
mine_transaction_without_consistency_checks(&nodes[1], &as_closing_tx[0]);
Expand DownExpand Up@@ -4494,13 +4494,13 @@ fn test_claim_to_closed_channel_blocks_forwarded_preimage_removal() {
check_added_monitors(&nodes[0], 1);
let a_reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true), message };
check_closed_event(&nodes[0], 1, a_reason, &[node_b_id], 1000000);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);

let as_commit_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
assert_eq!(as_commit_tx.len(), 1);

mine_transaction(&nodes[1], &as_commit_tx[0]);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
check_added_monitors(&nodes[1], 1);
let b_reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, b_reason, &[node_a_id], 1000000);
Expand DownExpand Up@@ -4572,13 +4572,13 @@ fn test_claim_to_closed_channel_blocks_claimed_event() {
check_added_monitors(&nodes[0], 1);
let a_reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true), message };
check_closed_event(&nodes[0], 1, a_reason, &[node_b_id], 1000000);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);

let as_commit_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
assert_eq!(as_commit_tx.len(), 1);

mine_transaction(&nodes[1], &as_commit_tx[0]);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
check_added_monitors(&nodes[1], 1);
let b_reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, b_reason, &[node_a_id], 1000000);
Expand DownExpand Up@@ -5099,7 +5099,8 @@ fn test_mpp_claim_to_holding_cell() {
send_along_route_with_secret(&nodes[0], route, paths, 500_000, paymnt_hash_1, payment_secret);

// Put the C <-> D channel into AwaitingRaa
let (preimage_2, paymnt_hash_2, payment_secret_2) = get_payment_preimage_hash!(nodes[3]);
let (preimage_2, paymnt_hash_2, payment_secret_2) =
get_payment_preimage_hash(&nodes[3], None, None);
let onion = RecipientOnionFields::secret_only(payment_secret_2);
let id = PaymentId([42; 32]);
let pay_params = PaymentParameters::from_node_id(node_d_id, TEST_FINAL_CLTV);
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -20522,7 +20522,7 @@ mod tests {
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);

let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(&nodes[0]);
let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[0], None, None);
let payment_data = msgs::FinalOnionHopData {
payment_secret,
total_msat: 100_000,
Expand Down
87 changes: 28 additions & 59 deletions lightning/src/ln/functional_test_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2210,31 +2210,31 @@ macro_rules! check_spends {
}
}

macro_rules! get_closing_signed_broadcast {
($node: expr, $dest_pubkey: expr) => {{
let events = $node.get_and_clear_pending_msg_events();
assert!(events.len() == 1 || events.len() == 2);
(
match events[events.len() - 1] {
MessageSendEvent::BroadcastChannelUpdate { ref msg, .. } => {
assert_eq!(msg.contents.channel_flags & 2, 2);
msg.clone()
pub fn get_closing_signed_broadcast(
node: &Node, dest_pubkey: PublicKey,
) -> (msgs::ChannelUpdate, Option<msgs::ClosingSigned>) {
let events = node.node.get_and_clear_pending_msg_events();
assert!(events.len() == 1 || events.len() == 2);
(
match events[events.len() - 1] {
MessageSendEvent::BroadcastChannelUpdate { ref msg, .. } => {
assert_eq!(msg.contents.channel_flags & 2, 2);
msg.clone()
},
_ => panic!("Unexpected event"),
},
if events.len() == 2 {
match events[0] {
MessageSendEvent::SendClosingSigned { ref node_id, ref msg } => {
assert_eq!(*node_id, dest_pubkey);
Some(msg.clone())
},
_ => panic!("Unexpected event"),
},
if events.len() == 2 {
match events[0] {
MessageSendEvent::SendClosingSigned { ref node_id, ref msg } => {
assert_eq!(*node_id, $dest_pubkey);
Some(msg.clone())
},
_ => panic!("Unexpected event"),
}
} else {
None
},
)
}};
}
} else {
None
},
)
}

#[cfg(test)]
Expand DownExpand Up@@ -2313,17 +2313,6 @@ pub fn check_closed_broadcast(
.collect()
}

/// Check that a channel's closing channel update has been broadcasted, and optionally
/// check whether an error message event has occurred.
///
/// Don't use this, use the identically-named function instead.
#[macro_export]
macro_rules! check_closed_broadcast {
($node: expr, $with_error_msg: expr) => {
$crate::ln::functional_test_utils::check_closed_broadcast(&$node, 1, $with_error_msg).pop()
};
}

#[derive(Default)]
pub struct ExpectedCloseEvent {
pub channel_capacity_sats: Option<u64>,
Expand DownExpand Up@@ -2530,10 +2519,10 @@ pub fn close_channel<'a, 'b, 'c>(
assert_eq!(broadcaster_b.txn_broadcasted.lock().unwrap().len(), 1);
tx_b = broadcaster_b.txn_broadcasted.lock().unwrap().remove(0);
let (bs_update, closing_signed_b) =
get_closing_signed_broadcast!(node_b, node_a.get_our_node_id());
get_closing_signed_broadcast(struct_b, node_a.get_our_node_id());

node_a.handle_closing_signed(node_b.get_our_node_id(), &closing_signed_b.unwrap());
let (as_update, none_a) = get_closing_signed_broadcast!(node_a, node_b.get_our_node_id());
let (as_update, none_a) = get_closing_signed_broadcast(struct_a, node_b.get_our_node_id());
assert!(none_a.is_none());
assert_eq!(broadcaster_a.txn_broadcasted.lock().unwrap().len(), 1);
tx_a = broadcaster_a.txn_broadcasted.lock().unwrap().remove(0);
Expand All@@ -2550,10 +2539,10 @@ pub fn close_channel<'a, 'b, 'c>(
assert_eq!(broadcaster_a.txn_broadcasted.lock().unwrap().len(), 1);
tx_a = broadcaster_a.txn_broadcasted.lock().unwrap().remove(0);
let (as_update, closing_signed_a) =
get_closing_signed_broadcast!(node_a, node_b.get_our_node_id());
get_closing_signed_broadcast(struct_a, node_b.get_our_node_id());

node_b.handle_closing_signed(node_a.get_our_node_id(), &closing_signed_a.unwrap());
let (bs_update, none_b) = get_closing_signed_broadcast!(node_b, node_a.get_our_node_id());
let (bs_update, none_b) = get_closing_signed_broadcast(struct_b, node_a.get_our_node_id());
assert!(none_b.is_none());
assert_eq!(broadcaster_b.txn_broadcasted.lock().unwrap().len(), 1);
tx_b = broadcaster_b.txn_broadcasted.lock().unwrap().remove(0);
Expand DownExpand Up@@ -2829,26 +2818,6 @@ pub fn get_payment_preimage_hash(
(payment_preimage, payment_hash, payment_secret)
}

/// Get a payment preimage and hash.
///
/// Don't use this, use the identically-named function instead.
#[macro_export]
macro_rules! get_payment_preimage_hash {
($dest_node: expr) => {
get_payment_preimage_hash!($dest_node, None)
};
($dest_node: expr, $min_value_msat: expr) => {
$crate::get_payment_preimage_hash!($dest_node, $min_value_msat, None)
};
($dest_node: expr, $min_value_msat: expr, $min_final_cltv_expiry_delta: expr) => {
$crate::ln::functional_test_utils::get_payment_preimage_hash(
&$dest_node,
$min_value_msat,
$min_final_cltv_expiry_delta,
)
};
}

/// Gets a route from the given sender to the node described in `payment_params`.
pub fn get_route(send_node: &Node, route_params: &RouteParameters) -> Result<Route, &'static str> {
let scorer = TestScorer::new();
Expand DownExpand Up@@ -3820,7 +3789,7 @@ pub fn send_along_route<'a, 'b, 'c>(
recv_value: u64,
) -> (PaymentPreimage, PaymentHash, PaymentSecret, PaymentId) {
let (our_payment_preimage, our_payment_hash, our_payment_secret) =
get_payment_preimage_hash!(expected_route.last().unwrap());
get_payment_preimage_hash(expected_route.last().unwrap(), None, None);
let payment_id = send_along_route_with_secret(
origin_node,
route,
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
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
5 changes: 2 additions & 3 deletions lightning-persister/src/test_utils.rs
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
use lightning::check_closed_broadcast;
use lightning::events::ClosureReason;
use lightning::ln::functional_test_utils::*;
use lightning::util::persist::{
Expand DownExpand Up@@ -188,7 +187,7 @@ pub(crate) fn do_test_store<K: KVStoreSync + Sync>(store_0: &K, store_1: &K) {
.unwrap();
let reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true), message };
check_closed_event(&nodes[0], 1, reason, &[node_b_id], 100000);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);
check_added_monitors(&nodes[0], 1);

let node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
Expand All@@ -202,7 +201,7 @@ pub(crate) fn do_test_store<K: KVStoreSync + Sync>(store_0: &K, store_1: &K) {
vec![node_txn[0].clone(), node_txn[0].clone()],
),
);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
let reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, reason, &[nodes[0].node.get_our_node_id()], 100000);
check_added_monitors(&nodes[1], 1);
Expand Down
3 changes: 2 additions & 1 deletion lightning/src/ln/accountable_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,7 +26,8 @@ fn test_accountable_forwarding_with_override(
let _chan_ab = create_announced_chan_between_nodes(&nodes, 0, 1);
let _chan_bc = create_announced_chan_between_nodes(&nodes, 1, 2);

let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);
let (payment_preimage, payment_hash, payment_secret) =
get_payment_preimage_hash(&nodes[2], None, None);
let route_params = RouteParameters::from_payment_params_and_value(
PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV),
100_000,
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/async_signer_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1308,9 +1308,9 @@ fn do_test_closing_signed(extra_closing_signed: bool, reconnect: bool) {
}

nodes[0].node.signer_unblocked(None);
let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast!(nodes[0].node, node_b_id);
let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast(&nodes[0], node_b_id);
nodes[1].node.handle_closing_signed(node_a_id, &node_0_2nd_closing_signed.unwrap());
let (_, node_1_closing_signed) = get_closing_signed_broadcast!(nodes[1].node, node_a_id);
let (_, node_1_closing_signed) = get_closing_signed_broadcast(&nodes[1], node_a_id);
assert!(node_1_closing_signed.is_none());

assert!(nodes[0].node.list_channels().is_empty());
Expand Down
29 changes: 15 additions & 14 deletions lightning/src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -277,7 +277,7 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool) {
};
nodes[0].node.force_close_broadcasting_latest_txn(&channel_id, &node_b_id, message).unwrap();
check_added_monitors(&nodes[0], 1);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);

// TODO: Once we hit the chain with the failure transaction we should check that we get a
// PaymentPathFailed event
Expand DownExpand Up@@ -1382,9 +1382,9 @@ fn raa_no_response_awaiting_raa_state() {
let (route, payment_hash_1, payment_preimage_1, payment_secret_1) =
get_route_and_payment_hash!(nodes[0], nodes[1], 1000000);
let (payment_preimage_2, payment_hash_2, payment_secret_2) =
get_payment_preimage_hash!(nodes[1]);
get_payment_preimage_hash(&nodes[1], None, None);
let (payment_preimage_3, payment_hash_3, payment_secret_3) =
get_payment_preimage_hash!(nodes[1]);
get_payment_preimage_hash(&nodes[1], None, None);

// Queue up two payments - one will be delivered right away, one immediately goes into the
// holding cell as nodes[0] is AwaitingRAA. Ultimately this allows us to deliver an RAA
Expand DownExpand Up@@ -1872,7 +1872,7 @@ fn test_monitor_update_fail_claim() {
do_commitment_signed_dance(&nodes[1], &nodes[2], &payment_event.commitment_msg, false, true);
expect_htlc_failure_conditions(nodes[1].node.get_and_clear_pending_events(), &[]);

let (_, payment_hash_3, payment_secret_3) = get_payment_preimage_hash!(nodes[0]);
let (_, payment_hash_3, payment_secret_3) = get_payment_preimage_hash(&nodes[0], None, None);
let id_3 = PaymentId(payment_hash_3.0);
let onion_3 = RecipientOnionFields::secret_only(payment_secret_3);
nodes[2].node.send_payment_with_route(route, payment_hash_3, onion_3, id_3).unwrap();
Expand DownExpand Up@@ -2509,7 +2509,7 @@ fn test_fail_htlc_on_broadcast_after_claim() {
mine_transaction(&nodes[1], &bs_txn[0]);
let reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, reason, &[node_c_id], 100000);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1);
check_added_monitors(&nodes[1], 1);
expect_and_process_pending_htlcs_and_htlc_handling_failed(
Expand DownExpand Up@@ -2663,7 +2663,7 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
let (route, payment_hash_1, payment_preimage_1, payment_secret_1) =
get_route_and_payment_hash!(&nodes[0], nodes[1], 100000);
let (payment_preimage_2, payment_hash_2, payment_secret_2) =
get_payment_preimage_hash!(&nodes[1]);
get_payment_preimage_hash(&nodes[1], None, None);

// Do a really complicated dance to get an HTLC into the holding cell, with
// MonitorUpdateInProgress set but AwaitingRemoteRevoke unset. When this test was written, any
Expand DownExpand Up@@ -3048,11 +3048,11 @@ fn test_temporary_error_during_shutdown() {
node_b_id,
&get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, node_a_id),
);
let (_, closing_signed_a) = get_closing_signed_broadcast!(nodes[0].node, node_b_id);
let (_, closing_signed_a) = get_closing_signed_broadcast(&nodes[0], node_b_id);
let txn_a = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);

nodes[1].node.handle_closing_signed(node_a_id, &closing_signed_a.unwrap());
let (_, none_b) = get_closing_signed_broadcast!(nodes[1].node, node_a_id);
let (_, none_b) = get_closing_signed_broadcast(&nodes[1], node_a_id);
assert!(none_b.is_none());
let txn_b = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);

Expand DownExpand Up@@ -4043,7 +4043,7 @@ fn do_test_reload_mon_update_completion_actions(close_during_reload: bool) {
};
nodes[0].node.force_close_broadcasting_latest_txn(&chan_id_ab, &node_b_id, msg).unwrap();
check_added_monitors(&nodes[0], 1);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);
check_closed_event(&nodes[0], 1, reason, &[node_b_id], 100_000);
let as_closing_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
mine_transaction_without_consistency_checks(&nodes[1], &as_closing_tx[0]);
Expand DownExpand Up@@ -4494,13 +4494,13 @@ fn test_claim_to_closed_channel_blocks_forwarded_preimage_removal() {
check_added_monitors(&nodes[0], 1);
let a_reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true), message };
check_closed_event(&nodes[0], 1, a_reason, &[node_b_id], 1000000);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);

let as_commit_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
assert_eq!(as_commit_tx.len(), 1);

mine_transaction(&nodes[1], &as_commit_tx[0]);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
check_added_monitors(&nodes[1], 1);
let b_reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, b_reason, &[node_a_id], 1000000);
Expand DownExpand Up@@ -4572,13 +4572,13 @@ fn test_claim_to_closed_channel_blocks_claimed_event() {
check_added_monitors(&nodes[0], 1);
let a_reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true), message };
check_closed_event(&nodes[0], 1, a_reason, &[node_b_id], 1000000);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);

let as_commit_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
assert_eq!(as_commit_tx.len(), 1);

mine_transaction(&nodes[1], &as_commit_tx[0]);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
check_added_monitors(&nodes[1], 1);
let b_reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, b_reason, &[node_a_id], 1000000);
Expand DownExpand Up@@ -5099,7 +5099,8 @@ fn test_mpp_claim_to_holding_cell() {
send_along_route_with_secret(&nodes[0], route, paths, 500_000, paymnt_hash_1, payment_secret);

// Put the C <-> D channel into AwaitingRaa
let (preimage_2, paymnt_hash_2, payment_secret_2) = get_payment_preimage_hash!(nodes[3]);
let (preimage_2, paymnt_hash_2, payment_secret_2) =
get_payment_preimage_hash(&nodes[3], None, None);
let onion = RecipientOnionFields::secret_only(payment_secret_2);
let id = PaymentId([42; 32]);
let pay_params = PaymentParameters::from_node_id(node_d_id, TEST_FINAL_CLTV);
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -20522,7 +20522,7 @@ mod tests {
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);

let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(&nodes[0]);
let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[0], None, None);
let payment_data = msgs::FinalOnionHopData {
payment_secret,
total_msat: 100_000,
Expand Down
87 changes: 28 additions & 59 deletions lightning/src/ln/functional_test_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2210,31 +2210,31 @@ macro_rules! check_spends {
}
}

macro_rules! get_closing_signed_broadcast {
($node: expr, $dest_pubkey: expr) => {{
let events = $node.get_and_clear_pending_msg_events();
assert!(events.len() == 1 || events.len() == 2);
(
match events[events.len() - 1] {
MessageSendEvent::BroadcastChannelUpdate { ref msg, .. } => {
assert_eq!(msg.contents.channel_flags & 2, 2);
msg.clone()
pub fn get_closing_signed_broadcast(
node: &Node, dest_pubkey: PublicKey,
) -> (msgs::ChannelUpdate, Option<msgs::ClosingSigned>) {
let events = node.node.get_and_clear_pending_msg_events();
assert!(events.len() == 1 || events.len() == 2);
(
match events[events.len() - 1] {
MessageSendEvent::BroadcastChannelUpdate { ref msg, .. } => {
assert_eq!(msg.contents.channel_flags & 2, 2);
msg.clone()
},
_ => panic!("Unexpected event"),
},
if events.len() == 2 {
match events[0] {
MessageSendEvent::SendClosingSigned { ref node_id, ref msg } => {
assert_eq!(*node_id, dest_pubkey);
Some(msg.clone())
},
_ => panic!("Unexpected event"),
},
if events.len() == 2 {
match events[0] {
MessageSendEvent::SendClosingSigned { ref node_id, ref msg } => {
assert_eq!(*node_id, $dest_pubkey);
Some(msg.clone())
},
_ => panic!("Unexpected event"),
}
} else {
None
},
)
}};
}
} else {
None
},
)
}

#[cfg(test)]
Expand DownExpand Up@@ -2313,17 +2313,6 @@ pub fn check_closed_broadcast(
.collect()
}

/// Check that a channel's closing channel update has been broadcasted, and optionally
/// check whether an error message event has occurred.
///
/// Don't use this, use the identically-named function instead.
#[macro_export]
macro_rules! check_closed_broadcast {
($node: expr, $with_error_msg: expr) => {
$crate::ln::functional_test_utils::check_closed_broadcast(&$node, 1, $with_error_msg).pop()
};
}

#[derive(Default)]
pub struct ExpectedCloseEvent {
pub channel_capacity_sats: Option<u64>,
Expand DownExpand Up@@ -2530,10 +2519,10 @@ pub fn close_channel<'a, 'b, 'c>(
assert_eq!(broadcaster_b.txn_broadcasted.lock().unwrap().len(), 1);
tx_b = broadcaster_b.txn_broadcasted.lock().unwrap().remove(0);
let (bs_update, closing_signed_b) =
get_closing_signed_broadcast!(node_b, node_a.get_our_node_id());
get_closing_signed_broadcast(struct_b, node_a.get_our_node_id());

node_a.handle_closing_signed(node_b.get_our_node_id(), &closing_signed_b.unwrap());
let (as_update, none_a) = get_closing_signed_broadcast!(node_a, node_b.get_our_node_id());
let (as_update, none_a) = get_closing_signed_broadcast(struct_a, node_b.get_our_node_id());
assert!(none_a.is_none());
assert_eq!(broadcaster_a.txn_broadcasted.lock().unwrap().len(), 1);
tx_a = broadcaster_a.txn_broadcasted.lock().unwrap().remove(0);
Expand All@@ -2550,10 +2539,10 @@ pub fn close_channel<'a, 'b, 'c>(
assert_eq!(broadcaster_a.txn_broadcasted.lock().unwrap().len(), 1);
tx_a = broadcaster_a.txn_broadcasted.lock().unwrap().remove(0);
let (as_update, closing_signed_a) =
get_closing_signed_broadcast!(node_a, node_b.get_our_node_id());
get_closing_signed_broadcast(struct_a, node_b.get_our_node_id());

node_b.handle_closing_signed(node_a.get_our_node_id(), &closing_signed_a.unwrap());
let (bs_update, none_b) = get_closing_signed_broadcast!(node_b, node_a.get_our_node_id());
let (bs_update, none_b) = get_closing_signed_broadcast(struct_b, node_a.get_our_node_id());
assert!(none_b.is_none());
assert_eq!(broadcaster_b.txn_broadcasted.lock().unwrap().len(), 1);
tx_b = broadcaster_b.txn_broadcasted.lock().unwrap().remove(0);
Expand DownExpand Up@@ -2829,26 +2818,6 @@ pub fn get_payment_preimage_hash(
(payment_preimage, payment_hash, payment_secret)
}

/// Get a payment preimage and hash.
///
/// Don't use this, use the identically-named function instead.
#[macro_export]
macro_rules! get_payment_preimage_hash {
($dest_node: expr) => {
get_payment_preimage_hash!($dest_node, None)
};
($dest_node: expr, $min_value_msat: expr) => {
$crate::get_payment_preimage_hash!($dest_node, $min_value_msat, None)
};
($dest_node: expr, $min_value_msat: expr, $min_final_cltv_expiry_delta: expr) => {
$crate::ln::functional_test_utils::get_payment_preimage_hash(
&$dest_node,
$min_value_msat,
$min_final_cltv_expiry_delta,
)
};
}

/// Gets a route from the given sender to the node described in `payment_params`.
pub fn get_route(send_node: &Node, route_params: &RouteParameters) -> Result<Route, &'static str> {
let scorer = TestScorer::new();
Expand DownExpand Up@@ -3820,7 +3789,7 @@ pub fn send_along_route<'a, 'b, 'c>(
recv_value: u64,
) -> (PaymentPreimage, PaymentHash, PaymentSecret, PaymentId) {
let (our_payment_preimage, our_payment_hash, our_payment_secret) =
get_payment_preimage_hash!(expected_route.last().unwrap());
get_payment_preimage_hash(expected_route.last().unwrap(), None, None);
let payment_id = send_along_route_with_secret(
origin_node,
route,
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
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
5 changes: 2 additions & 3 deletions lightning-persister/src/test_utils.rs
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
use lightning::check_closed_broadcast;
use lightning::events::ClosureReason;
use lightning::ln::functional_test_utils::*;
use lightning::util::persist::{
Expand DownExpand Up@@ -188,7 +187,7 @@ pub(crate) fn do_test_store<K: KVStoreSync + Sync>(store_0: &K, store_1: &K) {
.unwrap();
let reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true), message };
check_closed_event(&nodes[0], 1, reason, &[node_b_id], 100000);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);
check_added_monitors(&nodes[0], 1);

let node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
Expand All@@ -202,7 +201,7 @@ pub(crate) fn do_test_store<K: KVStoreSync + Sync>(store_0: &K, store_1: &K) {
vec![node_txn[0].clone(), node_txn[0].clone()],
),
);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
let reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, reason, &[nodes[0].node.get_our_node_id()], 100000);
check_added_monitors(&nodes[1], 1);
Expand Down
3 changes: 2 additions & 1 deletion lightning/src/ln/accountable_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,7 +26,8 @@ fn test_accountable_forwarding_with_override(
let _chan_ab = create_announced_chan_between_nodes(&nodes, 0, 1);
let _chan_bc = create_announced_chan_between_nodes(&nodes, 1, 2);

let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);
let (payment_preimage, payment_hash, payment_secret) =
get_payment_preimage_hash(&nodes[2], None, None);
let route_params = RouteParameters::from_payment_params_and_value(
PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV),
100_000,
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/async_signer_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1308,9 +1308,9 @@ fn do_test_closing_signed(extra_closing_signed: bool, reconnect: bool) {
}

nodes[0].node.signer_unblocked(None);
let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast!(nodes[0].node, node_b_id);
let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast(&nodes[0], node_b_id);
nodes[1].node.handle_closing_signed(node_a_id, &node_0_2nd_closing_signed.unwrap());
let (_, node_1_closing_signed) = get_closing_signed_broadcast!(nodes[1].node, node_a_id);
let (_, node_1_closing_signed) = get_closing_signed_broadcast(&nodes[1], node_a_id);
assert!(node_1_closing_signed.is_none());

assert!(nodes[0].node.list_channels().is_empty());
Expand Down
29 changes: 15 additions & 14 deletions lightning/src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -277,7 +277,7 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool) {
};
nodes[0].node.force_close_broadcasting_latest_txn(&channel_id, &node_b_id, message).unwrap();
check_added_monitors(&nodes[0], 1);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);

// TODO: Once we hit the chain with the failure transaction we should check that we get a
// PaymentPathFailed event
Expand DownExpand Up@@ -1382,9 +1382,9 @@ fn raa_no_response_awaiting_raa_state() {
let (route, payment_hash_1, payment_preimage_1, payment_secret_1) =
get_route_and_payment_hash!(nodes[0], nodes[1], 1000000);
let (payment_preimage_2, payment_hash_2, payment_secret_2) =
get_payment_preimage_hash!(nodes[1]);
get_payment_preimage_hash(&nodes[1], None, None);
let (payment_preimage_3, payment_hash_3, payment_secret_3) =
get_payment_preimage_hash!(nodes[1]);
get_payment_preimage_hash(&nodes[1], None, None);

// Queue up two payments - one will be delivered right away, one immediately goes into the
// holding cell as nodes[0] is AwaitingRAA. Ultimately this allows us to deliver an RAA
Expand DownExpand Up@@ -1872,7 +1872,7 @@ fn test_monitor_update_fail_claim() {
do_commitment_signed_dance(&nodes[1], &nodes[2], &payment_event.commitment_msg, false, true);
expect_htlc_failure_conditions(nodes[1].node.get_and_clear_pending_events(), &[]);

let (_, payment_hash_3, payment_secret_3) = get_payment_preimage_hash!(nodes[0]);
let (_, payment_hash_3, payment_secret_3) = get_payment_preimage_hash(&nodes[0], None, None);
let id_3 = PaymentId(payment_hash_3.0);
let onion_3 = RecipientOnionFields::secret_only(payment_secret_3);
nodes[2].node.send_payment_with_route(route, payment_hash_3, onion_3, id_3).unwrap();
Expand DownExpand Up@@ -2509,7 +2509,7 @@ fn test_fail_htlc_on_broadcast_after_claim() {
mine_transaction(&nodes[1], &bs_txn[0]);
let reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, reason, &[node_c_id], 100000);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1);
check_added_monitors(&nodes[1], 1);
expect_and_process_pending_htlcs_and_htlc_handling_failed(
Expand DownExpand Up@@ -2663,7 +2663,7 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
let (route, payment_hash_1, payment_preimage_1, payment_secret_1) =
get_route_and_payment_hash!(&nodes[0], nodes[1], 100000);
let (payment_preimage_2, payment_hash_2, payment_secret_2) =
get_payment_preimage_hash!(&nodes[1]);
get_payment_preimage_hash(&nodes[1], None, None);

// Do a really complicated dance to get an HTLC into the holding cell, with
// MonitorUpdateInProgress set but AwaitingRemoteRevoke unset. When this test was written, any
Expand DownExpand Up@@ -3048,11 +3048,11 @@ fn test_temporary_error_during_shutdown() {
node_b_id,
&get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, node_a_id),
);
let (_, closing_signed_a) = get_closing_signed_broadcast!(nodes[0].node, node_b_id);
let (_, closing_signed_a) = get_closing_signed_broadcast(&nodes[0], node_b_id);
let txn_a = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);

nodes[1].node.handle_closing_signed(node_a_id, &closing_signed_a.unwrap());
let (_, none_b) = get_closing_signed_broadcast!(nodes[1].node, node_a_id);
let (_, none_b) = get_closing_signed_broadcast(&nodes[1], node_a_id);
assert!(none_b.is_none());
let txn_b = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);

Expand DownExpand Up@@ -4043,7 +4043,7 @@ fn do_test_reload_mon_update_completion_actions(close_during_reload: bool) {
};
nodes[0].node.force_close_broadcasting_latest_txn(&chan_id_ab, &node_b_id, msg).unwrap();
check_added_monitors(&nodes[0], 1);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);
check_closed_event(&nodes[0], 1, reason, &[node_b_id], 100_000);
let as_closing_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
mine_transaction_without_consistency_checks(&nodes[1], &as_closing_tx[0]);
Expand DownExpand Up@@ -4494,13 +4494,13 @@ fn test_claim_to_closed_channel_blocks_forwarded_preimage_removal() {
check_added_monitors(&nodes[0], 1);
let a_reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true), message };
check_closed_event(&nodes[0], 1, a_reason, &[node_b_id], 1000000);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);

let as_commit_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
assert_eq!(as_commit_tx.len(), 1);

mine_transaction(&nodes[1], &as_commit_tx[0]);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
check_added_monitors(&nodes[1], 1);
let b_reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, b_reason, &[node_a_id], 1000000);
Expand DownExpand Up@@ -4572,13 +4572,13 @@ fn test_claim_to_closed_channel_blocks_claimed_event() {
check_added_monitors(&nodes[0], 1);
let a_reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true), message };
check_closed_event(&nodes[0], 1, a_reason, &[node_b_id], 1000000);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);

let as_commit_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
assert_eq!(as_commit_tx.len(), 1);

mine_transaction(&nodes[1], &as_commit_tx[0]);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
check_added_monitors(&nodes[1], 1);
let b_reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, b_reason, &[node_a_id], 1000000);
Expand DownExpand Up@@ -5099,7 +5099,8 @@ fn test_mpp_claim_to_holding_cell() {
send_along_route_with_secret(&nodes[0], route, paths, 500_000, paymnt_hash_1, payment_secret);

// Put the C <-> D channel into AwaitingRaa
let (preimage_2, paymnt_hash_2, payment_secret_2) = get_payment_preimage_hash!(nodes[3]);
let (preimage_2, paymnt_hash_2, payment_secret_2) =
get_payment_preimage_hash(&nodes[3], None, None);
let onion = RecipientOnionFields::secret_only(payment_secret_2);
let id = PaymentId([42; 32]);
let pay_params = PaymentParameters::from_node_id(node_d_id, TEST_FINAL_CLTV);
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -20522,7 +20522,7 @@ mod tests {
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);

let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(&nodes[0]);
let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[0], None, None);
let payment_data = msgs::FinalOnionHopData {
payment_secret,
total_msat: 100_000,
Expand Down
87 changes: 28 additions & 59 deletions lightning/src/ln/functional_test_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2210,31 +2210,31 @@ macro_rules! check_spends {
}
}

macro_rules! get_closing_signed_broadcast {
($node: expr, $dest_pubkey: expr) => {{
let events = $node.get_and_clear_pending_msg_events();
assert!(events.len() == 1 || events.len() == 2);
(
match events[events.len() - 1] {
MessageSendEvent::BroadcastChannelUpdate { ref msg, .. } => {
assert_eq!(msg.contents.channel_flags & 2, 2);
msg.clone()
pub fn get_closing_signed_broadcast(
node: &Node, dest_pubkey: PublicKey,
) -> (msgs::ChannelUpdate, Option<msgs::ClosingSigned>) {
let events = node.node.get_and_clear_pending_msg_events();
assert!(events.len() == 1 || events.len() == 2);
(
match events[events.len() - 1] {
MessageSendEvent::BroadcastChannelUpdate { ref msg, .. } => {
assert_eq!(msg.contents.channel_flags & 2, 2);
msg.clone()
},
_ => panic!("Unexpected event"),
},
if events.len() == 2 {
match events[0] {
MessageSendEvent::SendClosingSigned { ref node_id, ref msg } => {
assert_eq!(*node_id, dest_pubkey);
Some(msg.clone())
},
_ => panic!("Unexpected event"),
},
if events.len() == 2 {
match events[0] {
MessageSendEvent::SendClosingSigned { ref node_id, ref msg } => {
assert_eq!(*node_id, $dest_pubkey);
Some(msg.clone())
},
_ => panic!("Unexpected event"),
}
} else {
None
},
)
}};
}
} else {
None
},
)
}

#[cfg(test)]
Expand DownExpand Up@@ -2313,17 +2313,6 @@ pub fn check_closed_broadcast(
.collect()
}

/// Check that a channel's closing channel update has been broadcasted, and optionally
/// check whether an error message event has occurred.
///
/// Don't use this, use the identically-named function instead.
#[macro_export]
macro_rules! check_closed_broadcast {
($node: expr, $with_error_msg: expr) => {
$crate::ln::functional_test_utils::check_closed_broadcast(&$node, 1, $with_error_msg).pop()
};
}

#[derive(Default)]
pub struct ExpectedCloseEvent {
pub channel_capacity_sats: Option<u64>,
Expand DownExpand Up@@ -2530,10 +2519,10 @@ pub fn close_channel<'a, 'b, 'c>(
assert_eq!(broadcaster_b.txn_broadcasted.lock().unwrap().len(), 1);
tx_b = broadcaster_b.txn_broadcasted.lock().unwrap().remove(0);
let (bs_update, closing_signed_b) =
get_closing_signed_broadcast!(node_b, node_a.get_our_node_id());
get_closing_signed_broadcast(struct_b, node_a.get_our_node_id());

node_a.handle_closing_signed(node_b.get_our_node_id(), &closing_signed_b.unwrap());
let (as_update, none_a) = get_closing_signed_broadcast!(node_a, node_b.get_our_node_id());
let (as_update, none_a) = get_closing_signed_broadcast(struct_a, node_b.get_our_node_id());
assert!(none_a.is_none());
assert_eq!(broadcaster_a.txn_broadcasted.lock().unwrap().len(), 1);
tx_a = broadcaster_a.txn_broadcasted.lock().unwrap().remove(0);
Expand All@@ -2550,10 +2539,10 @@ pub fn close_channel<'a, 'b, 'c>(
assert_eq!(broadcaster_a.txn_broadcasted.lock().unwrap().len(), 1);
tx_a = broadcaster_a.txn_broadcasted.lock().unwrap().remove(0);
let (as_update, closing_signed_a) =
get_closing_signed_broadcast!(node_a, node_b.get_our_node_id());
get_closing_signed_broadcast(struct_a, node_b.get_our_node_id());

node_b.handle_closing_signed(node_a.get_our_node_id(), &closing_signed_a.unwrap());
let (bs_update, none_b) = get_closing_signed_broadcast!(node_b, node_a.get_our_node_id());
let (bs_update, none_b) = get_closing_signed_broadcast(struct_b, node_a.get_our_node_id());
assert!(none_b.is_none());
assert_eq!(broadcaster_b.txn_broadcasted.lock().unwrap().len(), 1);
tx_b = broadcaster_b.txn_broadcasted.lock().unwrap().remove(0);
Expand DownExpand Up@@ -2829,26 +2818,6 @@ pub fn get_payment_preimage_hash(
(payment_preimage, payment_hash, payment_secret)
}

/// Get a payment preimage and hash.
///
/// Don't use this, use the identically-named function instead.
#[macro_export]
macro_rules! get_payment_preimage_hash {
($dest_node: expr) => {
get_payment_preimage_hash!($dest_node, None)
};
($dest_node: expr, $min_value_msat: expr) => {
$crate::get_payment_preimage_hash!($dest_node, $min_value_msat, None)
};
($dest_node: expr, $min_value_msat: expr, $min_final_cltv_expiry_delta: expr) => {
$crate::ln::functional_test_utils::get_payment_preimage_hash(
&$dest_node,
$min_value_msat,
$min_final_cltv_expiry_delta,
)
};
}

/// Gets a route from the given sender to the node described in `payment_params`.
pub fn get_route(send_node: &Node, route_params: &RouteParameters) -> Result<Route, &'static str> {
let scorer = TestScorer::new();
Expand DownExpand Up@@ -3820,7 +3789,7 @@ pub fn send_along_route<'a, 'b, 'c>(
recv_value: u64,
) -> (PaymentPreimage, PaymentHash, PaymentSecret, PaymentId) {
let (our_payment_preimage, our_payment_hash, our_payment_secret) =
get_payment_preimage_hash!(expected_route.last().unwrap());
get_payment_preimage_hash(expected_route.last().unwrap(), None, None);
let payment_id = send_along_route_with_secret(
origin_node,
route,
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
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
5 changes: 2 additions & 3 deletions lightning-persister/src/test_utils.rs
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
use lightning::check_closed_broadcast;
use lightning::events::ClosureReason;
use lightning::ln::functional_test_utils::*;
use lightning::util::persist::{
Expand DownExpand Up@@ -188,7 +187,7 @@ pub(crate) fn do_test_store<K: KVStoreSync + Sync>(store_0: &K, store_1: &K) {
.unwrap();
let reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true), message };
check_closed_event(&nodes[0], 1, reason, &[node_b_id], 100000);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);
check_added_monitors(&nodes[0], 1);

let node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
Expand All@@ -202,7 +201,7 @@ pub(crate) fn do_test_store<K: KVStoreSync + Sync>(store_0: &K, store_1: &K) {
vec![node_txn[0].clone(), node_txn[0].clone()],
),
);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
let reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, reason, &[nodes[0].node.get_our_node_id()], 100000);
check_added_monitors(&nodes[1], 1);
Expand Down
3 changes: 2 additions & 1 deletion lightning/src/ln/accountable_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,7 +26,8 @@ fn test_accountable_forwarding_with_override(
let _chan_ab = create_announced_chan_between_nodes(&nodes, 0, 1);
let _chan_bc = create_announced_chan_between_nodes(&nodes, 1, 2);

let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);
let (payment_preimage, payment_hash, payment_secret) =
get_payment_preimage_hash(&nodes[2], None, None);
let route_params = RouteParameters::from_payment_params_and_value(
PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV),
100_000,
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/async_signer_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1308,9 +1308,9 @@ fn do_test_closing_signed(extra_closing_signed: bool, reconnect: bool) {
}

nodes[0].node.signer_unblocked(None);
let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast!(nodes[0].node, node_b_id);
let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast(&nodes[0], node_b_id);
nodes[1].node.handle_closing_signed(node_a_id, &node_0_2nd_closing_signed.unwrap());
let (_, node_1_closing_signed) = get_closing_signed_broadcast!(nodes[1].node, node_a_id);
let (_, node_1_closing_signed) = get_closing_signed_broadcast(&nodes[1], node_a_id);
assert!(node_1_closing_signed.is_none());

assert!(nodes[0].node.list_channels().is_empty());
Expand Down
29 changes: 15 additions & 14 deletions lightning/src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -277,7 +277,7 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool) {
};
nodes[0].node.force_close_broadcasting_latest_txn(&channel_id, &node_b_id, message).unwrap();
check_added_monitors(&nodes[0], 1);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);

// TODO: Once we hit the chain with the failure transaction we should check that we get a
// PaymentPathFailed event
Expand DownExpand Up@@ -1382,9 +1382,9 @@ fn raa_no_response_awaiting_raa_state() {
let (route, payment_hash_1, payment_preimage_1, payment_secret_1) =
get_route_and_payment_hash!(nodes[0], nodes[1], 1000000);
let (payment_preimage_2, payment_hash_2, payment_secret_2) =
get_payment_preimage_hash!(nodes[1]);
get_payment_preimage_hash(&nodes[1], None, None);
let (payment_preimage_3, payment_hash_3, payment_secret_3) =
get_payment_preimage_hash!(nodes[1]);
get_payment_preimage_hash(&nodes[1], None, None);

// Queue up two payments - one will be delivered right away, one immediately goes into the
// holding cell as nodes[0] is AwaitingRAA. Ultimately this allows us to deliver an RAA
Expand DownExpand Up@@ -1872,7 +1872,7 @@ fn test_monitor_update_fail_claim() {
do_commitment_signed_dance(&nodes[1], &nodes[2], &payment_event.commitment_msg, false, true);
expect_htlc_failure_conditions(nodes[1].node.get_and_clear_pending_events(), &[]);

let (_, payment_hash_3, payment_secret_3) = get_payment_preimage_hash!(nodes[0]);
let (_, payment_hash_3, payment_secret_3) = get_payment_preimage_hash(&nodes[0], None, None);
let id_3 = PaymentId(payment_hash_3.0);
let onion_3 = RecipientOnionFields::secret_only(payment_secret_3);
nodes[2].node.send_payment_with_route(route, payment_hash_3, onion_3, id_3).unwrap();
Expand DownExpand Up@@ -2509,7 +2509,7 @@ fn test_fail_htlc_on_broadcast_after_claim() {
mine_transaction(&nodes[1], &bs_txn[0]);
let reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, reason, &[node_c_id], 100000);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1);
check_added_monitors(&nodes[1], 1);
expect_and_process_pending_htlcs_and_htlc_handling_failed(
Expand DownExpand Up@@ -2663,7 +2663,7 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
let (route, payment_hash_1, payment_preimage_1, payment_secret_1) =
get_route_and_payment_hash!(&nodes[0], nodes[1], 100000);
let (payment_preimage_2, payment_hash_2, payment_secret_2) =
get_payment_preimage_hash!(&nodes[1]);
get_payment_preimage_hash(&nodes[1], None, None);

// Do a really complicated dance to get an HTLC into the holding cell, with
// MonitorUpdateInProgress set but AwaitingRemoteRevoke unset. When this test was written, any
Expand DownExpand Up@@ -3048,11 +3048,11 @@ fn test_temporary_error_during_shutdown() {
node_b_id,
&get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, node_a_id),
);
let (_, closing_signed_a) = get_closing_signed_broadcast!(nodes[0].node, node_b_id);
let (_, closing_signed_a) = get_closing_signed_broadcast(&nodes[0], node_b_id);
let txn_a = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);

nodes[1].node.handle_closing_signed(node_a_id, &closing_signed_a.unwrap());
let (_, none_b) = get_closing_signed_broadcast!(nodes[1].node, node_a_id);
let (_, none_b) = get_closing_signed_broadcast(&nodes[1], node_a_id);
assert!(none_b.is_none());
let txn_b = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);

Expand DownExpand Up@@ -4043,7 +4043,7 @@ fn do_test_reload_mon_update_completion_actions(close_during_reload: bool) {
};
nodes[0].node.force_close_broadcasting_latest_txn(&chan_id_ab, &node_b_id, msg).unwrap();
check_added_monitors(&nodes[0], 1);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);
check_closed_event(&nodes[0], 1, reason, &[node_b_id], 100_000);
let as_closing_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
mine_transaction_without_consistency_checks(&nodes[1], &as_closing_tx[0]);
Expand DownExpand Up@@ -4494,13 +4494,13 @@ fn test_claim_to_closed_channel_blocks_forwarded_preimage_removal() {
check_added_monitors(&nodes[0], 1);
let a_reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true), message };
check_closed_event(&nodes[0], 1, a_reason, &[node_b_id], 1000000);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);

let as_commit_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
assert_eq!(as_commit_tx.len(), 1);

mine_transaction(&nodes[1], &as_commit_tx[0]);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
check_added_monitors(&nodes[1], 1);
let b_reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, b_reason, &[node_a_id], 1000000);
Expand DownExpand Up@@ -4572,13 +4572,13 @@ fn test_claim_to_closed_channel_blocks_claimed_event() {
check_added_monitors(&nodes[0], 1);
let a_reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true), message };
check_closed_event(&nodes[0], 1, a_reason, &[node_b_id], 1000000);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);

let as_commit_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
assert_eq!(as_commit_tx.len(), 1);

mine_transaction(&nodes[1], &as_commit_tx[0]);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
check_added_monitors(&nodes[1], 1);
let b_reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, b_reason, &[node_a_id], 1000000);
Expand DownExpand Up@@ -5099,7 +5099,8 @@ fn test_mpp_claim_to_holding_cell() {
send_along_route_with_secret(&nodes[0], route, paths, 500_000, paymnt_hash_1, payment_secret);

// Put the C <-> D channel into AwaitingRaa
let (preimage_2, paymnt_hash_2, payment_secret_2) = get_payment_preimage_hash!(nodes[3]);
let (preimage_2, paymnt_hash_2, payment_secret_2) =
get_payment_preimage_hash(&nodes[3], None, None);
let onion = RecipientOnionFields::secret_only(payment_secret_2);
let id = PaymentId([42; 32]);
let pay_params = PaymentParameters::from_node_id(node_d_id, TEST_FINAL_CLTV);
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -20522,7 +20522,7 @@ mod tests {
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);

let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(&nodes[0]);
let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[0], None, None);
let payment_data = msgs::FinalOnionHopData {
payment_secret,
total_msat: 100_000,
Expand Down
87 changes: 28 additions & 59 deletions lightning/src/ln/functional_test_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2210,31 +2210,31 @@ macro_rules! check_spends {
}
}

macro_rules! get_closing_signed_broadcast {
($node: expr, $dest_pubkey: expr) => {{
let events = $node.get_and_clear_pending_msg_events();
assert!(events.len() == 1 || events.len() == 2);
(
match events[events.len() - 1] {
MessageSendEvent::BroadcastChannelUpdate { ref msg, .. } => {
assert_eq!(msg.contents.channel_flags & 2, 2);
msg.clone()
pub fn get_closing_signed_broadcast(
node: &Node, dest_pubkey: PublicKey,
) -> (msgs::ChannelUpdate, Option<msgs::ClosingSigned>) {
let events = node.node.get_and_clear_pending_msg_events();
assert!(events.len() == 1 || events.len() == 2);
(
match events[events.len() - 1] {
MessageSendEvent::BroadcastChannelUpdate { ref msg, .. } => {
assert_eq!(msg.contents.channel_flags & 2, 2);
msg.clone()
},
_ => panic!("Unexpected event"),
},
if events.len() == 2 {
match events[0] {
MessageSendEvent::SendClosingSigned { ref node_id, ref msg } => {
assert_eq!(*node_id, dest_pubkey);
Some(msg.clone())
},
_ => panic!("Unexpected event"),
},
if events.len() == 2 {
match events[0] {
MessageSendEvent::SendClosingSigned { ref node_id, ref msg } => {
assert_eq!(*node_id, $dest_pubkey);
Some(msg.clone())
},
_ => panic!("Unexpected event"),
}
} else {
None
},
)
}};
}
} else {
None
},
)
}

#[cfg(test)]
Expand DownExpand Up@@ -2313,17 +2313,6 @@ pub fn check_closed_broadcast(
.collect()
}

/// Check that a channel's closing channel update has been broadcasted, and optionally
/// check whether an error message event has occurred.
///
/// Don't use this, use the identically-named function instead.
#[macro_export]
macro_rules! check_closed_broadcast {
($node: expr, $with_error_msg: expr) => {
$crate::ln::functional_test_utils::check_closed_broadcast(&$node, 1, $with_error_msg).pop()
};
}

#[derive(Default)]
pub struct ExpectedCloseEvent {
pub channel_capacity_sats: Option<u64>,
Expand DownExpand Up@@ -2530,10 +2519,10 @@ pub fn close_channel<'a, 'b, 'c>(
assert_eq!(broadcaster_b.txn_broadcasted.lock().unwrap().len(), 1);
tx_b = broadcaster_b.txn_broadcasted.lock().unwrap().remove(0);
let (bs_update, closing_signed_b) =
get_closing_signed_broadcast!(node_b, node_a.get_our_node_id());
get_closing_signed_broadcast(struct_b, node_a.get_our_node_id());

node_a.handle_closing_signed(node_b.get_our_node_id(), &closing_signed_b.unwrap());
let (as_update, none_a) = get_closing_signed_broadcast!(node_a, node_b.get_our_node_id());
let (as_update, none_a) = get_closing_signed_broadcast(struct_a, node_b.get_our_node_id());
assert!(none_a.is_none());
assert_eq!(broadcaster_a.txn_broadcasted.lock().unwrap().len(), 1);
tx_a = broadcaster_a.txn_broadcasted.lock().unwrap().remove(0);
Expand All@@ -2550,10 +2539,10 @@ pub fn close_channel<'a, 'b, 'c>(
assert_eq!(broadcaster_a.txn_broadcasted.lock().unwrap().len(), 1);
tx_a = broadcaster_a.txn_broadcasted.lock().unwrap().remove(0);
let (as_update, closing_signed_a) =
get_closing_signed_broadcast!(node_a, node_b.get_our_node_id());
get_closing_signed_broadcast(struct_a, node_b.get_our_node_id());

node_b.handle_closing_signed(node_a.get_our_node_id(), &closing_signed_a.unwrap());
let (bs_update, none_b) = get_closing_signed_broadcast!(node_b, node_a.get_our_node_id());
let (bs_update, none_b) = get_closing_signed_broadcast(struct_b, node_a.get_our_node_id());
assert!(none_b.is_none());
assert_eq!(broadcaster_b.txn_broadcasted.lock().unwrap().len(), 1);
tx_b = broadcaster_b.txn_broadcasted.lock().unwrap().remove(0);
Expand DownExpand Up@@ -2829,26 +2818,6 @@ pub fn get_payment_preimage_hash(
(payment_preimage, payment_hash, payment_secret)
}

/// Get a payment preimage and hash.
///
/// Don't use this, use the identically-named function instead.
#[macro_export]
macro_rules! get_payment_preimage_hash {
($dest_node: expr) => {
get_payment_preimage_hash!($dest_node, None)
};
($dest_node: expr, $min_value_msat: expr) => {
$crate::get_payment_preimage_hash!($dest_node, $min_value_msat, None)
};
($dest_node: expr, $min_value_msat: expr, $min_final_cltv_expiry_delta: expr) => {
$crate::ln::functional_test_utils::get_payment_preimage_hash(
&$dest_node,
$min_value_msat,
$min_final_cltv_expiry_delta,
)
};
}

/// Gets a route from the given sender to the node described in `payment_params`.
pub fn get_route(send_node: &Node, route_params: &RouteParameters) -> Result<Route, &'static str> {
let scorer = TestScorer::new();
Expand DownExpand Up@@ -3820,7 +3789,7 @@ pub fn send_along_route<'a, 'b, 'c>(
recv_value: u64,
) -> (PaymentPreimage, PaymentHash, PaymentSecret, PaymentId) {
let (our_payment_preimage, our_payment_hash, our_payment_secret) =
get_payment_preimage_hash!(expected_route.last().unwrap());
get_payment_preimage_hash(expected_route.last().unwrap(), None, None);
let payment_id = send_along_route_with_secret(
origin_node,
route,
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
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
5 changes: 2 additions & 3 deletions lightning-persister/src/test_utils.rs
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
use lightning::check_closed_broadcast;
use lightning::events::ClosureReason;
use lightning::ln::functional_test_utils::*;
use lightning::util::persist::{
Expand DownExpand Up@@ -188,7 +187,7 @@ pub(crate) fn do_test_store<K: KVStoreSync + Sync>(store_0: &K, store_1: &K) {
.unwrap();
let reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true), message };
check_closed_event(&nodes[0], 1, reason, &[node_b_id], 100000);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);
check_added_monitors(&nodes[0], 1);

let node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
Expand All@@ -202,7 +201,7 @@ pub(crate) fn do_test_store<K: KVStoreSync + Sync>(store_0: &K, store_1: &K) {
vec![node_txn[0].clone(), node_txn[0].clone()],
),
);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
let reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, reason, &[nodes[0].node.get_our_node_id()], 100000);
check_added_monitors(&nodes[1], 1);
Expand Down
3 changes: 2 additions & 1 deletion lightning/src/ln/accountable_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,7 +26,8 @@ fn test_accountable_forwarding_with_override(
let _chan_ab = create_announced_chan_between_nodes(&nodes, 0, 1);
let _chan_bc = create_announced_chan_between_nodes(&nodes, 1, 2);

let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);
let (payment_preimage, payment_hash, payment_secret) =
get_payment_preimage_hash(&nodes[2], None, None);
let route_params = RouteParameters::from_payment_params_and_value(
PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV),
100_000,
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/async_signer_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1308,9 +1308,9 @@ fn do_test_closing_signed(extra_closing_signed: bool, reconnect: bool) {
}

nodes[0].node.signer_unblocked(None);
let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast!(nodes[0].node, node_b_id);
let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast(&nodes[0], node_b_id);
nodes[1].node.handle_closing_signed(node_a_id, &node_0_2nd_closing_signed.unwrap());
let (_, node_1_closing_signed) = get_closing_signed_broadcast!(nodes[1].node, node_a_id);
let (_, node_1_closing_signed) = get_closing_signed_broadcast(&nodes[1], node_a_id);
assert!(node_1_closing_signed.is_none());

assert!(nodes[0].node.list_channels().is_empty());
Expand Down
29 changes: 15 additions & 14 deletions lightning/src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -277,7 +277,7 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool) {
};
nodes[0].node.force_close_broadcasting_latest_txn(&channel_id, &node_b_id, message).unwrap();
check_added_monitors(&nodes[0], 1);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);

// TODO: Once we hit the chain with the failure transaction we should check that we get a
// PaymentPathFailed event
Expand DownExpand Up@@ -1382,9 +1382,9 @@ fn raa_no_response_awaiting_raa_state() {
let (route, payment_hash_1, payment_preimage_1, payment_secret_1) =
get_route_and_payment_hash!(nodes[0], nodes[1], 1000000);
let (payment_preimage_2, payment_hash_2, payment_secret_2) =
get_payment_preimage_hash!(nodes[1]);
get_payment_preimage_hash(&nodes[1], None, None);
let (payment_preimage_3, payment_hash_3, payment_secret_3) =
get_payment_preimage_hash!(nodes[1]);
get_payment_preimage_hash(&nodes[1], None, None);

// Queue up two payments - one will be delivered right away, one immediately goes into the
// holding cell as nodes[0] is AwaitingRAA. Ultimately this allows us to deliver an RAA
Expand DownExpand Up@@ -1872,7 +1872,7 @@ fn test_monitor_update_fail_claim() {
do_commitment_signed_dance(&nodes[1], &nodes[2], &payment_event.commitment_msg, false, true);
expect_htlc_failure_conditions(nodes[1].node.get_and_clear_pending_events(), &[]);

let (_, payment_hash_3, payment_secret_3) = get_payment_preimage_hash!(nodes[0]);
let (_, payment_hash_3, payment_secret_3) = get_payment_preimage_hash(&nodes[0], None, None);
let id_3 = PaymentId(payment_hash_3.0);
let onion_3 = RecipientOnionFields::secret_only(payment_secret_3);
nodes[2].node.send_payment_with_route(route, payment_hash_3, onion_3, id_3).unwrap();
Expand DownExpand Up@@ -2509,7 +2509,7 @@ fn test_fail_htlc_on_broadcast_after_claim() {
mine_transaction(&nodes[1], &bs_txn[0]);
let reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, reason, &[node_c_id], 100000);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1);
check_added_monitors(&nodes[1], 1);
expect_and_process_pending_htlcs_and_htlc_handling_failed(
Expand DownExpand Up@@ -2663,7 +2663,7 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
let (route, payment_hash_1, payment_preimage_1, payment_secret_1) =
get_route_and_payment_hash!(&nodes[0], nodes[1], 100000);
let (payment_preimage_2, payment_hash_2, payment_secret_2) =
get_payment_preimage_hash!(&nodes[1]);
get_payment_preimage_hash(&nodes[1], None, None);

// Do a really complicated dance to get an HTLC into the holding cell, with
// MonitorUpdateInProgress set but AwaitingRemoteRevoke unset. When this test was written, any
Expand DownExpand Up@@ -3048,11 +3048,11 @@ fn test_temporary_error_during_shutdown() {
node_b_id,
&get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, node_a_id),
);
let (_, closing_signed_a) = get_closing_signed_broadcast!(nodes[0].node, node_b_id);
let (_, closing_signed_a) = get_closing_signed_broadcast(&nodes[0], node_b_id);
let txn_a = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);

nodes[1].node.handle_closing_signed(node_a_id, &closing_signed_a.unwrap());
let (_, none_b) = get_closing_signed_broadcast!(nodes[1].node, node_a_id);
let (_, none_b) = get_closing_signed_broadcast(&nodes[1], node_a_id);
assert!(none_b.is_none());
let txn_b = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);

Expand DownExpand Up@@ -4043,7 +4043,7 @@ fn do_test_reload_mon_update_completion_actions(close_during_reload: bool) {
};
nodes[0].node.force_close_broadcasting_latest_txn(&chan_id_ab, &node_b_id, msg).unwrap();
check_added_monitors(&nodes[0], 1);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);
check_closed_event(&nodes[0], 1, reason, &[node_b_id], 100_000);
let as_closing_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
mine_transaction_without_consistency_checks(&nodes[1], &as_closing_tx[0]);
Expand DownExpand Up@@ -4494,13 +4494,13 @@ fn test_claim_to_closed_channel_blocks_forwarded_preimage_removal() {
check_added_monitors(&nodes[0], 1);
let a_reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true), message };
check_closed_event(&nodes[0], 1, a_reason, &[node_b_id], 1000000);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);

let as_commit_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
assert_eq!(as_commit_tx.len(), 1);

mine_transaction(&nodes[1], &as_commit_tx[0]);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
check_added_monitors(&nodes[1], 1);
let b_reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, b_reason, &[node_a_id], 1000000);
Expand DownExpand Up@@ -4572,13 +4572,13 @@ fn test_claim_to_closed_channel_blocks_claimed_event() {
check_added_monitors(&nodes[0], 1);
let a_reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true), message };
check_closed_event(&nodes[0], 1, a_reason, &[node_b_id], 1000000);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);

let as_commit_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
assert_eq!(as_commit_tx.len(), 1);

mine_transaction(&nodes[1], &as_commit_tx[0]);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
check_added_monitors(&nodes[1], 1);
let b_reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, b_reason, &[node_a_id], 1000000);
Expand DownExpand Up@@ -5099,7 +5099,8 @@ fn test_mpp_claim_to_holding_cell() {
send_along_route_with_secret(&nodes[0], route, paths, 500_000, paymnt_hash_1, payment_secret);

// Put the C <-> D channel into AwaitingRaa
let (preimage_2, paymnt_hash_2, payment_secret_2) = get_payment_preimage_hash!(nodes[3]);
let (preimage_2, paymnt_hash_2, payment_secret_2) =
get_payment_preimage_hash(&nodes[3], None, None);
let onion = RecipientOnionFields::secret_only(payment_secret_2);
let id = PaymentId([42; 32]);
let pay_params = PaymentParameters::from_node_id(node_d_id, TEST_FINAL_CLTV);
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -20522,7 +20522,7 @@ mod tests {
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);

let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(&nodes[0]);
let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[0], None, None);
let payment_data = msgs::FinalOnionHopData {
payment_secret,
total_msat: 100_000,
Expand Down
87 changes: 28 additions & 59 deletions lightning/src/ln/functional_test_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2210,31 +2210,31 @@ macro_rules! check_spends {
}
}

macro_rules! get_closing_signed_broadcast {
($node: expr, $dest_pubkey: expr) => {{
let events = $node.get_and_clear_pending_msg_events();
assert!(events.len() == 1 || events.len() == 2);
(
match events[events.len() - 1] {
MessageSendEvent::BroadcastChannelUpdate { ref msg, .. } => {
assert_eq!(msg.contents.channel_flags & 2, 2);
msg.clone()
pub fn get_closing_signed_broadcast(
node: &Node, dest_pubkey: PublicKey,
) -> (msgs::ChannelUpdate, Option<msgs::ClosingSigned>) {
let events = node.node.get_and_clear_pending_msg_events();
assert!(events.len() == 1 || events.len() == 2);
(
match events[events.len() - 1] {
MessageSendEvent::BroadcastChannelUpdate { ref msg, .. } => {
assert_eq!(msg.contents.channel_flags & 2, 2);
msg.clone()
},
_ => panic!("Unexpected event"),
},
if events.len() == 2 {
match events[0] {
MessageSendEvent::SendClosingSigned { ref node_id, ref msg } => {
assert_eq!(*node_id, dest_pubkey);
Some(msg.clone())
},
_ => panic!("Unexpected event"),
},
if events.len() == 2 {
match events[0] {
MessageSendEvent::SendClosingSigned { ref node_id, ref msg } => {
assert_eq!(*node_id, $dest_pubkey);
Some(msg.clone())
},
_ => panic!("Unexpected event"),
}
} else {
None
},
)
}};
}
} else {
None
},
)
}

#[cfg(test)]
Expand DownExpand Up@@ -2313,17 +2313,6 @@ pub fn check_closed_broadcast(
.collect()
}

/// Check that a channel's closing channel update has been broadcasted, and optionally
/// check whether an error message event has occurred.
///
/// Don't use this, use the identically-named function instead.
#[macro_export]
macro_rules! check_closed_broadcast {
($node: expr, $with_error_msg: expr) => {
$crate::ln::functional_test_utils::check_closed_broadcast(&$node, 1, $with_error_msg).pop()
};
}

#[derive(Default)]
pub struct ExpectedCloseEvent {
pub channel_capacity_sats: Option<u64>,
Expand DownExpand Up@@ -2530,10 +2519,10 @@ pub fn close_channel<'a, 'b, 'c>(
assert_eq!(broadcaster_b.txn_broadcasted.lock().unwrap().len(), 1);
tx_b = broadcaster_b.txn_broadcasted.lock().unwrap().remove(0);
let (bs_update, closing_signed_b) =
get_closing_signed_broadcast!(node_b, node_a.get_our_node_id());
get_closing_signed_broadcast(struct_b, node_a.get_our_node_id());

node_a.handle_closing_signed(node_b.get_our_node_id(), &closing_signed_b.unwrap());
let (as_update, none_a) = get_closing_signed_broadcast!(node_a, node_b.get_our_node_id());
let (as_update, none_a) = get_closing_signed_broadcast(struct_a, node_b.get_our_node_id());
assert!(none_a.is_none());
assert_eq!(broadcaster_a.txn_broadcasted.lock().unwrap().len(), 1);
tx_a = broadcaster_a.txn_broadcasted.lock().unwrap().remove(0);
Expand All@@ -2550,10 +2539,10 @@ pub fn close_channel<'a, 'b, 'c>(
assert_eq!(broadcaster_a.txn_broadcasted.lock().unwrap().len(), 1);
tx_a = broadcaster_a.txn_broadcasted.lock().unwrap().remove(0);
let (as_update, closing_signed_a) =
get_closing_signed_broadcast!(node_a, node_b.get_our_node_id());
get_closing_signed_broadcast(struct_a, node_b.get_our_node_id());

node_b.handle_closing_signed(node_a.get_our_node_id(), &closing_signed_a.unwrap());
let (bs_update, none_b) = get_closing_signed_broadcast!(node_b, node_a.get_our_node_id());
let (bs_update, none_b) = get_closing_signed_broadcast(struct_b, node_a.get_our_node_id());
assert!(none_b.is_none());
assert_eq!(broadcaster_b.txn_broadcasted.lock().unwrap().len(), 1);
tx_b = broadcaster_b.txn_broadcasted.lock().unwrap().remove(0);
Expand DownExpand Up@@ -2829,26 +2818,6 @@ pub fn get_payment_preimage_hash(
(payment_preimage, payment_hash, payment_secret)
}

/// Get a payment preimage and hash.
///
/// Don't use this, use the identically-named function instead.
#[macro_export]
macro_rules! get_payment_preimage_hash {
($dest_node: expr) => {
get_payment_preimage_hash!($dest_node, None)
};
($dest_node: expr, $min_value_msat: expr) => {
$crate::get_payment_preimage_hash!($dest_node, $min_value_msat, None)
};
($dest_node: expr, $min_value_msat: expr, $min_final_cltv_expiry_delta: expr) => {
$crate::ln::functional_test_utils::get_payment_preimage_hash(
&$dest_node,
$min_value_msat,
$min_final_cltv_expiry_delta,
)
};
}

/// Gets a route from the given sender to the node described in `payment_params`.
pub fn get_route(send_node: &Node, route_params: &RouteParameters) -> Result<Route, &'static str> {
let scorer = TestScorer::new();
Expand DownExpand Up@@ -3820,7 +3789,7 @@ pub fn send_along_route<'a, 'b, 'c>(
recv_value: u64,
) -> (PaymentPreimage, PaymentHash, PaymentSecret, PaymentId) {
let (our_payment_preimage, our_payment_hash, our_payment_secret) =
get_payment_preimage_hash!(expected_route.last().unwrap());
get_payment_preimage_hash(expected_route.last().unwrap(), None, None);
let payment_id = send_along_route_with_secret(
origin_node,
route,
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
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
5 changes: 2 additions & 3 deletions lightning-persister/src/test_utils.rs
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
use lightning::check_closed_broadcast;
use lightning::events::ClosureReason;
use lightning::ln::functional_test_utils::*;
use lightning::util::persist::{
Expand DownExpand Up@@ -188,7 +187,7 @@ pub(crate) fn do_test_store<K: KVStoreSync + Sync>(store_0: &K, store_1: &K) {
.unwrap();
let reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true), message };
check_closed_event(&nodes[0], 1, reason, &[node_b_id], 100000);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);
check_added_monitors(&nodes[0], 1);

let node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
Expand All@@ -202,7 +201,7 @@ pub(crate) fn do_test_store<K: KVStoreSync + Sync>(store_0: &K, store_1: &K) {
vec![node_txn[0].clone(), node_txn[0].clone()],
),
);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
let reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, reason, &[nodes[0].node.get_our_node_id()], 100000);
check_added_monitors(&nodes[1], 1);
Expand Down
3 changes: 2 additions & 1 deletion lightning/src/ln/accountable_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,7 +26,8 @@ fn test_accountable_forwarding_with_override(
let _chan_ab = create_announced_chan_between_nodes(&nodes, 0, 1);
let _chan_bc = create_announced_chan_between_nodes(&nodes, 1, 2);

let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);
let (payment_preimage, payment_hash, payment_secret) =
get_payment_preimage_hash(&nodes[2], None, None);
let route_params = RouteParameters::from_payment_params_and_value(
PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV),
100_000,
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/async_signer_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1308,9 +1308,9 @@ fn do_test_closing_signed(extra_closing_signed: bool, reconnect: bool) {
}

nodes[0].node.signer_unblocked(None);
let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast!(nodes[0].node, node_b_id);
let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast(&nodes[0], node_b_id);
nodes[1].node.handle_closing_signed(node_a_id, &node_0_2nd_closing_signed.unwrap());
let (_, node_1_closing_signed) = get_closing_signed_broadcast!(nodes[1].node, node_a_id);
let (_, node_1_closing_signed) = get_closing_signed_broadcast(&nodes[1], node_a_id);
assert!(node_1_closing_signed.is_none());

assert!(nodes[0].node.list_channels().is_empty());
Expand Down
29 changes: 15 additions & 14 deletions lightning/src/ln/chanmon_update_fail_tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -277,7 +277,7 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool) {
};
nodes[0].node.force_close_broadcasting_latest_txn(&channel_id, &node_b_id, message).unwrap();
check_added_monitors(&nodes[0], 1);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);

// TODO: Once we hit the chain with the failure transaction we should check that we get a
// PaymentPathFailed event
Expand DownExpand Up@@ -1382,9 +1382,9 @@ fn raa_no_response_awaiting_raa_state() {
let (route, payment_hash_1, payment_preimage_1, payment_secret_1) =
get_route_and_payment_hash!(nodes[0], nodes[1], 1000000);
let (payment_preimage_2, payment_hash_2, payment_secret_2) =
get_payment_preimage_hash!(nodes[1]);
get_payment_preimage_hash(&nodes[1], None, None);
let (payment_preimage_3, payment_hash_3, payment_secret_3) =
get_payment_preimage_hash!(nodes[1]);
get_payment_preimage_hash(&nodes[1], None, None);

// Queue up two payments - one will be delivered right away, one immediately goes into the
// holding cell as nodes[0] is AwaitingRAA. Ultimately this allows us to deliver an RAA
Expand DownExpand Up@@ -1872,7 +1872,7 @@ fn test_monitor_update_fail_claim() {
do_commitment_signed_dance(&nodes[1], &nodes[2], &payment_event.commitment_msg, false, true);
expect_htlc_failure_conditions(nodes[1].node.get_and_clear_pending_events(), &[]);

let (_, payment_hash_3, payment_secret_3) = get_payment_preimage_hash!(nodes[0]);
let (_, payment_hash_3, payment_secret_3) = get_payment_preimage_hash(&nodes[0], None, None);
let id_3 = PaymentId(payment_hash_3.0);
let onion_3 = RecipientOnionFields::secret_only(payment_secret_3);
nodes[2].node.send_payment_with_route(route, payment_hash_3, onion_3, id_3).unwrap();
Expand DownExpand Up@@ -2509,7 +2509,7 @@ fn test_fail_htlc_on_broadcast_after_claim() {
mine_transaction(&nodes[1], &bs_txn[0]);
let reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, reason, &[node_c_id], 100000);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1);
check_added_monitors(&nodes[1], 1);
expect_and_process_pending_htlcs_and_htlc_handling_failed(
Expand DownExpand Up@@ -2663,7 +2663,7 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
let (route, payment_hash_1, payment_preimage_1, payment_secret_1) =
get_route_and_payment_hash!(&nodes[0], nodes[1], 100000);
let (payment_preimage_2, payment_hash_2, payment_secret_2) =
get_payment_preimage_hash!(&nodes[1]);
get_payment_preimage_hash(&nodes[1], None, None);

// Do a really complicated dance to get an HTLC into the holding cell, with
// MonitorUpdateInProgress set but AwaitingRemoteRevoke unset. When this test was written, any
Expand DownExpand Up@@ -3048,11 +3048,11 @@ fn test_temporary_error_during_shutdown() {
node_b_id,
&get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, node_a_id),
);
let (_, closing_signed_a) = get_closing_signed_broadcast!(nodes[0].node, node_b_id);
let (_, closing_signed_a) = get_closing_signed_broadcast(&nodes[0], node_b_id);
let txn_a = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);

nodes[1].node.handle_closing_signed(node_a_id, &closing_signed_a.unwrap());
let (_, none_b) = get_closing_signed_broadcast!(nodes[1].node, node_a_id);
let (_, none_b) = get_closing_signed_broadcast(&nodes[1], node_a_id);
assert!(none_b.is_none());
let txn_b = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);

Expand DownExpand Up@@ -4043,7 +4043,7 @@ fn do_test_reload_mon_update_completion_actions(close_during_reload: bool) {
};
nodes[0].node.force_close_broadcasting_latest_txn(&chan_id_ab, &node_b_id, msg).unwrap();
check_added_monitors(&nodes[0], 1);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);
check_closed_event(&nodes[0], 1, reason, &[node_b_id], 100_000);
let as_closing_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
mine_transaction_without_consistency_checks(&nodes[1], &as_closing_tx[0]);
Expand DownExpand Up@@ -4494,13 +4494,13 @@ fn test_claim_to_closed_channel_blocks_forwarded_preimage_removal() {
check_added_monitors(&nodes[0], 1);
let a_reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true), message };
check_closed_event(&nodes[0], 1, a_reason, &[node_b_id], 1000000);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);

let as_commit_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
assert_eq!(as_commit_tx.len(), 1);

mine_transaction(&nodes[1], &as_commit_tx[0]);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
check_added_monitors(&nodes[1], 1);
let b_reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, b_reason, &[node_a_id], 1000000);
Expand DownExpand Up@@ -4572,13 +4572,13 @@ fn test_claim_to_closed_channel_blocks_claimed_event() {
check_added_monitors(&nodes[0], 1);
let a_reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true), message };
check_closed_event(&nodes[0], 1, a_reason, &[node_b_id], 1000000);
check_closed_broadcast!(nodes[0], true);
check_closed_broadcast(&nodes[0], 1, true);

let as_commit_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
assert_eq!(as_commit_tx.len(), 1);

mine_transaction(&nodes[1], &as_commit_tx[0]);
check_closed_broadcast!(nodes[1], true);
check_closed_broadcast(&nodes[1], 1, true);
check_added_monitors(&nodes[1], 1);
let b_reason = ClosureReason::CommitmentTxConfirmed;
check_closed_event(&nodes[1], 1, b_reason, &[node_a_id], 1000000);
Expand DownExpand Up@@ -5099,7 +5099,8 @@ fn test_mpp_claim_to_holding_cell() {
send_along_route_with_secret(&nodes[0], route, paths, 500_000, paymnt_hash_1, payment_secret);

// Put the C <-> D channel into AwaitingRaa
let (preimage_2, paymnt_hash_2, payment_secret_2) = get_payment_preimage_hash!(nodes[3]);
let (preimage_2, paymnt_hash_2, payment_secret_2) =
get_payment_preimage_hash(&nodes[3], None, None);
let onion = RecipientOnionFields::secret_only(payment_secret_2);
let id = PaymentId([42; 32]);
let pay_params = PaymentParameters::from_node_id(node_d_id, TEST_FINAL_CLTV);
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/channelmanager.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -20522,7 +20522,7 @@ mod tests {
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);

let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(&nodes[0]);
let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[0], None, None);
let payment_data = msgs::FinalOnionHopData {
payment_secret,
total_msat: 100_000,
Expand Down
87 changes: 28 additions & 59 deletions lightning/src/ln/functional_test_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -2210,31 +2210,31 @@ macro_rules! check_spends {
}
}

macro_rules! get_closing_signed_broadcast {
($node: expr, $dest_pubkey: expr) => {{
let events = $node.get_and_clear_pending_msg_events();
assert!(events.len() == 1 || events.len() == 2);
(
match events[events.len() - 1] {
MessageSendEvent::BroadcastChannelUpdate { ref msg, .. } => {
assert_eq!(msg.contents.channel_flags & 2, 2);
msg.clone()
pub fn get_closing_signed_broadcast(
node: &Node, dest_pubkey: PublicKey,
) -> (msgs::ChannelUpdate, Option<msgs::ClosingSigned>) {
let events = node.node.get_and_clear_pending_msg_events();
assert!(events.len() == 1 || events.len() == 2);
(
match events[events.len() - 1] {
MessageSendEvent::BroadcastChannelUpdate { ref msg, .. } => {
assert_eq!(msg.contents.channel_flags & 2, 2);
msg.clone()
},
_ => panic!("Unexpected event"),
},
if events.len() == 2 {
match events[0] {
MessageSendEvent::SendClosingSigned { ref node_id, ref msg } => {
assert_eq!(*node_id, dest_pubkey);
Some(msg.clone())
},
_ => panic!("Unexpected event"),
},
if events.len() == 2 {
match events[0] {
MessageSendEvent::SendClosingSigned { ref node_id, ref msg } => {
assert_eq!(*node_id, $dest_pubkey);
Some(msg.clone())
},
_ => panic!("Unexpected event"),
}
} else {
None
},
)
}};
}
} else {
None
},
)
}

#[cfg(test)]
Expand DownExpand Up@@ -2313,17 +2313,6 @@ pub fn check_closed_broadcast(
.collect()
}

/// Check that a channel's closing channel update has been broadcasted, and optionally
/// check whether an error message event has occurred.
///
/// Don't use this, use the identically-named function instead.
#[macro_export]
macro_rules! check_closed_broadcast {
($node: expr, $with_error_msg: expr) => {
$crate::ln::functional_test_utils::check_closed_broadcast(&$node, 1, $with_error_msg).pop()
};
}

#[derive(Default)]
pub struct ExpectedCloseEvent {
pub channel_capacity_sats: Option<u64>,
Expand DownExpand Up@@ -2530,10 +2519,10 @@ pub fn close_channel<'a, 'b, 'c>(
assert_eq!(broadcaster_b.txn_broadcasted.lock().unwrap().len(), 1);
tx_b = broadcaster_b.txn_broadcasted.lock().unwrap().remove(0);
let (bs_update, closing_signed_b) =
get_closing_signed_broadcast!(node_b, node_a.get_our_node_id());
get_closing_signed_broadcast(struct_b, node_a.get_our_node_id());

node_a.handle_closing_signed(node_b.get_our_node_id(), &closing_signed_b.unwrap());
let (as_update, none_a) = get_closing_signed_broadcast!(node_a, node_b.get_our_node_id());
let (as_update, none_a) = get_closing_signed_broadcast(struct_a, node_b.get_our_node_id());
assert!(none_a.is_none());
assert_eq!(broadcaster_a.txn_broadcasted.lock().unwrap().len(), 1);
tx_a = broadcaster_a.txn_broadcasted.lock().unwrap().remove(0);
Expand All@@ -2550,10 +2539,10 @@ pub fn close_channel<'a, 'b, 'c>(
assert_eq!(broadcaster_a.txn_broadcasted.lock().unwrap().len(), 1);
tx_a = broadcaster_a.txn_broadcasted.lock().unwrap().remove(0);
let (as_update, closing_signed_a) =
get_closing_signed_broadcast!(node_a, node_b.get_our_node_id());
get_closing_signed_broadcast(struct_a, node_b.get_our_node_id());

node_b.handle_closing_signed(node_a.get_our_node_id(), &closing_signed_a.unwrap());
let (bs_update, none_b) = get_closing_signed_broadcast!(node_b, node_a.get_our_node_id());
let (bs_update, none_b) = get_closing_signed_broadcast(struct_b, node_a.get_our_node_id());
assert!(none_b.is_none());
assert_eq!(broadcaster_b.txn_broadcasted.lock().unwrap().len(), 1);
tx_b = broadcaster_b.txn_broadcasted.lock().unwrap().remove(0);
Expand DownExpand Up@@ -2829,26 +2818,6 @@ pub fn get_payment_preimage_hash(
(payment_preimage, payment_hash, payment_secret)
}

/// Get a payment preimage and hash.
///
/// Don't use this, use the identically-named function instead.
#[macro_export]
macro_rules! get_payment_preimage_hash {
($dest_node: expr) => {
get_payment_preimage_hash!($dest_node, None)
};
($dest_node: expr, $min_value_msat: expr) => {
$crate::get_payment_preimage_hash!($dest_node, $min_value_msat, None)
};
($dest_node: expr, $min_value_msat: expr, $min_final_cltv_expiry_delta: expr) => {
$crate::ln::functional_test_utils::get_payment_preimage_hash(
&$dest_node,
$min_value_msat,
$min_final_cltv_expiry_delta,
)
};
}

/// Gets a route from the given sender to the node described in `payment_params`.
pub fn get_route(send_node: &Node, route_params: &RouteParameters) -> Result<Route, &'static str> {
let scorer = TestScorer::new();
Expand DownExpand Up@@ -3820,7 +3789,7 @@ pub fn send_along_route<'a, 'b, 'c>(
recv_value: u64,
) -> (PaymentPreimage, PaymentHash, PaymentSecret, PaymentId) {
let (our_payment_preimage, our_payment_hash, our_payment_secret) =
get_payment_preimage_hash!(expected_route.last().unwrap());
get_payment_preimage_hash(expected_route.last().unwrap(), None, None);
let payment_id = send_along_route_with_secret(
origin_node,
route,
Expand Down
Loading
Loading