-
Notifications
You must be signed in to change notification settings - Fork 421
Allow KeysManager
to opt-into the new remote_key
derivation
#4117
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
Open
TheBlueMatt
wants to merge
6
commits into
lightningdevkit:main
Choose a base branch
from
TheBlueMatt:2025-09-actually-static-remote_key
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c9d169e
Add support for deriving and signing a new static remote key
TheBlueMatt c1cd423
Convert `ChannelSigner::pubkeys` to only fetch *new* pubkeys
TheBlueMatt f335ecb
Allow `KeysManager` to opt-into the new `remote_key` derivation
TheBlueMatt 9d46c4f
f always use v2 derivation for splices
TheBlueMatt b0d3ee6
Add a method to fetch all possible remote-closure `script_pubkey`s
TheBlueMatt e0cc7c9
Add a test of upgrading an old node with V1 `remote_key` derivation
TheBlueMatt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
//! Tests which test upgrading from previous versions of LDK or downgrading to previous versions of | ||
//! LDK. | ||
use lightning_0_1::events::ClosureReason as ClosureReason_0_1; | ||
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 as _; | ||
|
@@ -28,10 +29,19 @@ use lightning_0_0_125::ln::msgs::ChannelMessageHandler as _; | |
use lightning_0_0_125::routing::router as router_0_0_125; | ||
use lightning_0_0_125::util::ser::Writeable as _; | ||
|
||
use lightning::chain::channelmonitor::ANTI_REORG_DELAY; | ||
use lightning::events::{ClosureReason, Event}; | ||
use lightning::ln::functional_test_utils::*; | ||
use lightning::sign::OutputSpender; | ||
|
||
use lightning_types::payment::PaymentPreimage; | ||
|
||
use bitcoin::opcodes; | ||
use bitcoin::script::Builder; | ||
use bitcoin::secp256k1::Secp256k1; | ||
|
||
use std::sync::Arc; | ||
|
||
#[test] | ||
fn simple_upgrade() { | ||
// Tests a simple case of upgrading from LDK 0.1 with a pending payment | ||
|
@@ -213,3 +223,85 @@ fn test_125_dangling_post_update_actions() { | |
let config = test_default_channel_config(); | ||
reload_node!(nodes[3], config, &node_d_ser, &[&mon_ser], persister, chain_mon, node); | ||
} | ||
|
||
#[test] | ||
fn test_0_1_legacy_remote_key_derivation() { | ||
// Test that a channel opened with a v1/legacy `remote_key` derivation will be properly spent | ||
// even after upgrading to 0.2 and opting into the new v2 derivation for new channels. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe 'upgrading to 0.2 and later' as this test will continue to assert backwards compat, even after 0.2 is released? |
||
let (node_a_ser, node_b_ser, mon_a_ser, mon_b_ser, commitment_tx, channel_id); | ||
let node_a_blocks; | ||
{ | ||
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 node_a_id = nodes[0].node.get_our_node_id(); | ||
|
||
let chan_id = lightning_0_1_utils::create_announced_chan_between_nodes(&nodes, 0, 1).2; | ||
channel_id = chan_id.0; | ||
|
||
let err = "".to_owned(); | ||
nodes[1].node.force_close_broadcasting_latest_txn(&chan_id, &node_a_id, err).unwrap(); | ||
commitment_tx = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0); | ||
assert_eq!(commitment_tx.len(), 1); | ||
|
||
lightning_0_1_utils::check_added_monitors(&nodes[1], 1); | ||
let reason = ClosureReason_0_1::HolderForceClosed { broadcasted_latest_txn: Some(true) }; | ||
lightning_0_1_utils::check_closed_event(&nodes[1], 1, reason, false, &[node_a_id], 100000); | ||
lightning_0_1_utils::check_closed_broadcast(&nodes[1], 1, true); | ||
|
||
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(); | ||
|
||
node_a_blocks = Arc::clone(&nodes[0].blocks); | ||
} | ||
|
||
// 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); | ||
|
||
nodes[0].blocks = node_a_blocks; | ||
|
||
let node_b_id = nodes[1].node.get_our_node_id(); | ||
|
||
mine_transaction(&nodes[0], &commitment_tx[0]); | ||
let reason = ClosureReason::CommitmentTxConfirmed; | ||
check_closed_event(&nodes[0], 1, reason, false, &[node_b_id], 100_000); | ||
check_added_monitors(&nodes[0], 1); | ||
check_closed_broadcast(&nodes[0], 1, false); | ||
|
||
connect_blocks(&nodes[0], ANTI_REORG_DELAY - 1); | ||
let mut spendable_event = nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events(); | ||
assert_eq!(spendable_event.len(), 1); | ||
if let Event::SpendableOutputs { outputs, channel_id: ev_id } = spendable_event.pop().unwrap() { | ||
assert_eq!(ev_id.unwrap().0, channel_id); | ||
assert_eq!(outputs.len(), 1); | ||
let spk = Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script(); | ||
let spend_tx = nodes[0] | ||
.keys_manager | ||
.backing | ||
.spend_spendable_outputs(&[&outputs[0]], Vec::new(), spk, 253, None, &Secp256k1::new()) | ||
.unwrap(); | ||
check_spends!(spend_tx, commitment_tx[0]); | ||
} else { | ||
panic!("Wrong event"); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would there any benefit if we used a different key here? Is this kept the same for convenience here and below? If so, maybe add a comment to explain why these are duplicated?