Add channel_keys_id as param in get_destination_script
authorRachel Malonson <rachel@lightspark.com>
Wed, 22 Nov 2023 20:24:20 +0000 (12:24 -0800)
committerRachel Malonson <rachel@lightspark.com>
Mon, 27 Nov 2023 18:42:01 +0000 (10:42 -0800)
This enables implementers to generate a different destination script for each channel.

fuzz/src/chanmon_consistency.rs
fuzz/src/full_stack.rs
fuzz/src/onion_message.rs
lightning/src/ln/channel.rs
lightning/src/ln/functional_tests.rs
lightning/src/sign/mod.rs
lightning/src/util/test_utils.rs

index af0c64d88aea7f76f751ebc24a15bade136919ed..dcfc7cf61c14ac9af44db6f16696367e28506ea4 100644 (file)
@@ -270,7 +270,7 @@ impl SignerProvider for KeyProvider {
                })
        }
 
-       fn get_destination_script(&self) -> Result<ScriptBuf, ()> {
+       fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> {
                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());
index 8a597a614772a46d711c34a4ba0758eea4cd2d64..4111067edacbec63a5b2135b333a53cb0f0c3fd0 100644 (file)
@@ -392,7 +392,7 @@ impl SignerProvider for KeyProvider {
                ))
        }
 
-       fn get_destination_script(&self) -> Result<ScriptBuf, ()> {
+       fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> {
                let secp_ctx = Secp256k1::signing_only();
                let channel_monitor_claim_key = SecretKey::from_slice(&<Vec<u8>>::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());
index c071d806e93aa42fb7bc653d2232f3dbf3491238..b40975068e1dc35d5a54bb87f923baea3b22df27 100644 (file)
@@ -199,7 +199,7 @@ impl SignerProvider for KeyProvider {
 
        fn read_chan_signer(&self, _data: &[u8]) -> Result<TestChannelSigner, DecodeError> { unreachable!() }
 
-       fn get_destination_script(&self) -> Result<ScriptBuf, ()> { unreachable!() }
+       fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> { unreachable!() }
 
        fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> { unreachable!() }
 }
index 740d26448073492e5fcaad20170231a8e9012681..61e99c45a9c69e31fc9d586803aaead7a9414f84 100644 (file)
@@ -5960,7 +5960,7 @@ impl<SP: Deref> OutboundV1Channel<SP> 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<SP: Deref> InboundV1Channel<SP> 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<Self::Signer, DecodeError> { panic!(); }
 
-               fn get_destination_script(&self) -> Result<ScriptBuf, ()> {
+               fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> {
                        let secp_ctx = Secp256k1::signing_only();
                        let channel_monitor_claim_key = SecretKey::from_slice(&<Vec<u8>>::from_hex("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
                        let channel_monitor_claim_key_hash = WPubkeyHash::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
index 450bc482c1a2dcbcf031be1f5f36a3304c945953..b182d17fe8285a724e151081af2affb4e76adf93 100644 (file)
@@ -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());
index bc15a3a7662c0dd12b06aab8b1927ee2f6e2eab3..18cd59b182c29fbcea11a0c3e49acfa81410c894 100644 (file)
@@ -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<ScriptBuf, ()>;
+       /// 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<ScriptBuf, ()>;
 
        /// 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<ScriptBuf, ()> {
+       fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> {
                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<ScriptBuf, ()> {
-               self.inner.get_destination_script()
+       fn get_destination_script(&self, channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> {
+               self.inner.get_destination_script(channel_keys_id)
        }
 
        fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
index e9a7f0ebfca856cfb3a88aec9c32fad4e3f50507..4512dab8cc5727da55511364358f9127a11230a2 100644 (file)
@@ -192,7 +192,7 @@ impl SignerProvider for OnlyReadsKeysInterface {
                ))
        }
 
-       fn get_destination_script(&self) -> Result<ScriptBuf, ()> { Err(()) }
+       fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> { Err(()) }
        fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> { Err(()) }
 }
 
@@ -1121,7 +1121,7 @@ impl SignerProvider for TestKeysInterface {
                ))
        }
 
-       fn get_destination_script(&self) -> Result<ScriptBuf, ()> { self.backing.get_destination_script() }
+       fn get_destination_script(&self, channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> { self.backing.get_destination_script(channel_keys_id) }
 
        fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
                match &mut *self.expectations.lock().unwrap() {