Skip to content

Commit c15c0a5

Browse files
Remove Channel::counterparty_htlc_minimum_msat
1 parent 4988b76 commit c15c0a5

File tree

2 files changed

+29
-109
lines changed

2 files changed

+29
-109
lines changed

lightning-invoice/src/utils.rs

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,6 @@ mod test {
476476
use lightning::util::enforcing_trait_impls::EnforcingSigner;
477477
use lightning::util::events::{MessageSendEvent, MessageSendEventsProvider, Event};
478478
use lightning::util::test_utils;
479-
use lightning::util::config::UserConfig;
480479
use lightning::chain::keysinterface::KeysInterface;
481480
use utils::create_invoice_from_channelmanager_and_duration_since_epoch;
482481
use std::collections::HashSet;
@@ -594,46 +593,6 @@ mod test {
594593
match_invoice_routes(Some(5000), &nodes[0], scid_aliases);
595594
}
596595

597-
#[test]
598-
fn test_forwarding_info_not_assigned_channel_excluded_from_hints() {
599-
let chanmon_cfgs = create_chanmon_cfgs(3);
600-
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
601-
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]);
602-
let nodes = create_network(3, &node_cfgs, &node_chanmgrs);
603-
let chan_1_0 = create_unannounced_chan_between_nodes_with_value(&nodes, 1, 0, 100000, 10001, InitFeatures::known(), InitFeatures::known());
604-
605-
// Create an unannonced channel between `nodes[2]` and `nodes[0]`, for which the
606-
// `msgs::ChannelUpdate` is never handled for the node(s). As the `msgs::ChannelUpdate`
607-
// is never handled, the `channel.counterparty.forwarding_info` is never assigned.
608-
let mut private_chan_cfg = UserConfig::default();
609-
private_chan_cfg.channel_options.announced_channel = false;
610-
let temporary_channel_id = nodes[2].node.create_channel(nodes[0].node.get_our_node_id(), 1_000_000, 500_000_000, 42, Some(private_chan_cfg)).unwrap();
611-
let open_channel = get_event_msg!(nodes[2], MessageSendEvent::SendOpenChannel, nodes[0].node.get_our_node_id());
612-
nodes[0].node.handle_open_channel(&nodes[2].node.get_our_node_id(), InitFeatures::known(), &open_channel);
613-
let accept_channel = get_event_msg!(nodes[0], MessageSendEvent::SendAcceptChannel, nodes[2].node.get_our_node_id());
614-
nodes[2].node.handle_accept_channel(&nodes[0].node.get_our_node_id(), InitFeatures::known(), &accept_channel);
615-
616-
let tx = sign_funding_transaction(&nodes[2], &nodes[0], 1_000_000, temporary_channel_id);
617-
618-
let conf_height = core::cmp::max(nodes[2].best_block_info().1 + 1, nodes[0].best_block_info().1 + 1);
619-
confirm_transaction_at(&nodes[2], &tx, conf_height);
620-
connect_blocks(&nodes[2], CHAN_CONFIRM_DEPTH - 1);
621-
confirm_transaction_at(&nodes[0], &tx, conf_height);
622-
connect_blocks(&nodes[0], CHAN_CONFIRM_DEPTH - 1);
623-
let as_funding_locked = get_event_msg!(nodes[2], MessageSendEvent::SendFundingLocked, nodes[0].node.get_our_node_id());
624-
nodes[2].node.handle_funding_locked(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendFundingLocked, nodes[2].node.get_our_node_id()));
625-
get_event_msg!(nodes[2], MessageSendEvent::SendChannelUpdate, nodes[0].node.get_our_node_id());
626-
nodes[0].node.handle_funding_locked(&nodes[2].node.get_our_node_id(), &as_funding_locked);
627-
get_event_msg!(nodes[0], MessageSendEvent::SendChannelUpdate, nodes[2].node.get_our_node_id());
628-
629-
// As `msgs::ChannelUpdate` was never handled for the participating node(s) of the second
630-
// channel, the channel will never be assigned any `counterparty.forwarding_info`.
631-
// Therefore only `chan_1_0` should be included in the hints.
632-
let mut scid_aliases = HashSet::new();
633-
scid_aliases.insert(chan_1_0.0.short_channel_id_alias.unwrap());
634-
match_invoice_routes(Some(5000), &nodes[0], scid_aliases);
635-
}
636-
637596
#[test]
638597
fn test_no_hints_if_a_mix_between_public_and_private_channel_exists() {
639598
let chanmon_cfgs = create_chanmon_cfgs(3);
@@ -959,62 +918,6 @@ mod test {
959918
);
960919
}
961920

