Skip to content

Commit c70f7ec

Browse files
committed
Have SignerProvider::get_shutdown_scriptpubkey take channel_keys_id
.. to allow users to return specific scripts per channel.
1 parent bf14ec8 commit c70f7ec

File tree

8 files changed

+23
-19
lines changed

8 files changed

+23
-19
lines changed

fuzz/src/chanmon_consistency.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ impl SignerProvider for KeyProvider {
417417
.into_script())
418418
}
419419

420-
fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
420+
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
421421
let secp_ctx = Secp256k1::signing_only();
422422
#[rustfmt::skip]
423423
let secret_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, 3, self.node_secret[31]]).unwrap();

fuzz/src/full_stack.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ impl SignerProvider for KeyProvider {
559559
.into_script())
560560
}
561561

562-
fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
562+
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
563563
let secp_ctx = Secp256k1::signing_only();
564564
let secret_key = SecretKey::from_slice(&[
565565
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,

fuzz/src/onion_message.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ impl SignerProvider for KeyProvider {
278278
unreachable!()
279279
}
280280

281-
fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
281+
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
282282
unreachable!()
283283
}
284284
}

lightning/src/ln/async_signer_tests.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -917,8 +917,9 @@ fn do_test_closing_signed(extra_closing_signed: bool, reconnect: bool) {
917917
if extra_closing_signed {
918918
let node_1_closing_signed_2_bad = {
919919
let mut node_1_closing_signed_2 = node_1_closing_signed.clone();
920-
let holder_script = nodes[0].keys_manager.get_shutdown_scriptpubkey().unwrap();
921-
let counterparty_script = nodes[1].keys_manager.get_shutdown_scriptpubkey().unwrap();
920+
let channel_keys_id = [42u8; 32];
921+
let holder_script = nodes[0].keys_manager.get_shutdown_scriptpubkey(channel_keys_id).unwrap();
922+
let counterparty_script = nodes[1].keys_manager.get_shutdown_scriptpubkey(channel_keys_id).unwrap();
922923
let funding_outpoint = bitcoin::OutPoint { txid: chan_1.3.compute_txid(), vout: 0 };
923924
let closing_tx_2 = ClosingTransaction::new(50000, 0, holder_script.into(),
924925
counterparty_script.into(), funding_outpoint);

lightning/src/ln/channel.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1805,7 +1805,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
18051805
} else { None };
18061806

18071807
let shutdown_scriptpubkey = if config.channel_handshake_config.commit_upfront_shutdown_pubkey {
1808-
match signer_provider.get_shutdown_scriptpubkey() {
1808+
match signer_provider.get_shutdown_scriptpubkey(channel_keys_id) {
18091809
Ok(scriptpubkey) => Some(scriptpubkey),
18101810
Err(_) => return Err(ChannelError::close("Failed to get upfront shutdown scriptpubkey".to_owned())),
18111811
}
@@ -2050,7 +2050,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
20502050
secp_ctx.seeded_randomize(&entropy_source.get_secure_random_bytes());
20512051

20522052
let shutdown_scriptpubkey = if config.channel_handshake_config.commit_upfront_shutdown_pubkey {
2053-
match signer_provider.get_shutdown_scriptpubkey() {
2053+
match signer_provider.get_shutdown_scriptpubkey(channel_keys_id) {
20542054
Ok(scriptpubkey) => Some(scriptpubkey),
20552055
Err(_) => return Err(APIError::ChannelUnavailable { err: "Failed to get shutdown scriptpubkey".to_owned()}),
20562056
}
@@ -6219,7 +6219,7 @@ impl<SP: Deref> Channel<SP> where
62196219
Some(_) => false,
62206220
None => {
62216221
assert!(send_shutdown);
6222-
let shutdown_scriptpubkey = match signer_provider.get_shutdown_scriptpubkey() {
6222+
let shutdown_scriptpubkey = match signer_provider.get_shutdown_scriptpubkey(self.context.channel_keys_id) {
62236223
Ok(scriptpubkey) => scriptpubkey,
62246224
Err(_) => return Err(ChannelError::close("Failed to get shutdown scriptpubkey".to_owned())),
62256225
};
@@ -7711,7 +7711,7 @@ impl<SP: Deref> Channel<SP> where
77117711
Some(script) => script,
77127712
None => {
77137713
// otherwise, use the shutdown scriptpubkey provided by the signer
7714-
match signer_provider.get_shutdown_scriptpubkey() {
7714+
match signer_provider.get_shutdown_scriptpubkey(self.context.channel_keys_id) {
77157715
Ok(scriptpubkey) => scriptpubkey,
77167716
Err(_) => return Err(APIError::ChannelUnavailable{err: "Failed to get shutdown scriptpubkey".to_owned()}),
77177717
}
@@ -9724,7 +9724,7 @@ mod tests {
97249724
Ok(Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(channel_monitor_claim_key_hash).into_script())
97259725
}
97269726

9727-
fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
9727+
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
97289728
let secp_ctx = Secp256k1::signing_only();
97299729
let channel_close_key = SecretKey::from_slice(&<Vec<u8>>::from_hex("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
97309730
Ok(ShutdownScript::new_p2wpkh_from_pubkey(PublicKey::from_secret_key(&secp_ctx, &channel_close_key)))

lightning/src/ln/shutdown_tests.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,9 @@ fn test_unsupported_anysegwit_shutdown_script() {
984984
let nodes = create_network(3, &node_cfgs, &node_chanmgrs);
985985

986986
// Check that using an unsupported shutdown script fails and a supported one succeeds.
987-
let supported_shutdown_script = chanmon_cfgs[1].keys_manager.get_shutdown_scriptpubkey().unwrap();
987+
let channel_keys_id = [42u8; 32];
988+
let supported_shutdown_script = chanmon_cfgs[1].keys_manager
989+
.get_shutdown_scriptpubkey(channel_keys_id).unwrap();
988990
let unsupported_witness_program = WitnessProgram::new(WitnessVersion::V16, &[0, 40]).unwrap();
989991
let unsupported_shutdown_script =
990992
ShutdownScript::new_witness_program(&unsupported_witness_program).unwrap();

lightning/src/sign/mod.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1010,8 +1010,9 @@ pub trait SignerProvider {
10101010
/// channel force close.
10111011
///
10121012
/// This method should return a different value each time it is called, to avoid linking
1013-
/// on-chain funds across channels as controlled to the same user.
1014-
fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()>;
1013+
/// on-chain funds across channels as controlled to the same user. `channel_keys_id` may be
1014+
/// used to derive a unique value for each channel.
1015+
fn get_shutdown_scriptpubkey(&self, channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()>;
10151016
}
10161017

10171018
/// A helper trait that describes an on-chain wallet capable of returning a (change) destination
@@ -2331,7 +2332,7 @@ impl SignerProvider for KeysManager {
23312332
Ok(self.destination_script.clone())
23322333
}
23332334

2334-
fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
2335+
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
23352336
Ok(ShutdownScript::new_p2wpkh_from_pubkey(self.shutdown_pubkey.clone()))
23362337
}
23372338
}
@@ -2470,8 +2471,8 @@ impl SignerProvider for PhantomKeysManager {
24702471
self.inner.get_destination_script(channel_keys_id)
24712472
}
24722473

2473-
fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
2474-
self.inner.get_shutdown_scriptpubkey()
2474+
fn get_shutdown_scriptpubkey(&self, channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
2475+
self.inner.get_shutdown_scriptpubkey(channel_keys_id)
24752476
}
24762477
}
24772478

lightning/src/util/test_utils.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ impl SignerProvider for OnlyReadsKeysInterface {
332332
}
333333

334334
fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> { Err(()) }
335-
fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> { Err(()) }
335+
fn get_shutdown_scriptpubkey(&self, _channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> { Err(()) }
336336
}
337337

338338
pub struct TestChainMonitor<'a> {
@@ -1328,9 +1328,9 @@ impl SignerProvider for TestKeysInterface {
13281328

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

1331-
fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
1331+
fn get_shutdown_scriptpubkey(&self, channel_keys_id: [u8; 32]) -> Result<ShutdownScript, ()> {
13321332
match &mut *self.expectations.lock().unwrap() {
1333-
None => self.backing.get_shutdown_scriptpubkey(),
1333+
None => self.backing.get_shutdown_scriptpubkey(channel_keys_id),
13341334
Some(expectations) => match expectations.pop_front() {
13351335
None => panic!("Unexpected get_shutdown_scriptpubkey"),
13361336
Some(expectation) => Ok(expectation.returns),

0 commit comments

Comments
 (0)