From: Rachel Malonson Date: Wed, 22 Nov 2023 20:24:20 +0000 (-0800) Subject: Add channel_keys_id as param in get_destination_script X-Git-Tag: v0.0.119~42^2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=7f0fd868ad4e8072440f1eb79e78894de1629157;p=rust-lightning Add channel_keys_id as param in get_destination_script This enables implementers to generate a different destination script for each channel. --- diff --git a/fuzz/src/chanmon_consistency.rs b/fuzz/src/chanmon_consistency.rs index af0c64d88..dcfc7cf61 100644 --- a/fuzz/src/chanmon_consistency.rs +++ b/fuzz/src/chanmon_consistency.rs @@ -270,7 +270,7 @@ impl SignerProvider for KeyProvider { }) } - fn get_destination_script(&self) -> Result { + fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result { let secp_ctx = Secp256k1::signing_only(); let channel_monitor_claim_key = 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, self.node_secret[31]]).unwrap(); let our_channel_monitor_claim_key_hash = WPubkeyHash::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize()); diff --git a/fuzz/src/full_stack.rs b/fuzz/src/full_stack.rs index 8a597a614..4111067ed 100644 --- a/fuzz/src/full_stack.rs +++ b/fuzz/src/full_stack.rs @@ -392,7 +392,7 @@ impl SignerProvider for KeyProvider { )) } - fn get_destination_script(&self) -> Result { + fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result { let secp_ctx = Secp256k1::signing_only(); let channel_monitor_claim_key = SecretKey::from_slice(&>::from_hex("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap(); let our_channel_monitor_claim_key_hash = WPubkeyHash::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize()); diff --git a/fuzz/src/onion_message.rs b/fuzz/src/onion_message.rs index c071d806e..b40975068 100644 --- a/fuzz/src/onion_message.rs +++ b/fuzz/src/onion_message.rs @@ -199,7 +199,7 @@ impl SignerProvider for KeyProvider { fn read_chan_signer(&self, _data: &[u8]) -> Result { unreachable!() } - fn get_destination_script(&self) -> Result { unreachable!() } + fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result { unreachable!() } fn get_shutdown_scriptpubkey(&self) -> Result { unreachable!() } } diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 740d26448..61e99c45a 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -5960,7 +5960,7 @@ impl OutboundV1Channel where SP::Target: SignerProvider { } } - let destination_script = match signer_provider.get_destination_script() { + let destination_script = match signer_provider.get_destination_script(channel_keys_id) { Ok(script) => script, Err(_) => return Err(APIError::ChannelUnavailable { err: "Failed to get destination script".to_owned()}), }; @@ -6587,7 +6587,7 @@ impl InboundV1Channel where SP::Target: SignerProvider { } } - let destination_script = match signer_provider.get_destination_script() { + let destination_script = match signer_provider.get_destination_script(channel_keys_id) { Ok(script) => script, Err(_) => return Err(ChannelError::Close("Failed to get destination script".to_owned())), }; @@ -7872,7 +7872,7 @@ mod tests { fn read_chan_signer(&self, _data: &[u8]) -> Result { panic!(); } - fn get_destination_script(&self) -> Result { + fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result { let secp_ctx = Secp256k1::signing_only(); let channel_monitor_claim_key = SecretKey::from_slice(&>::from_hex("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap(); let channel_monitor_claim_key_hash = WPubkeyHash::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize()); diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index 450bc482c..b182d17fe 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -2590,8 +2590,8 @@ fn do_test_forming_justice_tx_from_monitor_updates(broadcast_initial_commitment: // that a revoked commitment transaction is broadcasted // (Similar to `revoked_output_claim` test but we get the justice tx + broadcast manually) let chanmon_cfgs = create_chanmon_cfgs(2); - let destination_script0 = chanmon_cfgs[0].keys_manager.get_destination_script().unwrap(); - let destination_script1 = chanmon_cfgs[1].keys_manager.get_destination_script().unwrap(); + let destination_script0 = chanmon_cfgs[0].keys_manager.get_destination_script([0; 32]).unwrap(); + let destination_script1 = chanmon_cfgs[1].keys_manager.get_destination_script([0; 32]).unwrap(); let persisters = vec![WatchtowerPersister::new(destination_script0), WatchtowerPersister::new(destination_script1)]; let node_cfgs = create_node_cfgs_with_persisters(2, &chanmon_cfgs, persisters.iter().collect()); diff --git a/lightning/src/sign/mod.rs b/lightning/src/sign/mod.rs index bc15a3a76..18cd59b18 100644 --- a/lightning/src/sign/mod.rs +++ b/lightning/src/sign/mod.rs @@ -906,8 +906,9 @@ pub trait SignerProvider { /// If this function returns an error, this will result in a channel failing to open. /// /// This method should return a different value each time it is called, to avoid linking - /// on-chain funds across channels as controlled to the same user. - fn get_destination_script(&self) -> Result; + /// on-chain funds across channels as controlled to the same user. `channel_keys_id` may be + /// used to derive a unique value for each channel. + fn get_destination_script(&self, channel_keys_id: [u8; 32]) -> Result; /// Get a script pubkey which we will send funds to when closing a channel. /// @@ -1795,7 +1796,7 @@ impl SignerProvider for KeysManager { InMemorySigner::read(&mut io::Cursor::new(reader), self) } - fn get_destination_script(&self) -> Result { + fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result { Ok(self.destination_script.clone()) } @@ -1902,8 +1903,8 @@ impl SignerProvider for PhantomKeysManager { self.inner.read_chan_signer(reader) } - fn get_destination_script(&self) -> Result { - self.inner.get_destination_script() + fn get_destination_script(&self, channel_keys_id: [u8; 32]) -> Result { + self.inner.get_destination_script(channel_keys_id) } fn get_shutdown_scriptpubkey(&self) -> Result { diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index e9a7f0ebf..4512dab8c 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -192,7 +192,7 @@ impl SignerProvider for OnlyReadsKeysInterface { )) } - fn get_destination_script(&self) -> Result { Err(()) } + fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result { Err(()) } fn get_shutdown_scriptpubkey(&self) -> Result { Err(()) } } @@ -1121,7 +1121,7 @@ impl SignerProvider for TestKeysInterface { )) } - fn get_destination_script(&self) -> Result { self.backing.get_destination_script() } + fn get_destination_script(&self, channel_keys_id: [u8; 32]) -> Result { self.backing.get_destination_script(channel_keys_id) } fn get_shutdown_scriptpubkey(&self) -> Result { match &mut *self.expectations.lock().unwrap() {