Skip to content

Add a simple test of upgrading from LDK 0.1 and correct in_flight_monitor_updates on upgrade #3584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 21, 2025
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ members = [

exclude = [
"lightning-transaction-sync",
"lightning-tests",
"ext-functional-test-demo",
"no-std-check",
"msrv-no-dev-deps-check",
Expand Down
12 changes: 10 additions & 2 deletions ci/ci-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,17 @@ WORKSPACE_MEMBERS=(
possiblyrandom
)

echo -e "\n\nChecking, testing, and building docs for all workspace members individually..."
echo -e "\n\nTesting the workspace, except lightning-transaction-sync."
cargo test --verbose --color always

echo -e "\n\nTesting upgrade from prior versions of LDK"
pushd lightning-tests
[ "$RUSTC_MINOR_VERSION" -lt 65 ] && cargo update -p regex --precise "1.9.6" --verbose
cargo test
popd

echo -e "\n\nChecking and building docs for all workspace members individually..."
for DIR in "${WORKSPACE_MEMBERS[@]}"; do
cargo test -p "$DIR" --verbose --color always
cargo check -p "$DIR" --verbose --color always
cargo doc -p "$DIR" --document-private-items
done
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/chanmon_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ impl SignerProvider for KeyProvider {
);
let revoked_commitment = self.make_enforcement_state_cell(keys.commitment_seed);
let keys = DynSigner::new(keys);
TestChannelSigner::new_with_revoked(keys, revoked_commitment, false)
TestChannelSigner::new_with_revoked(keys, revoked_commitment, false, false)
}

fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> {
Expand Down
98 changes: 21 additions & 77 deletions fuzz/src/full_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,85 +443,29 @@ impl SignerProvider for KeyProvider {
[ctr; 32]
}

fn derive_channel_signer(&self, channel_keys_id: [u8; 32]) -> Self::EcdsaSigner {
fn derive_channel_signer(&self, keys_id: [u8; 32]) -> Self::EcdsaSigner {
let secp_ctx = Secp256k1::signing_only();
let ctr = channel_keys_id[0];
let ctr = keys_id[0];
let (inbound, state) = self.signer_state.borrow().get(&ctr).unwrap().clone();
TestChannelSigner::new_with_revoked(
DynSigner::new(if inbound {
InMemorySigner::new(
&secp_ctx,
SecretKey::from_slice(&[
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,
0, 0, 0, 0, 0, 1, ctr,
])
.unwrap(),
SecretKey::from_slice(&[
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,
0, 0, 0, 0, 0, 2, ctr,
])
.unwrap(),
SecretKey::from_slice(&[
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,
0, 0, 0, 0, 0, 3, ctr,
])
.unwrap(),
SecretKey::from_slice(&[
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,
0, 0, 0, 0, 0, 4, ctr,
])
.unwrap(),
SecretKey::from_slice(&[
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,
0, 0, 0, 0, 0, 5, ctr,
])
.unwrap(),
[
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,
0, 0, 0, 0, 0, 6, ctr,
],
channel_keys_id,
channel_keys_id,
)
} else {
InMemorySigner::new(
&secp_ctx,
SecretKey::from_slice(&[
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,
0, 0, 0, 0, 0, 7, ctr,
])
.unwrap(),
SecretKey::from_slice(&[
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,
0, 0, 0, 0, 0, 8, ctr,
])
.unwrap(),
SecretKey::from_slice(&[
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,
0, 0, 0, 0, 0, 9, ctr,
])
.unwrap(),
SecretKey::from_slice(&[
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,
0, 0, 0, 0, 0, 10, ctr,
])
.unwrap(),
SecretKey::from_slice(&[
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,
0, 0, 0, 0, 0, 11, ctr,
])
.unwrap(),
[
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,
0, 0, 0, 0, 0, 12, ctr,
],
channel_keys_id,
channel_keys_id,
)
}),
state,
false,
)

let (a, b, c, d, e, f);
let mut key = [0; 32];
key[31] = ctr;
key[30] = 1 + if inbound { 0 } else { 6 };
a = SecretKey::from_slice(&key).unwrap();
key[30] = 2 + if inbound { 0 } else { 6 };
b = SecretKey::from_slice(&key).unwrap();
key[30] = 3 + if inbound { 0 } else { 6 };
c = SecretKey::from_slice(&key).unwrap();
key[30] = 4 + if inbound { 0 } else { 6 };
d = SecretKey::from_slice(&key).unwrap();
key[30] = 5 + if inbound { 0 } else { 6 };
e = SecretKey::from_slice(&key).unwrap();
key[30] = 6 + if inbound { 0 } else { 6 };
f = key;
let signer = InMemorySigner::new(&secp_ctx, a, b, c, d, e, f, keys_id, keys_id);

TestChannelSigner::new_with_revoked(DynSigner::new(signer), state, false, false)
}

fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> {
Expand Down
21 changes: 21 additions & 0 deletions lightning-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "lightning-tests"
version = "0.0.1"
authors = ["Matt Corallo"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/lightningdevkit/rust-lightning/"
description = "Tests for LDK crates"
edition = "2021"

[features]

[dependencies]
lightning-types = { path = "../lightning-types", features = ["_test_utils"] }
lightning-invoice = { path = "../lightning-invoice", default-features = false }
lightning-macros = { path = "../lightning-macros" }
lightning = { path = "../lightning", features = ["_test_utils"] }
lightning_0_1 = { package = "lightning", version = "0.1.1", features = ["_test_utils"] }

bitcoin = { version = "0.32.2", default-features = false }

[dev-dependencies]
5 changes: 5 additions & 0 deletions lightning-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[cfg_attr(test, macro_use)]
extern crate lightning;

#[cfg(all(test, not(taproot)))]
pub mod upgrade_downgrade_tests;
65 changes: 65 additions & 0 deletions lightning-tests/src/upgrade_downgrade_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// This file is Copyright its original authors, visible in version control
// history.
//
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
// You may not use this file except in accordance with one or both of these
// licenses.

//! Tests which test upgrading from previous versions of LDK or downgrading to previous versions of
//! LDK.

use lightning_0_1::get_monitor as get_monitor_0_1;
use lightning_0_1::ln::functional_test_utils as lightning_0_1_utils;
use lightning_0_1::util::ser::Writeable;

use lightning::ln::functional_test_utils::*;

use lightning_types::payment::PaymentPreimage;

#[test]
fn simple_upgrade() {
// Tests a simple case of upgrading from LDK 0.1 with a pending payment
let (node_a_ser, node_b_ser, mon_a_ser, mon_b_ser, preimage);
{
let chanmon_cfgs = lightning_0_1_utils::create_chanmon_cfgs(2);
let node_cfgs = lightning_0_1_utils::create_node_cfgs(2, &chanmon_cfgs);
let node_chanmgrs = lightning_0_1_utils::create_node_chanmgrs(2, &node_cfgs, &[None, None]);
let nodes = lightning_0_1_utils::create_network(2, &node_cfgs, &node_chanmgrs);

let chan_id = lightning_0_1_utils::create_announced_chan_between_nodes(&nodes, 0, 1).2;

let payment_preimage =
lightning_0_1_utils::route_payment(&nodes[0], &[&nodes[1]], 1_000_000);
preimage = PaymentPreimage(payment_preimage.0 .0);

node_a_ser = nodes[0].node.encode();
node_b_ser = nodes[1].node.encode();
mon_a_ser = get_monitor_0_1!(nodes[0], chan_id).encode();
mon_b_ser = get_monitor_0_1!(nodes[1], chan_id).encode();
}

// Create a dummy node to reload over with the 0.1 state

let mut chanmon_cfgs = create_chanmon_cfgs(2);

// Our TestChannelSigner will fail as we're jumping ahead, so disable its state-based checks
chanmon_cfgs[0].keys_manager.disable_all_state_policy_checks = true;
chanmon_cfgs[1].keys_manager.disable_all_state_policy_checks = true;

let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
let (persister_a, persister_b, chain_mon_a, chain_mon_b);
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
let (node_a, node_b);
let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);

let config = test_default_channel_config();
let a_mons = &[&mon_a_ser[..]];
reload_node!(nodes[0], config.clone(), &node_a_ser, a_mons, persister_a, chain_mon_a, node_a);
reload_node!(nodes[1], config, &node_b_ser, &[&mon_b_ser], persister_b, chain_mon_b, node_b);

reconnect_nodes(ReconnectArgs::new(&nodes[0], &nodes[1]));

claim_payment(&nodes[0], &[&nodes[1]], preimage);
}
4 changes: 2 additions & 2 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13566,7 +13566,7 @@ where
(13, htlc_onion_fields, optional_vec),
(14, decode_update_add_htlcs_opt, option),
(15, self.inbound_payment_id_secret, required),
(17, in_flight_monitor_updates, required),
(17, in_flight_monitor_updates, option),
(19, peer_storage_dir, optional_vec),
});

Expand Down Expand Up @@ -14097,7 +14097,7 @@ where
(13, claimable_htlc_onion_fields, optional_vec),
(14, decode_update_add_htlcs, option),
(15, inbound_payment_id_secret, option),
(17, in_flight_monitor_updates, required),
(17, in_flight_monitor_updates, option),
(19, peer_storage_dir, optional_vec),
});
let mut decode_update_add_htlcs = decode_update_add_htlcs.unwrap_or_else(|| new_hash_map());
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/functional_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ pub fn _reload_node<'a, 'b, 'c>(node: &'a Node<'a, 'b, 'c>, default_config: User
node_deserialized
}

#[cfg(any(test, feature = "_externalize_tests"))]
#[macro_export]
macro_rules! reload_node {
($node: expr, $new_config: expr, $chanman_encoded: expr, $monitors_encoded: expr, $persister: ident, $new_chain_monitor: ident, $new_channelmanager: ident) => {
let chanman_encoded = $chanman_encoded;
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/onion_message/messenger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1313,8 +1313,8 @@ where
}
}

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

Expand Down
Loading
Loading