Skip to content

Commit 925c73a

Browse files
committed
Refactor features a bit more and fix endianness.
The spec is a bit mum on feature endianness, so I suppose it falls under the "everything is big endian unless otherwise specified" clause, but we were treating it as little. Further, the Features::new() method is nonsense - we introduce an empty() and a our_features() instead.
1 parent 9e1bef1 commit 925c73a

File tree

7 files changed

+199
-181
lines changed

7 files changed

+199
-181
lines changed

fuzz/src/chanmon_consistency.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ pub fn do_test(data: &[u8]) {
252252
} else { panic!("Wrong event type"); }
253253
};
254254

255-
$dest.handle_open_channel(&$source.get_our_node_id(), Features::<FeatureContextInit>::new(), &open_channel).unwrap();
255+
$dest.handle_open_channel(&$source.get_our_node_id(), Features::<FeatureContextInit>::our_features(), &open_channel).unwrap();
256256
let accept_channel = {
257257
let events = $dest.get_and_clear_pending_msg_events();
258258
assert_eq!(events.len(), 1);
@@ -261,7 +261,7 @@ pub fn do_test(data: &[u8]) {
261261
} else { panic!("Wrong event type"); }
262262
};
263263

264-
$source.handle_accept_channel(&$dest.get_our_node_id(), Features::<FeatureContextInit>::new(), &accept_channel).unwrap();
264+
$source.handle_accept_channel(&$dest.get_our_node_id(), Features::<FeatureContextInit>::our_features(), &accept_channel).unwrap();
265265
{
266266
let events = $source.get_and_clear_pending_events();
267267
assert_eq!(events.len(), 1);

lightning/src/ln/chanmon_update_fail_tests.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use ln::functional_test_utils::*;
1919
fn test_simple_monitor_permanent_update_fail() {
2020
// Test that we handle a simple permanent monitor update failure
2121
let mut nodes = create_network(2, &[None, None]);
22-
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::new(), Features::<FeatureContextInit>::new());
22+
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::our_features(), Features::<FeatureContextInit>::our_features());
2323

2424
let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &Vec::new(), 1000000, TEST_FINAL_CLTV).unwrap();
2525
let (_, payment_hash_1) = get_payment_preimage_hash!(nodes[0]);
@@ -49,7 +49,7 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool) {
4949
// Test that we can recover from a simple temporary monitor update failure optionally with
5050
// a disconnect in between
5151
let mut nodes = create_network(2, &[None, None]);
52-
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::new(), Features::<FeatureContextInit>::new());
52+
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::our_features(), Features::<FeatureContextInit>::our_features());
5353

5454
let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &Vec::new(), 1000000, TEST_FINAL_CLTV).unwrap();
5555
let (payment_preimage_1, payment_hash_1) = get_payment_preimage_hash!(nodes[0]);
@@ -148,7 +148,7 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) {
148148
// through, swapping message ordering based on disconnect_count & 8 and optionally
149149
// disconnect/reconnecting based on disconnect_count.
150150
let mut nodes = create_network(2, &[None, None]);
151-
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::new(), Features::<FeatureContextInit>::new());
151+
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::our_features(), Features::<FeatureContextInit>::our_features());
152152

153153
let (payment_preimage_1, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000);
154154

@@ -474,7 +474,7 @@ fn test_monitor_temporary_update_fail_c() {
474474
fn test_monitor_update_fail_cs() {
475475
// Tests handling of a monitor update failure when processing an incoming commitment_signed
476476
let mut nodes = create_network(2, &[None, None]);
477-
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::new(), Features::<FeatureContextInit>::new());
477+
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::our_features(), Features::<FeatureContextInit>::our_features());
478478

479479
let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &Vec::new(), 1000000, TEST_FINAL_CLTV).unwrap();
480480
let (payment_preimage, our_payment_hash) = get_payment_preimage_hash!(nodes[0]);
@@ -553,7 +553,7 @@ fn test_monitor_update_fail_no_rebroadcast() {
553553
// test_restore_channel_monitor() is required. Backported from
554554
// chanmon_fail_consistency fuzz tests.
555555
let mut nodes = create_network(2, &[None, None]);
556-
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::new(), Features::<FeatureContextInit>::new());
556+
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::our_features(), Features::<FeatureContextInit>::our_features());
557557

