Skip to content

Commit 4a64e98

Browse files
committed
ln: add accountable signal to HTLCUpdateAwaitingACK::AddHTLC
1 parent 1da4e9e commit 4a64e98

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
@@ -462,6 +462,7 @@ enum HTLCUpdateAwaitingACK {
462462
skimmed_fee_msat: Option<u64>,
463463
blinding_point: Option<PublicKey>,
464464
hold_htlc: Option<()>,
465+
accountable: bool,
465466
},
466467
ClaimHTLC {
467468
payment_preimage: PaymentPreimage,
@@ -8384,7 +8385,7 @@ where
83848385
skimmed_fee_msat,
83858386
blinding_point,
83868387
hold_htlc,
8387-
..
8388+
accountable,
83888389
} => {
83898390
match self.send_htlc(
83908391
amount_msat,
@@ -8396,6 +8397,7 @@ where
83968397
skimmed_fee_msat,
83978398
blinding_point,
83988399
hold_htlc.is_some(),
8400+
accountable,
83998401
fee_estimator,
84008402
logger,
84018403
) {
@@ -12546,7 +12548,8 @@ where
1254612548
pub fn queue_add_htlc<F: Deref, L: Deref>(
1254712549
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32,
1254812550
source: HTLCSource, onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>,
12549-
blinding_point: Option<PublicKey>, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
12551+
blinding_point: Option<PublicKey>, accountable: bool,
12552+
fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
1255012553
) -> Result<(), (LocalHTLCFailureReason, String)>
1255112554
where
1255212555
F::Target: FeeEstimator,
@@ -12563,6 +12566,7 @@ where
1256312566
blinding_point,
1256412567
// This method is only called for forwarded HTLCs, which are never held at the next hop
1256512568
false,
12569+
accountable,
1256612570
fee_estimator,
1256712571
logger,
1256812572
)
@@ -12594,7 +12598,7 @@ where
1259412598
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32,
1259512599
source: HTLCSource, onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool,
1259612600
skimmed_fee_msat: Option<u64>, blinding_point: Option<PublicKey>, hold_htlc: bool,
12597-
fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
12601+
accountable: bool, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
1259812602
) -> Result<bool, (LocalHTLCFailureReason, String)>
1259912603
where
1260012604
F::Target: FeeEstimator,
@@ -12676,6 +12680,7 @@ where
1267612680
skimmed_fee_msat,
1267712681
blinding_point,
1267812682
hold_htlc: hold_htlc.then(|| ()),
12683+
accountable,
1267912684
});
1268012685
return Ok(false);
1268112686
}
@@ -12947,7 +12952,8 @@ where
1294712952
pub fn send_htlc_and_commit<F: Deref, L: Deref>(
1294812953
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32,
1294912954
source: HTLCSource, onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>,
12950-
hold_htlc: bool, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
12955+
hold_htlc: bool, accountable: bool, fee_estimator: &LowerBoundedFeeEstimator<F>,
12956+
logger: &L,
1295112957
) -> Result<Option<ChannelMonitorUpdate>, ChannelError>
1295212958
where
1295312959
F::Target: FeeEstimator,
@@ -12963,6 +12969,7 @@ where
1296312969
skimmed_fee_msat,
1296412970
None,
1296512971
hold_htlc,
12972+
accountable,
1296612973
fee_estimator,
1296712974
logger,
1296812975
);
@@ -14630,6 +14637,8 @@ where
1463014637
Vec::with_capacity(holding_cell_htlc_update_count);
1463114638
let mut holding_cell_held_htlc_flags: Vec<Option<()>> =
1463214639
Vec::with_capacity(holding_cell_htlc_update_count);
14640+
let mut holding_cell_accountable_flags: Vec<bool> =
14641+
Vec::with_capacity(holding_cell_htlc_update_count);
1463314642
// Vec of (htlc_id, failure_code, sha256_of_onion)
1463414643
let mut malformed_htlcs: Vec<(u64, u16, [u8; 32])> = Vec::new();
1463514644
(holding_cell_htlc_update_count as u64).write(writer)?;
@@ -14644,6 +14653,7 @@ where
1464414653
blinding_point,
1464514654
skimmed_fee_msat,
1464614655
hold_htlc,
14656+
accountable,
1464714657
} => {
1464814658
0u8.write(writer)?;
1464914659
amount_msat.write(writer)?;
@@ -14655,6 +14665,7 @@ where
1465514665
holding_cell_skimmed_fees.push(skimmed_fee_msat);
1465614666
holding_cell_blinding_points.push(blinding_point);
1465714667
holding_cell_held_htlc_flags.push(hold_htlc);
14668+
holding_cell_accountable_flags.push(accountable);
1465814669
},
1465914670
&HTLCUpdateAwaitingACK::ClaimHTLC {
1466014671
ref payment_preimage,
@@ -14915,6 +14926,7 @@ where
1491514926
(69, holding_cell_held_htlc_flags, optional_vec), // Added in 0.2
1491614927
(71, holder_commitment_point_previous_revoked, option), // Added in 0.3
1491714928
(73, holder_commitment_point_last_revoked, option), // Added in 0.3
14929+
(75, holding_cell_accountable_flags, optional_vec), // Added in 0.3
1491814930
});
1491914931

