Skip to content

Commit 02b5564

Browse files
authored
Merge pull request #3584 from TheBlueMatt/2025-02-upgrade-tests
Add a simple test of upgrading from LDK 0.1 and correct `in_flight_monitor_updates` on upgrade
2 parents 4277868 + 86c661a commit 02b5564

12 files changed

+186
-125
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ members = [
2121

2222
exclude = [
2323
"lightning-transaction-sync",
24+
"lightning-tests",
2425
"ext-functional-test-demo",
2526
"no-std-check",
2627
"msrv-no-dev-deps-check",

ci/ci-tests.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,17 @@ WORKSPACE_MEMBERS=(
5050
possiblyrandom
5151
)
5252

53-
echo -e "\n\nChecking, testing, and building docs for all workspace members individually..."
53+
echo -e "\n\nTesting the workspace, except lightning-transaction-sync."
54+
cargo test --verbose --color always
55+
56+
echo -e "\n\nTesting upgrade from prior versions of LDK"
57+
pushd lightning-tests
58+
[ "$RUSTC_MINOR_VERSION" -lt 65 ] && cargo update -p regex --precise "1.9.6" --verbose
59+
cargo test
60+
popd
61+
62+
echo -e "\n\nChecking and building docs for all workspace members individually..."
5463
for DIR in "${WORKSPACE_MEMBERS[@]}"; do
55-
cargo test -p "$DIR" --verbose --color always
5664
cargo check -p "$DIR" --verbose --color always
5765
cargo doc -p "$DIR" --document-private-items
5866
done

fuzz/src/chanmon_consistency.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ impl SignerProvider for KeyProvider {
380380
);
381381
let revoked_commitment = self.make_enforcement_state_cell(keys.commitment_seed);
382382
let keys = DynSigner::new(keys);
383-
TestChannelSigner::new_with_revoked(keys, revoked_commitment, false)
383+
TestChannelSigner::new_with_revoked(keys, revoked_commitment, false, false)
384384
}
385385

386386
fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> {

fuzz/src/full_stack.rs

Lines changed: 21 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -443,85 +443,29 @@ impl SignerProvider for KeyProvider {
443443
[ctr; 32]
444444
}
445445

446-
fn derive_channel_signer(&self, channel_keys_id: [u8; 32]) -> Self::EcdsaSigner {
446+
fn derive_channel_signer(&self, keys_id: [u8; 32]) -> Self::EcdsaSigner {
447447
let secp_ctx = Secp256k1::signing_only();
448-
let ctr = channel_keys_id[0];
448+
let ctr = keys_id[0];
449449
let (inbound, state) = self.signer_state.borrow().get(&ctr).unwrap().clone();
450-
TestChannelSigner::new_with_revoked(
451-
DynSigner::new(if inbound {
452-
InMemorySigner::new(
453-
&secp_ctx,
454-
SecretKey::from_slice(&[
455-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
456-
0, 0, 0, 0, 0, 1, ctr,
457-
])
458-
.unwrap(),
459-
SecretKey::from_slice(&[
460-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
461-
0, 0, 0, 0, 0, 2, ctr,
462-
])
463-
.unwrap(),
464-
SecretKey::from_slice(&[
465-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
466-
0, 0, 0, 0, 0, 3, ctr,
467-
])
468-
.unwrap(),
469-
SecretKey::from_slice(&[
470-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
471-
0, 0, 0, 0, 0, 4, ctr,
472-
])
473-
.unwrap(),
474-
SecretKey::from_slice(&[
475-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
476-
0, 0, 0, 0, 0, 5, ctr,
477-
])
478-
.unwrap(),
479-
[
480-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
481-
0, 0, 0, 0, 0, 6, ctr,
482-
],
483-
channel_keys_id,
484-
channel_keys_id,
485-
)
486-
} else {
487-
InMemorySigner::new(
488-
&secp_ctx,
489-
SecretKey::from_slice(&[
490-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
491-
0, 0, 0, 0, 0, 7, ctr,
492-
])
493-
.unwrap(),
494-
SecretKey::from_slice(&[
495-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
496-
0, 0, 0, 0, 0, 8, ctr,
497-
])
498-
.unwrap(),
499-
SecretKey::from_slice(&[
500-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
501-
0, 0, 0, 0, 0, 9, ctr,
502-
])
503-
.unwrap(),
504-
SecretKey::from_slice(&[
505-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
506-
0, 0, 0, 0, 0, 10, ctr,
507-
])
508-
.unwrap(),
509-
SecretKey::from_slice(&[
510-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
511-
0, 0, 0, 0, 0, 11, ctr,
512-
])
513-
.unwrap(),
514-
[
515-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
516-
0, 0, 0, 0, 0, 12, ctr,
517-
],
518-
channel_keys_id,
519-
channel_keys_id,
520-
)
521-
}),
522-
state,
523-
false,
524-
)
450+
451+
let (a, b, c, d, e, f);
452+
let mut key = [0; 32];
453+
key[31] = ctr;
454+
key[30] = 1 + if inbound { 0 } else { 6 };
455+
a = SecretKey::from_slice(&key).unwrap();
456+
key[30] = 2 + if inbound { 0 } else { 6 };
457+
b = SecretKey::from_slice(&key).unwrap();
458+
key[30] = 3 + if inbound { 0 } else { 6 };
459+
c = SecretKey::from_slice(&key).unwrap();
460+
key[30] = 4 + if inbound { 0 } else { 6 };
461+
d = SecretKey::from_slice(&key).unwrap();
462+
key[30] = 5 + if inbound { 0 } else { 6 };
463+
e = SecretKey::from_slice(&key).unwrap();
464+
key[30] = 6 + if inbound { 0 } else { 6 };
465+
f = key;
466+
let signer = InMemorySigner::new(&secp_ctx, a, b, c, d, e, f, keys_id, keys_id);
467+
468+
TestChannelSigner::new_with_revoked(DynSigner::new(signer), state, false, false)
525469
}
526470

527471
fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> {

lightning-tests/Cargo.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
name = "lightning-tests"
3+
version = "0.0.1"
4+
authors = ["Matt Corallo"]
5+
license = "MIT OR Apache-2.0"
6+
repository = "https://github.com/lightningdevkit/rust-lightning/"
7+
description = "Tests for LDK crates"
8+
edition = "2021"
9+
10+
[features]
11+
12+
[dependencies]
13+
lightning-types = { path = "../lightning-types", features = ["_test_utils"] }
14+
lightning-invoice = { path = "../lightning-invoice", default-features = false }
15+
lightning-macros = { path = "../lightning-macros" }
16+
lightning = { path = "../lightning", features = ["_test_utils"] }
17+
lightning_0_1 = { package = "lightning", version = "0.1.1", features = ["_test_utils"] }
18+
19+
bitcoin = { version = "0.32.2", default-features = false }
20+
21+
[dev-dependencies]

lightning-tests/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#[cfg_attr(test, macro_use)]
2+
extern crate lightning;
3+
4+
#[cfg(all(test, not(taproot)))]
5+
pub mod upgrade_downgrade_tests;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// This file is Copyright its original authors, visible in version control
2+
// history.
3+
//
4+
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5+
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7+
// You may not use this file except in accordance with one or both of these
8+
// licenses.
9+
10+
//! Tests which test upgrading from previous versions of LDK or downgrading to previous versions of
11+
//! LDK.
12+
13+
use lightning_0_1::get_monitor as get_monitor_0_1;
14+
use lightning_0_1::ln::functional_test_utils as lightning_0_1_utils;
15+
use lightning_0_1::util::ser::Writeable;
16+
17+
use lightning::ln::functional_test_utils::*;
18+
19+
use lightning_types::payment::PaymentPreimage;
20+
21+
#[test]
22+
fn simple_upgrade() {
23+
// Tests a simple case of upgrading from LDK 0.1 with a pending payment
24+
let (node_a_ser, node_b_ser, mon_a_ser, mon_b_ser, preimage);
25+
{
26+
let chanmon_cfgs = lightning_0_1_utils::create_chanmon_cfgs(2);
27+
let node_cfgs = lightning_0_1_utils::create_node_cfgs(2, &chanmon_cfgs);
28+
let node_chanmgrs = lightning_0_1_utils::create_node_chanmgrs(2, &node_cfgs, &[None, None]);
29+
let nodes = lightning_0_1_utils::create_network(2, &node_cfgs, &node_chanmgrs);
30+
31+
let chan_id = lightning_0_1_utils::create_announced_chan_between_nodes(&nodes, 0, 1).2;
32+
33+
let payment_preimage =
34+
lightning_0_1_utils::route_payment(&nodes[0], &[&nodes[1]], 1_000_000);
35+
preimage = PaymentPreimage(payment_preimage.0 .0);
36+
37+
node_a_ser = nodes[0].node.encode();
38+
node_b_ser = nodes[1].node.encode();
39+
mon_a_ser = get_monitor_0_1!(nodes[0], chan_id).encode();
40+
mon_b_ser = get_monitor_0_1!(nodes[1], chan_id).encode();
41+
}
42+
43+
// Create a dummy node to reload over with the 0.1 state
44+
45+
let mut chanmon_cfgs = create_chanmon_cfgs(2);
46+
47+
// Our TestChannelSigner will fail as we're jumping ahead, so disable its state-based checks
48+
chanmon_cfgs[0].keys_manager.disable_all_state_policy_checks = true;
49+
chanmon_cfgs[1].keys_manager.disable_all_state_policy_checks = true;
50+
51+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
52+
let (persister_a, persister_b, chain_mon_a, chain_mon_b);
53+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
54+
let (node_a, node_b);
55+
let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
56+
57+
let config = test_default_channel_config();
58+
let a_mons = &[&mon_a_ser[..]];
59+
reload_node!(nodes[0], config.clone(), &node_a_ser, a_mons, persister_a, chain_mon_a, node_a);
60+
reload_node!(nodes[1], config, &node_b_ser, &[&mon_b_ser], persister_b, chain_mon_b, node_b);
61+
62+
reconnect_nodes(ReconnectArgs::new(&nodes[0], &nodes[1]));
63+
64+
claim_payment(&nodes[0], &[&nodes[1]], preimage);
65+
}

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13566,7 +13566,7 @@ where
1356613566
(13, htlc_onion_fields, optional_vec),
1356713567
(14, decode_update_add_htlcs_opt, option),
1356813568
(15, self.inbound_payment_id_secret, required),
13569-
(17, in_flight_monitor_updates, required),
13569+
(17, in_flight_monitor_updates, option),
1357013570
(19, peer_storage_dir, optional_vec),
1357113571
});
1357213572

@@ -14097,7 +14097,7 @@ where
1409714097
(13, claimable_htlc_onion_fields, optional_vec),
1409814098
(14, decode_update_add_htlcs, option),
1409914099
(15, inbound_payment_id_secret, option),
14100-
(17, in_flight_monitor_updates, required),
14100+
(17, in_flight_monitor_updates, option),
1410114101
(19, peer_storage_dir, optional_vec),
1410214102
});
1410314103
let mut decode_update_add_htlcs = decode_update_add_htlcs.unwrap_or_else(|| new_hash_map());

lightning/src/ln/functional_test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,7 @@ pub fn _reload_node<'a, 'b, 'c>(node: &'a Node<'a, 'b, 'c>, default_config: User
11971197
node_deserialized
11981198
}
11991199

1200-
#[cfg(any(test, feature = "_externalize_tests"))]
1200+
#[macro_export]
12011201
macro_rules! reload_node {
12021202
($node: expr, $new_config: expr, $chanman_encoded: expr, $monitors_encoded: expr, $persister: ident, $new_chain_monitor: ident, $new_channelmanager: ident) => {
12031203
let chanman_encoded = $chanman_encoded;

lightning/src/onion_message/messenger.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,8 +1313,8 @@ where
13131313
}
13141314
}
13151315

1316-
#[cfg(any(test, feature = "_externalize_tests"))]
1317-
pub(crate) fn set_offers_handler(&mut self, offers_handler: OMH) {
1316+
#[cfg(any(test, feature = "_test_utils"))]
1317+
pub fn set_offers_handler(&mut self, offers_handler: OMH) {
13181318
self.offers_handler = offers_handler;
13191319
}
13201320

0 commit comments

Comments
 (0)