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
+78-62
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
if htlc.state.included_in_commitment(generated_by_local) {
3712
+
for_each_included(htlc);
3713
+
} else {
3714
+
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());
3715
+
for_each_excluded(htlc);
3716
+
}
3717
+
})
3718
+
}
3719
+
3720
+
fn sort_outbounds_by_state<I, E, L: Deref>(&self, generated_by_local: bool, mut for_each_included: I, mut for_each_excluded: E, logger: &L)
3721
+
where I: FnMut(&OutboundHTLCOutput), E: FnMut(&OutboundHTLCOutput), L::Target: Logger,
if htlc.state.included_in_commitment(generated_by_local) {
3725
+
for_each_included(htlc);
3726
+
} else {
3727
+
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());
3728
+
for_each_excluded(htlc);
3729
+
}
3730
+
})
3731
+
}
3732
+
3708
3733
/// Generates stats on a potential commitment transaction build, without actually building the
3709
3734
/// commitment transaction. See `build_commitment_transaction` for further docs.
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());
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());
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
+
if let Some(preimage) = htlc.state.preimage() {
3908
+
inbound_htlc_preimages.push(preimage);
3892
3909
}
3893
-
}
3894
-
3895
-
let mut outbound_htlc_preimages: Vec<PaymentPreimage> = Vec::new();
let for_each_excluded = |htlc: &OutboundHTLCOutput| {
3918
+
// We previously included outbound preimages for both included and excluded HTLCs,
3919
+
// but now only include preimages for HTLCs excluded from the commitment transaction.
3898
3920
if let Some(preimage) = htlc.state.preimage() {
3899
3921
outbound_htlc_preimages.push(preimage);
3900
3922
}
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