962-
#[test]
963-
#[cfg(feature = "std")]
964-
fn test_multi_node_forwarding_info_not_assigned_channel_excluded_from_hints() {
965-
let mut chanmon_cfgs = create_chanmon_cfgs(4);
966-
let seed_1 = [42 as u8; 32];
967-
let seed_2 = [43 as u8; 32];
968-
let cross_node_seed = [44 as u8; 32];
969-
chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
970-
chanmon_cfgs[3].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
971-
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
972-
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
973-
let nodes = create_network(4, &node_cfgs, &node_chanmgrs);
974-
975-
let chan_0_2 = create_unannounced_chan_between_nodes_with_value(&nodes, 0, 2, 100000, 10001, InitFeatures::known(), InitFeatures::known());
976-
let chan_0_3 = create_unannounced_chan_between_nodes_with_value(&nodes, 0, 3, 1000000, 10001, InitFeatures::known(), InitFeatures::known());
977-
978-
// Create an unannonced channel between `nodes[1]` and `nodes[3]`, for which the
979-
// `msgs::ChannelUpdate` is never handled for the node(s). As the `msgs::ChannelUpdate`
980-
// is never handled, the `channel.counterparty.forwarding_info` is never assigned.
981-
let mut private_chan_cfg = UserConfig::default();
982-
private_chan_cfg.channel_options.announced_channel = false;
983-
let temporary_channel_id = nodes[1].node.create_channel(nodes[3].node.get_our_node_id(), 1_000_000, 500_000_000, 42, Some(private_chan_cfg)).unwrap();
984-
let open_channel = get_event_msg!(nodes[1], MessageSendEvent::SendOpenChannel, nodes[3].node.get_our_node_id());
985-
nodes[3].node.handle_open_channel(&nodes[1].node.get_our_node_id(), InitFeatures::known(), &open_channel);
986-
let accept_channel = get_event_msg!(nodes[3], MessageSendEvent::SendAcceptChannel, nodes[1].node.get_our_node_id());
987-
nodes[1].node.handle_accept_channel(&nodes[3].node.get_our_node_id(), InitFeatures::known(), &accept_channel);
988-
989-
let tx = sign_funding_transaction(&nodes[1], &nodes[3], 1_000_000, temporary_channel_id);
990-
991-
let conf_height = core::cmp::max(nodes[1].best_block_info().1 + 1, nodes[3].best_block_info().1 + 1);
992-
confirm_transaction_at(&nodes[1], &tx, conf_height);
993-
connect_blocks(&nodes[1], CHAN_CONFIRM_DEPTH - 1);
994-
confirm_transaction_at(&nodes[3], &tx, conf_height);
995-
connect_blocks(&nodes[3], CHAN_CONFIRM_DEPTH - 1);
996-
let as_funding_locked = get_event_msg!(nodes[1], MessageSendEvent::SendFundingLocked, nodes[3].node.get_our_node_id());
997-
nodes[1].node.handle_funding_locked(&nodes[3].node.get_our_node_id(), &get_event_msg!(nodes[3], MessageSendEvent::SendFundingLocked, nodes[1].node.get_our_node_id()));
998-
get_event_msg!(nodes[1], MessageSendEvent::SendChannelUpdate, nodes[3].node.get_our_node_id());
999-
nodes[3].node.handle_funding_locked(&nodes[1].node.get_our_node_id(), &as_funding_locked);
1000-
get_event_msg!(nodes[3], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id());
1001-
1002-
// As `msgs::ChannelUpdate` was never handled for the participating node(s) of the third
1003-
// channel, the channel will never be assigned any `counterparty.forwarding_info`.
1004-
// Therefore only `chan_0_3` should be included in the hints for `nodes[3]`.
1005-
let mut scid_aliases = HashSet::new();
1006-
scid_aliases.insert(chan_0_2.0.short_channel_id_alias.unwrap());
1007-
scid_aliases.insert(chan_0_3.0.short_channel_id_alias.unwrap());
1008-
1009-
match_multi_node_invoice_routes(
1010-
Some(10_000),
1011-
&nodes[2],
1012-
vec![&nodes[2], &nodes[3],],
1013-
scid_aliases,
1014-
false
1015-
);
1016-
}
1017-
1018921
#[test]
1019922
#[cfg(feature = "std")]
1020923
fn test_multi_node_with_only_public_channels_hints_includes_only_phantom_route() {

lightning/src/ln/channel.rs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,6 @@ pub(super) struct Channel<Signer: Sign> {
631631
#[cfg(not(test))]
632632
holder_selected_channel_reserve_satoshis: u64,
633633

634-
counterparty_htlc_minimum_msat: u64,
635634
holder_htlc_minimum_msat: u64,
636635
#[cfg(test)]
637636
pub counterparty_max_accepted_htlcs: u16,
@@ -924,7 +923,6 @@ impl<Signer: Sign> Channel<Signer> {
924923
holder_max_htlc_value_in_flight_msat: Self::get_holder_max_htlc_value_in_flight_msat(channel_value_satoshis),
925924
counterparty_selected_channel_reserve_satoshis: None, // Filled in in accept_channel
926925
holder_selected_channel_reserve_satoshis,
927-
counterparty_htlc_minimum_msat: 0,
928926
holder_htlc_minimum_msat: if config.own_channel_config.our_htlc_minimum_msat == 0 { 1 } else { config.own_channel_config.our_htlc_minimum_msat },
929927
counterparty_max_accepted_htlcs: 0,
930928
minimum_depth: None, // Filled in in accept_channel
@@ -1230,12 +1228,17 @@ impl<Signer: Sign> Channel<Signer> {
12301228
holder_max_htlc_value_in_flight_msat: Self::get_holder_max_htlc_value_in_flight_msat(msg.funding_satoshis),
12311229
counterparty_selected_channel_reserve_satoshis: Some(msg.channel_reserve_satoshis),
12321230
holder_selected_channel_reserve_satoshis,
1233-
counterparty_htlc_minimum_msat: msg.htlc_minimum_msat,
12341231
holder_htlc_minimum_msat: if config.own_channel_config.our_htlc_minimum_msat == 0 { 1 } else { config.own_channel_config.our_htlc_minimum_msat },
12351232
counterparty_max_accepted_htlcs: msg.max_accepted_htlcs,
12361233
minimum_depth: Some(config.own_channel_config.minimum_depth),
12371234

1238-
counterparty_forwarding_info: None,
1235+
counterparty_forwarding_info: Some(CounterpartyForwardingInfo {
1236+
fee_base_msat: 0,
1237+
fee_proportional_millionths: 0,
1238+
cltv_expiry_delta: 0,
1239+
outbound_htlc_minimum_msat: Some(msg.htlc_minimum_msat),
1240+
outbound_htlc_maximum_msat: None,
1241+
}),
12391242

12401243
channel_transaction_parameters: ChannelTransactionParameters {
12411244
holder_pubkeys: pubkeys,
@@ -1949,8 +1952,15 @@ impl<Signer: Sign> Channel<Signer> {
19491952
self.counterparty_dust_limit_satoshis = msg.dust_limit_satoshis;
19501953
self.counterparty_max_htlc_value_in_flight_msat = cmp::min(msg.max_htlc_value_in_flight_msat, self.channel_value_satoshis * 1000);
19511954
self.counterparty_selected_channel_reserve_satoshis = Some(msg.channel_reserve_satoshis);
1952-
self.counterparty_htlc_minimum_msat = msg.htlc_minimum_msat;
19531955
self.counterparty_max_accepted_htlcs = msg.max_accepted_htlcs;
1956+
self.counterparty_forwarding_info = Some(CounterpartyForwardingInfo {
1957+
fee_base_msat: 0,
1958+
fee_proportional_millionths: 0,
1959+
cltv_expiry_delta: 0,
1960+
outbound_htlc_minimum_msat: Some(msg.htlc_minimum_msat),
1961+
outbound_htlc_maximum_msat: self.get_counterparty_htlc_maximum_msat(),
1962+
});
1963+
19541964
self.minimum_depth = Some(msg.minimum_depth);
19551965

19561966
let counterparty_pubkeys = ChannelPublicKeys {
@@ -4307,7 +4317,7 @@ impl<Signer: Sign> Channel<Signer> {
43074317

43084318
/// Allowed in any state (including after shutdown)
43094319
pub fn get_counterparty_htlc_minimum_msat(&self) -> u64 {
4310-
self.counterparty_htlc_minimum_msat
4320+
self.counterparty_forwarding_info.as_ref().map(|info| info.outbound_htlc_minimum_msat.unwrap_or(0)).unwrap_or(0)
43114321
}
43124322

43134323
/// Allowed in any state (including after shutdown), but will return none before TheirInitSent
@@ -5103,8 +5113,9 @@ impl<Signer: Sign> Channel<Signer> {
51035113
return Err(ChannelError::Ignore("Cannot send 0-msat HTLC".to_owned()));
51045114
}
51055115

5106-
if amount_msat < self.counterparty_htlc_minimum_msat {
5107-
return Err(ChannelError::Ignore(format!("Cannot send less than their minimum HTLC value ({})", self.counterparty_htlc_minimum_msat)));
5116+
let counterparty_htlc_minimum_msat = self.get_counterparty_htlc_minimum_msat();
5117+
if amount_msat < counterparty_htlc_minimum_msat {
5118+
return Err(ChannelError::Ignore(format!("Cannot send less than their minimum HTLC value ({})", counterparty_htlc_minimum_msat)));
51085119
}
51095120

51105121
if (self.channel_state & (ChannelState::PeerDisconnected as u32)) != 0 {
@@ -5775,7 +5786,11 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
57755786
// Note that this field is ignored by 0.0.99+ as the TLV Optional variant is used instead.
57765787
self.counterparty_selected_channel_reserve_satoshis.unwrap_or(0).write(writer)?;
57775788

5778-
self.counterparty_htlc_minimum_msat.write(writer)?;
5789+
// Versions prior to 0.0.107, stored the `outbound_htlc_minimum_msat` field as a
5790+
// non-optional field of the `Channel` struct, which was written here. It has since been
5791+
// refactored to be part of the `CounterpartyForwardingInfo` struct.
5792+
self.counterparty_forwarding_info.as_ref()
5793+
.map(|info| info.outbound_htlc_minimum_msat.unwrap_or(0)).unwrap_or(0).write(writer)?;
57795794
self.holder_htlc_minimum_msat.write(writer)?;
57805795
self.counterparty_max_accepted_htlcs.write(writer)?;
57815796

@@ -6036,7 +6051,10 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
60366051
// Read the 8 bytes of backwards-compatibility data.
60376052
let _dummy: u64 = Readable::read(reader)?;
60386053
}
6039-
let counterparty_htlc_minimum_msat = Readable::read(reader)?;
6054+
// Versions prior to 0.0.107, stored the `outbound_htlc_minimum_msat` field as a
6055+
// non-optional field of the `Channel` struct, which has since been refactored to be part
6056+
// of the `CounterpartyForwardingInfo` struct. It's therefore read here.
6057+
let outbound_htlc_minimum_msat = Readable::read(reader)?;
60406058
let holder_htlc_minimum_msat = Readable::read(reader)?;
60416059
let counterparty_max_accepted_htlcs = Readable::read(reader)?;
60426060

@@ -6055,7 +6073,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
60556073
fee_base_msat: Readable::read(reader)?,
60566074
fee_proportional_millionths: Readable::read(reader)?,
60576075
cltv_expiry_delta: Readable::read(reader)?,
6058-
outbound_htlc_minimum_msat: Some(counterparty_htlc_minimum_msat),
6076+
outbound_htlc_minimum_msat: Some(outbound_htlc_minimum_msat),
60596077
outbound_htlc_maximum_msat: None,
60606078
}),
60616079
_ => return Err(DecodeError::InvalidValue),
@@ -6238,7 +6256,6 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
62386256
holder_max_htlc_value_in_flight_msat: holder_max_htlc_value_in_flight_msat.unwrap(),
62396257
counterparty_selected_channel_reserve_satoshis,
62406258
holder_selected_channel_reserve_satoshis: holder_selected_channel_reserve_satoshis.unwrap(),
6241-
counterparty_htlc_minimum_msat,
62426259
holder_htlc_minimum_msat,
62436260
counterparty_max_accepted_htlcs,
62446261
minimum_depth,

0 commit comments

Comments
 (0)