Merge pull request #2375 from TonyGiorgio/remove-doc-future-anchor-support
authorMatt Corallo <649246+TheBlueMatt@users.noreply.github.com>
Sun, 2 Jul 2023 20:10:10 +0000 (20:10 +0000)
committerGitHub <noreply@github.com>
Sun, 2 Jul 2023 20:10:10 +0000 (20:10 +0000)
Remove doc specifying future anchor support

15 files changed:
ci/ci-tests.sh
fuzz/src/chanmon_consistency.rs
fuzz/src/full_stack.rs
lightning-background-processor/src/lib.rs
lightning-invoice/src/utils.rs
lightning/src/chain/package.rs
lightning/src/ln/chan_utils.rs
lightning/src/ln/channel.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/functional_test_utils.rs
lightning/src/ln/outbound_payment.rs
lightning/src/ln/reload_tests.rs
lightning/src/routing/router.rs
lightning/src/routing/scoring.rs
lightning/src/util/time.rs

index b3af73f2169bc2cd91784c3801cef03307dd7525..40e118a2fd05094c965d6fecd4b6ae61505e1769 100755 (executable)
@@ -11,6 +11,9 @@ HOST_PLATFORM="$(rustc --version --verbose | grep "host:" | awk '{ print $2 }')"
 # Sadly the log crate is always a dependency of tokio until 1.20, and has no reasonable MSRV guarantees
 [ "$RUSTC_MINOR_VERSION" -lt 49 ] && cargo update -p log --precise "0.4.18" --verbose
 
+# The addr2line v0.20 crate (a dependency of `backtrace` starting with 0.3.68) relies on 1.55+
+[ "$RUSTC_MINOR_VERSION" -lt 55 ] && cargo update -p backtrace --precise "0.3.67" --verbose
+
 [ "$LDK_COVERAGE_BUILD" != "" ] && export RUSTFLAGS="-C link-dead-code"
 
 export RUST_BACKTRACE=1
index 309faaa95522f0773080cd9a82bd0aa822f6165b..8f2c30ffa0bc4b3cc0b0656e62b10d523c39e0ca 100644 (file)
@@ -436,11 +436,12 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {
                        config.channel_config.forwarding_fee_proportional_millionths = 0;
                        config.channel_handshake_config.announced_channel = true;
                        let network = Network::Bitcoin;
+                       let best_block_timestamp = genesis_block(network).header.time;
                        let params = ChainParameters {
                                network,
                                best_block: BestBlock::from_network(network),
                        };
-                       (ChannelManager::new($fee_estimator.clone(), monitor.clone(), broadcast.clone(), &router, Arc::clone(&logger), keys_manager.clone(), keys_manager.clone(), keys_manager.clone(), config, params),
+                       (ChannelManager::new($fee_estimator.clone(), monitor.clone(), broadcast.clone(), &router, Arc::clone(&logger), keys_manager.clone(), keys_manager.clone(), keys_manager.clone(), config, params, best_block_timestamp),
                        monitor, keys_manager)
                } }
        }
index 1192766bf3e0baadb5c61fef3c0c07dbff0f56f3..2b9449d72b8ed00c978bb3ad817062ccef0a1f9a 100644 (file)
@@ -441,11 +441,12 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
        config.channel_config.forwarding_fee_proportional_millionths =  slice_to_be32(get_slice!(4));
        config.channel_handshake_config.announced_channel = get_slice!(1)[0] != 0;
        let network = Network::Bitcoin;
+       let best_block_timestamp = genesis_block(network).header.time;
        let params = ChainParameters {
                network,
                best_block: BestBlock::from_network(network),
        };
-       let channelmanager = Arc::new(ChannelManager::new(fee_est.clone(), monitor.clone(), broadcast.clone(), &router, Arc::clone(&logger), keys_manager.clone(), keys_manager.clone(), keys_manager.clone(), config, params));
+       let channelmanager = Arc::new(ChannelManager::new(fee_est.clone(), monitor.clone(), broadcast.clone(), &router, Arc::clone(&logger), keys_manager.clone(), keys_manager.clone(), keys_manager.clone(), config, params, best_block_timestamp));
        // Adding new calls to `EntropySource::get_secure_random_bytes` during startup can change all the
        // keys subsequently generated in this test. Rather than regenerating all the messages manually,
        // it's easier to just increment the counter here so the keys don't change.
