Skip to content

Commit a252f81

Browse files
authored
Merge pull request #428 from TheBlueMatt/2019-12-flat-features
Implement Flat Features
2 parents f8b06ec + 49f88ec commit a252f81

15 files changed

+661
-429
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, UpdateAddHTLC, LocalFeatures, ErrorAction};
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(), LocalFeatures::new(), &open_channel);
256+
$dest.handle_open_channel(&$source.get_our_node_id(), InitFeatures::supported(), &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(), LocalFeatures::new(), &accept_channel);
265+
$source.handle_accept_channel(&$dest.get_our_node_id(), InitFeatures::supported(), &accept_channel);
265266
{
266267
let events = $source.get_and_clear_pending_events();
267268
assert_eq!(events.len(), 1);

fuzz/src/msg_targets/gen_target.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ GEN_TEST DecodedOnionErrorPacket test_msg ""
2020
GEN_TEST FundingCreated test_msg ""
2121
GEN_TEST FundingLocked test_msg ""
2222
GEN_TEST FundingSigned test_msg ""
23-
GEN_TEST Init test_msg ""
2423
GEN_TEST OpenChannel test_msg ""
2524
GEN_TEST RevokeAndACK test_msg ""
2625
GEN_TEST Shutdown test_msg ""
@@ -37,5 +36,6 @@ GEN_TEST UpdateAddHTLC test_msg_hole ", 85, 33"
3736
GEN_TEST ErrorMessage test_msg_hole ", 32, 2"
3837
GEN_TEST OnionHopData test_msg_hole ", 1+8+8+4, 12"
3938

39+
GEN_TEST Init test_msg_simple ""
4040
GEN_TEST Ping test_msg_simple ""
4141
GEN_TEST Pong test_msg_simple ""

fuzz/src/msg_targets/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ pub mod msg_decoded_onion_error_packet;
88
pub mod msg_funding_created;
99
pub mod msg_funding_locked;
1010
pub mod msg_funding_signed;
11-
pub mod msg_init;
1211
pub mod msg_open_channel;
1312
pub mod msg_revoke_and_ack;
1413
pub mod msg_shutdown;
@@ -22,5 +21,6 @@ pub mod msg_node_announcement;
2221
pub mod msg_update_add_htlc;
2322
pub mod msg_error_message;
2423
pub mod msg_onion_hop_data;
24+
pub mod msg_init;
2525
pub mod msg_ping;
2626
pub mod msg_pong;

fuzz/src/msg_targets/msg_init.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use msg_targets::utils::VecWriter;
77

88
#[inline]
99
pub fn do_test(data: &[u8]) {
10-
test_msg!(msgs::Init, data);
10+
test_msg_simple!(msgs::Init, data);
1111
}
1212

1313
#[no_mangle]

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, LocalFeatures, RoutingMessageHandler, ErrorAction};
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, LocalFeatures::new(), LocalFeatures::new());
23+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported());
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, LocalFeatures::new(), LocalFeatures::new());
53+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported());
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, LocalFeatures::new(), LocalFeatures::new());
152+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported());
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, LocalFeatures::new(), LocalFeatures::new());
478+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported());
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, LocalFeatures::new(), LocalFeatures::new());
557+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported());
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, LocalFeatures::new(), LocalFeatures::new());
599+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported());
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, LocalFeatures::new(), LocalFeatures::new());
666-
let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, LocalFeatures::new(), LocalFeatures::new());
666+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported());
667+
let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported());
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, LocalFeatures::new(), LocalFeatures::new());
919-
create_announced_chan_between_nodes(&nodes, 1, 2, LocalFeatures::new(), LocalFeatures::new());
919+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported());
920+
create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported());
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, LocalFeatures::new(), LocalFeatures::new());
997+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported());
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, LocalFeatures::new(), LocalFeatures::new());
1110+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported());
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, LocalFeatures::new(), LocalFeatures::new());
1225+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported());
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, LocalFeatures::new(), LocalFeatures::new());
1291+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported());
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, LocalFeatures::new(), LocalFeatures::new());
1376-
create_announced_chan_between_nodes(&nodes, 1, 2, LocalFeatures::new(), LocalFeatures::new());
1376+
let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported());
1377+
create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported());
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, LocalFeatures::new(), LocalFeatures::new());
1449-
create_announced_chan_between_nodes(&nodes, 1, 2, LocalFeatures::new(), LocalFeatures::new());
1449+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported());
1450+
create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported());
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, LocalFeatures::new(), LocalFeatures::new());
1514+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported());
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(), LocalFeatures::new(), &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(), LocalFeatures::new(), &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::supported(), &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::supported(), &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

