Skip to content

Commit 4846570

Browse files
committed
Stop relying on the *Features::known method in lightning-invoice
As we move towards specify supported/required feature bits in the module(s) where they are supported, the global `known` feature set constructors no longer make sense. Here we stop relying on the `known` method in the `lightning-invoice` crate.
1 parent 32b5d84 commit 4846570

File tree

3 files changed

+74
-66
lines changed

3 files changed

+74
-66
lines changed

lightning-invoice/src/lib.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,11 +1712,14 @@ mod test {
17121712
}.unwrap();
17131713
assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::InvalidFeatures));
17141714

1715+
let mut payment_secret_features = InvoiceFeatures::empty();
1716+
payment_secret_features.set_payment_secret_required();
1717+
17151718
// Including payment secret and feature bits
17161719
let invoice = {
17171720
let mut invoice = invoice_template.clone();
17181721
invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
1719-
invoice.data.tagged_fields.push(Features(InvoiceFeatures::known()).into());
1722+
invoice.data.tagged_fields.push(Features(payment_secret_features.clone()).into());
17201723
invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)))
17211724
}.unwrap();
17221725
assert!(Invoice::from_signed(invoice).is_ok());
@@ -1739,7 +1742,7 @@ mod test {
17391742
// Missing payment secret
17401743
let invoice = {
17411744
let mut invoice = invoice_template.clone();
1742-
invoice.data.tagged_fields.push(Features(InvoiceFeatures::known()).into());
1745+
invoice.data.tagged_fields.push(Features(payment_secret_features).into());
17431746
invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)))
17441747
}.unwrap();
17451748
assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::NoPaymentSecret));
@@ -1944,7 +1947,12 @@ mod test {
19441947
);
19451948
assert_eq!(invoice.payment_hash(), &sha256::Hash::from_slice(&[21;32][..]).unwrap());
19461949
assert_eq!(invoice.payment_secret(), &PaymentSecret([42; 32]));
1947-
assert_eq!(invoice.features(), Some(&InvoiceFeatures::known()));
1950+
1951+
let mut expected_features = InvoiceFeatures::empty();
1952+
expected_features.set_variable_length_onion_required();
1953+
expected_features.set_payment_secret_required();
1954+
expected_features.set_basic_mpp_optional();
1955+
assert_eq!(invoice.features(), Some(&expected_features));
19481956

19491957
let raw_invoice = builder.build_raw().unwrap();
19501958
assert_eq!(raw_invoice, *invoice.into_signed_raw().raw_invoice())

lightning-invoice/src/payment.rs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,8 @@ mod tests {
780780
use utils::create_invoice_from_channelmanager_and_duration_since_epoch;
781781
use bitcoin_hashes::sha256::Hash as Sha256;
782782
use lightning::ln::PaymentPreimage;
783-
use lightning::ln::features::{ChannelFeatures, NodeFeatures, InitFeatures};
783+
use lightning::ln::channelmanager;
784+
use lightning::ln::features::{ChannelFeatures, NodeFeatures};
784785
use lightning::ln::functional_test_utils::*;
785786
use lightning::ln::msgs::{ChannelMessageHandler, ErrorAction, LightningError};
786787
use lightning::routing::gossip::{EffectiveCapacity, NodeId};
@@ -2160,24 +2161,24 @@ mod tests {
21602161
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None, None]);
21612162
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
21622163

