Skip to content

Commit a6c69b0

Browse files
committed
Use UserConfig to determine advertised InitFeatures by ChannelManager
This is purely a refactor that does not change the InitFeatures advertised by a ChannelManager. This allows users to configure which features should be advertised based on the values of `UserConfig`. While there aren't any existing features currently leveraging this behavior, it will be used by the upcoming anchors_zero_fee_htlc_tx feature. The UserConfig dependency on provided_init_features caused most callsites of the main test methods responsible for opening channels to be updated. This commit foregos that completely by no longer requiring the InitFeatures of each side to be provided to these methods. The methods already require a reference to each node's ChannelManager to open the channel, so we use that same reference to obtain their InitFeatures. A way to override such features was required for some tests, so a new `override_init_features` config option now exists on the test harness.
1 parent e8b91a4 commit a6c69b0

25 files changed

+826
-763
lines changed

fuzz/src/chanmon_consistency.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use lightning::chain::transaction::OutPoint;
3838
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
3939
use lightning::chain::keysinterface::{KeyMaterial, KeysInterface, InMemorySigner, Recipient, EntropySource, NodeSigner, SignerProvider};
4040
use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
41-
use lightning::ln::channelmanager::{self, ChainParameters, ChannelDetails, ChannelManager, PaymentSendFailure, ChannelManagerReadArgs, PaymentId};
41+
use lightning::ln::channelmanager::{ChainParameters, ChannelDetails, ChannelManager, PaymentSendFailure, ChannelManagerReadArgs, PaymentId};
4242
use lightning::ln::channel::FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE;
4343
use lightning::ln::msgs::{self, CommitmentUpdate, ChannelMessageHandler, DecodeError, UpdateAddHTLC, Init};
4444
use lightning::ln::script::ShutdownScript;
@@ -353,9 +353,9 @@ fn send_payment(source: &ChanMan, dest: &ChanMan, dest_chan_id: u64, amt: u64, p
353353
if let Err(err) = source.send_payment(&Route {
354354
paths: vec![vec![RouteHop {
355355
pubkey: dest.get_our_node_id(),
356-
node_features: channelmanager::provided_node_features(),
356+
node_features: dest.node_features(),
357357
short_channel_id: dest_chan_id,
358-
channel_features: channelmanager::provided_channel_features(),
358+
channel_features: dest.channel_features(),
359359
fee_msat: amt,
360360
cltv_expiry_delta: 200,
361361
}]],
@@ -375,16 +375,16 @@ fn send_hop_payment(source: &ChanMan, middle: &ChanMan, middle_chan_id: u64, des
375375
if let Err(err) = source.send_payment(&Route {
376376
paths: vec![vec![RouteHop {
377377
pubkey: middle.get_our_node_id(),
378-
node_features: channelmanager::provided_node_features(),
378+
node_features: middle.node_features(),
379379
short_channel_id: middle_chan_id,
380-
channel_features: channelmanager::provided_channel_features(),
380+
channel_features: middle.channel_features(),
381381
fee_msat: 50000,
382382
cltv_expiry_delta: 100,
383383
},RouteHop {
384384
pubkey: dest.get_our_node_id(),
385-
node_features: channelmanager::provided_node_features(),
385+
node_features: dest.node_features(),
386386
short_channel_id: dest_chan_id,
387-
channel_features: channelmanager::provided_channel_features(),
387+
channel_features: dest.channel_features(),
388388
fee_msat: amt,
389389
cltv_expiry_delta: 200,
390390
}]],
@@ -470,8 +470,8 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {
470470
let mut channel_txn = Vec::new();
471471
macro_rules! make_channel {
472472
($source: expr, $dest: expr, $chan_id: expr) => { {
473-
$source.peer_connected(&$dest.get_our_node_id(), &Init { features: channelmanager::provided_init_features(), remote_network_address: None }).unwrap();
474-
$dest.peer_connected(&$source.get_our_node_id(), &Init { features: channelmanager::provided_init_features(), remote_network_address: None }).unwrap();
473+
$source.peer_connected(&$dest.get_our_node_id(), &Init { features: $dest.init_features(), remote_network_address: None }).unwrap();
474+
$dest.peer_connected(&$source.get_our_node_id(), &Init { features: $source.init_features(), remote_network_address: None }).unwrap();
475475

476476
$source.create_channel($dest.get_our_node_id(), 100_000, 42, 0, None).unwrap();
477477
let open_channel = {
@@ -482,7 +482,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {
482482
} else { panic!("Wrong event type"); }
483483
};
484484

485-
$dest.handle_open_channel(&$source.get_our_node_id(), channelmanager::provided_init_features(), &open_channel);
485+
$dest.handle_open_channel(&$source.get_our_node_id(), $source.init_features(), &open_channel);
486486
let accept_channel = {
487487
let events = $dest.get_and_clear_pending_msg_events();
488488
assert_eq!(events.len(), 1);
@@ -491,7 +491,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {
491491
} else { panic!("Wrong event type"); }
492492
};
493493

494-
$source.handle_accept_channel(&$dest.get_our_node_id(), channelmanager::provided_init_features(), &accept_channel);
494+
$source.handle_accept_channel(&$dest.get_our_node_id(), $dest.init_features(), &accept_channel);
495495
let funding_output;
496496
{
497497
let events = $source.get_and_clear_pending_events();
@@ -990,15 +990,15 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {
990990
},
991991
0x0e => {
992992
if chan_a_disconnected {
993-
nodes[0].peer_connected(&nodes[1].get_our_node_id(), &Init { features: channelmanager::provided_init_features(), remote_network_address: None }).unwrap();
994-
nodes[1].peer_connected(&nodes[0].get_our_node_id(), &Init { features: channelmanager::provided_init_features(), remote_network_address: None }).unwrap();
993+
nodes[0].peer_connected(&nodes[1].get_our_node_id(), &Init { features: nodes[1].init_features(), remote_network_address: None }).unwrap();
994+
nodes[1].peer_connected(&nodes[0].get_our_node_id(), &Init { features: nodes[0].init_features(), remote_network_address: None }).unwrap();
995995
chan_a_disconnected = false;
996996
}
997997
},
998998
0x0f => {
999999
if chan_b_disconnected {
1000-
nodes[1].peer_connected(&nodes[2].get_our_node_id(), &Init { features: channelmanager::provided_init_features(), remote_network_address: None }).unwrap();
1001-
nodes[2].peer_connected(&nodes[1].get_our_node_id(), &Init { features: channelmanager::provided_init_features(), remote_network_address: None }).unwrap();
1000+
nodes[1].peer_connected(&nodes[2].get_our_node_id(), &Init { features: nodes[2].init_features(), remote_network_address: None }).unwrap();
1001+
nodes[2].peer_connected(&nodes[1].get_our_node_id(), &Init { features: nodes[1].init_features(), remote_network_address: None }).unwrap();
10021002
chan_b_disconnected = false;
10031003
}
10041004
},
@@ -1193,13 +1193,13 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {
11931193

11941194
// Next, make sure peers are all connected to each other
11951195
if chan_a_disconnected {
1196-
nodes[0].peer_connected(&nodes[1].get_our_node_id(), &Init { features: channelmanager::provided_init_features(), remote_network_address: None }).unwrap();
1197-
nodes[1].peer_connected(&nodes[0].get_our_node_id(), &Init { features: channelmanager::provided_init_features(), remote_network_address: None }).unwrap();
1196+
nodes[0].peer_connected(&nodes[1].get_our_node_id(), &Init { features: nodes[1].init_features(), remote_network_address: None }).unwrap();
1197+
nodes[1].peer_connected(&nodes[0].get_our_node_id(), &Init { features: nodes[0].init_features(), remote_network_address: None }).unwrap();
11981198
chan_a_disconnected = false;
11991199
}
12001200
if chan_b_disconnected {
1201-
nodes[1].peer_connected(&nodes[2].get_our_node_id(), &Init { features: channelmanager::provided_init_features(), remote_network_address: None }).unwrap();
1202-
nodes[2].peer_connected(&nodes[1].get_our_node_id(), &Init { features: channelmanager::provided_init_features(), remote_network_address: None }).unwrap();
1201+
nodes[1].peer_connected(&nodes[2].get_our_node_id(), &Init { features: nodes[2].init_features(), remote_network_address: None }).unwrap();
1202+
nodes[2].peer_connected(&nodes[1].get_our_node_id(), &Init { features: nodes[1].init_features(), remote_network_address: None }).unwrap();
12031203
chan_b_disconnected = false;
12041204
}
12051205

fuzz/src/router.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use lightning::ln::msgs;
1818
use lightning::routing::gossip::{NetworkGraph, RoutingFees};
1919
use lightning::routing::router::{find_route, PaymentParameters, RouteHint, RouteHintHop, RouteParameters};
2020
use lightning::routing::scoring::FixedPenaltyScorer;
21+
use lightning::util::config::UserConfig;
2122
use lightning::util::ser::Readable;
2223

2324
use bitcoin::hashes::Hash;
@@ -210,7 +211,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
210211
channel_id: [0; 32],
211212
counterparty: ChannelCounterparty {
212213
node_id: *rnid,
213-
features: channelmanager::provided_init_features(),
214+
features: channelmanager::provided_init_features(&UserConfig::default()),
214215
unspendable_punishment_reserve: 0,
215216
forwarding_info: None,
216217
outbound_htlc_minimum_msat: None,

lightning-background-processor/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ mod tests {
578578
use lightning::chain::keysinterface::{InMemorySigner, Recipient, EntropySource, KeysInterface, KeysManager, NodeSigner};
579579
use lightning::chain::transaction::OutPoint;
580580
use lightning::get_event_msg;
581-
use lightning::ln::channelmanager::{self, BREAKDOWN_TIMEOUT, ChainParameters, ChannelManager, SimpleArcChannelManager};
581+
use lightning::ln::channelmanager::{BREAKDOWN_TIMEOUT, ChainParameters, ChannelManager, SimpleArcChannelManager};
582582
use lightning::ln::features::ChannelFeatures;
583583
use lightning::ln::msgs::{ChannelMessageHandler, Init};
584584
use lightning::ln::peer_handler::{PeerManager, MessageHandler, SocketDescriptor, IgnoringMessageHandler};
@@ -753,8 +753,8 @@ mod tests {
753753

754754
for i in 0..num_nodes {
755755
for j in (i+1)..num_nodes {
756-
nodes[i].node.peer_connected(&nodes[j].node.get_our_node_id(), &Init { features: channelmanager::provided_init_features(), remote_network_address: None }).unwrap();
757-
nodes[j].node.peer_connected(&nodes[i].node.get_our_node_id(), &Init { features: channelmanager::provided_init_features(), remote_network_address: None }).unwrap();
756+
nodes[i].node.peer_connected(&nodes[j].node.get_our_node_id(), &Init { features: nodes[j].node.init_features(), remote_network_address: None }).unwrap();
757+
nodes[j].node.peer_connected(&nodes[i].node.get_our_node_id(), &Init { features: nodes[i].node.init_features(), remote_network_address: None }).unwrap();
758758
}
759759
}
760760

@@ -775,8 +775,8 @@ mod tests {
775775
macro_rules! begin_open_channel {
776776
($node_a: expr, $node_b: expr, $channel_value: expr) => {{
777777
$node_a.node.create_channel($node_b.node.get_our_node_id(), $channel_value, 100, 42, None).unwrap();
778-
$node_b.node.handle_open_channel(&$node_a.node.get_our_node_id(), channelmanager::provided_init_features(), &get_event_msg!($node_a, MessageSendEvent::SendOpenChannel, $node_b.node.get_our_node_id()));
779-
$node_a.node.handle_accept_channel(&$node_b.node.get_our_node_id(), channelmanager::provided_init_features(), &get_event_msg!($node_b, MessageSendEvent::SendAcceptChannel, $node_a.node.get_our_node_id()));
778+
$node_b.node.handle_open_channel(&$node_a.node.get_our_node_id(), $node_a.node.init_features(), &get_event_msg!($node_a, MessageSendEvent::SendOpenChannel, $node_b.node.get_our_node_id()));
779+
$node_a.node.handle_accept_channel(&$node_b.node.get_our_node_id(), $node_b.node.init_features(), &get_event_msg!($node_b, MessageSendEvent::SendAcceptChannel, $node_a.node.get_our_node_id()));
780780
}}
781781
}
782782

lightning-invoice/src/payment.rs

+20-21
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,6 @@ mod tests {
734734
use crate::utils::create_invoice_from_channelmanager_and_duration_since_epoch;
735735
use bitcoin_hashes::sha256::Hash as Sha256;
736736
use lightning::ln::PaymentPreimage;
737-
use lightning::ln::channelmanager;
738737
use lightning::ln::features::{ChannelFeatures, NodeFeatures};
739738
use lightning::ln::functional_test_utils::*;
740739
use lightning::ln::msgs::{ChannelMessageHandler, ErrorAction, LightningError};
@@ -2046,24 +2045,24 @@ mod tests {
20462045
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None, None]);
20472046
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
20482047

2049-
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, channelmanager::provided_init_features(), channelmanager::provided_init_features());
2050-
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, channelmanager::provided_init_features(), channelmanager::provided_init_features());
2048+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0);
2049+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0);
20512050
let chans = nodes[0].node.list_usable_channels();
20522051
let mut route = Route {
20532052
paths: vec![
20542053
vec![RouteHop {
20552054
pubkey: nodes[1].node.get_our_node_id(),
2056-
node_features: channelmanager::provided_node_features(),
2055+
node_features: nodes[1].node.node_features(),
20572056
short_channel_id: chans[0].short_channel_id.unwrap(),
2058-
channel_features: channelmanager::provided_channel_features(),
2057+
channel_features: nodes[1].node.channel_features(),
20592058
fee_msat: 10_000,
20602059
cltv_expiry_delta: 100,
20612060
}],
20622061
vec![RouteHop {
20632062
pubkey: nodes[1].node.get_our_node_id(),
2064-
node_features: channelmanager::provided_node_features(),
2063+
node_features: nodes[1].node.node_features(),
20652064
short_channel_id: chans[1].short_channel_id.unwrap(),
2066-
channel_features: channelmanager::provided_channel_features(),
2065+
channel_features: nodes[1].node.channel_features(),
20672066
fee_msat: 100_000_001, // Our default max-HTLC-value is 10% of the channel value, which this is one more than
20682067
cltv_expiry_delta: 100,
20692068
}],
@@ -2097,16 +2096,16 @@ mod tests {
20972096
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None, None]);
20982097
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
20992098

2100-
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, channelmanager::provided_init_features(), channelmanager::provided_init_features());
2101-
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, channelmanager::provided_init_features(), channelmanager::provided_init_features());
2099+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0);
2100+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0);
21022101
let chans = nodes[0].node.list_usable_channels();
21032102
let mut route = Route {
21042103
paths: vec![
21052104
vec![RouteHop {
21062105
pubkey: nodes[1].node.get_our_node_id(),
2107-
node_features: channelmanager::provided_node_features(),
2106+
node_features: nodes[1].node.node_features(),
21082107
short_channel_id: chans[0].short_channel_id.unwrap(),
2109-
channel_features: channelmanager::provided_channel_features(),
2108+
channel_features: nodes[1].node.channel_features(),
21102109
fee_msat: 100_000_001, // Our default max-HTLC-value is 10% of the channel value, which this is one more than
21112110
cltv_expiry_delta: 100,
21122111
}],
@@ -2155,38 +2154,38 @@ mod tests {
21552154
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]);
21562155
let nodes = create_network(3, &node_cfgs, &node_chanmgrs);
21572156

2158-
let chan_1_scid = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 0, channelmanager::provided_init_features(), channelmanager::provided_init_features()).0.contents.short_channel_id;
2159-
let chan_2_scid = create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 0, channelmanager::provided_init_features(), channelmanager::provided_init_features()).0.contents.short_channel_id;
2157+
let chan_1_scid = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 0).0.contents.short_channel_id;
2158+
let chan_2_scid = create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 0).0.contents.short_channel_id;
21602159

21612160
let mut route = Route {
21622161
paths: vec![
21632162
vec![RouteHop {
21642163
pubkey: nodes[1].node.get_our_node_id(),
2165-
node_features: channelmanager::provided_node_features(),
2164+
node_features: nodes[1].node.node_features(),
21662165
short_channel_id: chan_1_scid,
2167-
channel_features: channelmanager::provided_channel_features(),
2166+
channel_features: nodes[1].node.channel_features(),
21682167
fee_msat: 0,
21692168
cltv_expiry_delta: 100,
21702169
}, RouteHop {
21712170
pubkey: nodes[2].node.get_our_node_id(),
2172-
node_features: channelmanager::provided_node_features(),
2171+
node_features: nodes[2].node.node_features(),
21732172
short_channel_id: chan_2_scid,
2174-
channel_features: channelmanager::provided_channel_features(),
2173+
channel_features: nodes[2].node.channel_features(),
21752174
fee_msat: 100_000_000,
21762175
cltv_expiry_delta: 100,
21772176
}],
21782177
vec![RouteHop {
21792178
pubkey: nodes[1].node.get_our_node_id(),
2180-
node_features: channelmanager::provided_node_features(),
2179+
node_features: nodes[1].node.node_features(),
21812180
short_channel_id: chan_1_scid,
2182-
channel_features: channelmanager::provided_channel_features(),
2181+
channel_features: nodes[2].node.channel_features(),
21832182
fee_msat: 0,
21842183
cltv_expiry_delta: 100,
21852184
}, RouteHop {
21862185
pubkey: nodes[2].node.get_our_node_id(),
2187-
node_features: channelmanager::provided_node_features(),
2186+
node_features: nodes[2].node.node_features(),
21882187
short_channel_id: chan_2_scid,
2189-
channel_features: channelmanager::provided_channel_features(),
2188+
channel_features: nodes[2].node.channel_features(),
21902189
fee_msat: 100_000_000,
21912190
cltv_expiry_delta: 100,
21922191
}]

0 commit comments

Comments
 (0)