index 0cfa9801badb3a8d31a30cbdce81b93cbaab1f5a..401c3c19ec2200cf9fd101cbd1fdb2f5b3dcce5b 100644 (file)
@@ -1143,7 +1143,7 @@ mod tests {
                        let chain_monitor = Arc::new(chainmonitor::ChainMonitor::new(Some(chain_source.clone()), tx_broadcaster.clone(), logger.clone(), fee_estimator.clone(), persister.clone()));
                        let best_block = BestBlock::from_network(network);
                        let params = ChainParameters { network, best_block };
-                       let manager = Arc::new(ChannelManager::new(fee_estimator.clone(), chain_monitor.clone(), tx_broadcaster.clone(), router.clone(), logger.clone(), keys_manager.clone(), keys_manager.clone(), keys_manager.clone(), UserConfig::default(), params));
+                       let manager = Arc::new(ChannelManager::new(fee_estimator.clone(), chain_monitor.clone(), tx_broadcaster.clone(), router.clone(), logger.clone(), keys_manager.clone(), keys_manager.clone(), keys_manager.clone(), UserConfig::default(), params, genesis_block.header.time));
                        let p2p_gossip_sync = Arc::new(P2PGossipSync::new(network_graph.clone(), Some(chain_source.clone()), logger.clone()));
                        let rapid_gossip_sync = Arc::new(RapidGossipSync::new(network_graph.clone(), logger.clone()));
                        let msg_handler = MessageHandler {
index d8e7bf12726454cfec9ac0134e7f3ab9fd6a1406..c052706975968105c95b7dbf08c4ec7132b6c6c5 100644 (file)
@@ -1299,13 +1299,14 @@ mod test {
                } else {
                        None
                };
+               let genesis_timestamp = bitcoin::blockdata::constants::genesis_block(bitcoin::Network::Testnet).header.time as u64;
                let non_default_invoice_expiry_secs = 4200;
 
                let invoice =
                        crate::utils::create_phantom_invoice::<&test_utils::TestKeysInterface, &test_utils::TestKeysInterface, &test_utils::TestLogger>(
                                Some(payment_amt), payment_hash, "test".to_string(), non_default_invoice_expiry_secs,
                                route_hints, nodes[1].keys_manager, nodes[1].keys_manager, nodes[1].logger,
-                               Currency::BitcoinTestnet, None, Duration::from_secs(1234567)
+                               Currency::BitcoinTestnet, None, Duration::from_secs(genesis_timestamp)
                        ).unwrap();
                let (payment_hash, payment_secret) = (PaymentHash(invoice.payment_hash().into_inner()), *invoice.payment_secret());
                let payment_preimage = if user_generated_pmt_hash {
index 4576fde02153e2043f0316c509bafa82fa86cb10..9e61cbc4598772c1a9fa8cdd31a2f330dbd8c548 100644 (file)
@@ -247,7 +247,7 @@ impl Readable for CounterpartyOfferedHTLCOutput {
                let mut counterparty_htlc_base_key = RequiredWrapper(None);
                let mut preimage = RequiredWrapper(None);
                let mut htlc = RequiredWrapper(None);
-               let mut legacy_deserialization_prevention_marker: Option<()> = None;
+               let mut _legacy_deserialization_prevention_marker: Option<()> = None;
                let mut channel_type_features = None;
 
                read_tlv_fields!(reader, {
@@ -256,7 +256,7 @@ impl Readable for CounterpartyOfferedHTLCOutput {
                        (4, counterparty_htlc_base_key, required),
                        (6, preimage, required),
                        (8, htlc, required),
-                       (10, legacy_deserialization_prevention_marker, option),
+                       (10, _legacy_deserialization_prevention_marker, option),
                        (11, channel_type_features, option),
                });
 
@@ -321,7 +321,7 @@ impl Readable for CounterpartyReceivedHTLCOutput {
                let mut counterparty_delayed_payment_base_key = RequiredWrapper(None);
                let mut counterparty_htlc_base_key = RequiredWrapper(None);
                let mut htlc = RequiredWrapper(None);
-               let mut legacy_deserialization_prevention_marker: Option<()> = None;
+               let mut _legacy_deserialization_prevention_marker: Option<()> = None;
                let mut channel_type_features = None;
 
                read_tlv_fields!(reader, {
@@ -329,7 +329,7 @@ impl Readable for CounterpartyReceivedHTLCOutput {
                        (2, counterparty_delayed_payment_base_key, required),
                        (4, counterparty_htlc_base_key, required),
                        (6, htlc, required),
-                       (8, legacy_deserialization_prevention_marker, option),
+                       (8, _legacy_deserialization_prevention_marker, option),
                        (9, channel_type_features, option),
                });
 
@@ -399,14 +399,14 @@ impl Readable for HolderHTLCOutput {
                let mut amount_msat = RequiredWrapper(None);
                let mut cltv_expiry = RequiredWrapper(None);
                let mut preimage = None;
-               let mut legacy_deserialization_prevention_marker: Option<()> = None;
+               let mut _legacy_deserialization_prevention_marker: Option<()> = None;
                let mut channel_type_features = None;
 
                read_tlv_fields!(reader, {
                        (0, amount_msat, required),
                        (2, cltv_expiry, required),
                        (4, preimage, option),
-                       (6, legacy_deserialization_prevention_marker, option),
+                       (6, _legacy_deserialization_prevention_marker, option),
                        (7, channel_type_features, option),
                });
 
@@ -460,14 +460,14 @@ impl Writeable for HolderFundingOutput {
 impl Readable for HolderFundingOutput {
        fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
                let mut funding_redeemscript = RequiredWrapper(None);
-               let mut legacy_deserialization_prevention_marker: Option<()> = None;
+               let mut _legacy_deserialization_prevention_marker: Option<()> = None;
                let mut channel_type_features = None;
                let mut funding_amount = None;
 
                read_tlv_fields!(reader, {
                        (0, funding_redeemscript, required),
                        (1, channel_type_features, option),
-                       (2, legacy_deserialization_prevention_marker, option),
+                       (2, _legacy_deserialization_prevention_marker, option),
                        (3, funding_amount, option)
                });
 
index 0f5a453461a921d1072a7d718baa26b7b75972f1..fd27d2308664469034564691395c263adb1808bb 100644 (file)
@@ -938,7 +938,7 @@ impl Readable for ChannelTransactionParameters {
                let mut is_outbound_from_holder = RequiredWrapper(None);
                let mut counterparty_parameters = None;
                let mut funding_outpoint = None;
-               let mut legacy_deserialization_prevention_marker: Option<()> = None;
+               let mut _legacy_deserialization_prevention_marker: Option<()> = None;
                let mut channel_type_features = None;
 
                read_tlv_fields!(reader, {
@@ -947,7 +947,7 @@ impl Readable for ChannelTransactionParameters {
                        (4, is_outbound_from_holder, required),
                        (6, counterparty_parameters, option),
                        (8, funding_outpoint, option),
-                       (10, legacy_deserialization_prevention_marker, option),
+                       (10, _legacy_deserialization_prevention_marker, option),
                        (11, channel_type_features, option),
                });
 
@@ -1363,7 +1363,7 @@ impl Readable for CommitmentTransaction {
                let mut keys = RequiredWrapper(None);
                let mut built = RequiredWrapper(None);
                _init_tlv_field_var!(htlcs, vec_type);
-               let mut legacy_deserialization_prevention_marker: Option<()> = None;
+               let mut _legacy_deserialization_prevention_marker: Option<()> = None;
                let mut channel_type_features = None;
 
                read_tlv_fields!(reader, {
@@ -1374,7 +1374,7 @@ impl Readable for CommitmentTransaction {
                        (8, keys, required),
                        (10, built, required),
                        (12, htlcs, vec_type),
-                       (14, legacy_deserialization_prevention_marker, option),
+                       (14, _legacy_deserialization_prevention_marker, option),
                        (15, channel_type_features, option),
                });
 
index 4d6e02ccf69e4bdfa3e4fc3136991bae3fe1cdba..db38588230b77e153f967aba6781296fe459967d 100644 (file)
@@ -7405,7 +7405,7 @@ mod tests {
                }
        }
 
-       #[cfg(not(feature = "grind_signatures"))]
+       #[cfg(all(feature = "_test_vectors", not(feature = "grind_signatures")))]
        fn public_from_secret_hex(secp_ctx: &Secp256k1<bitcoin::secp256k1::All>, hex: &str) -> PublicKey {
                PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode(hex).unwrap()[..]).unwrap())
        }
index a03f11d57443f340713909cac761e057d7637ead..65f442f1c097ea80018e33f9c56d06f1f61cc072 100644 (file)
@@ -317,7 +317,7 @@ impl core::hash::Hash for HTLCSource {
        }
 }
 impl HTLCSource {
-       #[cfg(not(feature = "grind_signatures"))]
+       #[cfg(all(feature = "_test_vectors", not(feature = "grind_signatures")))]
        #[cfg(test)]
        pub fn dummy() -> Self {
                HTLCSource::OutboundRoute {
@@ -2007,6 +2007,8 @@ where
 {
        /// Constructs a new `ChannelManager` to hold several channels and route between them.
        ///
+       /// The current time or latest block header time can be provided as the `current_timestamp`.
+       ///
        /// This is the main "logic hub" for all channel-related actions, and implements
        /// [`ChannelMessageHandler`].
        ///
@@ -2020,7 +2022,11 @@ where
        /// [`block_connected`]: chain::Listen::block_connected
        /// [`block_disconnected`]: chain::Listen::block_disconnected
        /// [`params.best_block.block_hash`]: chain::BestBlock::block_hash
-       pub fn new(fee_est: F, chain_monitor: M, tx_broadcaster: T, router: R, logger: L, entropy_source: ES, node_signer: NS, signer_provider: SP, config: UserConfig, params: ChainParameters) -> Self {
+       pub fn new(
+               fee_est: F, chain_monitor: M, tx_broadcaster: T, router: R, logger: L, entropy_source: ES,
+               node_signer: NS, signer_provider: SP, config: UserConfig, params: ChainParameters,
+               current_timestamp: u32,
+       ) -> Self {
                let mut secp_ctx = Secp256k1::new();
                secp_ctx.seeded_randomize(&entropy_source.get_secure_random_bytes());
                let inbound_pmt_key_material = node_signer.get_inbound_payment_key_material();
@@ -2052,7 +2058,7 @@ where
 
                        probing_cookie_secret: entropy_source.get_secure_random_bytes(),
 
-                       highest_seen_timestamp: AtomicUsize::new(0),
+                       highest_seen_timestamp: AtomicUsize::new(current_timestamp as usize),
 
                        per_peer_state: FairRwLock::new(HashMap::new()),
 
@@ -10039,6 +10045,7 @@ pub mod bench {
                // Note that this is unrealistic as each payment send will require at least two fsync
                // calls per node.
                let network = bitcoin::Network::Testnet;
+               let genesis_block = bitcoin::blockdata::constants::genesis_block(network);
 
                let tx_broadcaster = test_utils::TestBroadcaster::new(network);
                let fee_estimator = test_utils::TestFeeEstimator { sat_per_kw: Mutex::new(253) };
@@ -10055,7 +10062,7 @@ pub mod bench {
                let node_a = ChannelManager::new(&fee_estimator, &chain_monitor_a, &tx_broadcaster, &router, &logger_a, &keys_manager_a, &keys_manager_a, &keys_manager_a, config.clone(), ChainParameters {
                        network,
                        best_block: BestBlock::from_network(network),
-               });
+               }, genesis_block.header.time);
                let node_a_holder = ANodeHolder { node: &node_a };
 
                let logger_b = test_utils::TestLogger::with_id("node a".to_owned());
@@ -10065,7 +10072,7 @@ pub mod bench {
                let node_b = ChannelManager::new(&fee_estimator, &chain_monitor_b, &tx_broadcaster, &router, &logger_b, &keys_manager_b, &keys_manager_b, &keys_manager_b, config.clone(), ChainParameters {
                        network,
                        best_block: BestBlock::from_network(network),
-               });
+               }, genesis_block.header.time);
                let node_b_holder = ANodeHolder { node: &node_b };
 
                node_a.peer_connected(&node_b.get_our_node_id(), &Init {
index a1ac66a800a9e6b98c8abb60261d8d83bb69a09b..64bd679a94f89cdf32402a2681166028fce44ca7 100644 (file)
@@ -2581,12 +2581,13 @@ pub fn create_node_chanmgrs<'a, 'b>(node_count: usize, cfgs: &'a Vec<NodeCfg<'b>
        let mut chanmgrs = Vec::new();
        for i in 0..node_count {
                let network = Network::Testnet;
+               let genesis_block = bitcoin::blockdata::constants::genesis_block(network);
                let params = ChainParameters {
                        network,
                        best_block: BestBlock::from_network(network),
                };
                let node = ChannelManager::new(cfgs[i].fee_estimator, &cfgs[i].chain_monitor, cfgs[i].tx_broadcaster, &cfgs[i].router, cfgs[i].logger, cfgs[i].keys_manager,
-                       cfgs[i].keys_manager, cfgs[i].keys_manager, if node_config[i].is_some() { node_config[i].clone().unwrap() } else { test_default_channel_config() }, params);
+                       cfgs[i].keys_manager, cfgs[i].keys_manager, if node_config[i].is_some() { node_config[i].clone().unwrap() } else { test_default_channel_config() }, params, genesis_block.header.time);
                chanmgrs.push(node);
        }
 
index 2ac24baa58b3466315c2628c711f17e4f3d17d73..546dc6c5bcd93171411263ff1c77229a08ea2ae1 100644 (file)
@@ -239,7 +239,7 @@ impl Retry {
                        },
                        #[cfg(all(not(feature = "no-std"), not(test)))]
                        (Retry::Timeout(max_duration), PaymentAttempts { first_attempted_at, .. }) =>
-                               *max_duration >= std::time::Instant::now().duration_since(*first_attempted_at),
+                               *max_duration >= crate::util::time::MonotonicTime::now().duration_since(*first_attempted_at),
                        #[cfg(all(not(feature = "no-std"), test))]
                        (Retry::Timeout(max_duration), PaymentAttempts { first_attempted_at, .. }) =>
                                *max_duration >= SinceEpoch::now().duration_since(*first_attempted_at),
@@ -274,7 +274,7 @@ pub(crate) struct PaymentAttemptsUsingTime<T: Time> {
 }
 
 #[cfg(not(any(feature = "no-std", test)))]
-type ConfiguredTime = std::time::Instant;
+type ConfiguredTime = crate::util::time::MonotonicTime;
 #[cfg(feature = "no-std")]
 type ConfiguredTime = crate::util::time::Eternity;
 #[cfg(all(not(feature = "no-std"), test))]
index bf2fb1de1e30d4a9ff3bf1fa5498d8f37fbbf5f8..b53c617916a16deb8efc52b0197dacd61f5af780 100644 (file)
@@ -384,7 +384,7 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
        fee_estimator = test_utils::TestFeeEstimator { sat_per_kw: Mutex::new(253) };
        persister = test_utils::TestPersister::new();
        let keys_manager = &chanmon_cfgs[0].keys_manager;
-       new_chain_monitor = test_utils::TestChainMonitor::new(Some(nodes[0].chain_source), nodes[0].tx_broadcaster.clone(), &logger, &fee_estimator, &persister, keys_manager);
+       new_chain_monitor = test_utils::TestChainMonitor::new(Some(nodes[0].chain_source), nodes[0].tx_broadcaster, &logger, &fee_estimator, &persister, keys_manager);
        nodes[0].chain_monitor = &new_chain_monitor;
 
 
index 7342e813a9ed906d4f6a45412203106a7445c59e..a8da26c23a630959190439f179cf1e00eb9a652c 100644 (file)
@@ -417,7 +417,7 @@ impl Readable for Route {
                let blinded_tails = blinded_tails.unwrap_or(Vec::new());
                if blinded_tails.len() != 0 {
                        if blinded_tails.len() != paths.len() { return Err(DecodeError::InvalidValue) }
-                       for (mut path, blinded_tail_opt) in paths.iter_mut().zip(blinded_tails.into_iter()) {
+                       for (path, blinded_tail_opt) in paths.iter_mut().zip(blinded_tails.into_iter()) {
                                path.blinded_tail = blinded_tail_opt;
                        }
                }
@@ -1221,7 +1221,7 @@ impl<'a> PaymentPath<'a> {
                                cur_hop_fees_msat = self.hops.get(i + 1).unwrap().0.hop_use_fee_msat;
                        }
 
-                       let mut cur_hop = &mut self.hops.get_mut(i).unwrap().0;
+                       let cur_hop = &mut self.hops.get_mut(i).unwrap().0;
                        cur_hop.next_hops_fee_msat = total_fee_paid_msat;
                        // Overpay in fees if we can't save these funds due to htlc_minimum_msat.
                        // We try to account for htlc_minimum_msat in scoring (add_entry!), so that nodes don't
index ee9c3d0c47356ddc53d9f7efc21f368b1ef77743..eca5ee6058b7841398b07d8137cd9842c9ec8e2d 100644 (file)
@@ -325,7 +325,7 @@ impl ReadableArgs<u64> for FixedPenaltyScorer {
 }
 
 #[cfg(not(feature = "no-std"))]
-type ConfiguredTime = std::time::Instant;
+type ConfiguredTime = crate::util::time::MonotonicTime;
 #[cfg(feature = "no-std")]
 use crate::util::time::Eternity;
 #[cfg(feature = "no-std")]
index f450dc2c3015ae4da00faa2d609d01542753b85d..0d969e7470952625d8db04965220c25df589f30f 100644 (file)
@@ -58,10 +58,20 @@ impl Sub<Duration> for Eternity {
        }
 }
 
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+#[cfg(not(feature = "no-std"))]
+pub struct MonotonicTime(std::time::Instant);
+
+/// The amount of time to shift `Instant` forward to prevent overflow when subtracting a `Duration`
+/// from `Instant::now` on some operating systems (e.g., iOS representing `Instance` as `u64`).
+#[cfg(not(feature = "no-std"))]
+const SHIFT: Duration = Duration::from_secs(10 * 365 * 24 * 60 * 60); // 10 years.
+
 #[cfg(not(feature = "no-std"))]
-impl Time for std::time::Instant {
+impl Time for MonotonicTime {
        fn now() -> Self {
-               std::time::Instant::now()
+               let instant = std::time::Instant::now().checked_add(SHIFT).expect("Overflow on MonotonicTime instantiation");
+               Self(instant)
        }
 
        fn duration_since(&self, earlier: Self) -> Duration {
@@ -70,15 +80,26 @@ impl Time for std::time::Instant {
                // clocks" that go backwards in practice (likely relatively ancient kernels/etc). Thus, we
                // manually check for time going backwards here and return a duration of zero in that case.
                let now = Self::now();
-               if now > earlier { now - earlier } else { Duration::from_secs(0) }
+               if now.0 > earlier.0 { now.0 - earlier.0 } else { Duration::from_secs(0) }
        }
 
        fn duration_since_epoch() -> Duration {
                use std::time::SystemTime;
                SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap()
        }
+
        fn elapsed(&self) -> Duration {
-               std::time::Instant::elapsed(self)
+               Self::now().0 - self.0
+       }
+}
+
+#[cfg(not(feature = "no-std"))]
+impl Sub<Duration> for MonotonicTime {
+       type Output = Self;
+
+       fn sub(self, other: Duration) -> Self {
+               let instant = self.0.checked_sub(other).expect("MonotonicTime is not supposed to go backward futher than 10 years");
+               Self(instant)
        }
 }
 
@@ -154,4 +175,15 @@ pub mod tests {
                assert_eq!(now.elapsed(), Duration::from_secs(0));
                assert_eq!(later - elapsed, now);
        }
+
+       #[test]
+       #[cfg(not(feature = "no-std"))]
+       fn monotonic_time_subtracts() {
+               let now = super::MonotonicTime::now();
+               assert!(now.elapsed() < Duration::from_secs(10));
+
+               let ten_years = Duration::from_secs(10 * 365 * 24 * 60 * 60);
+               let past = now - ten_years;
+               assert!(past.elapsed() >= ten_years);
+       }
 }