Skip to content

Commit d084a9d

Browse files
committed
ln: add accountable signal to HTLCUpdateAwaitingACK::AddHTLC
1 parent 413aa95 commit d084a9d

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

lightning/src/ln/channel.rs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ enum HTLCUpdateAwaitingACK {
469469
skimmed_fee_msat: Option<u64>,
470470
blinding_point: Option<PublicKey>,
471471
hold_htlc: Option<()>,
472+
accountable: bool,
472473
},
473474
ClaimHTLC {
474475
payment_preimage: PaymentPreimage,
@@ -8405,7 +8406,7 @@ where
84058406
skimmed_fee_msat,
84068407
blinding_point,
84078408
hold_htlc,
8408-
..
8409+
accountable,
84098410
} => {
84108411
match self.send_htlc(
84118412
amount_msat,
@@ -8417,6 +8418,7 @@ where
84178418
skimmed_fee_msat,
84188419
blinding_point,
84198420
hold_htlc.is_some(),
8421+
accountable,
84208422
fee_estimator,
84218423
logger,
84228424
) {
@@ -12593,7 +12595,8 @@ where
1259312595
pub fn queue_add_htlc<F: Deref, L: Deref>(
1259412596
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32,
1259512597
source: HTLCSource, onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>,
12596-
blinding_point: Option<PublicKey>, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
12598+
blinding_point: Option<PublicKey>, accountable: bool,
12599+
fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
1259712600
) -> Result<(), (LocalHTLCFailureReason, String)>
1259812601
where
1259912602
F::Target: FeeEstimator,
@@ -12610,6 +12613,7 @@ where
1261012613
blinding_point,
1261112614
// This method is only called for forwarded HTLCs, which are never held at the next hop
1261212615
false,
12616+
accountable,
1261312617
fee_estimator,
1261412618
logger,
1261512619
)
@@ -12641,7 +12645,7 @@ where
1264112645
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32,
1264212646
source: HTLCSource, onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool,
1264312647
skimmed_fee_msat: Option<u64>, blinding_point: Option<PublicKey>, hold_htlc: bool,
12644-
fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
12648+
accountable: bool, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
1264512649
) -> Result<bool, (LocalHTLCFailureReason, String)>
1264612650
where
1264712651
F::Target: FeeEstimator,
@@ -12723,6 +12727,7 @@ where
1272312727
skimmed_fee_msat,
1272412728
blinding_point,
1272512729
hold_htlc: hold_htlc.then(|| ()),
12730+
accountable,
1272612731
});
1272712732
return Ok(false);
1272812733
}
@@ -12994,7 +12999,8 @@ where
1299412999
pub fn send_htlc_and_commit<F: Deref, L: Deref>(
1299513000
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32,
1299613001
source: HTLCSource, onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>,
12997-
hold_htlc: bool, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
13002+
hold_htlc: bool, accountable: bool, fee_estimator: &LowerBoundedFeeEstimator<F>,
13003+
logger: &L,
1299813004
) -> Result<Option<ChannelMonitorUpdate>, ChannelError>
1299913005
where
1300013006
F::Target: FeeEstimator,
@@ -13010,6 +13016,7 @@ where
1301013016
skimmed_fee_msat,
1301113017
None,
1301213018
hold_htlc,
13019+
accountable,
1301313020
fee_estimator,
1301413021
logger,
1301513022
);
@@ -14679,6 +14686,8 @@ where
1467914686
Vec::with_capacity(holding_cell_htlc_update_count);
1468014687
let mut holding_cell_held_htlc_flags: Vec<Option<()>> =
1468114688
Vec::with_capacity(holding_cell_htlc_update_count);
14689+
let mut holding_cell_accountable_flags: Vec<bool> =
14690+
Vec::with_capacity(holding_cell_htlc_update_count);
1468214691
// Vec of (htlc_id, failure_code, sha256_of_onion)
1468314692
let mut malformed_htlcs: Vec<(u64, u16, [u8; 32])> = Vec::new();
1468414693
(holding_cell_htlc_update_count as u64).write(writer)?;
@@ -14693,6 +14702,7 @@ where
1469314702
blinding_point,
1469414703
skimmed_fee_msat,
1469514704
hold_htlc,
14705+
accountable,
1469614706
} => {
1469714707
0u8.write(writer)?;
1469814708
amount_msat.write(writer)?;
@@ -14704,6 +14714,7 @@ where
1470414714
holding_cell_skimmed_fees.push(skimmed_fee_msat);
1470514715
holding_cell_blinding_points.push(blinding_point);
1470614716
holding_cell_held_htlc_flags.push(hold_htlc);
14717+
holding_cell_accountable_flags.push(accountable);
1470714718
},
1470814719
&HTLCUpdateAwaitingACK::ClaimHTLC {
1470914720
ref payment_preimage,
@@ -14965,6 +14976,7 @@ where
1496514976
(71, holder_commitment_point_previous_revoked, option), // Added in 0.3
1496614977
(73, holder_commitment_point_last_revoked, option), // Added in 0.3
1496714978
(75, inbound_committed_update_adds, optional_vec),
14979+
(77, holding_cell_accountable_flags, optional_vec), // Added in 0.3
1496814980
});
1496914981

