Skip to content

Commit 5180686

Browse files
Antoine RiardTheBlueMatt
Antoine Riard
authored andcommitted
Integrate destination_script from KeysInterface in ChannelManager/Channel
Drop channel_monitor_claim_key from ChannelKeys
1 parent 32a9378 commit 5180686

File tree

3 files changed

+13
-20
lines changed

3 files changed

+13
-20
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_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(),
231230
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],
232231
}
233232
} else {
@@ -237,7 +236,6 @@ impl KeysInterface for KeyProvider {
237236
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(),
238237
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(),
239238
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(),
240-
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(),
241239
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],
242240
}
243241
}

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 in justice tx, claim tx and preimage tx outputs
78-
pub channel_monitor_claim_key: SecretKey,
7977
/// Commitment seed
8078
pub commitment_seed: [u8; 32],
8179
}
@@ -104,9 +102,6 @@ impl ChannelKeys {
104102
hkdf_expand(Sha256::new(), &prk, b"rust-lightning htlc base key info", &mut okm);
105103
let htlc_base_key = SecretKey::from_slice(&secp_ctx, &okm).expect("Sha256 is broken");
106104

107-
hkdf_expand(Sha256::new(), &prk, b"rust-lightning channel monitor claim key info", &mut okm);
108-
let channel_monitor_claim_key = SecretKey::from_slice(&secp_ctx, &okm).expect("Sha256 is broken");
109-
110105
hkdf_expand(Sha256::new(), &prk, b"rust-lightning local commitment seed info", &mut okm);
111106

112107
ChannelKeys {
@@ -115,7 +110,6 @@ impl ChannelKeys {
115110
payment_base_key: payment_base_key,
116111
delayed_payment_base_key: delayed_payment_base_key,
117112
htlc_base_key: htlc_base_key,
118-
channel_monitor_claim_key: channel_monitor_claim_key,
119113
commitment_seed: okm
120114
}
121115
}

src/ln/channel.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,9 @@ impl Channel {
436436
let feerate = fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::Normal);
437437

438438
let secp_ctx = Secp256k1::new();
439-
let our_channel_monitor_claim_key_hash = Hash160::from_data(&PublicKey::from_secret_key(&secp_ctx, &chan_keys.channel_monitor_claim_key).serialize());
440-
let our_channel_monitor_claim_script = Builder::new().push_opcode(opcodes::All::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script();
441439
let channel_monitor = ChannelMonitor::new(&chan_keys.revocation_base_key, &chan_keys.delayed_payment_base_key,
442-
&chan_keys.htlc_base_key,
443-
BREAKDOWN_TIMEOUT, our_channel_monitor_claim_script);
440+
&chan_keys.htlc_base_key, BREAKDOWN_TIMEOUT,
441+
keys_provider.get_destination_script());
444442

445443
Ok(Channel {
446444
user_id: user_id,
@@ -600,11 +598,9 @@ impl Channel {
600598
}
601599

602600
let secp_ctx = Secp256k1::new();
603-
let our_channel_monitor_claim_key_hash = Hash160::from_data(&PublicKey::from_secret_key(&secp_ctx, &chan_keys.channel_monitor_claim_key).serialize());
604-
let our_channel_monitor_claim_script = Builder::new().push_opcode(opcodes::All::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script();
605601
let mut channel_monitor = ChannelMonitor::new(&chan_keys.revocation_base_key, &chan_keys.delayed_payment_base_key,
606-
&chan_keys.htlc_base_key,
607-
BREAKDOWN_TIMEOUT, our_channel_monitor_claim_script);
602+
&chan_keys.htlc_base_key, BREAKDOWN_TIMEOUT,
603+
keys_provider.get_destination_script());
608604
channel_monitor.set_their_base_keys(&msg.htlc_basepoint, &msg.delayed_payment_basepoint);
609605
channel_monitor.set_their_to_self_delay(msg.to_self_delay);
610606

@@ -3232,11 +3228,12 @@ impl Channel {
32323228

32333229
#[cfg(test)]
32343230
mod tests {
3235-
use bitcoin::util::hash::Sha256dHash;
3231+
use bitcoin::util::hash::{Sha256dHash, Hash160};
32363232
use bitcoin::util::bip143;
32373233
use bitcoin::network::serialize::serialize;
3238-
use bitcoin::blockdata::script::Script;
3234+
use bitcoin::blockdata::script::{Script, Builder};
32393235
use bitcoin::blockdata::transaction::Transaction;
3236+
use bitcoin::blockdata::opcodes;
32403237
use hex;
32413238
use ln::channelmanager::HTLCSource;
32423239
use ln::channel::{Channel,ChannelKeys,InboundHTLCOutput,OutboundHTLCOutput,InboundHTLCState,OutboundHTLCState,HTLCOutputInCommitment,TxCreationKeys};
@@ -3273,7 +3270,12 @@ mod tests {
32733270
}
32743271
impl KeysInterface for Keys {
32753272
fn get_node_secret(&self) -> SecretKey { panic!(); }
3276-
fn get_destination_script(&self) -> Script { panic!(); }
3273+
fn get_destination_script(&self) -> Script {
3274+
let secp_ctx = Secp256k1::signing_only();
3275+
let channel_monitor_claim_key = SecretKey::from_slice(&secp_ctx, &hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
3276+
let our_channel_monitor_claim_key_hash = Hash160::from_data(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
3277+
Builder::new().push_opcode(opcodes::All::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script()
3278+
}
32773279

32783280
fn get_shutdown_pubkey(&self) -> PublicKey {
32793281
let secp_ctx = Secp256k1::signing_only();
@@ -3299,7 +3301,6 @@ mod tests {
32993301

33003302
// These aren't set in the test vectors:
33013303
revocation_base_key: SecretKey::from_slice(&secp_ctx, &hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap(),
3302-
channel_monitor_claim_key: SecretKey::from_slice(&secp_ctx, &hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap(),
33033304
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],
33043305
};
33053306
assert_eq!(PublicKey::from_secret_key(&secp_ctx, &chan_keys.funding_key).serialize()[..],

0 commit comments

Comments
 (0)