Skip to content

Commit b8cc07b

Browse files
committed
Rename KeysInterface ready_channel to provide_channel_parameters
Now that ready_channel is also called on startup upon deserializing channels, we opt to rename it to a more indicative name. We also derive `PartialEq` on ChannelTransactionParameters to allow implementations to determine whether `provide_channel_parameters` calls are idempotent after the channel parameters have already been provided.
1 parent 01ae0ea commit b8cc07b

File tree

4 files changed

+22
-24
lines changed

4 files changed

+22
-24
lines changed

lightning/src/chain/keysinterface.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ pub enum SpendableOutputDescriptor {
161161
///
162162
/// To derive the revocation_pubkey provided here (which is used in the witness
163163
/// script generation), you must pass the counterparty revocation_basepoint (which appears in the
164-
/// call to Sign::ready_channel) and the provided per_commitment point
164+
/// call to Sign::provide_channel_parameters) and the provided per_commitment point
165165
/// to chan_utils::derive_public_revocation_key.
166166
///
167167
/// The witness script which is hashed and included in the output script_pubkey may be
@@ -368,16 +368,14 @@ pub trait BaseSign {
368368
-> Result<(Signature, Signature), ()>;
369369

370370
/// Set the counterparty static channel data, including basepoints,
371-
/// counterparty_selected/holder_selected_contest_delay and funding outpoint.
372-
/// This is done as soon as the funding outpoint is known. Since these are static channel data,
373-
/// they MUST NOT be allowed to change to different values once set.
371+
/// counterparty_selected/holder_selected_contest_delay and funding outpoint. Since these are
372+
/// static channel data, they MUST NOT be allowed to change to different values once set.
374373
///
375-
/// channel_parameters.is_populated() MUST be true.
376-
///
377-
/// We bind holder_selected_contest_delay late here for API convenience.
374+
/// LDK will call this method once per signer derivation, either immediately after, or if the
375+
/// channel has yet to be funded, as soon as the funding outpoint is known.
378376
///
379-
/// Will be called before any signatures are applied.
380-
fn ready_channel(&mut self, channel_parameters: &ChannelTransactionParameters);
377+
/// channel_parameters.is_populated() MUST be true.
378+
fn provide_channel_parameters(&mut self, channel_parameters: &ChannelTransactionParameters);
381379
}
382380

383381
/// A cloneable signer.
@@ -583,39 +581,39 @@ impl InMemorySigner {
583581
}
584582

585583
/// Counterparty pubkeys.
586-
/// Will panic if ready_channel wasn't called.
584+
/// Will panic if provide_channel_parameters wasn't called.
587585
pub fn counterparty_pubkeys(&self) -> &ChannelPublicKeys { &self.get_channel_parameters().counterparty_parameters.as_ref().unwrap().pubkeys }
588586

589587
/// The contest_delay value specified by our counterparty and applied on holder-broadcastable
590588
/// transactions, ie the amount of time that we have to wait to recover our funds if we
591589
/// broadcast a transaction.
592-
/// Will panic if ready_channel wasn't called.
590+
/// Will panic if provide_channel_parameters wasn't called.
593591
pub fn counterparty_selected_contest_delay(&self) -> u16 { self.get_channel_parameters().counterparty_parameters.as_ref().unwrap().selected_contest_delay }
594592

595593
/// The contest_delay value specified by us and applied on transactions broadcastable
596594
/// by our counterparty, ie the amount of time that they have to wait to recover their funds
597595
/// if they broadcast a transaction.
598-
/// Will panic if ready_channel wasn't called.
596+
/// Will panic if provide_channel_parameters wasn't called.
599597
pub fn holder_selected_contest_delay(&self) -> u16 { self.get_channel_parameters().holder_selected_contest_delay }
600598

601599
/// Whether the holder is the initiator
602-
/// Will panic if ready_channel wasn't called.
600+
/// Will panic if provide_channel_parameters wasn't called.
603601
pub fn is_outbound(&self) -> bool { self.get_channel_parameters().is_outbound_from_holder }
604602

605603
/// Funding outpoint
606-
/// Will panic if ready_channel wasn't called.
604+
/// Will panic if provide_channel_parameters wasn't called.
607605
pub fn funding_outpoint(&self) -> &OutPoint { self.get_channel_parameters().funding_outpoint.as_ref().unwrap() }
608606

609607
/// Obtain a ChannelTransactionParameters for this channel, to be used when verifying or
610608
/// building transactions.
611609
///
612-
/// Will panic if ready_channel wasn't called.
610+
/// Will panic if provide_channel_parameters wasn't called.
613611
pub fn get_channel_parameters(&self) -> &ChannelTransactionParameters {
614612
self.channel_parameters.as_ref().unwrap()
615613
}
616614

617615
/// Whether anchors should be used.
618-
/// Will panic if ready_channel wasn't called.
616+
/// Will panic if provide_channel_parameters wasn't called.
619617
pub fn opt_anchors(&self) -> bool {
620618
self.get_channel_parameters().opt_anchors.is_some()
621619
}
@@ -819,7 +817,7 @@ impl BaseSign for InMemorySigner {
819817
Ok((sign(secp_ctx, &msghash, &self.node_secret), sign(secp_ctx, &msghash, &self.funding_key)))
820818
}
821819

822-
fn ready_channel(&mut self, channel_parameters: &ChannelTransactionParameters) {
820+
fn provide_channel_parameters(&mut self, channel_parameters: &ChannelTransactionParameters) {
823821
assert!(self.channel_parameters.is_none(), "Acceptance already noted");
824822
assert!(channel_parameters.is_populated(), "Channel parameters must be fully populated");
825823
self.channel_parameters = Some(channel_parameters.clone());

lightning/src/ln/chan_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ pub fn build_anchor_input_witness(funding_key: &PublicKey, funding_sig: &Signatu
763763
///
764764
/// Normally, this is converted to the broadcaster/countersignatory-organized DirectedChannelTransactionParameters
765765
/// before use, via the as_holder_broadcastable and as_counterparty_broadcastable functions.
766-
#[derive(Clone)]
766+
#[derive(Clone, PartialEq)]
767767
pub struct ChannelTransactionParameters {
768768
/// Holder public keys
769769
pub holder_pubkeys: ChannelPublicKeys,
@@ -787,7 +787,7 @@ pub struct ChannelTransactionParameters {
787787
}
788788

789789
/// Late-bound per-channel counterparty data used to build transactions.
790-
#[derive(Clone)]
790+
#[derive(Clone, PartialEq)]
791791
pub struct CounterpartyChannelTransactionParameters {
792792
/// Counter-party public keys
793793
pub pubkeys: ChannelPublicKeys,

lightning/src/ln/channel.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,7 +2215,7 @@ impl<Signer: Sign> Channel<Signer> {
22152215
self.channel_transaction_parameters.funding_outpoint = Some(funding_txo);
22162216
// This is an externally observable change before we finish all our checks. In particular
22172217
// funding_created_signature may fail.
2218-
self.holder_signer.ready_channel(&self.channel_transaction_parameters);
2218+
self.holder_signer.provide_channel_parameters(&self.channel_transaction_parameters);
22192219

22202220
let (counterparty_initial_commitment_txid, initial_commitment_tx, signature) = match self.funding_created_signature(&msg.signature, logger) {
22212221
Ok(res) => res,
@@ -5250,7 +5250,7 @@ impl<Signer: Sign> Channel<Signer> {
52505250
}
52515251

52525252
self.channel_transaction_parameters.funding_outpoint = Some(funding_txo);
5253-
self.holder_signer.ready_channel(&self.channel_transaction_parameters);
5253+
self.holder_signer.provide_channel_parameters(&self.channel_transaction_parameters);
52545254

52555255
let signature = match self.get_outbound_funding_created_signature(logger) {
52565256
Ok(res) => res,
@@ -7296,7 +7296,7 @@ mod tests {
72967296
selected_contest_delay: 144
72977297
});
72987298
chan.channel_transaction_parameters.funding_outpoint = Some(funding_info);
7299-
signer.ready_channel(&chan.channel_transaction_parameters);
7299+
signer.provide_channel_parameters(&chan.channel_transaction_parameters);
73007300

73017301
assert_eq!(counterparty_pubkeys.payment_point.serialize()[..],
73027302
hex::decode("032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991").unwrap()[..]);

lightning/src/util/enforcing_trait_impls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ impl BaseSign for EnforcingSigner {
215215
self.inner.sign_channel_announcement(msg, secp_ctx)
216216
}
217217

218-
fn ready_channel(&mut self, channel_parameters: &ChannelTransactionParameters) {
219-
self.inner.ready_channel(channel_parameters)
218+
fn provide_channel_parameters(&mut self, channel_parameters: &ChannelTransactionParameters) {
219+
self.inner.provide_channel_parameters(channel_parameters)
220220
}
221221
}
222222

0 commit comments

Comments
 (0)