You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This function sorts included from excluded htlcs based on their state,
and runs the two passed closures on the resulting sets.
To avoid mutating the outbound preimages vector in both the included and
the excluded closures, this commit stops including outbound preimages
for HTLCs which are included in the commitment transaction, and only
includes outbound preimages for HTLCs which are not included in the
commitment transaction. This seems ok from the available docs on
`sign_counterparty_commitment`, but test coverage is missing.
Copy file name to clipboardExpand all lines: lightning/src/ln/channel.rs
+80-62Lines changed: 80 additions & 62 deletions
Original file line number
Diff line number
Diff line change
@@ -974,10 +974,10 @@ struct HTLCStats {
974
974
}
975
975
976
976
/// A struct gathering data on a commitment, either local or remote.
977
-
struct CommitmentData<'a> {
977
+
struct CommitmentData {
978
978
tx: CommitmentTransaction,
979
979
stats: CommitmentStats,
980
-
htlcs_included: Vec<(HTLCOutputInCommitment, Option<&'a HTLCSource>)>, // the list of HTLCs (dust HTLCs *included*) which were not ignored when building the transaction
980
+
htlcs_included: Vec<(HTLCOutputInCommitment, Option<Box<HTLCSource>>)>, // the list of HTLCs (dust HTLCs *included*) which were not ignored when building the transaction
981
981
outbound_htlc_preimages: Vec<PaymentPreimage>, // preimages for successful offered HTLCs since last commitment
982
982
inbound_htlc_preimages: Vec<PaymentPreimage>, // preimages for successful received HTLCs since last commitment
for ref htlc in self.pending_inbound_htlcs.iter() {
3749
-
if htlc.state.included_in_commitment(generated_by_local) {
3750
-
count_nondust_htlc!(htlc, false);
3751
-
remote_htlc_total_msat += htlc.amount_msat;
3752
-
} else {
3753
-
log_trace!(logger, " ...not counting inbound HTLC {} (hash {}) with value {} due to state ({})", htlc.htlc_id, htlc.payment_hash, htlc.amount_msat, htlc.state.as_str());
value_to_self_msat_offset += htlc.amount_msat as i64;
3757
-
},
3758
-
_ => {},
3759
-
}
3770
+
3771
+
let for_each_included = |htlc: &InboundHTLCOutput| {
3772
+
count_nondust_htlc!(htlc, false);
3773
+
remote_htlc_total_msat += htlc.amount_msat;
3774
+
};
3775
+
let for_each_excluded = |htlc: &InboundHTLCOutput| {
3776
+
log_trace!(logger, " ...not counting inbound HTLC {} (hash {}) with value {} due to state ({})", htlc.htlc_id, htlc.payment_hash, htlc.amount_msat, htlc.state.as_str());
3777
+
if let InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_preimage)) = htlc.state {
3778
+
value_to_self_msat_offset += htlc.amount_msat as i64;
for ref htlc in self.pending_outbound_htlcs.iter() {
3764
-
if htlc.state.included_in_commitment(generated_by_local) {
3765
-
count_nondust_htlc!(htlc, true);
3766
-
local_htlc_total_msat += htlc.amount_msat;
3767
-
} else {
3768
-
log_trace!(logger, " ...not counting outbound HTLC {} (hash {}) with value {} due to state ({})", htlc.htlc_id, htlc.payment_hash, htlc.amount_msat, htlc.state.as_str());
value_to_self_msat_offset -= htlc.amount_msat as i64;
3774
-
},
3775
-
_ => {},
3776
-
}
3783
+
let for_each_included = |htlc: &OutboundHTLCOutput| {
3784
+
count_nondust_htlc!(htlc, true);
3785
+
local_htlc_total_msat += htlc.amount_msat;
3786
+
};
3787
+
let for_each_excluded = |htlc: &OutboundHTLCOutput| {
3788
+
log_trace!(logger, " ...not counting outbound HTLC {} (hash {}) with value {} due to state ({})", htlc.htlc_id, htlc.payment_hash, htlc.amount_msat, htlc.state.as_str());
3789
+
if let OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_)) |
let mut inbound_htlc_preimages: Vec<PaymentPreimage> = Vec::new();
3901
+
let mut outbound_htlc_preimages: Vec<PaymentPreimage> = Vec::new();
3883
3902
3884
-
for ref htlc in self.pending_inbound_htlcs.iter() {
3885
-
if htlc.state.included_in_commitment(generated_by_local) {
3886
-
add_htlc_output!(htlc, false, None);
3887
-
} else {
3888
-
log_trace!(logger, " ...not including inbound HTLC {} (hash {}) with value {} due to state ({})", htlc.htlc_id, htlc.payment_hash, htlc.amount_msat, htlc.state.as_str());
3889
-
if let Some(preimage) = htlc.state.preimage() {
3890
-
inbound_htlc_preimages.push(preimage);
3891
-
}
3903
+
let for_each_included = |htlc: &InboundHTLCOutput| {
3904
+
add_htlc_output!(htlc, false, None);
3905
+
};
3906
+
let for_each_excluded = |htlc: &InboundHTLCOutput| {
3907
+
log_trace!(logger, " ...not including inbound HTLC {} (hash {}) with value {} due to state ({})", htlc.htlc_id, htlc.payment_hash, htlc.amount_msat, htlc.state.as_str());
3908
+
if let Some(preimage) = htlc.state.preimage() {
3909
+
inbound_htlc_preimages.push(preimage);
3892
3910
}
3893
-
}
3894
-
3895
-
let mut outbound_htlc_preimages: Vec<PaymentPreimage> = Vec::new();
let for_each_excluded = |htlc: &OutboundHTLCOutput| {
3919
+
log_trace!(logger, " ...not including outbound HTLC {} (hash {}) with value {} due to state ({})", htlc.htlc_id, htlc.payment_hash, htlc.amount_msat, htlc.state.as_str());
3920
+
// We previously included outbound preimages for both included and excluded HTLCs,
3921
+
// but now only include preimages for HTLCs excluded from the commitment transaction.
3898
3922
if let Some(preimage) = htlc.state.preimage() {
3899
3923
outbound_htlc_preimages.push(preimage);
3900
3924
}
3901
-
if htlc.state.included_in_commitment(generated_by_local) {
3902
-
add_htlc_output!(htlc, true, Some(&htlc.source));
3903
-
} else {
3904
-
log_trace!(logger, " ...not including outbound HTLC {} (hash {}) with value {} due to state ({})", htlc.htlc_id, htlc.payment_hash, htlc.amount_msat, htlc.state.as_str());
0 commit comments