558558
let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &Vec::new(), 1000000, TEST_FINAL_CLTV).unwrap();
559559
let (payment_preimage_1, our_payment_hash) = get_payment_preimage_hash!(nodes[0]);
@@ -595,7 +595,7 @@ fn test_monitor_update_raa_while_paused() {
595595
// Tests handling of an RAA while monitor updating has already been marked failed.
596596
// Backported from chanmon_fail_consistency fuzz tests as this used to be broken.
597597
let mut nodes = create_network(2, &[None, None]);
598-
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::new(), Features::<FeatureContextInit>::new());
598+
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::our_features(), Features::<FeatureContextInit>::our_features());
599599

600600
send_payment(&nodes[0], &[&nodes[1]], 5000000, 5_000_000);
601601

@@ -662,8 +662,8 @@ fn test_monitor_update_raa_while_paused() {
662662
fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) {
663663
// Tests handling of a monitor update failure when processing an incoming RAA
664664
let mut nodes = create_network(3, &[None, None, None]);
665-
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::new(), Features::<FeatureContextInit>::new());
666-
let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, Features::<FeatureContextInit>::new(), Features::<FeatureContextInit>::new());
665+
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::our_features(), Features::<FeatureContextInit>::our_features());
666+
let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, Features::<FeatureContextInit>::our_features(), Features::<FeatureContextInit>::our_features());
667667

668668
// Rebalance a bit so that we can send backwards from 2 to 1.
669669
send_payment(&nodes[0], &[&nodes[1], &nodes[2]], 5000000, 5_000_000);
@@ -915,8 +915,8 @@ fn test_monitor_update_fail_reestablish() {
915915
// channel_reestablish generating a monitor update (which comes from freeing holding cell
916916
// HTLCs).
917917
let mut nodes = create_network(3, &[None, None, None]);
918-
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::new(), Features::<FeatureContextInit>::new());
919-
create_announced_chan_between_nodes(&nodes, 1, 2, Features::<FeatureContextInit>::new(), Features::<FeatureContextInit>::new());
918+
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::our_features(), Features::<FeatureContextInit>::our_features());
919+
create_announced_chan_between_nodes(&nodes, 1, 2, Features::<FeatureContextInit>::our_features(), Features::<FeatureContextInit>::our_features());
920920

921921
let (our_payment_preimage, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 1000000);
922922

@@ -993,7 +993,7 @@ fn raa_no_response_awaiting_raa_state() {
993993
// in question (assuming it intends to respond with a CS after monitor updating is restored).
994994
// Backported from chanmon_fail_consistency fuzz tests as this used to be broken.
995995
let mut nodes = create_network(2, &[None, None]);
996-
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::new(), Features::<FeatureContextInit>::new());
996+
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::our_features(), Features::<FeatureContextInit>::our_features());
997997

998998
let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &Vec::new(), 1000000, TEST_FINAL_CLTV).unwrap();
999999
let (payment_preimage_1, payment_hash_1) = get_payment_preimage_hash!(nodes[0]);
@@ -1106,7 +1106,7 @@ fn claim_while_disconnected_monitor_update_fail() {
11061106
// code introduced a regression in this test (specifically, this caught a removal of the
11071107
// channel_reestablish handling ensuring the order was sensical given the messages used).
11081108
let mut nodes = create_network(2, &[None, None]);
1109-
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::new(), Features::<FeatureContextInit>::new());
1109+
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::our_features(), Features::<FeatureContextInit>::our_features());
11101110

11111111
// Forward a payment for B to claim
11121112
let (payment_preimage_1, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000);
@@ -1221,7 +1221,7 @@ fn monitor_failed_no_reestablish_response() {
12211221
// Backported from chanmon_fail_consistency fuzz tests as it caught a long-standing
12221222
// debug_assert!() failure in channel_reestablish handling.
12231223
let mut nodes = create_network(2, &[None, None]);
1224-
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::new(), Features::<FeatureContextInit>::new());
1224+
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::our_features(), Features::<FeatureContextInit>::our_features());
12251225

