Skip to content

Commit 7f0fd86

Browse files
committed
Add channel_keys_id as param in get_destination_script
This enables implementers to generate a different destination script for each channel.
1 parent fa0d015 commit 7f0fd86

File tree

7 files changed

+16
-15
lines changed

7 files changed

+16
-15
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl SignerProvider for KeyProvider {
270270
})
271271
}
272272

273-
fn get_destination_script(&self) -> Result<ScriptBuf, ()> {
273+
fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> {
274274
let secp_ctx = Secp256k1::signing_only();
275275
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();
276276
let our_channel_monitor_claim_key_hash = WPubkeyHash::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());

fuzz/src/full_stack.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ impl SignerProvider for KeyProvider {
392392
))
393393
}
394394

395-
fn get_destination_script(&self) -> Result<ScriptBuf, ()> {
395+
fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> {
396396
let secp_ctx = Secp256k1::signing_only();
397397
let channel_monitor_claim_key = SecretKey::from_slice(&<Vec<u8>>::from_hex("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
398398
let our_channel_monitor_claim_key_hash = WPubkeyHash::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());

fuzz/src/onion_message.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl SignerProvider for KeyProvider {
199199

200200
fn read_chan_signer(&self, _data: &[u8]) -> Result<TestChannelSigner, DecodeError> { unreachable!() }
201201

202-
fn get_destination_script(&self) -> Result<ScriptBuf, ()> { unreachable!() }
202+
fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> { unreachable!() }
203203

204204
fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> { unreachable!() }
205205
}

lightning/src/ln/channel.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5960,7 +5960,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
59605960
}
59615961
}
59625962

5963-
let destination_script = match signer_provider.get_destination_script() {
5963+
let destination_script = match signer_provider.get_destination_script(channel_keys_id) {
59645964
Ok(script) => script,
59655965
Err(_) => return Err(APIError::ChannelUnavailable { err: "Failed to get destination script".to_owned()}),
59665966
};
@@ -6587,7 +6587,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
65876587
}
65886588
}
65896589

6590-
let destination_script = match signer_provider.get_destination_script() {
6590+
let destination_script = match signer_provider.get_destination_script(channel_keys_id) {
65916591
Ok(script) => script,
65926592
Err(_) => return Err(ChannelError::Close("Failed to get destination script".to_owned())),
65936593
};
@@ -7872,7 +7872,7 @@ mod tests {
78727872

78737873
fn read_chan_signer(&self, _data: &[u8]) -> Result<Self::Signer, DecodeError> { panic!(); }
78747874

7875-
fn get_destination_script(&self) -> Result<ScriptBuf, ()> {
7875+
fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> {
78767876
let secp_ctx = Secp256k1::signing_only();
78777877
let channel_monitor_claim_key = SecretKey::from_slice(&<Vec<u8>>::from_hex("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
78787878
let channel_monitor_claim_key_hash = WPubkeyHash::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());

lightning/src/ln/functional_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2590,8 +2590,8 @@ fn do_test_forming_justice_tx_from_monitor_updates(broadcast_initial_commitment:
25902590
// that a revoked commitment transaction is broadcasted
25912591
// (Similar to `revoked_output_claim` test but we get the justice tx + broadcast manually)
25922592
let chanmon_cfgs = create_chanmon_cfgs(2);
2593-
let destination_script0 = chanmon_cfgs[0].keys_manager.get_destination_script().unwrap();
2594-
let destination_script1 = chanmon_cfgs[1].keys_manager.get_destination_script().unwrap();
2593+
let destination_script0 = chanmon_cfgs[0].keys_manager.get_destination_script([0; 32]).unwrap();
2594+
let destination_script1 = chanmon_cfgs[1].keys_manager.get_destination_script([0; 32]).unwrap();
25952595
let persisters = vec![WatchtowerPersister::new(destination_script0),
25962596
WatchtowerPersister::new(destination_script1)];
25972597
let node_cfgs = create_node_cfgs_with_persisters(2, &chanmon_cfgs, persisters.iter().collect());

lightning/src/sign/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -906,8 +906,9 @@ pub trait SignerProvider {
906906
/// If this function returns an error, this will result in a channel failing to open.
907907
///
908908
/// This method should return a different value each time it is called, to avoid linking
909-
/// on-chain funds across channels as controlled to the same user.
910-
fn get_destination_script(&self) -> Result<ScriptBuf, ()>;
909+
/// on-chain funds across channels as controlled to the same user. `channel_keys_id` may be
910+
/// used to derive a unique value for each channel.
911+
fn get_destination_script(&self, channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()>;
911912

912913
/// Get a script pubkey which we will send funds to when closing a channel.
913914
///
@@ -1795,7 +1796,7 @@ impl SignerProvider for KeysManager {
17951796
InMemorySigner::read(&mut io::Cursor::new(reader), self)
17961797
}
17971798

1798-
fn get_destination_script(&self) -> Result<ScriptBuf, ()> {
1799+
fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> {
17991800
Ok(self.destination_script.clone())
18001801
}
18011802

@@ -1902,8 +1903,8 @@ impl SignerProvider for PhantomKeysManager {
19021903
self.inner.read_chan_signer(reader)
19031904
}
19041905

1905-
fn get_destination_script(&self) -> Result<ScriptBuf, ()> {
1906-
self.inner.get_destination_script()
1906+
fn get_destination_script(&self, channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> {
1907+
self.inner.get_destination_script(channel_keys_id)
19071908
}
19081909

19091910
fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {

lightning/src/util/test_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl SignerProvider for OnlyReadsKeysInterface {
192192
))
193193
}
194194

195-
fn get_destination_script(&self) -> Result<ScriptBuf, ()> { Err(()) }
195+
fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> { Err(()) }
196196
fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> { Err(()) }
197197
}
198198

@@ -1121,7 +1121,7 @@ impl SignerProvider for TestKeysInterface {
11211121
))
11221122
}
11231123

1124-
fn get_destination_script(&self) -> Result<ScriptBuf, ()> { self.backing.get_destination_script() }
1124+
fn get_destination_script(&self, channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> { self.backing.get_destination_script(channel_keys_id) }
11251125

11261126
fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
11271127
match &mut *self.expectations.lock().unwrap() {

0 commit comments

Comments
 (0)