Skip to content

Commit 7e3de70

Browse files
authored
Merge pull request #2481 from TheBlueMatt/2023-08-keysend-robust-test
Scope payment preimage in do_test_keysend_payments
2 parents 4b24135 + 67e5399 commit 7e3de70

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

ci/ci-tests.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,30 +37,30 @@ PIN_RELEASE_DEPS # pin the release dependencies in our main workspace
3737
export RUST_BACKTRACE=1
3838

3939
echo -e "\n\nBuilding and testing all workspace crates..."
40-
cargo build --verbose --color always
4140
cargo test --verbose --color always
41+
cargo build --verbose --color always
4242

4343
echo -e "\n\nBuilding and testing Block Sync Clients with features"
4444
pushd lightning-block-sync
45-
cargo build --verbose --color always --features rest-client
4645
cargo test --verbose --color always --features rest-client
47-
cargo build --verbose --color always --features rpc-client
46+
cargo build --verbose --color always --features rest-client
4847
cargo test --verbose --color always --features rpc-client
49-
cargo build --verbose --color always --features rpc-client,rest-client
48+
cargo build --verbose --color always --features rpc-client
5049
cargo test --verbose --color always --features rpc-client,rest-client
51-
cargo build --verbose --color always --features rpc-client,rest-client,tokio
50+
cargo build --verbose --color always --features rpc-client,rest-client
5251
cargo test --verbose --color always --features rpc-client,rest-client,tokio
52+
cargo build --verbose --color always --features rpc-client,rest-client,tokio
5353
popd
5454

5555
if [[ $RUSTC_MINOR_VERSION -gt 67 && "$HOST_PLATFORM" != *windows* ]]; then
5656
echo -e "\n\nBuilding and testing Transaction Sync Clients with features"
5757
pushd lightning-transaction-sync
58-
cargo build --verbose --color always --features esplora-blocking
5958
cargo test --verbose --color always --features esplora-blocking
60-
cargo build --verbose --color always --features esplora-async
59+
cargo build --verbose --color always --features esplora-blocking
6160
cargo test --verbose --color always --features esplora-async
62-
cargo build --verbose --color always --features esplora-async-https
61+
cargo build --verbose --color always --features esplora-async
6362
cargo test --verbose --color always --features esplora-async-https
63+
cargo build --verbose --color always --features esplora-async-https
6464
popd
6565
fi
6666

lightning/src/ln/payment_tests.rs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::chain::{ChannelMonitorUpdateStatus, Confirm, Listen, Watch};
1515
use crate::chain::channelmonitor::{ANTI_REORG_DELAY, HTLC_FAIL_BACK_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS};
1616
use crate::sign::EntropySource;
1717
use crate::chain::transaction::OutPoint;
18-
use crate::events::{ClosureReason, Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider, PathFailure, PaymentFailureReason};
18+
use crate::events::{ClosureReason, Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider, PathFailure, PaymentFailureReason, PaymentPurpose};
1919
use crate::ln::channel::EXPIRE_PREV_CONFIG_TICKS;
2020
use crate::ln::channelmanager::{BREAKDOWN_TIMEOUT, ChannelManager, MPP_TIMEOUT_TICKS, MIN_CLTV_EXPIRY_DELTA, PaymentId, PaymentSendFailure, IDEMPOTENCY_TIMEOUT_TICKS, RecentPaymentDetails, RecipientOnionFields, HTLCForwardInfo, PendingHTLCRouting, PendingAddHTLCInfo};
2121
use crate::ln::features::Bolt11InvoiceFeatures;
@@ -274,22 +274,31 @@ fn do_test_keysend_payments(public_node: bool, with_retry: bool) {
274274
nodes[0].logger, &scorer, &(), &random_seed_bytes
275275
).unwrap();
276276

277-
let test_preimage = PaymentPreimage([42; 32]);
278-
let payment_hash = if with_retry {
279-
nodes[0].node.send_spontaneous_payment_with_retry(Some(test_preimage),
280-
RecipientOnionFields::spontaneous_empty(), PaymentId(test_preimage.0),
281-
route_params, Retry::Attempts(1)).unwrap()
282-
} else {
283-
nodes[0].node.send_spontaneous_payment(&route, Some(test_preimage),
284-
RecipientOnionFields::spontaneous_empty(), PaymentId(test_preimage.0)).unwrap()
285-
};
277+
{
278+
let test_preimage = PaymentPreimage([42; 32]);
279+
if with_retry {
280+
nodes[0].node.send_spontaneous_payment_with_retry(Some(test_preimage),
281+
RecipientOnionFields::spontaneous_empty(), PaymentId(test_preimage.0),
282+
route_params, Retry::Attempts(1)).unwrap()
283+
} else {
284+
nodes[0].node.send_spontaneous_payment(&route, Some(test_preimage),
285+
RecipientOnionFields::spontaneous_empty(), PaymentId(test_preimage.0)).unwrap()
286+
};
287+
}
286288
check_added_monitors!(nodes[0], 1);
287-
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
288-
assert_eq!(events.len(), 1);
289-
let event = events.pop().unwrap();
290-
let path = vec![&nodes[1]];
291-
pass_along_path(&nodes[0], &path, 10000, payment_hash, None, event, true, Some(test_preimage));
292-
claim_payment(&nodes[0], &path, test_preimage);
289+
let send_event = SendEvent::from_node(&nodes[0]);
290+
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &send_event.msgs[0]);
291+
do_commitment_signed_dance(&nodes[1], &nodes[0], &send_event.commitment_msg, false, false);
292+
expect_pending_htlcs_forwardable!(nodes[1]);
293+
// Previously, a refactor caused us to stop including the payment preimage in the onion which
294+
// is sent as a part of keysend payments. Thus, to be extra careful here, we scope the preimage
295+
// above to demonstrate that we have no way to get the preimage at this point except by
296+
// extracting it from the onion nodes[1] received.
297+
let event = nodes[1].node.get_and_clear_pending_events();
298+
assert_eq!(event.len(), 1);
299+
if let Event::PaymentClaimable { purpose: PaymentPurpose::SpontaneousPayment(preimage), .. } = event[0] {
300+
claim_payment(&nodes[0], &[&nodes[1]], preimage);
301+
} else { panic!(); }
293302
}
294303

295304
#[test]

0 commit comments

Comments
 (0)