Skip to content

Commit 42cc4e7

Browse files
authored
Merge pull request #3486 from TheBlueMatt/2024-12-async-sign
Remove the async_signing cfg flag
2 parents 0e6f47e + d2172e3 commit 42cc4e7

File tree

7 files changed

+93
-87
lines changed

7 files changed

+93
-87
lines changed

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ check-cfg = [
6262
"cfg(ldk_bench)",
6363
"cfg(ldk_test_vectors)",
6464
"cfg(taproot)",
65-
"cfg(async_signing)",
6665
"cfg(require_route_graph_test)",
6766
"cfg(splicing)",
6867
"cfg(async_payments)",

ci/ci-tests.sh

-2
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,6 @@ fi
166166
echo -e "\n\nTest cfg-flag builds"
167167
RUSTFLAGS="--cfg=taproot" cargo test --verbose --color always -p lightning
168168
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
169-
RUSTFLAGS="--cfg=async_signing" cargo test --verbose --color always -p lightning
170-
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
171169
RUSTFLAGS="--cfg=splicing" cargo test --verbose --color always -p lightning
172170
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
173171
RUSTFLAGS="--cfg=async_payments" cargo test --verbose --color always -p lightning

lightning/src/ln/channel.rs

+24-58
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,6 @@ pub(super) struct MonitorRestoreUpdates {
906906
}
907907

908908
/// The return value of `signer_maybe_unblocked`
909-
#[allow(unused)]
910909
pub(super) struct SignerResumeUpdates {
911910
pub commitment_update: Option<msgs::CommitmentUpdate>,
912911
pub revoke_and_ack: Option<msgs::RevokeAndACK>,
@@ -3960,13 +3959,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
39603959
log_trace!(logger, "Counterparty commitment signature available for funding_signed message; clearing signer_pending_funding");
39613960
self.signer_pending_funding = false;
39623961
} else if signature.is_none() {
3963-
#[cfg(not(async_signing))] {
3964-
panic!("Failed to get signature for funding_signed");
3965-
}
3966-
#[cfg(async_signing)] {
3967-
log_trace!(logger, "Counterparty commitment signature not available for funding_signed message; setting signer_pending_funding");
3968-
self.signer_pending_funding = true;
3969-
}
3962+
log_trace!(logger, "Counterparty commitment signature not available for funding_signed message; setting signer_pending_funding");
3963+
self.signer_pending_funding = true;
39703964
}
39713965

39723966
signature.map(|(signature, _)| msgs::FundingSigned {
@@ -6117,7 +6111,6 @@ impl<SP: Deref> Channel<SP> where
61176111

61186112
/// Indicates that the signer may have some signatures for us, so we should retry if we're
61196113
/// blocked.
6120-
#[cfg(async_signing)]
61216114
pub fn signer_maybe_unblocked<L: Deref>(&mut self, logger: &L) -> SignerResumeUpdates where L::Target: Logger {
61226115
if !self.holder_commitment_point.is_available() {
61236116
log_trace!(logger, "Attempting to update holder per-commitment point...");
@@ -6234,21 +6227,16 @@ impl<SP: Deref> Channel<SP> where
62346227
&self.context.channel_id(), self.holder_commitment_point.transaction_number(),
62356228
self.holder_commitment_point.transaction_number() + 2);
62366229
}
6237-
#[cfg(not(async_signing))] {
6238-
panic!("Holder commitment point and per commitment secret must be available when generating revoke_and_ack");
6239-
}
6240-
#[cfg(async_signing)] {
6241-
// Technically if we're at HolderCommitmentPoint::PendingNext,
6242-
// we have a commitment point ready to send in an RAA, however we
6243-
// choose to wait since if we send RAA now, we could get another
6244-
// CS before we have any commitment point available. Blocking our
6245-
// RAA here is a convenient way to make sure that post-funding
6246-
// we're only ever waiting on one commitment point at a time.
6247-
log_trace!(logger, "Last revoke-and-ack pending in channel {} for sequence {} because the next per-commitment point is not available",
6248-
&self.context.channel_id(), self.holder_commitment_point.transaction_number());
6249-
self.context.signer_pending_revoke_and_ack = true;
6250-
None
6251-
}
6230+
// Technically if we're at HolderCommitmentPoint::PendingNext,
6231+
// we have a commitment point ready to send in an RAA, however we
6232+
// choose to wait since if we send RAA now, we could get another
6233+
// CS before we have any commitment point available. Blocking our
6234+
// RAA here is a convenient way to make sure that post-funding
6235+
// we're only ever waiting on one commitment point at a time.
6236+
log_trace!(logger, "Last revoke-and-ack pending in channel {} for sequence {} because the next per-commitment point is not available",
6237+
&self.context.channel_id(), self.holder_commitment_point.transaction_number());
6238+
self.context.signer_pending_revoke_and_ack = true;
6239+
None
62526240
}
62536241