1497014982
Ok(())
@@ -15151,6 +15163,7 @@ where
1515115163
skimmed_fee_msat: None,
1515215164
blinding_point: None,
1515315165
hold_htlc: None,
15166+
accountable: false,
1515415167
},
1515515168
1 => HTLCUpdateAwaitingACK::ClaimHTLC {
1515615169
payment_preimage: Readable::read(reader)?,
@@ -15353,6 +15366,7 @@ where
1535315366
let mut pending_outbound_held_htlc_flags_opt: Option<Vec<Option<()>>> = None;
1535415367
let mut holding_cell_held_htlc_flags_opt: Option<Vec<Option<()>>> = None;
1535515368
let mut inbound_committed_update_adds_opt: Option<Vec<Option<msgs::UpdateAddHTLC>>> = None;
15369+
let mut holding_cell_accountable: Option<Vec<bool>> = None;
1535615370

1535715371
read_tlv_fields!(reader, {
1535815372
(0, announcement_sigs, option),
@@ -15403,6 +15417,7 @@ where
1540315417
(71, holder_commitment_point_previous_revoked_opt, option), // Added in 0.3
1540415418
(73, holder_commitment_point_last_revoked_opt, option), // Added in 0.3
1540515419
(75, inbound_committed_update_adds_opt, optional_vec),
15420+
(77, holding_cell_accountable, optional_vec), // Added in 0.3
1540615421
});
1540715422

1540815423
let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
@@ -15538,6 +15553,19 @@ where
1553815553
}
1553915554
}
1554015555

15556+
if let Some(accountable_htlcs) = holding_cell_accountable {
15557+
let mut iter = accountable_htlcs.into_iter();
15558+
for htlc in holding_cell_htlc_updates.iter_mut() {
15559+
if let HTLCUpdateAwaitingACK::AddHTLC { ref mut accountable, .. } = htlc {
15560+
*accountable = iter.next().ok_or(DecodeError::InvalidValue)?;
15561+
}
15562+
}
15563+
// We expect all accountable HTLC signals to be consumed above
15564+
if iter.next().is_some() {
15565+
return Err(DecodeError::InvalidValue);
15566+
}
15567+
}
15568+
1554115569
if let Some(attribution_data_list) = removed_htlc_attribution_data {
1554215570
let mut removed_htlcs = pending_inbound_htlcs.iter_mut().filter_map(|status| {
1554315571
if let InboundHTLCState::LocalRemoved(reason) = &mut status.state {
@@ -16622,6 +16650,7 @@ mod tests {
1662216650
skimmed_fee_msat: None,
1662316651
blinding_point: None,
1662416652
hold_htlc: None,
16653+
accountable: false,
1662516654
};
1662616655
let dummy_holding_cell_claim_htlc = |attribution_data| HTLCUpdateAwaitingACK::ClaimHTLC {
1662716656
payment_preimage: PaymentPreimage([42; 32]),

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5479,6 +5479,7 @@ where
54795479
onion_packet,
54805480
None,
54815481
hold_htlc_at_next_hop,
5482+
false, // Not accountable by default for sender.
54825483
&self.fee_estimator,
54835484
&&logger,
54845485
);
@@ -7587,6 +7588,7 @@ where
75877588
outgoing_cltv_value,
75887589
routing,
75897590
skimmed_fee_msat,
7591+
incoming_accountable,
75907592
..
75917593
},
75927594
..
@@ -7687,6 +7689,7 @@ where
76877689
onion_packet.clone(),
76887690
*skimmed_fee_msat,
76897691
next_blinding_point,
7692+
*incoming_accountable,
76907693
&self.fee_estimator,
76917694
&&logger,
76927695
) {

0 commit comments

Comments
 (0)