+7-6
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, LocalFeatures, 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};
@@ -543,7 +544,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
543544

544545
/// Creates a new channel from a remote sides' request for one.
545546
/// Assumes chain_hash has already been checked and corresponds with what we expect!
546-
pub fn new_from_req(fee_estimator: &FeeEstimator, keys_provider: &Arc<KeysInterface<ChanKeySigner = ChanSigner>>, their_node_id: PublicKey, their_local_features: LocalFeatures, msg: &msgs::OpenChannel, user_id: u64, logger: Arc<Logger>, config: &UserConfig) -> Result<Channel<ChanSigner>, ChannelError> {
547+
pub fn new_from_req(fee_estimator: &FeeEstimator, keys_provider: &Arc<KeysInterface<ChanKeySigner = ChanSigner>>, their_node_id: PublicKey, their_features: InitFeatures, msg: &msgs::OpenChannel, user_id: u64, logger: Arc<Logger>, config: &UserConfig) -> Result<Channel<ChanSigner>, ChannelError> {
547548
let chan_keys = keys_provider.get_channel_keys(true);
548549
let mut local_config = (*config).channel_options.clone();
549550

@@ -648,7 +649,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
648649
chan_keys.htlc_base_key(), chan_keys.payment_base_key(), &keys_provider.get_shutdown_pubkey(), config.own_channel_config.our_to_self_delay,
649650
keys_provider.get_destination_script(), logger.clone());
650651

651-
let their_shutdown_scriptpubkey = if their_local_features.supports_upfront_shutdown_script() {
652+
let their_shutdown_scriptpubkey = if their_features.supports_upfront_shutdown_script() {
652653
match &msg.shutdown_scriptpubkey {
653654
&OptionalField::Present(ref script) => {
654655
// Peer is signaling upfront_shutdown and has provided a non-accepted scriptpubkey format. We enforce it while receiving shutdown msg
@@ -1306,7 +1307,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
13061307

13071308
// Message handlers:
13081309

1309-
pub fn accept_channel(&mut self, msg: &msgs::AcceptChannel, config: &UserConfig, their_local_features: LocalFeatures) -> Result<(), ChannelError> {
1310+
pub fn accept_channel(&mut self, msg: &msgs::AcceptChannel, config: &UserConfig, their_features: InitFeatures) -> Result<(), ChannelError> {
13101311
// Check sanity of message fields:
13111312
if !self.channel_outbound {
13121313
return Err(ChannelError::Close("Got an accept_channel message from an inbound peer"));
@@ -1365,7 +1366,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
13651366
return Err(ChannelError::Close("We consider the minimum depth to be unreasonably large"));
13661367
}
13671368

1368-
let their_shutdown_scriptpubkey = if their_local_features.supports_upfront_shutdown_script() {
1369+
let their_shutdown_scriptpubkey = if their_features.supports_upfront_shutdown_script() {
13691370
match &msg.shutdown_scriptpubkey {
13701371
&OptionalField::Present(ref script) => {
13711372
// Peer is signaling upfront_shutdown and has provided a non-accepted scriptpubkey format. We enforce it while receiving shutdown msg
@@ -3225,7 +3226,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
32253226
let our_bitcoin_key = PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.funding_key());
32263227

32273228
let msg = msgs::UnsignedChannelAnnouncement {
3228-
features: msgs::GlobalFeatures::new(),
3229+
features: ChannelFeatures::supported(),
32293230
chain_hash: chain_hash,
32303231
short_channel_id: self.get_short_channel_id().unwrap(),
32313232
node_id_1: if were_node_one { our_node_id } else { self.get_their_node_id() },

0 commit comments

Comments
 (0)