Skip to content

Commit 32a9378

Browse files
Antoine RiardTheBlueMatt
Antoine Riard
authored andcommitted
Integrate shutdown_pubkey from KeysInterface in ChannelManager/Channel
Drop channel_close_key from ChannelKeys
1 parent e361fed commit 32a9378

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

fuzz/fuzz_targets/full_stack_target.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ impl KeysInterface for KeyProvider {
227227
payment_base_key: SecretKey::from_slice(&secp_ctx, &[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, 0]).unwrap(),
228228
delayed_payment_base_key: SecretKey::from_slice(&secp_ctx, &[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, 4, 0]).unwrap(),
229229
htlc_base_key: SecretKey::from_slice(&secp_ctx, &[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, 5, 0]).unwrap(),
230-
channel_close_key: SecretKey::from_slice(&secp_ctx, &[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, 6, 0]).unwrap(),
231230
channel_monitor_claim_key: SecretKey::from_slice(&secp_ctx, &[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, 7, 0]).unwrap(),
232231
commitment_seed: [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, 0, 0],
233232
}
@@ -238,7 +237,6 @@ impl KeysInterface for KeyProvider {
238237
payment_base_key: SecretKey::from_slice(&secp_ctx, &[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, 0, 0]).unwrap(),
239238
delayed_payment_base_key: SecretKey::from_slice(&secp_ctx, &[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, 0, 0]).unwrap(),
240239
htlc_base_key: SecretKey::from_slice(&secp_ctx, &[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, 0, 0]).unwrap(),
241-
channel_close_key: SecretKey::from_slice(&secp_ctx, &[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, 0, 0]).unwrap(),
242240
channel_monitor_claim_key: SecretKey::from_slice(&secp_ctx, &[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, 0, 0]).unwrap(),
243241
commitment_seed: [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, 0, 0],
244242
}

src/chain/keysinterface.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ pub struct ChannelKeys {
7474
pub delayed_payment_base_key: SecretKey,
7575
/// Local htlc secret key used in commitment tx htlc outputs
7676
pub htlc_base_key: SecretKey,
77-
/// Local secret key used for closing tx
78-
pub channel_close_key: SecretKey,
7977
/// Local secret key used in justice tx, claim tx and preimage tx outputs
8078
pub channel_monitor_claim_key: SecretKey,
8179
/// Commitment seed
@@ -106,9 +104,6 @@ impl ChannelKeys {
106104
hkdf_expand(Sha256::new(), &prk, b"rust-lightning htlc base key info", &mut okm);
107105
let htlc_base_key = SecretKey::from_slice(&secp_ctx, &okm).expect("Sha256 is broken");
108106

109-
hkdf_expand(Sha256::new(), &prk, b"rust-lightning channel close key info", &mut okm);
110-
let channel_close_key = SecretKey::from_slice(&secp_ctx, &okm).expect("Sha256 is broken");
111-
112107
hkdf_expand(Sha256::new(), &prk, b"rust-lightning channel monitor claim key info", &mut okm);
113108
let channel_monitor_claim_key = SecretKey::from_slice(&secp_ctx, &okm).expect("Sha256 is broken");
114109

@@ -120,7 +115,6 @@ impl ChannelKeys {
120115
payment_base_key: payment_base_key,
121116
delayed_payment_base_key: delayed_payment_base_key,
122117
htlc_base_key: htlc_base_key,
123-
channel_close_key: channel_close_key,
124118
channel_monitor_claim_key: channel_monitor_claim_key,
125119
commitment_seed: okm
126120
}

src/ln/channel.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ pub(super) struct Channel {
238238
channel_value_satoshis: u64,
239239

240240
local_keys: ChannelKeys,
241+
shutdown_pubkey: PublicKey,
241242

242243
// Our commitment numbers start at 2^48-1 and count down, whereas the ones used in transaction
243244
// generation start at 0 and count up...this simplifies some parts of implementation at the
@@ -452,6 +453,7 @@ impl Channel {
452453
channel_value_satoshis: channel_value_satoshis,
453454

454455
local_keys: chan_keys,
456+
shutdown_pubkey: keys_provider.get_shutdown_pubkey(),
455457
cur_local_commitment_transaction_number: INITIAL_COMMITMENT_NUMBER,
456458
cur_remote_commitment_transaction_number: INITIAL_COMMITMENT_NUMBER,
457459
value_to_self_msat: channel_value_satoshis * 1000 - push_msat,
@@ -616,6 +618,7 @@ impl Channel {
616618
announce_publicly: their_announce,
617619

618620
local_keys: chan_keys,
621+
shutdown_pubkey: keys_provider.get_shutdown_pubkey(),
619622
cur_local_commitment_transaction_number: INITIAL_COMMITMENT_NUMBER,
620623
cur_remote_commitment_transaction_number: INITIAL_COMMITMENT_NUMBER,
621624
value_to_self_msat: msg.push_msat,
@@ -898,7 +901,7 @@ impl Channel {
898901

899902
#[inline]
900903
fn get_closing_scriptpubkey(&self) -> Script {
901-
let our_channel_close_key_hash = Hash160::from_data(&PublicKey::from_secret_key(&self.secp_ctx, &self.local_keys.channel_close_key).serialize());
904+
let our_channel_close_key_hash = Hash160::from_data(&self.shutdown_pubkey.serialize());
902905
Builder::new().push_opcode(opcodes::All::OP_PUSHBYTES_0).push_slice(&our_channel_close_key_hash[..]).into_script()
903906
}
904907

@@ -3271,7 +3274,13 @@ mod tests {
32713274
impl KeysInterface for Keys {
32723275
fn get_node_secret(&self) -> SecretKey { panic!(); }
32733276
fn get_destination_script(&self) -> Script { panic!(); }
3274-
fn get_shutdown_pubkey(&self) -> PublicKey { panic!(); }
3277+
3278+
fn get_shutdown_pubkey(&self) -> PublicKey {
3279+
let secp_ctx = Secp256k1::signing_only();
3280+
let channel_close_key = SecretKey::from_slice(&secp_ctx, &hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
3281+
PublicKey::from_secret_key(&secp_ctx, &channel_close_key)
3282+
}
3283+
32753284
fn get_channel_keys(&self, _inbound: bool) -> ChannelKeys { self.chan_keys.clone() }
32763285
}
32773286

@@ -3290,7 +3299,6 @@ mod tests {
32903299

32913300
// These aren't set in the test vectors:
32923301
revocation_base_key: SecretKey::from_slice(&secp_ctx, &hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap(),
3293-
channel_close_key: SecretKey::from_slice(&secp_ctx, &hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap(),
32943302
channel_monitor_claim_key: SecretKey::from_slice(&secp_ctx, &hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap(),
32953303
commitment_seed: [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff],
32963304
};

0 commit comments

Comments
 (0)