1492014932
Ok(())
@@ -15101,6 +15113,7 @@ where
1510115113
skimmed_fee_msat: None,
1510215114
blinding_point: None,
1510315115
hold_htlc: None,
15116+
accountable: false,
1510415117
},
1510515118
1 => HTLCUpdateAwaitingACK::ClaimHTLC {
1510615119
payment_preimage: Readable::read(reader)?,
@@ -15302,6 +15315,7 @@ where
1530215315

1530315316
let mut pending_outbound_held_htlc_flags_opt: Option<Vec<Option<()>>> = None;
1530415317
let mut holding_cell_held_htlc_flags_opt: Option<Vec<Option<()>>> = None;
15318+
let mut holding_cell_accountable: Option<Vec<bool>> = None;
1530515319

1530615320
read_tlv_fields!(reader, {
1530715321
(0, announcement_sigs, option),
@@ -15351,6 +15365,7 @@ where
1535115365
(69, holding_cell_held_htlc_flags_opt, optional_vec), // Added in 0.2
1535215366
(71, holder_commitment_point_previous_revoked_opt, option), // Added in 0.3
1535315367
(73, holder_commitment_point_last_revoked_opt, option), // Added in 0.3
15368+
(75, holding_cell_accountable, optional_vec), // Added in 0.3
1535415369
});
1535515370

1535615371
let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
@@ -15475,6 +15490,19 @@ where
1547515490
}
1547615491
}
1547715492

15493+
if let Some(accountable_htlcs) = holding_cell_accountable {
15494+
let mut iter = accountable_htlcs.into_iter();
15495+
for htlc in holding_cell_htlc_updates.iter_mut() {
15496+
if let HTLCUpdateAwaitingACK::AddHTLC { ref mut accountable, .. } = htlc {
15497+
*accountable = iter.next().ok_or(DecodeError::InvalidValue)?;
15498+
}
15499+
}
15500+
// We expect all accountable HTLC signals to be consumed above
15501+
if iter.next().is_some() {
15502+
return Err(DecodeError::InvalidValue);
15503+
}
15504+
}
15505+
1547815506
if let Some(attribution_data_list) = removed_htlc_attribution_data {
1547915507
let mut removed_htlcs = pending_inbound_htlcs.iter_mut().filter_map(|status| {
1548015508
if let InboundHTLCState::LocalRemoved(reason) = &mut status.state {
@@ -16559,6 +16587,7 @@ mod tests {
1655916587
skimmed_fee_msat: None,
1656016588
blinding_point: None,
1656116589
hold_htlc: None,
16590+
accountable: false,
1656216591
};
1656316592
let dummy_holding_cell_claim_htlc = |attribution_data| HTLCUpdateAwaitingACK::ClaimHTLC {
1656416593
payment_preimage: PaymentPreimage([42; 32]),

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5330,6 +5330,7 @@ where
53305330
onion_packet,
53315331
None,
53325332
hold_htlc_at_next_hop,
5333+
false, // Not accountable by default for sender.
53335334
&self.fee_estimator,
53345335
&&logger,
53355336
);
@@ -7434,6 +7435,7 @@ where
74347435
outgoing_cltv_value,
74357436
routing,
74367437
skimmed_fee_msat,
7438+
incoming_accountable,
74377439
..
74387440
},
74397441
..
@@ -7534,6 +7536,7 @@ where
75347536
onion_packet.clone(),
75357537
*skimmed_fee_msat,
75367538
next_blinding_point,
7539+
*incoming_accountable,
75377540
&self.fee_estimator,
75387541
&&logger,
75397542
) {

0 commit comments

Comments
 (0)