15
15
//! few other things.
16
16
17
17
use crate :: chain:: keysinterface:: SpendableOutputDescriptor ;
18
+ #[ cfg( anchors) ]
18
19
use crate :: ln:: chan_utils:: HTLCOutputInCommitment ;
19
20
use crate :: ln:: channelmanager:: PaymentId ;
20
21
use crate :: ln:: channel:: FUNDING_CONF_DEADLINE_BLOCKS ;
@@ -26,11 +27,15 @@ use crate::routing::gossip::NetworkUpdate;
26
27
use crate :: util:: ser:: { BigSize , FixedLengthReader , Writeable , Writer , MaybeReadable , Readable , VecReadWrapper , VecWriteWrapper } ;
27
28
use crate :: routing:: router:: { RouteHop , RouteParameters } ;
28
29
29
- use bitcoin:: { PackedLockTime , Transaction , OutPoint } ;
30
+ #[ cfg( anchors) ]
31
+ use bitcoin:: OutPoint ;
32
+ use bitcoin:: { PackedLockTime , Transaction } ;
30
33
use bitcoin:: blockdata:: script:: Script ;
31
34
use bitcoin:: hashes:: Hash ;
32
35
use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
33
36
use bitcoin:: secp256k1:: PublicKey ;
37
+ #[ cfg( anchors) ]
38
+ use bitcoin:: secp256k1:: ecdsa:: Signature ;
34
39
use crate :: io;
35
40
use crate :: prelude:: * ;
36
41
use core:: time:: Duration ;
@@ -225,6 +230,37 @@ pub struct AnchorDescriptor {
225
230
pub outpoint : OutPoint ,
226
231
}
227
232
233
+ #[ cfg( anchors) ]
234
+ /// A descriptor used to sign for a commitment transaction's HTLC output.
235
+ #[ derive( Clone , Debug ) ]
236
+ pub struct HTLCDescriptor {
237
+ /// A unique identifier used along with `channel_value_satoshis` to re-derive the
238
+ /// [`InMemorySigner`] required to sign `input`.
239
+ ///
240
+ /// [`InMemorySigner`]: crate::chain::keysinterface::InMemorySigner
241
+ pub channel_keys_id : [ u8 ; 32 ] ,
242
+ /// The value in satoshis of the channel we're attempting to spend the anchor output of. This is
243
+ /// used along with `channel_keys_id` to re-derive the [`InMemorySigner`] required to sign
244
+ /// `input`.
245
+ ///
246
+ /// [`InMemorySigner`]: crate::chain::keysinterface::InMemorySigner
247
+ pub channel_value_satoshis : u64 ,
248
+ /// The number of the commitment transaction in which the HTLC output lives.
249
+ pub per_commitment_number : u64 ,
250
+ /// The details of the HTLC as it appears in a commitment transaction.
251
+ pub htlc : HTLCOutputInCommitment ,
252
+ /// The preimage, if one exists, to claim the HTLC output with.
253
+ pub preimage : Option < PaymentPreimage > ,
254
+ /// The counterparty's base HTLC key of the channel. This is required to reconstruct the HTLC
255
+ /// output's witness script.
256
+ pub counterparty_base_htlc_key : PublicKey ,
257
+ /// The counterparty's base revocation key of the channel. This is required to reconstruct the
258
+ /// HTLC output's witness script.
259
+ pub counterparty_base_revocation_key : PublicKey ,
260
+ /// The counterparty's signature required to spend the HTLC output.
261
+ pub counterparty_sig : Signature
262
+ }
263
+
228
264
#[ cfg( anchors) ]
229
265
/// Represents the different types of transactions, originating from LDK, to be bumped.
230
266
#[ derive( Clone , Debug ) ]
@@ -244,7 +280,10 @@ pub enum BumpTransactionEvent {
244
280
/// The consumer should be able to sign for any of the additional inputs included within the
245
281
/// child anchor transaction. To sign its anchor input, an [`InMemorySigner`] should be
246
282
/// re-derived through [`KeysManager::derive_channel_keys`] with the help of
247
- /// [`AnchorDescriptor::channel_keys_id`] and [`AnchorDescriptor::channel_value_satoshis`].
283
+ /// [`AnchorDescriptor::channel_keys_id`] and [`AnchorDescriptor::channel_value_satoshis`]. The
284
+ /// anchor input signature can be computed with [`InMemorySigner::sign_holder_anchor_input`],
285
+ /// which can then be provided to [`build_anchor_input_witness`] along with the `funding_pubkey`
286
+ /// to obtain the full witness required to spend.
248
287
///
249
288
/// It is possible to receive more than one instance of this event if a valid child anchor
250
289
/// transaction is never broadcast or is but not with a sufficient fee to be mined. Care should
@@ -265,6 +304,8 @@ pub enum BumpTransactionEvent {
265
304
///
266
305
/// [`InMemorySigner`]: crate::chain::keysinterface::InMemorySigner
267
306
/// [`KeysManager::derive_channel_keys`]: crate::chain::keysinterface::KeysManager::derive_channel_keys
307
+ /// [`InMemorySigner::sign_holder_anchor_input`]: crate::chain::keysinterface::InMemorySigner::sign_holder_anchor_input
308
+ /// [`build_anchor_input_witness`]: crate::ln::chan_utils::build_anchor_input_witness
268
309
ChannelClose {
269
310
/// The target feerate that the transaction package, which consists of the commitment
270
311
/// transaction and the to-be-crafted child anchor transaction, must meet.
@@ -283,6 +324,40 @@ pub enum BumpTransactionEvent {
283
324
/// commitment transaction confirms.
284
325
pending_htlcs : Vec < HTLCOutputInCommitment > ,
285
326
} ,
327
+ /// Indicates that a channel featuring anchor outputs has HTLC(s) that need to be resolved
328
+ /// onchain. With the zero-HTLC-transaction-fee variant of anchor outputs, the pre-signed HTLC
329
+ /// transactions have a zero fee, thus requiring additional inputs and/or outputs to be attached
330
+ /// for a timely confirmation within the chain. These additional inputs and/or outputs must be
331
+ /// appended to the enclosed `tx_template` to meet the target feerate. Failure to meet the
332
+ /// target feerate decreases the confirmation odds of the transaction, possibly resulting in a
333
+ /// loss of funds. Once the transaction is amended to meet the target feerate, it must be signed
334
+ /// for and broadcast by the consumer of the event.
335
+ ///
336
+ /// The consumer should be able to sign for any of the additional inputs added to `tx_template`.
337
+ /// To sign HTLC inputs, an [`InMemorySigner`] should be re-derived through
338
+ /// [`KeysManager::derive_channel_keys`] with the help of `channel_keys_id` and
339
+ /// `channel_value_satoshis`. Each HTLC input's signature can be computed with
340
+ /// [`InMemorySigner::sign_holder_htlc_transaction`], which can then be provided to
341
+ /// [`build_htlc_input_witness`] along with the enclosed [`HTLCDescriptor`] to obtain the full
342
+ /// witness required to spend.
343
+ ///
344
+ /// It is possible to receive more than one instance of this event if a valid HTLC transaction
345
+ /// is never broadcast or is but not with a sufficient fee to be mined. Care should be taken by
346
+ /// the consumer of the event to ensure any future iterations of the HTLC transaction adhere to
347
+ /// the [Replace-By-Fee rules](https://github.com/bitcoin/bitcoin/blob/master/doc/policy/mempool-replacements.md)
348
+ /// for fee bumps to be accepted into the mempool, and eventually the chain. As the frequency of
349
+ /// these events is not user-controlled, users may ignore/drop the event if they are no longer
350
+ /// able to commit external confirmed funds to the HTLC transaction.
351
+ ///
352
+ /// [`InMemorySigner`]: crate::chain::keysinterface::InMemorySigner
353
+ /// [`KeysManager::derive_channel_keys`]: crate::chain::keysinterface::KeysManager::derive_channel_keys
354
+ /// [`InMemorySigner::sign_holder_htlc_transaction`]: crate::chain::keysinterface::InMemorySigner::sign_holder_htlc_transaction
355
+ /// [`build_htlc_input_witness`]: crate::ln::chan_utils::build_htlc_input_witness
356
+ HTLCResolution {
357
+ target_feerate_sat_per_1000_weight : u32 ,
358
+ tx_template : Transaction ,
359
+ htlc_descriptors : Vec < HTLCDescriptor > ,
360
+ } ,
286
361
}
287
362
288
363
/// An Event which you should probably take some action in response to.
@@ -853,9 +928,10 @@ impl Writeable for Event {
853
928
& Event :: BumpTransaction ( ref event) => {
854
929
27u8 . write ( writer) ?;
855
930
match event {
856
- // We never write the ChannelClose events as they'll be replayed upon restarting
857
- // anyway if the commitment transaction remains unconfirmed .
931
+ // We never write the ChannelClose|HTLCResolution events as they'll be replayed
932
+ // upon restarting anyway if they remain unresolved .
858
933
BumpTransactionEvent :: ChannelClose { .. } => { }
934
+ BumpTransactionEvent :: HTLCResolution { .. } => { }
859
935
}
860
936
}
861
937
// Note that, going forward, all new events must only write data inside of
0 commit comments