Skip to content

Commit 6bcd1b6

Browse files
committed
ln: add experimental accountable signal to update_add_htlc
1 parent 97204d6 commit 6bcd1b6

File tree

7 files changed

+34
-0
lines changed

7 files changed

+34
-0
lines changed

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,7 @@ fn update_add_msg(
15021502
skimmed_fee_msat: None,
15031503
blinding_point,
15041504
hold_htlc: None,
1505+
accountable: None,
15051506
}
15061507
}
15071508

lightning/src/ln/channel.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9688,6 +9688,7 @@ where
96889688
skimmed_fee_msat: htlc.skimmed_fee_msat,
96899689
blinding_point: htlc.blinding_point,
96909690
hold_htlc: htlc.hold_htlc,
9691+
accountable: None,
96919692
});
96929693
}
96939694
}

lightning/src/ln/functional_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,6 +2270,7 @@ pub fn fail_backward_pending_htlc_upon_channel_failure() {
22702270
skimmed_fee_msat: None,
22712271
blinding_point: None,
22722272
hold_htlc: None,
2273+
accountable: None,
22732274
};
22742275
nodes[0].node.handle_update_add_htlc(node_b_id, &update_add_htlc);
22752276
}

lightning/src/ln/htlc_reserve_unit_tests.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,7 @@ pub fn do_test_fee_spike_buffer(cfg: Option<UserConfig>, htlc_fails: bool) {
839839
skimmed_fee_msat: None,
840840
blinding_point: None,
841841
hold_htlc: None,
842+
accountable: None,
842843
};
843844

844845
nodes[1].node.handle_update_add_htlc(node_a_id, &msg);
@@ -1082,6 +1083,7 @@ pub fn test_chan_reserve_violation_inbound_htlc_outbound_channel() {
10821083
skimmed_fee_msat: None,
10831084
blinding_point: None,
10841085
hold_htlc: None,
1086+
accountable: None,
10851087
};
10861088

10871089
nodes[0].node.handle_update_add_htlc(node_b_id, &msg);
@@ -1266,6 +1268,7 @@ pub fn test_chan_reserve_violation_inbound_htlc_inbound_chan() {
12661268
skimmed_fee_msat: None,
12671269
blinding_point: None,
12681270
hold_htlc: None,
1271+
accountable: None,
12691272
};
12701273

12711274
nodes[1].node.handle_update_add_htlc(node_a_id, &msg);
@@ -1650,6 +1653,7 @@ pub fn test_update_add_htlc_bolt2_receiver_check_max_htlc_limit() {
16501653
skimmed_fee_msat: None,
16511654
blinding_point: None,
16521655
hold_htlc: None,
1656+
accountable: None,
16531657
};
16541658

16551659
for i in 0..50 {
@@ -2256,6 +2260,7 @@ pub fn do_test_dust_limit_fee_accounting(can_afford: bool) {
22562260
skimmed_fee_msat: None,
22572261
blinding_point: None,
22582262
hold_htlc: None,
2263+
accountable: None,
22592264
};
22602265

22612266
nodes[1].node.handle_update_add_htlc(node_a_id, &msg);

lightning/src/ln/msgs.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,28 @@ pub struct UpdateAddHTLC {
768768
///
769769
/// [`ReleaseHeldHtlc`]: crate::onion_message::async_payments::ReleaseHeldHtlc
770770
pub hold_htlc: Option<()>,
771+
/// An experimental field indicating whether the receiving node's reputation would be held
772+
/// accountable for the timely resolution of the HTLC.
773+
///
774+
/// Note that this field is [`experimental`] so should not be used for forwarding decisions.
775+
///
776+
/// [`experimental`]: https://github.com/lightning/blips/blob/master/blip-0004.md
777+
pub accountable: ExperimentalAccountable,
778+
}
779+
780+
/// Represents the value sent on the wire to signal experimental accountability. For historical
781+
/// reasons the least significant three bits are used to represent the accountable signal's value,
782+
/// though it is now only interpreted as a binary value.
783+
pub type ExperimentalAccountable = Option<u8>;
784+
785+
/// Converts a boolean accountable signal to its wire representation.
786+
pub fn accountable_from_bool(value: bool) -> ExperimentalAccountable {
787+
Some(if value { 7 } else { 0 })
788+
}
789+
790+
/// Converts the accountable signal on the wire to a boolean signal.
791+
pub fn accountable_into_bool(accountable: ExperimentalAccountable) -> Option<bool> {
792+
accountable.map(|v| v == 7)
771793
}
772794

773795
/// An [`onion message`] to be sent to or received from a peer.
@@ -3373,6 +3395,7 @@ impl_writeable_msg!(UpdateAddHTLC, {
33733395
// TODO: currently we may fail to read the `ChannelManager` if we write a new even TLV in this message
33743396
// and then downgrade. Once this is fixed, update the type here to match BOLTs PR 989.
33753397
(75537, hold_htlc, option),
3398+
(106823, accountable, option),
33763399
});
33773400

33783401
impl LengthReadable for OnionMessage {
@@ -5872,6 +5895,7 @@ mod tests {
58725895
skimmed_fee_msat: None,
58735896
blinding_point: None,
58745897
hold_htlc: None,
5898+
accountable: None,
58755899
};
58765900
let encoded_value = update_add_htlc.encode();
58775901
let target_value = <Vec<u8>>::from_hex("020202020202020202020202020202020202020202020202020202020202020200083a840000034d32144668701144760101010101010101010101010101010101010101010101010101010101010101000c89d4ff031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010202020202020202020202020202020202020202020202020202020202020202").unwrap();

lightning/src/ln/onion_payment.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,7 @@ mod tests {
758758
skimmed_fee_msat: None,
759759
blinding_point: None,
760760
hold_htlc: None,
761+
accountable: None,
761762
}
762763
}
763764

lightning/src/ln/payment_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5103,6 +5103,7 @@ fn peel_payment_onion_custom_tlvs() {
51035103
onion_routing_packet,
51045104
blinding_point: None,
51055105
hold_htlc: None,
5106+
accountable: None,
51065107
};
51075108
let peeled_onion = crate::ln::onion_payment::peel_payment_onion(
51085109
&update_add,

0 commit comments

Comments
 (0)