12261226
// Route the payment and deliver the initial commitment_signed (with a monitor update failure
12271227
// on receipt).
@@ -1287,7 +1287,7 @@ fn first_message_on_recv_ordering() {
12871287
// payment applied).
12881288
// Backported from chanmon_fail_consistency fuzz tests as it caught a bug here.
12891289
let mut nodes = create_network(2, &[None, None]);
1290-
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::new(), Features::<FeatureContextInit>::new());
1290+
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::our_features(), Features::<FeatureContextInit>::our_features());
12911291

12921292
// Route the first payment outbound, holding the last RAA for B until we are set up so that we
12931293
// can deliver it and fail the monitor update.
@@ -1372,8 +1372,8 @@ fn test_monitor_update_fail_claim() {
13721372
// payment from B to A fail due to the paused channel. Finally, we restore the channel monitor
13731373
// updating and claim the payment on B.
13741374
let mut nodes = create_network(3, &[None, None, None]);
1375-
let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::new(), Features::<FeatureContextInit>::new());
1376-
create_announced_chan_between_nodes(&nodes, 1, 2, Features::<FeatureContextInit>::new(), Features::<FeatureContextInit>::new());
1375+
let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::our_features(), Features::<FeatureContextInit>::our_features());
1376+
create_announced_chan_between_nodes(&nodes, 1, 2, Features::<FeatureContextInit>::our_features(), Features::<FeatureContextInit>::our_features());
13771377

13781378
// Rebalance a bit so that we can send backwards from 3 to 2.
13791379
send_payment(&nodes[0], &[&nodes[1], &nodes[2]], 5000000, 5_000_000);
@@ -1442,8 +1442,8 @@ fn test_monitor_update_on_pending_forwards() {
14421442
// The payment from A to C will be failed by C and pending a back-fail to A, while the payment
14431443
// from C to A will be pending a forward to A.
14441444
let mut nodes = create_network(3, &[None, None, None]);
1445-
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::new(), Features::<FeatureContextInit>::new());
1446-
create_announced_chan_between_nodes(&nodes, 1, 2, Features::<FeatureContextInit>::new(), Features::<FeatureContextInit>::new());
1445+
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::our_features(), Features::<FeatureContextInit>::our_features());
1446+
create_announced_chan_between_nodes(&nodes, 1, 2, Features::<FeatureContextInit>::our_features(), Features::<FeatureContextInit>::our_features());
14471447

14481448
// Rebalance a bit so that we can send backwards from 3 to 1.
14491449
send_payment(&nodes[0], &[&nodes[1], &nodes[2]], 5000000, 5_000_000);
@@ -1506,7 +1506,7 @@ fn monitor_update_claim_fail_no_response() {
15061506
// Backported from chanmon_fail_consistency fuzz tests as an unmerged version of the handling
15071507
// code was broken.
15081508
let mut nodes = create_network(2, &[None, None]);
1509-
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::new(), Features::<FeatureContextInit>::new());
1509+
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::our_features(), Features::<FeatureContextInit>::our_features());
15101510

15111511
// Forward a payment for B to claim
15121512
let (payment_preimage_1, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000);
@@ -1565,8 +1565,8 @@ fn do_during_funding_monitor_fail(fail_on_generate: bool, restore_between_fails:
15651565
let mut nodes = create_network(2, &[None, None]);
15661566

15671567
nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 43).unwrap();
1568-
nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), Features::<FeatureContextInit>::new(), &get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id())).unwrap();
1569-
nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), Features::<FeatureContextInit>::new(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id())).unwrap();
1568+
nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), Features::<FeatureContextInit>::our_features(), &get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id())).unwrap();
1569+
nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), Features::<FeatureContextInit>::our_features(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id())).unwrap();
15701570

15711571
let (temporary_channel_id, funding_tx, funding_output) = create_funding_transaction(&nodes[0], 100000, 43);
15721572

lightning/src/ln/channel.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3225,7 +3225,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
32253225
let our_bitcoin_key = PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.funding_key());
32263226

32273227
let msg = msgs::UnsignedChannelAnnouncement {
3228-
features: msgs::Features::<msgs::FeatureContextChannel>::new(),
3228+
features: msgs::Features::<msgs::FeatureContextChannel>::our_features(),
32293229
chain_hash: chain_hash,
32303230
short_channel_id: self.get_short_channel_id().unwrap(),
32313231
node_id_1: if were_node_one { our_node_id } else { self.get_their_node_id() },

0 commit comments

Comments
 (0)