@@ -31,6 +31,8 @@ use bitcoin::blockdata::script::Script;
3131use bitcoin:: hashes:: Hash ;
3232use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
3333use bitcoin:: secp256k1:: PublicKey ;
34+ #[ cfg( anchors) ]
35+ use bitcoin:: secp256k1:: ecdsa:: Signature ;
3436use crate :: io;
3537use crate :: prelude:: * ;
3638use core:: time:: Duration ;
@@ -244,7 +246,10 @@ pub enum BumpTransactionEvent {
244246 /// The consumer should be able to sign for any of the additional inputs included within the
245247 /// child anchor transaction. To sign its anchor input, an [`InMemorySigner`] should be
246248 /// re-derived through [`KeysManager::derive_channel_keys`] with the help of
247- /// [`AnchorDescriptor::channel_keys_id`] and [`AnchorDescriptor::channel_value_satoshis`].
249+ /// [`AnchorDescriptor::channel_keys_id`] and [`AnchorDescriptor::channel_value_satoshis`]. The
250+ /// anchor input signature can be computed with [`InMemorySigner::sign_holder_anchor_input`],
251+ /// which can then be provided to [`build_anchor_input_witness`] along with the `funding_pubkey`
252+ /// to obtain the full witness required to spend.
248253 ///
249254 /// It is possible to receive more than one instance of this event if a valid child anchor
250255 /// transaction is never broadcast or is but not with a sufficient fee to be mined. Care should
@@ -265,6 +270,8 @@ pub enum BumpTransactionEvent {
265270 ///
266271 /// [`InMemorySigner`]: crate::chain::keysinterface::InMemorySigner
267272 /// [`KeysManager::derive_channel_keys`]: crate::chain::keysinterface::KeysManager::derive_channel_keys
273+ /// [`InMemorySigner::sign_holder_anchor_input`]: crate::chain::keysinterface::InMemorySigner::sign_holder_anchor_input
274+ /// [`build_anchor_input_witness`]: crate::ln::chan_utils::build_anchor_input_witness
268275 ChannelClose {
269276 /// The target feerate that the transaction package, which consists of the commitment
270277 /// transaction and the to-be-crafted child anchor transaction, must meet.
@@ -283,6 +290,55 @@ pub enum BumpTransactionEvent {
283290 /// commitment transaction confirms.
284291 pending_htlcs : Vec < HTLCOutputInCommitment > ,
285292 } ,
293+ /// Indicates that a channel featuring anchor outputs has HTLC(s) that need to be resolved
294+ /// onchain. With the zero-HTLC-transaction-fee variant of anchor outputs, the pre-signed HTLC
295+ /// transactions have a zero fee, thus requiring additional inputs and/or outputs to be attached
296+ /// for a timely confirmation within the chain. These additional inputs and/or outputs must be
297+ /// appended to the enclosed `tx_template` to meet the target feerate. Consumers must ensure the
298+ /// order of pre-existing inputs and outputs within `tx_template` are not changed, as it is
299+ /// crucial to the validity of the transaction itself. Failure to meet the target feerate
300+ /// decreases the confirmation odds of the transaction, possinly resulting in a loss of funds.
301+ /// Once the transaction is amended to meet the target feerate, it must be signed for and
302+ /// broadcast by the consumer of the event.
303+ ///
304+ /// The consumer should be able to sign for any of the additional inputs added to `tx_template`.
305+ /// To sign HTLC inputs, an [`InMemorySigner`] should be re-derived through
306+ /// [`KeysManager::derive_channel_keys`] with the help of `channel_keys_id` and
307+ /// `AnchorDescriptor::channel_value_satoshis`. Each HTLC input's signature can be computed
308+ /// with [`InMemorySigner::sign_holder_htlc_transaction`], which can then be provided to
309+ /// [`build_htlc_input_witness`] along with the enclosed [`HTLCDescriptor`] to obtain the full
310+ /// witness required to spend.
311+ ///
312+ /// It is possible to receive more than one instance of this event if a valid HTLC transaction
313+ /// is never broadcast or is but not with a sufficient fee to be mined. Care should be taken by
314+ /// the consumer of the event to ensure any future iterations of the HTLC transaction adhere to
315+ /// the [Replace-By-Fee rules](https://github.com/bitcoin/bitcoin/blob/master/doc/policy/mempool-replacements.md)
316+ /// for fee bumps to be accepted into the mempool, and eventually the chain. As the frequency of
317+ /// these events is not user-controlled, users may ignore/drop the event if they are no longer
318+ /// able to commit external confirmed funds to the HTLC transaction.
319+ ///
320+ /// [`InMemorySigner`]: crate::chain::keysinterface::InMemorySigner
321+ /// [`KeysManager::derive_channel_keys`]: crate::chain::keysinterface::KeysManager::derive_channel_keys
322+ /// [`InMemorySigner::sign_holder_htlc_transaction`]: crate::chain::keysinterface::InMemorySigner::sign_holder_htlc_transaction
323+ /// [`build_htlc_input_witness`]: crate::ln::chan_utils::build_htlc_input_witness
324+ HTLCResolution {
325+ target_feerate_sat_per_1000_weight : u32 ,
326+ tx_template : Transaction ,
327+ htlc_descriptors : Vec < HTLCDescriptor > ,
328+ } ,
329+ }
330+
331+ #[ derive( Clone , Debug ) ]
332+ pub enum HTLCDescriptor {
333+ SecondStage {
334+ channel_keys_id : [ u8 ; 32 ] ,
335+ channel_value_satoshis : u64 ,
336+ amount : u64 ,
337+ per_commitment_number : u64 ,
338+ redeem_script : Script ,
339+ preimage : Option < PaymentPreimage > ,
340+ counterparty_sig : Signature
341+ }
286342}
287343
288344/// An Event which you should probably take some action in response to.
@@ -853,9 +909,10 @@ impl Writeable for Event {
853909 & Event :: BumpTransaction ( ref event) => {
854910 27u8 . write ( writer) ?;
855911 match event {
856- // We never write the ChannelClose events as they'll be replayed upon restarting
857- // anyway if the commitment transaction remains unconfirmed .
912+ // We never write the ChannelClose|HTLCResolution events as they'll be replayed
913+ // upon restarting anyway if they remain unresolved .
858914 BumpTransactionEvent :: ChannelClose { .. } => { }
915+ BumpTransactionEvent :: HTLCResolution { .. } => { }
859916 }
860917 }
861918 // Note that, going forward, all new events must only write data inside of
0 commit comments