Skip to content

Commit d2172e3

Browse files
committed
Update signer docs to describe which methods are async
We should update the return types on the signing methods here as well, but we should at least start by documenting which methods are async and which are not. Once we complete async support for `get_per_commitment_point`, we can change the return types as most things in the channel signing traits will be finalized.
1 parent 47ca19d commit d2172e3

File tree

2 files changed

+68
-23
lines changed

2 files changed

+68
-23
lines changed

lightning/src/sign/ecdsa.rs

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,18 @@ use crate::sign::{ChannelSigner, HTLCDescriptor};
2424
/// policies in order to be secure. Please refer to the [VLS Policy
2525
/// Controls](https://gitlab.com/lightning-signer/validating-lightning-signer/-/blob/main/docs/policy-controls.md)
2626
/// for an example of such policies.
27+
///
28+
/// Like [`ChannelSigner`], many of the methods allow errors to be returned to support async
29+
/// signing. In such cases, the signing operation can be replayed by calling
30+
/// [`ChannelManager::signer_unblocked`] or [`ChainMonitor::signer_unblocked`] (see individual
31+
/// method documentation for which method should be called) once the result is ready, at which
32+
/// point the channel operation will resume.
33+
///
34+
/// [`ChannelManager::signer_unblocked`]: crate::ln::channelmanager::ChannelManager::signer_unblocked
35+
/// [`ChainMonitor::signer_unblocked`]: crate::chain::chainmonitor::ChainMonitor::signer_unblocked
2736
pub trait EcdsaChannelSigner: ChannelSigner {
2837
/// Create a signature for a counterparty's commitment transaction and associated HTLC transactions.
2938
///
30-
/// Note that if signing fails or is rejected, the channel will be force-closed.
31-
///
3239
/// Policy checks should be implemented in this function, including checking the amount
3340
/// sent to us and checking the HTLCs.
3441
///
@@ -39,8 +46,12 @@ pub trait EcdsaChannelSigner: ChannelSigner {
3946
///
4047
/// Note that all the relevant preimages will be provided, but there may also be additional
4148
/// irrelevant or duplicate preimages.
42-
//
43-
// TODO: Document the things someone using this interface should enforce before signing.
49+
///
50+
/// An `Err` can be returned to signal that the signer is unavailable/cannot produce a valid
51+
/// signature and should be retried later. Once the signer is ready to provide a signature after
52+
/// previously returning an `Err`, [`ChannelManager::signer_unblocked`] must be called.
53+
///
54+
/// [`ChannelManager::signer_unblocked`]: crate::ln::channelmanager::ChannelManager::signer_unblocked
4455
fn sign_counterparty_commitment(
4556
&self, commitment_tx: &CommitmentTransaction, inbound_htlc_preimages: Vec<PaymentPreimage>,
4657
outbound_htlc_preimages: Vec<PaymentPreimage>, secp_ctx: &Secp256k1<secp256k1::All>,
@@ -58,18 +69,19 @@ pub trait EcdsaChannelSigner: ChannelSigner {
5869
/// An `Err` can be returned to signal that the signer is unavailable/cannot produce a valid
5970
/// signature and should be retried later. Once the signer is ready to provide a signature after
6071
/// previously returning an `Err`, [`ChannelMonitor::signer_unblocked`] must be called on its
61-
/// monitor.
72+
/// monitor or [`ChainMonitor::signer_unblocked`] called to attempt unblocking all monitors.
6273
///
6374
/// [`ChannelMonitor::signer_unblocked`]: crate::chain::channelmonitor::ChannelMonitor::signer_unblocked
64-
//
65-
// TODO: Document the things someone using this interface should enforce before signing.
75+
/// [`ChainMonitor::signer_unblocked`]: crate::chain::chainmonitor::ChainMonitor::signer_unblocked
6676
fn sign_holder_commitment(
6777
&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
6878
) -> Result<Signature, ()>;
6979
/// Same as [`sign_holder_commitment`], but exists only for tests to get access to holder
7080
/// commitment transactions which will be broadcasted later, after the channel has moved on to a
7181
/// newer state. Thus, needs its own method as [`sign_holder_commitment`] may enforce that we
7282
/// only ever get called once.
83+
///
84+
/// This method is *not* async as it is intended only for testing purposes.
7385
#[cfg(any(test, feature = "unsafe_revoked_tx_signing"))]
7486
fn unsafe_sign_holder_commitment(
7587
&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
@@ -92,9 +104,10 @@ pub trait EcdsaChannelSigner: ChannelSigner {
92104
/// An `Err` can be returned to signal that the signer is unavailable/cannot produce a valid
93105
/// signature and should be retried later. Once the signer is ready to provide a signature after
94106
/// previously returning an `Err`, [`ChannelMonitor::signer_unblocked`] must be called on its
95-
/// monitor.
107+
/// monitor or [`ChainMonitor::signer_unblocked`] called to attempt unblocking all monitors.
96108
///
97109
/// [`ChannelMonitor::signer_unblocked`]: crate::chain::channelmonitor::ChannelMonitor::signer_unblocked
110+
/// [`ChainMonitor::signer_unblocked`]: crate::chain::chainmonitor::ChainMonitor::signer_unblocked
98111
fn sign_justice_revoked_output(
99112
&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey,
100113
secp_ctx: &Secp256k1<secp256k1::All>,
@@ -121,9 +134,10 @@ pub trait EcdsaChannelSigner: ChannelSigner {
121134
/// An `Err` can be returned to signal that the signer is unavailable/cannot produce a valid
122135
/// signature and should be retried later. Once the signer is ready to provide a signature after
123136
/// previously returning an `Err`, [`ChannelMonitor::signer_unblocked`] must be called on its
124-
/// monitor.
137+
/// monitor or [`ChainMonitor::signer_unblocked`] called to attempt unblocking all monitors.
125138
///
126139
/// [`ChannelMonitor::signer_unblocked`]: crate::chain::channelmonitor::ChannelMonitor::signer_unblocked
140+
/// [`ChainMonitor::signer_unblocked`]: crate::chain::chainmonitor::ChainMonitor::signer_unblocked
127141
fn sign_justice_revoked_htlc(
128142
&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey,
129143
htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>,
@@ -139,11 +153,12 @@ pub trait EcdsaChannelSigner: ChannelSigner {
139153
/// An `Err` can be returned to signal that the signer is unavailable/cannot produce a valid
140154
/// signature and should be retried later. Once the signer is ready to provide a signature after
141155
/// previously returning an `Err`, [`ChannelMonitor::signer_unblocked`] must be called on its
142-
/// monitor.
156+
/// monitor or [`ChainMonitor::signer_unblocked`] called to attempt unblocking all monitors.
143157
///
144158
/// [`EcdsaSighashType::All`]: bitcoin::sighash::EcdsaSighashType::All
145159
/// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
146160
/// [`ChannelMonitor::signer_unblocked`]: crate::chain::channelmonitor::ChannelMonitor::signer_unblocked
161+
/// [`ChainMonitor::signer_unblocked`]: crate::chain::chainmonitor::ChainMonitor::signer_unblocked
147162
fn sign_holder_htlc_transaction(
148163
&self, htlc_tx: &Transaction, input: usize, htlc_descriptor: &HTLCDescriptor,
149164
secp_ctx: &Secp256k1<secp256k1::All>,
@@ -169,9 +184,10 @@ pub trait EcdsaChannelSigner: ChannelSigner {
169184
/// An `Err` can be returned to signal that the signer is unavailable/cannot produce a valid
170185
/// signature and should be retried later. Once the signer is ready to provide a signature after
171186
/// previously returning an `Err`, [`ChannelMonitor::signer_unblocked`] must be called on its
172-
/// monitor.
187+
/// monitor or [`ChainMonitor::signer_unblocked`] called to attempt unblocking all monitors.
173188
///
174189
/// [`ChannelMonitor::signer_unblocked`]: crate::chain::channelmonitor::ChannelMonitor::signer_unblocked
190+
/// [`ChainMonitor::signer_unblocked`]: crate::chain::chainmonitor::ChainMonitor::signer_unblocked
175191
fn sign_counterparty_htlc_transaction(
176192
&self, htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &PublicKey,
177193
htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>,
@@ -180,6 +196,12 @@ pub trait EcdsaChannelSigner: ChannelSigner {
180196
///
181197
/// Note that, due to rounding, there may be one "missing" satoshi, and either party may have
182198
/// chosen to forgo their output as dust.
199+
///
200+
/// An `Err` can be returned to signal that the signer is unavailable/cannot produce a valid
201+
/// signature and should be retried later. Once the signer is ready to provide a signature after
202+
/// previously returning an `Err`, [`ChannelManager::signer_unblocked`] must be called.
203+
///
204+
/// [`ChannelManager::signer_unblocked`]: crate::ln::channelmanager::ChannelManager::signer_unblocked
183205
fn sign_closing_transaction(
184206
&self, closing_tx: &ClosingTransaction, secp_ctx: &Secp256k1<secp256k1::All>,
185207
) -> Result<Signature, ()>;
@@ -189,9 +211,10 @@ pub trait EcdsaChannelSigner: ChannelSigner {
189211
/// An `Err` can be returned to signal that the signer is unavailable/cannot produce a valid
190212
/// signature and should be retried later. Once the signer is ready to provide a signature after
191213
/// previously returning an `Err`, [`ChannelMonitor::signer_unblocked`] must be called on its
192-
/// monitor.
214+
/// monitor or [`ChainMonitor::signer_unblocked`] called to attempt unblocking all monitors.
193215
///
194216
/// [`ChannelMonitor::signer_unblocked`]: crate::chain::channelmonitor::ChannelMonitor::signer_unblocked
217+
/// [`ChainMonitor::signer_unblocked`]: crate::chain::chainmonitor::ChainMonitor::signer_unblocked
195218
fn sign_holder_anchor_input(
196219
&self, anchor_tx: &Transaction, input: usize, secp_ctx: &Secp256k1<secp256k1::All>,
197220
) -> Result<Signature, ()>;
@@ -201,9 +224,9 @@ pub trait EcdsaChannelSigner: ChannelSigner {
201224
/// Channel announcements also require a signature from each node's network key. Our node
202225
/// signature is computed through [`NodeSigner::sign_gossip_message`].
203226
///
204-
/// Note that if this fails or is rejected, the channel will not be publicly announced and
205-
/// our counterparty may (though likely will not) close the channel on us for violating the
206-
/// protocol.
227+
/// This method is *not* asynchronous. If an `Err` is returned, the channel will not be
228+
/// publicly announced and our counterparty may (though likely will not) close the channel on
229+
/// us for violating the protocol.
207230
///
208231
/// [`NodeSigner::sign_gossip_message`]: crate::sign::NodeSigner::sign_gossip_message
209232
fn sign_channel_announcement_with_funding_key(
@@ -219,6 +242,9 @@ pub trait EcdsaChannelSigner: ChannelSigner {
219242
/// spending the previous funding transaction's output
220243
///
221244
/// `input_value`: The value of the previous funding transaction output.
245+
///
246+
/// This method is *not* asynchronous. If an `Err` is returned, the channel will be immediately
247+
/// closed.
222248
fn sign_splicing_funding_input(
223249
&self, tx: &Transaction, input_index: usize, input_value: u64,
224250
secp_ctx: &Secp256k1<secp256k1::All>,

lightning/src/sign/mod.rs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -719,18 +719,20 @@ impl HTLCDescriptor {
719719
/// A trait to handle Lightning channel key material without concretizing the channel type or
720720
/// the signature mechanism.
721721
///
722-
/// Several methods allow error types to be returned to support async signing. This feature
723-
/// is not yet complete, and panics may occur in certain situations when returning errors
724-
/// for these methods.
722+
/// Several methods allow errors to be returned to support async signing. In such cases, the
723+
/// signing operation can be replayed by calling [`ChannelManager::signer_unblocked`] once the
724+
/// result is ready, at which point the channel operation will resume. Methods which allow for
725+
/// async results are explicitly documented as such
726+
///
727+
/// [`ChannelManager::signer_unblocked`]: crate::ln::channelmanager::ChannelManager::signer_unblocked
725728
pub trait ChannelSigner {
726729
/// Gets the per-commitment point for a specific commitment number
727730
///
728731
/// Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
729732
///
730-
/// If the signer returns `Err`, then the user is responsible for either force-closing the channel
731-
/// or calling `ChannelManager::signer_unblocked` once the signature is ready.
732-
///
733-
// TODO: link to `signer_unblocked` once the cfg flag is removed
733+
/// This method is *not* asynchronous. This method is expected to always return `Ok`
734+
/// immediately after we reconnect to peers, and returning an `Err` may lead to an immediate
735+
/// `panic`. This method will be made asynchronous in a future release.
734736
fn get_per_commitment_point(
735737
&self, idx: u64, secp_ctx: &Secp256k1<secp256k1::All>,
736738
) -> Result<PublicKey, ()>;
@@ -743,7 +745,12 @@ pub trait ChannelSigner {
743745
/// May be called more than once for the same index.
744746
///
745747
/// Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
746-
// TODO: return a Result so we can signal a validation error
748+
///
749+
/// An `Err` can be returned to signal that the signer is unavailable/cannot produce a valid
750+
/// signature and should be retried later. Once the signer is ready to provide a signature after
751+
/// previously returning an `Err`, [`ChannelManager::signer_unblocked`] must be called.
752+
///
753+
/// [`ChannelManager::signer_unblocked`]: crate::ln::channelmanager::ChannelManager::signer_unblocked
747754
fn release_commitment_secret(&self, idx: u64) -> Result<[u8; 32], ()>;
748755

749756
/// Validate the counterparty's signatures on the holder commitment transaction and HTLCs.
@@ -759,6 +766,10 @@ pub trait ChannelSigner {
759766
///
760767
/// Note that all the relevant preimages will be provided, but there may also be additional
761768
/// irrelevant or duplicate preimages.
769+
///
770+
/// This method is *not* asynchronous. If an `Err` is returned, the channel will be immediately
771+
/// closed. If you wish to make this operation asynchronous, you should instead return `Ok(())`
772+
/// and pause future signing operations until this validation completes.
762773
fn validate_holder_commitment(
763774
&self, holder_tx: &HolderCommitmentTransaction,
764775
outbound_htlc_preimages: Vec<PaymentPreimage>,
@@ -768,14 +779,22 @@ pub trait ChannelSigner {
768779
///
769780
/// This is required in order for the signer to make sure that the state has moved
770781
/// forward and it is safe to sign the next counterparty commitment.
782+
///
783+
/// This method is *not* asynchronous. If an `Err` is returned, the channel will be immediately
784+
/// closed. If you wish to make this operation asynchronous, you should instead return `Ok(())`
785+
/// and pause future signing operations until this validation completes.
771786
fn validate_counterparty_revocation(&self, idx: u64, secret: &SecretKey) -> Result<(), ()>;
772787

773788
/// Returns the holder's channel public keys and basepoints.
789+
///
790+
/// This method is *not* asynchronous. Instead, the value must be cached locally.
774791
fn pubkeys(&self) -> &ChannelPublicKeys;
775792

776793
/// Returns an arbitrary identifier describing the set of keys which are provided back to you in
777794
/// some [`SpendableOutputDescriptor`] types. This should be sufficient to identify this
778795
/// [`EcdsaChannelSigner`] object uniquely and lookup or re-derive its keys.
796+
///
797+
/// This method is *not* asynchronous. Instead, the value must be cached locally.
779798
fn channel_keys_id(&self) -> [u8; 32];
780799

781800
/// Set the counterparty static channel data, including basepoints,

0 commit comments

Comments
 (0)