Skip to content

Commit ebcddd9

Browse files
committed
cleanup
1 parent df84dd3 commit ebcddd9

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

lightning/src/chain/keysinterface.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,15 @@ impl Readable for SpendableOutputDescriptor {
196196
// ChannelMonitors instead of expecting to clone the one out of the Channel into the monitors.
197197
pub trait ChannelKeys : Send+Clone {
198198
/// Gets the per-commitment point for a specific commitment number
199-
/// Note that the commitment number starts at (1 << 48) - 1 and counts backwards
199+
///
200+
/// Note that the commitment number starts at (1 << 48) - 1 and counts backwards.
200201
fn get_per_commitment_point<T: secp256k1::Signing + secp256k1::Verification>(&self, idx: u64, secp_ctx: &Secp256k1<T>) -> PublicKey;
201202
/// Gets the commitment seed for a specific commitment number, thereby revoking the commitment
202-
/// Note that the commitment number starts at (1 << 48) - 1 and counts backwards
203-
fn revoke_commitment(&self, idx: u64) -> [u8; 32];
203+
///
204+
/// After this is called, it is an error to try to sign the relevant local commitment transaction.
205+
/// May be called more than once (e.g. if re-establishing the channel).
206+
/// Note that the commitment number starts at (1 << 48) - 1 and counts backwards.
207+
fn get_revoke_commitment_secret(&self, idx: u64) -> [u8; 32];
204208
/// Gets the local channel public keys and basepoints
205209
fn pubkeys(&self) -> &ChannelPublicKeys;
206210
/// Gets arbitrary identifiers describing the set of keys which are provided back to you in
@@ -220,6 +224,7 @@ pub trait ChannelKeys : Send+Clone {
220224
/// Create a signature for a local commitment transaction. This will only ever be called with
221225
/// the same local_commitment_tx (or a copy thereof), though there are currently no guarantees
222226
/// that it will not be called multiple times.
227+
/// The commitment must not have been revoked.
223228
//
224229
// TODO: Document the things someone using this interface should enforce before signing.
225230
// TODO: Add more input vars to enable better checking (preferably removing commitment_tx and
@@ -413,7 +418,7 @@ impl ChannelKeys for InMemoryChannelKeys {
413418
PublicKey::from_secret_key(secp_ctx, &commitment_secret)
414419
}
415420

416-
fn revoke_commitment(&self, idx: u64) -> [u8; 32] {
421+
fn get_revoke_commitment_secret(&self, idx: u64) -> [u8; 32] {
417422
chan_utils::build_commitment_secret(&self.commitment_seed, idx)
418423
}
419424

lightning/src/ln/chan_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,8 @@ pub fn build_htlc_transaction(prev_hash: &Txid, feerate_per_kw: u32, to_self_del
497497

498498
#[derive(Clone)]
499499
/// We use this to track local commitment transactions and put off signing them until we are ready
500-
/// to broadcast. Eventually this will require a signer which is possibly external, but for now we
501-
/// just pass in the SecretKeys required.
500+
/// to broadcast. This class can be used inside a signer implementation to generate a signature
501+
/// given the relevant secret key.
502502
pub struct LocalCommitmentTransaction {
503503
// TODO: We should migrate away from providing the transaction, instead providing enough to
504504
// allow the ChannelKeys to construct it from scratch. Luckily we already have HTLC data here,

lightning/src/ln/channel.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,7 +2014,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
20142014
}
20152015

20162016
let next_per_commitment_point = self.local_keys.get_per_commitment_point(self.cur_local_commitment_transaction_number - 1, &self.secp_ctx);
2017-
let per_commitment_secret = self.local_keys.revoke_commitment(self.cur_local_commitment_transaction_number + 1);
2017+
let per_commitment_secret = self.local_keys.get_revoke_commitment_secret(self.cur_local_commitment_transaction_number + 1);
20182018

20192019
// Update state now that we've passed all the can-fail calls...
20202020
let mut need_our_commitment = false;
@@ -2652,7 +2652,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
26522652

26532653
fn get_last_revoke_and_ack(&self) -> msgs::RevokeAndACK {
26542654
let next_per_commitment_point = self.local_keys.get_per_commitment_point(self.cur_local_commitment_transaction_number, &self.secp_ctx);
2655-
let per_commitment_secret = self.local_keys.revoke_commitment(self.cur_local_commitment_transaction_number + 2);
2655+
let per_commitment_secret = self.local_keys.get_revoke_commitment_secret(self.cur_local_commitment_transaction_number + 2);
26562656
msgs::RevokeAndACK {
26572657
channel_id: self.channel_id,
26582658
per_commitment_secret,

lightning/src/ln/functional_tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,15 +1609,15 @@ fn test_fee_spike_violation_fails_htlc() {
16091609
let chan_keys = local_chan.get_local_keys();
16101610
let pubkeys = chan_keys.pubkeys();
16111611
(pubkeys.revocation_basepoint, pubkeys.htlc_basepoint, pubkeys.payment_point,
1612-
chan_keys.revoke_commitment(INITIAL_COMMITMENT_NUMBER), chan_keys.revoke_commitment(INITIAL_COMMITMENT_NUMBER - 2))
1612+
chan_keys.get_revoke_commitment_secret(INITIAL_COMMITMENT_NUMBER), chan_keys.get_revoke_commitment_secret(INITIAL_COMMITMENT_NUMBER - 2))
16131613
};
16141614
let (remote_delayed_payment_basepoint, remote_htlc_basepoint, remote_payment_point, remote_secret1) = {
16151615
let chan_lock = nodes[1].node.channel_state.lock().unwrap();
16161616
let remote_chan = chan_lock.by_id.get(&chan.2).unwrap();
16171617
let chan_keys = remote_chan.get_local_keys();
16181618
let pubkeys = chan_keys.pubkeys();
16191619
(pubkeys.delayed_payment_basepoint, pubkeys.htlc_basepoint, pubkeys.payment_point,
1620-
chan_keys.revoke_commitment(INITIAL_COMMITMENT_NUMBER - 1))
1620+
chan_keys.get_revoke_commitment_secret(INITIAL_COMMITMENT_NUMBER - 1))
16211621
};
16221622

16231623
// Assemble the set of keys we can use for signatures for our commitment_signed message.
@@ -8129,8 +8129,8 @@ fn test_counterparty_raa_skip_no_crash() {
81298129
let local_keys = &guard.by_id.get_mut(&channel_id).unwrap().local_keys;
81308130
const INITIAL_COMMITMENT_NUMBER: u64 = (1 << 48) - 1;
81318131
let next_per_commitment_point = PublicKey::from_secret_key(&Secp256k1::new(),
8132-
&SecretKey::from_slice(&local_keys.revoke_commitment(INITIAL_COMMITMENT_NUMBER - 2)).unwrap());
8133-
let per_commitment_secret = local_keys.revoke_commitment(INITIAL_COMMITMENT_NUMBER);
8132+
&SecretKey::from_slice(&local_keys.get_revoke_commitment_secret(INITIAL_COMMITMENT_NUMBER - 2)).unwrap());
8133+
let per_commitment_secret = local_keys.get_revoke_commitment_secret(INITIAL_COMMITMENT_NUMBER);
81348134

81358135
nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(),
81368136
&msgs::RevokeAndACK { channel_id, per_commitment_secret, next_per_commitment_point });

lightning/src/util/enforcing_trait_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl ChannelKeys for EnforcingChannelKeys {
5252
self.inner.get_per_commitment_point(idx, secp_ctx)
5353
}
5454

55-
fn revoke_commitment(&self, idx: u64) -> [u8; 32] { self.inner.revoke_commitment(idx) }
55+
fn get_revoke_commitment_secret(&self, idx: u64) -> [u8; 32] { self.inner.get_revoke_commitment_secret(idx) }
5656
fn pubkeys(&self) -> &ChannelPublicKeys { self.inner.pubkeys() }
5757
fn key_derivation_params(&self) -> (u64, u64) { self.inner.key_derivation_params() }
5858

0 commit comments

Comments
 (0)