Skip to content

Commit

Permalink
f Allow legacy keys derivation for test_restored_packages_retry
Browse files Browse the repository at this point in the history
  • Loading branch information
tnull committed Nov 6, 2024
1 parent a7db955 commit bb1caf1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
7 changes: 6 additions & 1 deletion lightning/src/ln/functional_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3193,6 +3193,10 @@ pub fn fail_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_path: &
}

pub fn create_chanmon_cfgs(node_count: usize) -> Vec<TestChanMonCfg> {
create_chanmon_cfgs_with_params(node_count, false)
}

pub fn create_chanmon_cfgs_with_params(node_count: usize, legacy_channel_keys_derivation: bool) -> Vec<TestChanMonCfg> {
let mut chan_mon_cfgs = Vec::new();
for i in 0..node_count {
let tx_broadcaster = test_utils::TestBroadcaster::new(Network::Testnet);
Expand All @@ -3201,7 +3205,8 @@ pub fn create_chanmon_cfgs(node_count: usize) -> Vec<TestChanMonCfg> {
let logger = test_utils::TestLogger::with_id(format!("node {}", i));
let persister = test_utils::TestPersister::new();
let seed = [i as u8; 32];
let keys_manager = test_utils::TestKeysInterface::new(&seed, Network::Testnet);
let mut keys_manager = test_utils::TestKeysInterface::new(&seed, Network::Testnet);
keys_manager.legacy_channel_keys_derivation = legacy_channel_keys_derivation;
let scorer = RwLock::new(test_utils::TestScorer::new());

chan_mon_cfgs.push(TestChanMonCfg { tx_broadcaster, fee_estimator, chain_source, logger, persister, keys_manager, scorer });
Expand Down
5 changes: 3 additions & 2 deletions lightning/src/ln/monitor_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2242,8 +2242,9 @@ fn test_claimable_balance_correct_while_payment_pending() {

fn do_test_restored_packages_retry(check_old_monitor_retries_after_upgrade: bool) {
// Tests that we'll retry packages that were previously timelocked after we've restored them.
let chanmon_cfgs = create_chanmon_cfgs(2);
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
let chanmon_cfgs = create_chanmon_cfgs_with_params(2, true);
let mut node_cfgs = create_node_cfgs(2, &chanmon_cfgs);

let persister;
let new_chain_monitor;

Expand Down
8 changes: 7 additions & 1 deletion lightning/src/util/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,7 @@ pub struct TestKeysInterface {
enforcement_states: Mutex<HashMap<[u8;32], Arc<Mutex<EnforcementState>>>>,
expectations: Mutex<Option<VecDeque<OnGetShutdownScriptpubkey>>>,
pub unavailable_signers_ops: Mutex<HashMap<[u8; 32], HashSet<SignerOp>>>,
pub legacy_channel_keys_derivation: bool,
}

impl EntropySource for TestKeysInterface {
Expand Down Expand Up @@ -1292,7 +1293,11 @@ impl SignerProvider for TestKeysInterface {
type TaprootSigner = TestChannelSigner;

fn generate_channel_keys_id(&self, inbound: bool, channel_value_satoshis: u64, user_channel_id: u128) -> [u8; 32] {
self.backing.generate_channel_keys_id(inbound, channel_value_satoshis, user_channel_id)
let mut channel_keys_id = self.backing.generate_channel_keys_id(inbound, channel_value_satoshis, user_channel_id);
if self.legacy_channel_keys_derivation {
channel_keys_id[0] = 0;
}
channel_keys_id
}

fn derive_channel_signer(&self, channel_value_satoshis: u64, channel_keys_id: [u8; 32]) -> TestChannelSigner {
Expand Down Expand Up @@ -1344,6 +1349,7 @@ impl TestKeysInterface {
enforcement_states: Mutex::new(new_hash_map()),
expectations: Mutex::new(None),
unavailable_signers_ops: Mutex::new(new_hash_map()),
legacy_channel_keys_derivation: false,
}
}

Expand Down

0 comments on commit bb1caf1

Please sign in to comment.