]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Remove all remaining references to `*Features::known`
authorMatt Corallo <git@bluematt.me>
Wed, 14 Sep 2022 01:05:11 +0000 (01:05 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 14 Sep 2022 20:09:36 +0000 (20:09 +0000)
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.

In anticipation of removing the `known` constructor, this commit
removes all remaining references to it outside of features.rs.

lightning/src/chain/chainmonitor.rs
lightning/src/chain/channelmonitor.rs
lightning/src/ln/msgs.rs
lightning/src/ln/script.rs
lightning/src/onion_message/functional_tests.rs
lightning/src/routing/router.rs
lightning/src/util/test_utils.rs

index 3d84fdf93a52f391200fde732b0954e77e01d724..9f15a2a27996ba1e40faf27a97f80c27fb434659 100644 (file)
@@ -725,8 +725,7 @@ mod tests {
        use ::{get_htlc_update_msgs, get_local_commitment_txn, get_revoke_commit_msgs, get_route_and_payment_hash, unwrap_send_err};
        use chain::{ChannelMonitorUpdateErr, Confirm, Watch};
        use chain::channelmonitor::LATENCY_GRACE_PERIOD_BLOCKS;
-       use ln::channelmanager::PaymentSendFailure;
-       use ln::features::InitFeatures;
+       use ln::channelmanager::{self, PaymentSendFailure};
        use ln::functional_test_utils::*;
        use ln::msgs::ChannelMessageHandler;
        use util::errors::APIError;
@@ -741,7 +740,7 @@ mod tests {
                let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
                let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
                let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
-               create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
+               create_announced_chan_between_nodes(&nodes, 0, 1, channelmanager::provided_init_features(), channelmanager::provided_init_features());
 
                // Route two payments to be claimed at the same time.
                let (payment_preimage_1, payment_hash_1, _) = route_payment(&nodes[0], &[&nodes[1]], 1_000_000);
@@ -818,7 +817,7 @@ mod tests {
                let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
                let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
                let channel = create_announced_chan_between_nodes(
-                       &nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
+                       &nodes, 0, 1, channelmanager::provided_init_features(), channelmanager::provided_init_features());
 
                // Get a route for later and rebalance the channel somewhat
                send_payment(&nodes[0], &[&nodes[1]], 10_000_000);
@@ -894,7 +893,7 @@ mod tests {
                let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
                let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
                let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
-               create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
+               create_announced_chan_between_nodes(&nodes, 0, 1, channelmanager::provided_init_features(), channelmanager::provided_init_features());
 
                chanmon_cfgs[0].persister.chain_sync_monitor_persistences.lock().unwrap().clear();
                chanmon_cfgs[0].persister.set_update_ret(Err(ChannelMonitorUpdateErr::PermanentFailure));
index 28f3b59996c904c202b2bba0a62e476777005529..748adbd035983b574bccd4836e2f6aecd48a9323 100644 (file)
@@ -3767,8 +3767,7 @@ mod tests {
        use ln::{PaymentPreimage, PaymentHash};
        use ln::chan_utils;
        use ln::chan_utils::{HTLCOutputInCommitment, ChannelPublicKeys, ChannelTransactionParameters, HolderCommitmentTransaction, CounterpartyChannelTransactionParameters};
-       use ln::channelmanager::PaymentSendFailure;
-       use ln::features::InitFeatures;
+       use ln::channelmanager::{self, PaymentSendFailure};
        use ln::functional_test_utils::*;
        use ln::script::ShutdownScript;
        use util::errors::APIError;
@@ -3797,9 +3796,9 @@ mod tests {
                let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]);
                let nodes = create_network(3, &node_cfgs, &node_chanmgrs);
                let channel = create_announced_chan_between_nodes(
-                       &nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
+                       &nodes, 0, 1, channelmanager::provided_init_features(), channelmanager::provided_init_features());
                create_announced_chan_between_nodes(
-                       &nodes, 1, 2, InitFeatures::known(), InitFeatures::known());
+                       &nodes, 1, 2, channelmanager::provided_init_features(), channelmanager::provided_init_features());
 
                // Rebalance somewhat
                send_payment(&nodes[0], &[&nodes[1]], 10_000_000);
index 6f2d25a2b70e35a66d7c5054068920b5bb042648..4c103e1199dfdf3c05d41c2ca3aa1d60de5fd384 100644 (file)
@@ -2063,7 +2063,7 @@ mod tests {
                let sig_2 = get_sig_on!(privkey_2, secp_ctx, String::from("01010101010101010101010101010101"));
                let sig_3 = get_sig_on!(privkey_3, secp_ctx, String::from("01010101010101010101010101010101"));
                let sig_4 = get_sig_on!(privkey_4, secp_ctx, String::from("01010101010101010101010101010101"));
-               let mut features = ChannelFeatures::known();
+               let mut features = ChannelFeatures::empty();
                if unknown_features_bits {
                        features = ChannelFeatures::from_le_bytes(vec![0xFF, 0xFF]);
                }
index 595085114b0cdec9ee5e2988fa869f5a264eef35..09363b6b51749f033bb482db1ac7b50b28ffaaf2 100644 (file)
@@ -7,6 +7,7 @@ use bitcoin::hash_types::{WPubkeyHash, WScriptHash};
 use bitcoin::secp256k1::PublicKey;
 use bitcoin::util::address::WitnessVersion;
 
+use ln::channelmanager;
 use ln::features::InitFeatures;
 use ln::msgs::DecodeError;
 use util::ser::{Readable, Writeable, Writer};
@@ -134,7 +135,7 @@ impl TryFrom<Script> for ShutdownScript {
        type Error = InvalidShutdownScript;
 
        fn try_from(script: Script) -> Result<Self, Self::Error> {
-               Self::try_from((script, &InitFeatures::known()))
+               Self::try_from((script, &channelmanager::provided_init_features()))
        }
 }
 
@@ -199,6 +200,12 @@ mod shutdown_script_tests {
                        .into_script()
        }
 
+       fn any_segwit_features() -> InitFeatures {
+               let mut features = InitFeatures::empty();
+               features.set_shutdown_any_segwit_optional();
+               features
+       }
+
        #[test]
        fn generates_p2wpkh_from_pubkey() {
                let pubkey = pubkey();
@@ -206,8 +213,8 @@ mod shutdown_script_tests {
                let p2wpkh_script = Script::new_v0_p2wpkh(&pubkey_hash);
 
                let shutdown_script = ShutdownScript::new_p2wpkh_from_pubkey(pubkey.inner);
-               assert!(shutdown_script.is_compatible(&InitFeatures::known()));
-               assert!(shutdown_script.is_compatible(&InitFeatures::known().clear_shutdown_anysegwit()));
+               assert!(shutdown_script.is_compatible(&any_segwit_features()));
+               assert!(shutdown_script.is_compatible(&InitFeatures::empty()));
                assert_eq!(shutdown_script.into_inner(), p2wpkh_script);
        }
 
@@ -217,8 +224,8 @@ mod shutdown_script_tests {
                let p2wpkh_script = Script::new_v0_p2wpkh(&pubkey_hash);
 
                let shutdown_script = ShutdownScript::new_p2wpkh(&pubkey_hash);
-               assert!(shutdown_script.is_compatible(&InitFeatures::known()));
-               assert!(shutdown_script.is_compatible(&InitFeatures::known().clear_shutdown_anysegwit()));
+               assert!(shutdown_script.is_compatible(&any_segwit_features()));
+               assert!(shutdown_script.is_compatible(&InitFeatures::empty()));
                assert_eq!(shutdown_script.into_inner(), p2wpkh_script);
                assert!(ShutdownScript::try_from(p2wpkh_script).is_ok());
        }
@@ -229,8 +236,8 @@ mod shutdown_script_tests {
                let p2wsh_script = Script::new_v0_p2wsh(&script_hash);
 
                let shutdown_script = ShutdownScript::new_p2wsh(&script_hash);
-               assert!(shutdown_script.is_compatible(&InitFeatures::known()));
-               assert!(shutdown_script.is_compatible(&InitFeatures::known().clear_shutdown_anysegwit()));
+               assert!(shutdown_script.is_compatible(&any_segwit_features()));
+               assert!(shutdown_script.is_compatible(&InitFeatures::empty()));
                assert_eq!(shutdown_script.into_inner(), p2wsh_script);
                assert!(ShutdownScript::try_from(p2wsh_script).is_ok());
        }
@@ -239,8 +246,8 @@ mod shutdown_script_tests {
        fn generates_segwit_from_non_v0_witness_program() {
                let witness_program = Script::new_witness_program(WitnessVersion::V16, &[0; 40]);
                let shutdown_script = ShutdownScript::new_witness_program(WitnessVersion::V16, &[0; 40]).unwrap();
-               assert!(shutdown_script.is_compatible(&InitFeatures::known()));
-               assert!(!shutdown_script.is_compatible(&InitFeatures::known().clear_shutdown_anysegwit()));
+               assert!(shutdown_script.is_compatible(&any_segwit_features()));
+               assert!(!shutdown_script.is_compatible(&InitFeatures::empty()));
                assert_eq!(shutdown_script.into_inner(), witness_program);
        }
 
index 1b1ce0a6e253519cfe9ebed0b3da74e8803a7d36..22389bf520393eae77daea625ade73682e6a38c1 100644 (file)
@@ -48,7 +48,7 @@ fn create_nodes(num_messengers: u8) -> Vec<MessengerNode> {
        }
        for idx in 0..num_messengers - 1 {
                let i = idx as usize;
-               let mut features = InitFeatures::known();
+               let mut features = InitFeatures::empty();
                features.set_onion_messages_optional();
                let init_msg = msgs::Init { features, remote_network_address: None };
                nodes[i].messenger.peer_connected(&nodes[i + 1].get_node_pk(), &init_msg.clone()).unwrap();
index 8fdc92ba8a3b3320c9fb66c7fc09e6aa90e25c34..801acaa2ecb308847847de38d21d3c8961ebcc47 100644 (file)
@@ -2860,7 +2860,7 @@ mod tests {
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
 
                // Disable nodes 1, 2, and 8 by requiring unknown feature bits
-               let mut unknown_features = NodeFeatures::known();
+               let mut unknown_features = NodeFeatures::empty();
                unknown_features.set_unknown_feature_required();
                add_or_update_node(&gossip_sync, &secp_ctx, &privkeys[0], unknown_features.clone(), 1);
                add_or_update_node(&gossip_sync, &secp_ctx, &privkeys[1], unknown_features.clone(), 1);
index ed15a2008f7e5c31c77986ab2acc211a77fd51a5..4ce51fc8bedc252c9eb59f45aa2564db29b07b5c 100644 (file)
@@ -385,7 +385,7 @@ fn get_dummy_channel_announcement(short_chan_id: u64) -> msgs::ChannelAnnounceme
        let node_1_btckey = SecretKey::from_slice(&[40; 32]).unwrap();
        let node_2_btckey = SecretKey::from_slice(&[39; 32]).unwrap();
        let unsigned_ann = msgs::UnsignedChannelAnnouncement {
-               features: ChannelFeatures::known(),
+               features: ChannelFeatures::empty(),
                chain_hash: genesis_block(network).header.block_hash(),
                short_channel_id: short_chan_id,
                node_id_1: PublicKey::from_secret_key(&secp_ctx, &node_1_privkey),