Skip to content

Commit 146a291

Browse files
authored
Merge pull request #2744 from rmalonson/destinationscript
Add channel_keys_id as param in get_destination_script to support gen…
2 parents 74078c4 + 7f0fd86 commit 146a291

File tree

7 files changed

+16
-15
lines changed

7 files changed

+16
-15
lines changed

fuzz/src/chanmon_consistency.rs

+1-1
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

+1-1
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

+1-1
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

+3-3
Original file line numberDiff line numberDiff line change
@@ -5962,7 +5962,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
59625962
}
59635963
}
59645964

5965-
let destination_script = match signer_provider.get_destination_script() {
5965+
let destination_script = match signer_provider.get_destination_script(channel_keys_id) {
59665966
Ok(script) => script,
59675967
Err(_) => return Err(APIError::ChannelUnavailable { err: "Failed to get destination script".to_owned()}),
59685968
};
@@ -6589,7 +6589,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
65896589
}
65906590
}
65916591

6592-
let destination_script = match signer_provider.get_destination_script() {
6592+
let destination_script = match signer_provider.get_destination_script(channel_keys_id) {
65936593
Ok(script) => script,
65946594
Err(_) => return Err(ChannelError::Close("Failed to get destination script".to_owned())),
65956595
};
@@ -7874,7 +7874,7 @@ use crate::ln::channelmanager::{self, HTLCSource, PaymentId};
78747874

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

7877-
fn get_destination_script(&self) -> Result<ScriptBuf, ()> {
7877+
fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> {
78787878
let secp_ctx = Secp256k1::signing_only();
78797879
let channel_monitor_claim_key = SecretKey::from_slice(&<Vec<u8>>::from_hex("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
78807880
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

+2-2
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

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

909910
/// Get a script pubkey which we will send funds to when closing a channel.
910911
///
@@ -1804,7 +1805,7 @@ impl SignerProvider for KeysManager {
18041805
InMemorySigner::read(&mut io::Cursor::new(reader), self)
18051806
}
18061807

1807-
fn get_destination_script(&self) -> Result<ScriptBuf, ()> {
1808+
fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> {
18081809
Ok(self.destination_script.clone())
18091810
}
18101811

@@ -1911,8 +1912,8 @@ impl SignerProvider for PhantomKeysManager {
19111912
self.inner.read_chan_signer(reader)
19121913
}
19131914

1914-
fn get_destination_script(&self) -> Result<ScriptBuf, ()> {
1915-
self.inner.get_destination_script()
1915+
fn get_destination_script(&self, channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> {
1916+
self.inner.get_destination_script(channel_keys_id)
19161917
}
19171918

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

lightning/src/util/test_utils.rs

+2-2
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)