Skip to content

Commit 0e6f437

Browse files
committed
Move features into a separate module out of msgs.
1 parent 1dfc122 commit 0e6f437

12 files changed

+438
-410
lines changed

fuzz/src/chanmon_consistency.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ use lightning::ln::channelmonitor;
2929
use lightning::ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr, HTLCUpdate};
3030
use lightning::ln::channelmanager::{ChannelManager, PaymentHash, PaymentPreimage, ChannelManagerReadArgs};
3131
use lightning::ln::router::{Route, RouteHop};
32-
use lightning::ln::msgs::{CommitmentUpdate, ChannelMessageHandler, ErrorAction, UpdateAddHTLC, Features, FeatureContextInit};
32+
use lightning::ln::features::InitFeatures;
33+
use lightning::ln::msgs::{CommitmentUpdate, ChannelMessageHandler, ErrorAction, UpdateAddHTLC};
3334
use lightning::util::enforcing_trait_impls::EnforcingChannelKeys;
3435
use lightning::util::events;
3536
use lightning::util::logger::Logger;
@@ -252,7 +253,7 @@ pub fn do_test(data: &[u8]) {
252253
} else { panic!("Wrong event type"); }
253254
};
254255

255-
$dest.handle_open_channel(&$source.get_our_node_id(), Features::<FeatureContextInit>::our_features(), &open_channel);
256+
$dest.handle_open_channel(&$source.get_our_node_id(), InitFeatures::our_features(), &open_channel);
256257
let accept_channel = {
257258
let events = $dest.get_and_clear_pending_msg_events();
258259
assert_eq!(events.len(), 1);
@@ -261,7 +262,7 @@ pub fn do_test(data: &[u8]) {
261262
} else { panic!("Wrong event type"); }
262263
};
263264

264-
$source.handle_accept_channel(&$dest.get_our_node_id(), Features::<FeatureContextInit>::our_features(), &accept_channel);
265+
$source.handle_accept_channel(&$dest.get_our_node_id(), InitFeatures::our_features(), &accept_channel);
265266
{
266267
let events = $source.get_and_clear_pending_events();
267268
assert_eq!(events.len(), 1);

lightning/src/ln/chanmon_update_fail_tests.rs

+23-22
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
66
use ln::channelmanager::{RAACommitmentOrder, PaymentPreimage, PaymentHash};
77
use ln::channelmonitor::ChannelMonitorUpdateErr;
8+
use ln::features::InitFeatures;
89
use ln::msgs;
9-
use ln::msgs::{ChannelMessageHandler, ErrorAction, Features, FeatureContextInit, RoutingMessageHandler};
10+
use ln::msgs::{ChannelMessageHandler, ErrorAction, RoutingMessageHandler};
1011
use util::events::{Event, EventsProvider, MessageSendEvent, MessageSendEventsProvider};
1112
use util::errors::APIError;
1213

@@ -19,7 +20,7 @@ use ln::functional_test_utils::*;
1920
fn test_simple_monitor_permanent_update_fail() {
2021
// Test that we handle a simple permanent monitor update failure
2122
let mut nodes = create_network(2, &[None, None]);
22-
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::our_features(), Features::<FeatureContextInit>::our_features());
23+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::our_features(), InitFeatures::our_features());
2324

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

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

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

@@ -474,7 +475,7 @@ fn test_monitor_temporary_update_fail_c() {
474475
fn test_monitor_update_fail_cs() {
475476
// Tests handling of a monitor update failure when processing an incoming commitment_signed
476477
let mut nodes = create_network(2, &[None, None]);
477-
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::our_features(), Features::<FeatureContextInit>::our_features());
478+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::our_features(), InitFeatures::our_features());
478479

479480
let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &Vec::new(), 1000000, TEST_FINAL_CLTV).unwrap();
480481
let (payment_preimage, our_payment_hash) = get_payment_preimage_hash!(nodes[0]);
@@ -553,7 +554,7 @@ fn test_monitor_update_fail_no_rebroadcast() {
553554
// test_restore_channel_monitor() is required. Backported from
554555
// chanmon_fail_consistency fuzz tests.
555556
let mut nodes = create_network(2, &[None, None]);
556-
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::our_features(), Features::<FeatureContextInit>::our_features());
557+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::our_features(), InitFeatures::our_features());
557558

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

600601
send_payment(&nodes[0], &[&nodes[1]], 5000000, 5_000_000);
601602

@@ -662,8 +663,8 @@ fn test_monitor_update_raa_while_paused() {
662663
fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) {
663664
// Tests handling of a monitor update failure when processing an incoming RAA
664665
let mut nodes = create_network(3, &[None, None, None]);
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());
666+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::our_features(), InitFeatures::our_features());
667+
let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::our_features(), InitFeatures::our_features());
667668

668669
// Rebalance a bit so that we can send backwards from 2 to 1.
669670
send_payment(&nodes[0], &[&nodes[1], &nodes[2]], 5000000, 5_000_000);
@@ -915,8 +916,8 @@ fn test_monitor_update_fail_reestablish() {
915916
// channel_reestablish generating a monitor update (which comes from freeing holding cell
916917
// HTLCs).
917918
let mut nodes = create_network(3, &[None, None, None]);
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());
919+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::our_features(), InitFeatures::our_features());
920+
create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::our_features(), InitFeatures::our_features());
920921

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

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

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

