Skip to content

Commit e60486e

Browse files
committed
ln: add accountable signal to HTLCUpdateAwaitingACK::AddHTLC
1 parent b657945 commit e60486e

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

lightning/src/ln/channel.rs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ use crate::ln::interactivetxs::{
6262
InteractiveTxSigningSession, NegotiationError, SharedOwnedInput, SharedOwnedOutput,
6363
TX_COMMON_FIELDS_WEIGHT,
6464
};
65-
use crate::ln::msgs;
65+
use crate::ln::msgs::{self, accountable_from_bool};
6666
use crate::ln::msgs::{ClosingSigned, ClosingSignedFeeRange, DecodeError, OnionErrorPacket};
6767
use crate::ln::onion_utils::{
6868
AttributionData, HTLCFailReason, LocalHTLCFailureReason, HOLD_TIME_UNIT_MILLIS,
@@ -451,6 +451,7 @@ enum HTLCUpdateAwaitingACK {
451451
skimmed_fee_msat: Option<u64>,
452452
blinding_point: Option<PublicKey>,
453453
hold_htlc: Option<()>,
454+
accountable: Option<bool>,
454455
},
455456
ClaimHTLC {
456457
payment_preimage: PaymentPreimage,
@@ -8358,7 +8359,7 @@ where
83588359
skimmed_fee_msat,
83598360
blinding_point,
83608361
hold_htlc,
8361-
..
8362+
accountable,
83628363
} => {
83638364
match self.send_htlc(
83648365
amount_msat,
@@ -8370,6 +8371,7 @@ where
83708371
skimmed_fee_msat,
83718372
blinding_point,
83728373
hold_htlc.is_some(),
8374+
accountable.unwrap_or(false),
83738375
fee_estimator,
83748376
logger,
83758377
) {
@@ -12518,7 +12520,8 @@ where
1251812520
pub fn queue_add_htlc<F: Deref, L: Deref>(
1251912521
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32,
1252012522
source: HTLCSource, onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>,
12521-
blinding_point: Option<PublicKey>, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
12523+
blinding_point: Option<PublicKey>, accountable: bool,
12524+
fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
1252212525
) -> Result<(), (LocalHTLCFailureReason, String)>
1252312526
where
1252412527
F::Target: FeeEstimator,
@@ -12535,6 +12538,7 @@ where
1253512538
blinding_point,
1253612539
// This method is only called for forwarded HTLCs, which are never held at the next hop
1253712540
false,
12541+
accountable,
1253812542
fee_estimator,
1253912543
logger,
1254012544
)
@@ -12566,7 +12570,7 @@ where
1256612570
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32,
1256712571
source: HTLCSource, onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool,
1256812572
skimmed_fee_msat: Option<u64>, blinding_point: Option<PublicKey>, hold_htlc: bool,
12569-
fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
12573+
accountable: bool, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
1257012574
) -> Result<bool, (LocalHTLCFailureReason, String)>
1257112575
where
1257212576
F::Target: FeeEstimator,
@@ -12648,6 +12652,7 @@ where
1264812652
skimmed_fee_msat,
1264912653
blinding_point,
1265012654
hold_htlc: hold_htlc.then(|| ()),
12655+
accountable: Some(accountable),
1265112656
});
1265212657
return Ok(false);
1265312658
}
@@ -12896,7 +12901,8 @@ where
1289612901
pub fn send_htlc_and_commit<F: Deref, L: Deref>(
1289712902
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32,
1289812903
source: HTLCSource, onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>,
12899-
hold_htlc: bool, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
12904+
hold_htlc: bool, accountable: bool, fee_estimator: &LowerBoundedFeeEstimator<F>,
12905+
logger: &L,
1290012906
) -> Result<Option<ChannelMonitorUpdate>, ChannelError>
1290112907
where
1290212908
F::Target: FeeEstimator,
@@ -12912,6 +12918,7 @@ where
1291212918
skimmed_fee_msat,
1291312919
None,
1291412920
hold_htlc,
12921+
accountable,
1291512922
fee_estimator,
1291612923
logger,
1291712924
);
@@ -14576,6 +14583,8 @@ where
1457614583
Vec::with_capacity(holding_cell_htlc_update_count);
1457714584
let mut holding_cell_held_htlc_flags: Vec<Option<()>> =
1457814585
Vec::with_capacity(holding_cell_htlc_update_count);
14586+
let mut holding_cell_accountable_flags: Vec<Option<bool>> =
14587+
Vec::with_capacity(holding_cell_htlc_update_count);
1457914588
// Vec of (htlc_id, failure_code, sha256_of_onion)
1458014589
let mut malformed_htlcs: Vec<(u64, u16, [u8; 32])> = Vec::new();
1458114590
(holding_cell_htlc_update_count as u64).write(writer)?;
@@ -14590,6 +14599,7 @@ where
1459014599
blinding_point,
1459114600
skimmed_fee_msat,
1459214601
hold_htlc,
14602+
accountable,
1459314603
} => {
1459414604
0u8.write(writer)?;
1459514605
amount_msat.write(writer)?;
@@ -14601,6 +14611,7 @@ where
1460114611
holding_cell_skimmed_fees.push(skimmed_fee_msat);
1460214612
holding_cell_blinding_points.push(blinding_point);
1460314613
holding_cell_held_htlc_flags.push(hold_htlc);
14614+
holding_cell_accountable_flags.push(accountable);
1460414615
},
1460514616
&HTLCUpdateAwaitingACK::ClaimHTLC {
1460614617
ref payment_preimage,
@@ -14861,6 +14872,7 @@ where
1486114872
(69, holding_cell_held_htlc_flags, optional_vec), // Added in 0.2
1486214873
(71, holder_commitment_point_previous_revoked, option), // Added in 0.3
1486314874
(73, holder_commitment_point_last_revoked, option), // Added in 0.3
14875+
(75, holding_cell_accountable_flags, optional_vec), // Added in 0.3
1486414876
});
1486514877

