Skip to content

Add channel_keys_id as param in get_destination_script to support gen… #2744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fuzz/src/chanmon_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/full_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/onion_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!() }
}
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()}),
};
Expand Down Expand Up @@ -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())),
};
Expand Down Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/functional_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
11 changes: 6 additions & 5 deletions lightning/src/sign/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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())
}

Expand Down Expand Up @@ -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, ()> {
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/util/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(()) }
}

Expand Down Expand Up @@ -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() {
Expand Down