Skip to content

Commit e93c64c

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.
1 parent cf9cdf4 commit e93c64c

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

lightning/src/chain/keysinterface.rs

Lines changed: 18 additions & 14 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,18 @@ 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. This is usually
372+
/// done immediately upon signer derivation, unless the channel has yet to be funded, in which
373+
/// case it is done as soon as the funding outpoint is known. Since these are static channel
374+
/// data, they MUST NOT be allowed to change to different values once set. If the channel
375+
/// parameters are already known, any further calls should act as a no-op.
374376
///
375377
/// channel_parameters.is_populated() MUST be true.
376378
///
377379
/// We bind holder_selected_contest_delay late here for API convenience.
378380
///
379381
/// Will be called before any signatures are applied.
380-
fn ready_channel(&mut self, channel_parameters: &ChannelTransactionParameters);
382+
fn provide_channel_parameters(&mut self, channel_parameters: &ChannelTransactionParameters);
381383
}
382384

383385
/// A cloneable signer.
@@ -583,39 +585,39 @@ impl InMemorySigner {
583585
}
584586

585587
/// Counterparty pubkeys.
586-
/// Will panic if ready_channel wasn't called.
588+
/// Will panic if provide_channel_parameters wasn't called.
587589
pub fn counterparty_pubkeys(&self) -> &ChannelPublicKeys { &self.get_channel_parameters().counterparty_parameters.as_ref().unwrap().pubkeys }
588590

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

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

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

605607
/// Funding outpoint
606-
/// Will panic if ready_channel wasn't called.
608+
/// Will panic if provide_channel_parameters wasn't called.
607609
pub fn funding_outpoint(&self) -> &OutPoint { self.get_channel_parameters().funding_outpoint.as_ref().unwrap() }
608610

609611
/// Obtain a ChannelTransactionParameters for this channel, to be used when verifying or
610612
/// building transactions.
611613
///
612-
/// Will panic if ready_channel wasn't called.
614+
/// Will panic if provide_channel_parameters wasn't called.
613615
pub fn get_channel_parameters(&self) -> &ChannelTransactionParameters {
614616
self.channel_parameters.as_ref().unwrap()
615617
}
616618

617619
/// Whether anchors should be used.
618-
/// Will panic if ready_channel wasn't called.
620+
/// Will panic if provide_channel_parameters wasn't called.
619621
pub fn opt_anchors(&self) -> bool {
620622
self.get_channel_parameters().opt_anchors.is_some()
621623
}
@@ -819,8 +821,10 @@ impl BaseSign for InMemorySigner {
819821
Ok((sign(secp_ctx, &msghash, &self.node_secret), sign(secp_ctx, &msghash, &self.funding_key)))
820822
}
821823

822-
fn ready_channel(&mut self, channel_parameters: &ChannelTransactionParameters) {
823-
assert!(self.channel_parameters.is_none(), "Acceptance already noted");
824+
fn provide_channel_parameters(&mut self, channel_parameters: &ChannelTransactionParameters) {
825+
if self.channel_parameters.is_some() {
826+
return;
827+
}
824828
assert!(channel_parameters.is_populated(), "Channel parameters must be fully populated");
825829
self.channel_parameters = Some(channel_parameters.clone());
826830
}

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)