1486614878
Ok(())
@@ -15029,6 +15041,7 @@ where
1502915041
skimmed_fee_msat: None,
1503015042
blinding_point: None,
1503115043
hold_htlc: None,
15044+
accountable: None,
1503215045
},
1503315046
1 => HTLCUpdateAwaitingACK::ClaimHTLC {
1503415047
payment_preimage: Readable::read(reader)?,
@@ -15230,6 +15243,7 @@ where
1523015243

1523115244
let mut pending_outbound_held_htlc_flags_opt: Option<Vec<Option<()>>> = None;
1523215245
let mut holding_cell_held_htlc_flags_opt: Option<Vec<Option<()>>> = None;
15246+
let mut holding_cell_accountable_opt: Option<Vec<Option<bool>>> = None;
1523315247

1523415248
read_tlv_fields!(reader, {
1523515249
(0, announcement_sigs, option),
@@ -15279,6 +15293,7 @@ where
1527915293
(69, holding_cell_held_htlc_flags_opt, optional_vec), // Added in 0.2
1528015294
(71, holder_commitment_point_previous_revoked_opt, option), // Added in 0.3
1528115295
(73, holder_commitment_point_last_revoked_opt, option), // Added in 0.3
15296+
(75, holding_cell_accountable_opt, optional_vec), // Added in 0.3
1528215297
});
1528315298

1528415299
let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
@@ -15403,6 +15418,19 @@ where
1540315418
}
1540415419
}
1540515420

15421+
if let Some(accountable_htlcs) = holding_cell_accountable_opt {
15422+
let mut iter = accountable_htlcs.into_iter();
15423+
for htlc in holding_cell_htlc_updates.iter_mut() {
15424+
if let HTLCUpdateAwaitingACK::AddHTLC { ref mut accountable, .. } = htlc {
15425+
*accountable = iter.next().ok_or(DecodeError::InvalidValue)?;
15426+
}
15427+
}
15428+
// We expect all accountable HTLC signals to be consumed above
15429+
if iter.next().is_some() {
15430+
return Err(DecodeError::InvalidValue);
15431+
}
15432+
}
15433+
1540615434
if let Some(attribution_data_list) = removed_htlc_attribution_data {
1540715435
let mut removed_htlcs = pending_inbound_htlcs.iter_mut().filter_map(|status| {
1540815436
if let InboundHTLCState::LocalRemoved(reason) = &mut status.state {
@@ -16487,6 +16515,7 @@ mod tests {
1648716515
skimmed_fee_msat: None,
1648816516
blinding_point: None,
1648916517
hold_htlc: None,
16518+
accountable: None,
1649016519
};
1649116520
let dummy_holding_cell_claim_htlc = |attribution_data| HTLCUpdateAwaitingACK::ClaimHTLC {
1649216521
payment_preimage: PaymentPreimage([42; 32]),

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5307,6 +5307,7 @@ where
53075307
onion_packet,
53085308
None,
53095309
hold_htlc_at_next_hop,
5310+
false, // Not accountable by default for sender.
53105311
&self.fee_estimator,
53115312
&&logger,
53125313
);
@@ -7401,6 +7402,7 @@ where
74017402
outgoing_cltv_value,
74027403
routing,
74037404
skimmed_fee_msat,
7405+
incoming_accountable,
74047406
..
74057407
},
74067408
..
@@ -7496,6 +7498,7 @@ where
74967498
onion_packet.clone(),
74977499
*skimmed_fee_msat,
74987500
next_blinding_point,
7501+
incoming_accountable.unwrap_or(false),
74997502
&self.fee_estimator,
75007503
&&logger,
75017504
) {

0 commit comments

Comments
 (0)