62546242
/// Gets the last commitment update for immediate sending to our peer.
@@ -6319,16 +6307,11 @@ impl<SP: Deref> Channel<SP> where
63196307
}
63206308
update
63216309
} else {
6322-
#[cfg(not(async_signing))] {
6323-
panic!("Failed to get signature for new commitment state");
6324-
}
6325-
#[cfg(async_signing)] {
6326-
if !self.context.signer_pending_commitment_update {
6327-
log_trace!(logger, "Commitment update awaiting signer: setting signer_pending_commitment_update");
6328-
self.context.signer_pending_commitment_update = true;
6329-
}
6330-
return Err(());
6310+
if !self.context.signer_pending_commitment_update {
6311+
log_trace!(logger, "Commitment update awaiting signer: setting signer_pending_commitment_update");
6312+
self.context.signer_pending_commitment_update = true;
63316313
}
6314+
return Err(());
63326315
};
63336316
Ok(msgs::CommitmentUpdate {
63346317
update_add_htlcs, update_fulfill_htlcs, update_fail_htlcs, update_fail_malformed_htlcs, update_fee,
@@ -8366,13 +8349,8 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
83668349
log_trace!(logger, "Counterparty commitment signature ready for funding_created message: clearing signer_pending_funding");
83678350
self.context.signer_pending_funding = false;
83688351
} else if signature.is_none() {
8369-
#[cfg(not(async_signing))] {
8370-
panic!("Failed to get signature for new funding creation");
8371-
}
8372-
#[cfg(async_signing)] {
8373-
log_trace!(logger, "funding_created awaiting signer; setting signer_pending_funding");
8374-
self.context.signer_pending_funding = true;
8375-
}
8352+
log_trace!(logger, "funding_created awaiting signer; setting signer_pending_funding");
8353+
self.context.signer_pending_funding = true;
83768354
};
83778355

83788356
signature.map(|signature| msgs::FundingCreated {
@@ -8471,14 +8449,9 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
84718449
holder_commitment_point.current_point()
84728450
},
84738451
_ => {
8474-
#[cfg(not(async_signing))] {
8475-
panic!("Failed getting commitment point for open_channel message");
8476-
}
8477-
#[cfg(async_signing)] {
8478-
log_trace!(_logger, "Unable to generate open_channel message, waiting for commitment point");
8479-
self.signer_pending_open_channel = true;
8480-
return None;
8481-
}
8452+
log_trace!(_logger, "Unable to generate open_channel message, waiting for commitment point");
8453+
self.signer_pending_open_channel = true;
8454+
return None;
84828455
}
84838456
};
84848457
let keys = self.context.get_holder_pubkeys();
@@ -8566,7 +8539,6 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
85668539

85678540
/// Indicates that the signer may have some signatures for us, so we should retry if we're
85688541
/// blocked.
8569-
#[cfg(async_signing)]
85708542
pub fn signer_maybe_unblocked<L: Deref>(
85718543
&mut self, chain_hash: ChainHash, logger: &L
85728544
) -> (Option<msgs::OpenChannel>, Option<msgs::FundingCreated>) where L::Target: Logger {
@@ -8727,14 +8699,9 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
87278699
holder_commitment_point.current_point()
87288700
},
87298701
_ => {
8730-
#[cfg(not(async_signing))] {
8731-
panic!("Failed getting commitment point for accept_channel message");
8732-
}
8733-
#[cfg(async_signing)] {
8734-
log_trace!(_logger, "Unable to generate accept_channel message, waiting for commitment point");
8735-
self.signer_pending_accept_channel = true;
8736-
return None;
8737-
}
8702+
log_trace!(_logger, "Unable to generate accept_channel message, waiting for commitment point");
8703+
self.signer_pending_accept_channel = true;
8704+
return None;
87388705
}
87398706
};
87408707
let keys = self.context.get_holder_pubkeys();
@@ -8837,7 +8804,6 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
88378804

88388805
/// Indicates that the signer may have some signatures for us, so we should retry if we're
88398806
/// blocked.
8840-
#[allow(unused)]
88418807
pub fn signer_maybe_unblocked<L: Deref>(
88428808
&mut self, logger: &L
88438809
) -> Option<msgs::AcceptChannel> where L::Target: Logger {

lightning/src/ln/channelmanager.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9470,7 +9470,6 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
94709470
/// attempted in every channel, or in the specifically provided channel.
94719471
///
94729472
/// [`ChannelSigner`]: crate::sign::ChannelSigner
9473-
#[cfg(async_signing)]
94749473
pub fn signer_unblocked(&self, channel_opt: Option<(PublicKey, ChannelId)>) {
94759474
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
94769475

lightning/src/ln/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ mod monitor_tests;
8585
#[cfg(test)]
8686
#[allow(unused_mut)]
8787
mod shutdown_tests;
88-
#[cfg(all(test, async_signing))]
88+
#[cfg(test)]
8989
#[allow(unused_mut)]
9090
mod async_signer_tests;
9191
#[cfg(test)]

lightning/src/sign/ecdsa.rs

+41-15
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>,

0 commit comments

Comments
 (0)