@@ -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} ;
6666use crate::ln::msgs::{ClosingSigned, ClosingSignedFeeRange, DecodeError, OnionErrorPacket};
6767use 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,
@@ -8333,7 +8334,7 @@ where
83338334 skimmed_fee_msat,
83348335 blinding_point,
83358336 hold_htlc,
8336- ..
8337+ accountable,
83378338 } => {
83388339 match self.send_htlc(
83398340 amount_msat,
@@ -8345,6 +8346,7 @@ where
83458346 skimmed_fee_msat,
83468347 blinding_point,
83478348 hold_htlc.is_some(),
8349+ accountable.unwrap_or(false),
83488350 fee_estimator,
83498351 logger,
83508352 ) {
@@ -12457,7 +12459,8 @@ where
1245712459 pub fn queue_add_htlc<F: Deref, L: Deref>(
1245812460 &mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32,
1245912461 source: HTLCSource, onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>,
12460- blinding_point: Option<PublicKey>, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
12462+ blinding_point: Option<PublicKey>, accountable: bool,
12463+ fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
1246112464 ) -> Result<(), (LocalHTLCFailureReason, String)>
1246212465 where
1246312466 F::Target: FeeEstimator,
@@ -12474,6 +12477,7 @@ where
1247412477 blinding_point,
1247512478 // This method is only called for forwarded HTLCs, which are never held at the next hop
1247612479 false,
12480+ accountable,
1247712481 fee_estimator,
1247812482 logger,
1247912483 )
@@ -12505,7 +12509,7 @@ where
1250512509 &mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32,
1250612510 source: HTLCSource, onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool,
1250712511 skimmed_fee_msat: Option<u64>, blinding_point: Option<PublicKey>, hold_htlc: bool,
12508- fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
12512+ accountable: bool, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
1250912513 ) -> Result<bool, (LocalHTLCFailureReason, String)>
1251012514 where
1251112515 F::Target: FeeEstimator,
@@ -12587,6 +12591,7 @@ where
1258712591 skimmed_fee_msat,
1258812592 blinding_point,
1258912593 hold_htlc: hold_htlc.then(|| ()),
12594+ accountable: Some(accountable),
1259012595 });
1259112596 return Ok(false);
1259212597 }
@@ -12835,7 +12840,8 @@ where
1283512840 pub fn send_htlc_and_commit<F: Deref, L: Deref>(
1283612841 &mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32,
1283712842 source: HTLCSource, onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>,
12838- hold_htlc: bool, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
12843+ hold_htlc: bool, accountable: bool, fee_estimator: &LowerBoundedFeeEstimator<F>,
12844+ logger: &L,
1283912845 ) -> Result<Option<ChannelMonitorUpdate>, ChannelError>
1284012846 where
1284112847 F::Target: FeeEstimator,
@@ -12851,6 +12857,7 @@ where
1285112857 skimmed_fee_msat,
1285212858 None,
1285312859 hold_htlc,
12860+ accountable,
1285412861 fee_estimator,
1285512862 logger,
1285612863 );
@@ -14515,6 +14522,8 @@ where
1451514522 Vec::with_capacity(holding_cell_htlc_update_count);
1451614523 let mut holding_cell_held_htlc_flags: Vec<Option<()>> =
1451714524 Vec::with_capacity(holding_cell_htlc_update_count);
14525+ let mut holding_cell_accountable_flags: Vec<Option<bool>> =
14526+ Vec::with_capacity(holding_cell_htlc_update_count);
1451814527 // Vec of (htlc_id, failure_code, sha256_of_onion)
1451914528 let mut malformed_htlcs: Vec<(u64, u16, [u8; 32])> = Vec::new();
1452014529 (holding_cell_htlc_update_count as u64).write(writer)?;
@@ -14529,6 +14538,7 @@ where
1452914538 blinding_point,
1453014539 skimmed_fee_msat,
1453114540 hold_htlc,
14541+ accountable,
1453214542 } => {
1453314543 0u8.write(writer)?;
1453414544 amount_msat.write(writer)?;
@@ -14540,6 +14550,7 @@ where
1454014550 holding_cell_skimmed_fees.push(skimmed_fee_msat);
1454114551 holding_cell_blinding_points.push(blinding_point);
1454214552 holding_cell_held_htlc_flags.push(hold_htlc);
14553+ holding_cell_accountable_flags.push(accountable);
1454314554 },
1454414555 &HTLCUpdateAwaitingACK::ClaimHTLC {
1454514556 ref payment_preimage,
@@ -14794,6 +14805,7 @@ where
1479414805 (65, self.quiescent_action, option), // Added in 0.2
1479514806 (67, pending_outbound_held_htlc_flags, optional_vec), // Added in 0.2
1479614807 (69, holding_cell_held_htlc_flags, optional_vec), // Added in 0.2
14808+ (71, holding_cell_accountable_flags, optional_vec), // Added in 0.3
1479714809 });
1479814810
1479914811 Ok(())
@@ -14962,6 +14974,7 @@ where
1496214974 skimmed_fee_msat: None,
1496314975 blinding_point: None,
1496414976 hold_htlc: None,
14977+ accountable: None,
1496514978 },
1496614979 1 => HTLCUpdateAwaitingACK::ClaimHTLC {
1496714980 payment_preimage: Readable::read(reader)?,
@@ -15161,6 +15174,7 @@ where
1516115174
1516215175 let mut pending_outbound_held_htlc_flags_opt: Option<Vec<Option<()>>> = None;
1516315176 let mut holding_cell_held_htlc_flags_opt: Option<Vec<Option<()>>> = None;
15177+ let mut holding_cell_accountable_opt: Option<Vec<Option<bool>>> = None;
1516415178
1516515179 read_tlv_fields!(reader, {
1516615180 (0, announcement_sigs, option),
@@ -15208,6 +15222,7 @@ where
1520815222 (65, quiescent_action, upgradable_option), // Added in 0.2
1520915223 (67, pending_outbound_held_htlc_flags_opt, optional_vec), // Added in 0.2
1521015224 (69, holding_cell_held_htlc_flags_opt, optional_vec), // Added in 0.2
15225+ (71, holding_cell_accountable_opt, optional_vec), // Added in 0.3
1521115226 });
1521215227
1521315228 let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
@@ -15332,6 +15347,19 @@ where
1533215347 }
1533315348 }
1533415349
15350+ if let Some(accountable_htlcs) = holding_cell_accountable_opt {
15351+ let mut iter = accountable_htlcs.into_iter();
15352+ for htlc in holding_cell_htlc_updates.iter_mut() {
15353+ if let HTLCUpdateAwaitingACK::AddHTLC { ref mut accountable, .. } = htlc {
15354+ *accountable = iter.next().ok_or(DecodeError::InvalidValue)?;
15355+ }
15356+ }
15357+ // We expect all accountable HTLC signals to be consumed above
15358+ if iter.next().is_some() {
15359+ return Err(DecodeError::InvalidValue);
15360+ }
15361+ }
15362+
1533515363 if let Some(attribution_data_list) = removed_htlc_attribution_data {
1533615364 let mut removed_htlcs = pending_inbound_htlcs.iter_mut().filter_map(|status| {
1533715365 if let InboundHTLCState::LocalRemoved(reason) = &mut status.state {
@@ -16385,6 +16413,7 @@ mod tests {
1638516413 skimmed_fee_msat: None,
1638616414 blinding_point: None,
1638716415 hold_htlc: None,
16416+ accountable: None,
1638816417 };
1638916418 let dummy_holding_cell_claim_htlc = |attribution_data| HTLCUpdateAwaitingACK::ClaimHTLC {
1639016419 payment_preimage: PaymentPreimage([42; 32]),
0 commit comments