Skip to content

Commit 648a69a

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 b04d1b8 commit 648a69a

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

lightning/src/chain/keysinterface.rs

Lines changed: 18 additions & 18 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,12 @@ 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, as LDK
373+
/// may call this method more than once.
374374
///
375375
/// channel_parameters.is_populated() MUST be true.
376-
///
377-
/// We bind holder_selected_contest_delay late here for API convenience.
378-
///
379-
/// Will be called before any signatures are applied.
380-
fn ready_channel(&mut self, channel_parameters: &ChannelTransactionParameters);
376+
fn provide_channel_parameters(&mut self, channel_parameters: &ChannelTransactionParameters);
381377
}
382378

383379
/// A cloneable signer.
@@ -583,39 +579,39 @@ impl InMemorySigner {
583579
}
584580

585581
/// Counterparty pubkeys.
586-
/// Will panic if ready_channel wasn't called.
582+
/// Will panic if provide_channel_parameters wasn't called.
587583
pub fn counterparty_pubkeys(&self) -> &ChannelPublicKeys { &self.get_channel_parameters().counterparty_parameters.as_ref().unwrap().pubkeys }
588584

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

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

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

605601
/// Funding outpoint
606-
/// Will panic if ready_channel wasn't called.
602+
/// Will panic if provide_channel_parameters wasn't called.
607603
pub fn funding_outpoint(&self) -> &OutPoint { self.get_channel_parameters().funding_outpoint.as_ref().unwrap() }
608604

609605
/// Obtain a ChannelTransactionParameters for this channel, to be used when verifying or
610606
/// building transactions.
611607
///
612-
/// Will panic if ready_channel wasn't called.
608+
/// Will panic if provide_channel_parameters wasn't called.
613609
pub fn get_channel_parameters(&self) -> &ChannelTransactionParameters {
614610
self.channel_parameters.as_ref().unwrap()
615611
}
616612

617613
/// Whether anchors should be used.
618-
/// Will panic if ready_channel wasn't called.
614+
/// Will panic if provide_channel_parameters wasn't called.
619615
pub fn opt_anchors(&self) -> bool {
620616
self.get_channel_parameters().opt_anchors.is_some()
621617
}
@@ -819,8 +815,12 @@ impl BaseSign for InMemorySigner {
819815
Ok((sign(secp_ctx, &msghash, &self.node_secret), sign(secp_ctx, &msghash, &self.funding_key)))
820816
}
821817

822-
fn ready_channel(&mut self, channel_parameters: &ChannelTransactionParameters) {
823-
assert!(self.channel_parameters.is_none(), "Acceptance already noted");
818+
fn provide_channel_parameters(&mut self, channel_parameters: &ChannelTransactionParameters) {
819+
assert!(self.channel_parameters.is_none() || self.channel_parameters.as_ref().unwrap() == channel_parameters);
820+
if self.channel_parameters.is_some() {
821+
// The channel parameters were already set and they match, return early.
822+
return;
823+
}
824824
assert!(channel_parameters.is_populated(), "Channel parameters must be fully populated");
825825
self.channel_parameters = Some(channel_parameters.clone());
826826
}

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)