2163-
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, InitFeatures::known(), InitFeatures::known());
2164-
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, InitFeatures::known(), InitFeatures::known());
2164+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, channelmanager::provided_init_features(), channelmanager::provided_init_features());
2165+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, channelmanager::provided_init_features(), channelmanager::provided_init_features());
21652166
let chans = nodes[0].node.list_usable_channels();
21662167
let mut route = Route {
21672168
paths: vec![
21682169
vec![RouteHop {
21692170
pubkey: nodes[1].node.get_our_node_id(),
2170-
node_features: NodeFeatures::known(),
2171+
node_features: channelmanager::provided_node_features(),
21712172
short_channel_id: chans[0].short_channel_id.unwrap(),
2172-
channel_features: ChannelFeatures::known(),
2173+
channel_features: channelmanager::provided_channel_features(),
21732174
fee_msat: 10_000,
21742175
cltv_expiry_delta: 100,
21752176
}],
21762177
vec![RouteHop {
21772178
pubkey: nodes[1].node.get_our_node_id(),
2178-
node_features: NodeFeatures::known(),
2179+
node_features: channelmanager::provided_node_features(),
21792180
short_channel_id: chans[1].short_channel_id.unwrap(),
2180-
channel_features: ChannelFeatures::known(),
2181+
channel_features: channelmanager::provided_channel_features(),
21812182
fee_msat: 100_000_001, // Our default max-HTLC-value is 10% of the channel value, which this is one more than
21822183
cltv_expiry_delta: 100,
21832184
}],
@@ -2212,16 +2213,16 @@ mod tests {
22122213
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None, None]);
22132214
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
22142215

2215-
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, InitFeatures::known(), InitFeatures::known());
2216-
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, InitFeatures::known(), InitFeatures::known());
2216+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, channelmanager::provided_init_features(), channelmanager::provided_init_features());
2217+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, channelmanager::provided_init_features(), channelmanager::provided_init_features());
22172218
let chans = nodes[0].node.list_usable_channels();
22182219
let mut route = Route {
22192220
paths: vec![
22202221
vec![RouteHop {
22212222
pubkey: nodes[1].node.get_our_node_id(),
2222-
node_features: NodeFeatures::known(),
2223+
node_features: channelmanager::provided_node_features(),
22232224
short_channel_id: chans[0].short_channel_id.unwrap(),
2224-
channel_features: ChannelFeatures::known(),
2225+
channel_features: channelmanager::provided_channel_features(),
22252226
fee_msat: 100_000_001, // Our default max-HTLC-value is 10% of the channel value, which this is one more than
22262227
cltv_expiry_delta: 100,
22272228
}],
@@ -2271,38 +2272,38 @@ mod tests {
22712272
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]);
22722273
let nodes = create_network(3, &node_cfgs, &node_chanmgrs);
22732274

2274-
let chan_1_scid = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 0, InitFeatures::known(), InitFeatures::known()).0.contents.short_channel_id;
2275-
let chan_2_scid = create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 0, InitFeatures::known(), InitFeatures::known()).0.contents.short_channel_id;
2275+
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;
2276+
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;
22762277

22772278
let mut route = Route {
22782279
paths: vec![
22792280
vec![RouteHop {
22802281
pubkey: nodes[1].node.get_our_node_id(),
2281-
node_features: NodeFeatures::known(),
2282+
node_features: channelmanager::provided_node_features(),
22822283
short_channel_id: chan_1_scid,
2283-
channel_features: ChannelFeatures::known(),
2284+
channel_features: channelmanager::provided_channel_features(),
22842285
fee_msat: 0,
22852286
cltv_expiry_delta: 100,
22862287
}, RouteHop {
22872288
pubkey: nodes[2].node.get_our_node_id(),
2288-
node_features: NodeFeatures::known(),
2289+
node_features: channelmanager::provided_node_features(),
22892290
short_channel_id: chan_2_scid,
2290-
channel_features: ChannelFeatures::known(),
2291+
channel_features: channelmanager::provided_channel_features(),
22912292
fee_msat: 100_000_000,
22922293
cltv_expiry_delta: 100,
22932294
}],
22942295
vec![RouteHop {
22952296
pubkey: nodes[1].node.get_our_node_id(),
2296-
node_features: NodeFeatures::known(),
2297+
node_features: channelmanager::provided_node_features(),
22972298
short_channel_id: chan_1_scid,
2298-
channel_features: ChannelFeatures::known(),
2299+
channel_features: channelmanager::provided_channel_features(),
22992300
fee_msat: 0,
23002301
cltv_expiry_delta: 100,
23012302
}, RouteHop {
23022303
pubkey: nodes[2].node.get_our_node_id(),
2303-
node_features: NodeFeatures::known(),
2304+
node_features: channelmanager::provided_node_features(),
23042305
short_channel_id: chan_2_scid,
2305-
channel_features: ChannelFeatures::known(),
2306+
channel_features: channelmanager::provided_channel_features(),
23062307
fee_msat: 100_000_000,
23072308
cltv_expiry_delta: 100,
23082309
}]

0 commit comments

Comments
 (0)