11111112
// Forward a payment for B to claim
11121113
let (payment_preimage_1, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000);
@@ -1221,7 +1222,7 @@ fn monitor_failed_no_reestablish_response() {
12211222
// Backported from chanmon_fail_consistency fuzz tests as it caught a long-standing
12221223
// debug_assert!() failure in channel_reestablish handling.
12231224
let mut nodes = create_network(2, &[None, None]);
1224-
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::our_features(), Features::<FeatureContextInit>::our_features());
1225+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::our_features(), InitFeatures::our_features());
12251226

12261227
// Route the payment and deliver the initial commitment_signed (with a monitor update failure
12271228
// on receipt).
@@ -1287,7 +1288,7 @@ fn first_message_on_recv_ordering() {
12871288
// payment applied).
12881289
// Backported from chanmon_fail_consistency fuzz tests as it caught a bug here.
12891290
let mut nodes = create_network(2, &[None, None]);
1290-
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::our_features(), Features::<FeatureContextInit>::our_features());
1291+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::our_features(), InitFeatures::our_features());
12911292

12921293
// Route the first payment outbound, holding the last RAA for B until we are set up so that we
12931294
// can deliver it and fail the monitor update.
@@ -1372,8 +1373,8 @@ fn test_monitor_update_fail_claim() {
13721373
// payment from B to A fail due to the paused channel. Finally, we restore the channel monitor
13731374
// updating and claim the payment on B.
13741375
let mut nodes = create_network(3, &[None, None, None]);
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());
1376+
let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::our_features(), InitFeatures::our_features());
1377+
create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::our_features(), InitFeatures::our_features());
13771378

13781379
// Rebalance a bit so that we can send backwards from 3 to 2.
13791380
send_payment(&nodes[0], &[&nodes[1], &nodes[2]], 5000000, 5_000_000);
@@ -1445,8 +1446,8 @@ fn test_monitor_update_on_pending_forwards() {
14451446
// The payment from A to C will be failed by C and pending a back-fail to A, while the payment
14461447
// from C to A will be pending a forward to A.
14471448
let mut nodes = create_network(3, &[None, None, None]);
1448-
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::our_features(), Features::<FeatureContextInit>::our_features());
1449-
create_announced_chan_between_nodes(&nodes, 1, 2, Features::<FeatureContextInit>::our_features(), Features::<FeatureContextInit>::our_features());
1449+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::our_features(), InitFeatures::our_features());
1450+
create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::our_features(), InitFeatures::our_features());
14501451

14511452
// Rebalance a bit so that we can send backwards from 3 to 1.
14521453
send_payment(&nodes[0], &[&nodes[1], &nodes[2]], 5000000, 5_000_000);
@@ -1510,7 +1511,7 @@ fn monitor_update_claim_fail_no_response() {
15101511
// Backported from chanmon_fail_consistency fuzz tests as an unmerged version of the handling
15111512
// code was broken.
15121513
let mut nodes = create_network(2, &[None, None]);
1513-
create_announced_chan_between_nodes(&nodes, 0, 1, Features::<FeatureContextInit>::our_features(), Features::<FeatureContextInit>::our_features());
1514+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::our_features(), InitFeatures::our_features());
15141515

15151516
// Forward a payment for B to claim
15161517
let (payment_preimage_1, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000);
@@ -1571,8 +1572,8 @@ fn do_during_funding_monitor_fail(fail_on_generate: bool, restore_between_fails:
15711572
let mut nodes = create_network(2, &[None, None]);
15721573

15731574
nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 43).unwrap();
1574-
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()));
1575-
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()));
1575+
nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::our_features(), &get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()));
1576+
nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), InitFeatures::our_features(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()));
15761577

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

lightning/src/ln/channel.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ use secp256k1::key::{PublicKey,SecretKey};
1515
use secp256k1::{Secp256k1,Signature};
1616
use secp256k1;
1717

18+
use ln::features::{ChannelFeatures, InitFeatures};
1819
use ln::msgs;
19-
use ln::msgs::{DecodeError, OptionalField, ChannelFeatures, InitFeatures, DataLossProtect};
20+
use ln::msgs::{DecodeError, OptionalField, DataLossProtect};
2021
use ln::channelmonitor::ChannelMonitor;
2122
use ln::channelmanager::{PendingHTLCStatus, HTLCSource, HTLCFailReason, HTLCFailureMsg, PendingForwardHTLCInfo, RAACommitmentOrder, PaymentPreimage, PaymentHash, BREAKDOWN_TIMEOUT, MAX_LOCAL_BREAKDOWN_TIMEOUT};
2223
use ln::chan_utils::{LocalCommitmentTransaction,TxCreationKeys,HTLCOutputInCommitment,HTLC_SUCCESS_TX_WEIGHT,HTLC_TIMEOUT_TX_WEIGHT};

lightning/src/ln/channelmanager.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ use chain::transaction::OutPoint;
3030
use ln::channel::{Channel, ChannelError};
3131
use ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr, ManyChannelMonitor, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY};
3232
use ln::router::Route;
33+
use ln::features::InitFeatures;
3334
use ln::msgs;
34-
use ln::msgs::InitFeatures;
3535
use ln::onion_utils;
3636
use ln::msgs::{ChannelMessageHandler, DecodeError, LightningError};
3737
use chain::keysinterface::{ChannelKeys, KeysInterface};

0 commit comments

Comments
 (0)