@@ -29,7 +29,8 @@ use crate::ln::features::{ChannelTypeFeatures, InitFeatures};
29
29
use crate::ln::msgs;
30
30
use crate::ln::msgs::DecodeError;
31
31
use crate::ln::script::{self, ShutdownScript};
32
- use crate::ln::channelmanager::{self, CounterpartyForwardingInfo, PendingHTLCStatus, HTLCSource, SentHTLCId, HTLCFailureMsg, PendingHTLCInfo, RAACommitmentOrder, BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA, MAX_LOCAL_BREAKDOWN_TIMEOUT, ChannelShutdownState};
32
+ use crate::ln::channel_state::{ChannelShutdownState, CounterpartyForwardingInfo, InboundHTLCDetails, InboundHTLCStateDetails, OutboundHTLCDetails, OutboundHTLCStateDetails};
33
+ use crate::ln::channelmanager::{self, PendingHTLCStatus, HTLCSource, SentHTLCId, HTLCFailureMsg, PendingHTLCInfo, RAACommitmentOrder, BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA, MAX_LOCAL_BREAKDOWN_TIMEOUT};
33
34
use crate::ln::chan_utils::{CounterpartyCommitmentSecrets, TxCreationKeys, HTLCOutputInCommitment, htlc_success_tx_weight, htlc_timeout_tx_weight, make_funding_redeemscript, ChannelPublicKeys, CommitmentTransaction, HolderCommitmentTransaction, ChannelTransactionParameters, CounterpartyChannelTransactionParameters, MAX_HTLCS, get_commitment_transaction_number_obscure_factor, ClosingTransaction};
34
35
use crate::ln::chan_utils;
35
36
use crate::ln::onion_utils::HTLCFailReason;
@@ -185,45 +186,6 @@ enum InboundHTLCState {
185
186
LocalRemoved(InboundHTLCRemovalReason),
186
187
}
187
188
188
- /// Exposes the state of pending inbound HTLCs.
189
- ///
190
- /// At a high level, an HTLC being forwarded from one Lightning node to another Lightning node goes
191
- /// through the following states in the state machine:
192
- /// - Announced for addition by the originating node through the update_add_htlc message.
193
- /// - Added to the commitment transaction of the receiving node and originating node in turn
194
- /// through the exchange of commitment_signed and revoke_and_ack messages.
195
- /// - Announced for resolution (fulfillment or failure) by the receiving node through either one of
196
- /// the update_fulfill_htlc, update_fail_htlc, and update_fail_malformed_htlc messages.
197
- /// - Removed from the commitment transaction of the originating node and receiving node in turn
198
- /// through the exchange of commitment_signed and revoke_and_ack messages.
199
- ///
200
- /// This can be used to inspect what next message an HTLC is waiting for to advance its state.
201
- #[derive(Clone, Debug, PartialEq)]
202
- pub enum InboundHTLCStateDetails {
203
- /// We have added this HTLC in our commitment transaction by receiving commitment_signed and
204
- /// returning revoke_and_ack. We are awaiting the appropriate revoke_and_ack's from the remote
205
- /// before this HTLC is included on the remote commitment transaction.
206
- AwaitingRemoteRevokeToAdd,
207
- /// This HTLC has been included in the commitment_signed and revoke_and_ack messages on both sides
208
- /// and is included in both commitment transactions.
209
- ///
210
- /// This HTLC is now safe to either forward or be claimed as a payment by us. The HTLC will
211
- /// remain in this state until the forwarded upstream HTLC has been resolved and we resolve this
212
- /// HTLC correspondingly, or until we claim it as a payment. If it is part of a multipart
213
- /// payment, it will only be claimed together with other required parts.
214
- Committed,
215
- /// We have received the preimage for this HTLC and it is being removed by fulfilling it with
216
- /// update_fulfill_htlc. This HTLC is still on both commitment transactions, but we are awaiting
217
- /// the appropriate revoke_and_ack's from the remote before this HTLC is removed from the remote
218
- /// commitment transaction after update_fulfill_htlc.
219
- AwaitingRemoteRevokeToRemoveFulfill,
220
- /// The HTLC is being removed by failing it with update_fail_htlc or update_fail_malformed_htlc.
221
- /// This HTLC is still on both commitment transactions, but we are awaiting the appropriate
222
- /// revoke_and_ack's from the remote before this HTLC is removed from the remote commitment
223
- /// transaction.
224
- AwaitingRemoteRevokeToRemoveFail,
225
- }
226
-
227
189
impl From<&InboundHTLCState> for Option<InboundHTLCStateDetails> {
228
190
fn from(state: &InboundHTLCState) -> Option<InboundHTLCStateDetails> {
229
191
match state {
@@ -244,13 +206,6 @@ impl From<&InboundHTLCState> for Option<InboundHTLCStateDetails> {
244
206
}
245
207
}
246
208
247
- impl_writeable_tlv_based_enum_upgradable!(InboundHTLCStateDetails,
248
- (0, AwaitingRemoteRevokeToAdd) => {},
249
- (2, Committed) => {},
250
- (4, AwaitingRemoteRevokeToRemoveFulfill) => {},
251
- (6, AwaitingRemoteRevokeToRemoveFail) => {};
252
- );
253
-
254
209
struct InboundHTLCOutput {
255
210
htlc_id: u64,
256
211
amount_msat: u64,
@@ -259,53 +214,6 @@ struct InboundHTLCOutput {
259
214
state: InboundHTLCState,
260
215
}
261
216
262
- /// Exposes details around pending inbound HTLCs.
263
- #[derive(Clone, Debug, PartialEq)]
264
- pub struct InboundHTLCDetails {
265
- /// The HTLC ID.
266
- /// The IDs are incremented by 1 starting from 0 for each offered HTLC.
267
- /// They are unique per channel and inbound/outbound direction, unless an HTLC was only announced
268
- /// and not part of any commitment transaction.
269
- pub htlc_id: u64,
270
- /// The amount in msat.
271
- pub amount_msat: u64,
272
- /// The block height at which this HTLC expires.
273
- pub cltv_expiry: u32,
274
- /// The payment hash.
275
- pub payment_hash: PaymentHash,
276
- /// The state of the HTLC in the state machine.
277
- ///
278
- /// Determines on which commitment transactions the HTLC is included and what message the HTLC is
279
- /// waiting for to advance to the next state.
280
- ///
281
- /// See [`InboundHTLCStateDetails`] for information on the specific states.
282
- ///
283
- /// LDK will always fill this field in, but when downgrading to prior versions of LDK, new
284
- /// states may result in `None` here.
285
- pub state: Option<InboundHTLCStateDetails>,
286
- /// Whether the HTLC has an output below the local dust limit. If so, the output will be trimmed
287
- /// from the local commitment transaction and added to the commitment transaction fee.
288
- /// For non-anchor channels, this takes into account the cost of the second-stage HTLC
289
- /// transactions as well.
290
- ///
291
- /// When the local commitment transaction is broadcasted as part of a unilateral closure,
292
- /// the value of this HTLC will therefore not be claimable but instead burned as a transaction
293
- /// fee.
294
- ///
295
- /// Note that dust limits are specific to each party. An HTLC can be dust for the local
296
- /// commitment transaction but not for the counterparty's commitment transaction and vice versa.
297
- pub is_dust: bool,
298
- }
299
-
300
- impl_writeable_tlv_based!(InboundHTLCDetails, {
301
- (0, htlc_id, required),
302
- (2, amount_msat, required),
303
- (4, cltv_expiry, required),
304
- (6, payment_hash, required),
305
- (7, state, upgradable_option),
306
- (8, is_dust, required),
307
- });
308
-
309
217
#[cfg_attr(test, derive(Clone, Debug, PartialEq))]
310
218
enum OutboundHTLCState {
311
219
/// Added by us and included in a commitment_signed (if we were AwaitingRemoteRevoke when we
@@ -339,42 +247,6 @@ enum OutboundHTLCState {
339
247
AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome),
340
248
}
341
249
342
- /// Exposes the state of pending outbound HTLCs.
343
- ///
344
- /// At a high level, an HTLC being forwarded from one Lightning node to another Lightning node goes
345
- /// through the following states in the state machine:
346
- /// - Announced for addition by the originating node through the update_add_htlc message.
347
- /// - Added to the commitment transaction of the receiving node and originating node in turn
348
- /// through the exchange of commitment_signed and revoke_and_ack messages.
349
- /// - Announced for resolution (fulfillment or failure) by the receiving node through either one of
350
- /// the update_fulfill_htlc, update_fail_htlc, and update_fail_malformed_htlc messages.
351
- /// - Removed from the commitment transaction of the originating node and receiving node in turn
352
- /// through the exchange of commitment_signed and revoke_and_ack messages.
353
- ///
354
- /// This can be used to inspect what next message an HTLC is waiting for to advance its state.
355
- #[derive(Clone, Debug, PartialEq)]
356
- pub enum OutboundHTLCStateDetails {
357
- /// We are awaiting the appropriate revoke_and_ack's from the remote before the HTLC is added
358
- /// on the remote's commitment transaction after update_add_htlc.
359
- AwaitingRemoteRevokeToAdd,
360
- /// The HTLC has been added to the remote's commitment transaction by sending commitment_signed
361
- /// and receiving revoke_and_ack in return.
362
- ///
363
- /// The HTLC will remain in this state until the remote node resolves the HTLC, or until we
364
- /// unilaterally close the channel due to a timeout with an uncooperative remote node.
365
- Committed,
366
- /// The HTLC has been fulfilled successfully by the remote with a preimage in update_fulfill_htlc,
367
- /// and we removed the HTLC from our commitment transaction by receiving commitment_signed and
368
- /// returning revoke_and_ack. We are awaiting the appropriate revoke_and_ack's from the remote
369
- /// for the removal from its commitment transaction.
370
- AwaitingRemoteRevokeToRemoveSuccess,
371
- /// The HTLC has been failed by the remote with update_fail_htlc or update_fail_malformed_htlc,
372
- /// and we removed the HTLC from our commitment transaction by receiving commitment_signed and
373
- /// returning revoke_and_ack. We are awaiting the appropriate revoke_and_ack's from the remote
374
- /// for the removal from its commitment transaction.
375
- AwaitingRemoteRevokeToRemoveFailure,
376
- }
377
-
378
250
impl From<&OutboundHTLCState> for OutboundHTLCStateDetails {
379
251
fn from(state: &OutboundHTLCState) -> OutboundHTLCStateDetails {
380
252
match state {
@@ -398,13 +270,6 @@ impl From<&OutboundHTLCState> for OutboundHTLCStateDetails {
398
270
}
399
271
}
400
272
401
- impl_writeable_tlv_based_enum_upgradable!(OutboundHTLCStateDetails,
402
- (0, AwaitingRemoteRevokeToAdd) => {},
403
- (2, Committed) => {},
404
- (4, AwaitingRemoteRevokeToRemoveSuccess) => {},
405
- (6, AwaitingRemoteRevokeToRemoveFailure) => {};
406
- );
407
-
408
273
#[derive(Clone)]
409
274
#[cfg_attr(test, derive(Debug, PartialEq))]
410
275
enum OutboundHTLCOutcome {
@@ -443,58 +308,6 @@ struct OutboundHTLCOutput {
443
308
skimmed_fee_msat: Option<u64>,
444
309
}
445
310
446
- /// Exposes details around pending outbound HTLCs.
447
- #[derive(Clone, Debug, PartialEq)]
448
- pub struct OutboundHTLCDetails {
449
- /// The HTLC ID.
450
- /// The IDs are incremented by 1 starting from 0 for each offered HTLC.
451
- /// They are unique per channel and inbound/outbound direction, unless an HTLC was only announced
452
- /// and not part of any commitment transaction.
453
- ///
454
- /// Not present when we are awaiting a remote revocation and the HTLC is not added yet.
455
- pub htlc_id: Option<u64>,
456
- /// The amount in msat.
457
- pub amount_msat: u64,
458
- /// The block height at which this HTLC expires.
459
- pub cltv_expiry: u32,
460
- /// The payment hash.
461
- pub payment_hash: PaymentHash,
462
- /// The state of the HTLC in the state machine.
463
- ///
464
- /// Determines on which commitment transactions the HTLC is included and what message the HTLC is
465
- /// waiting for to advance to the next state.
466
- ///
467
- /// See [`OutboundHTLCStateDetails`] for information on the specific states.
468
- ///
469
- /// LDK will always fill this field in, but when downgrading to prior versions of LDK, new
470
- /// states may result in `None` here.
471
- pub state: Option<OutboundHTLCStateDetails>,
472
- /// The extra fee being skimmed off the top of this HTLC.
473
- pub skimmed_fee_msat: Option<u64>,
474
- /// Whether the HTLC has an output below the local dust limit. If so, the output will be trimmed
475
- /// from the local commitment transaction and added to the commitment transaction fee.
476
- /// For non-anchor channels, this takes into account the cost of the second-stage HTLC
477
- /// transactions as well.
478
- ///
479
- /// When the local commitment transaction is broadcasted as part of a unilateral closure,
480
- /// the value of this HTLC will therefore not be claimable but instead burned as a transaction
481
- /// fee.
482
- ///
483
- /// Note that dust limits are specific to each party. An HTLC can be dust for the local
484
- /// commitment transaction but not for the counterparty's commitment transaction and vice versa.
485
- pub is_dust: bool,
486
- }
487
-
488
- impl_writeable_tlv_based!(OutboundHTLCDetails, {
489
- (0, htlc_id, required),
490
- (2, amount_msat, required),
491
- (4, cltv_expiry, required),
492
- (6, payment_hash, required),
493
- (7, state, upgradable_option),
494
- (8, skimmed_fee_msat, required),
495
- (10, is_dust, required),
496
- });
497
-
498
311
/// See AwaitingRemoteRevoke ChannelState for more info
499
312
#[cfg_attr(test, derive(Clone, Debug, PartialEq))]
500
313
enum HTLCUpdateAwaitingACK {
0 commit comments