Merge pull request #2045 from wpaulino/fix-broken-commitment-test-vectors
authorMatt Corallo <649246+TheBlueMatt@users.noreply.github.com>
Tue, 14 Mar 2023 19:01:59 +0000 (19:01 +0000)
committerGitHub <noreply@github.com>
Tue, 14 Mar 2023 19:01:59 +0000 (19:01 +0000)
Update commitment test vectors

31 files changed:
.github/workflows/build.yml
CHANGELOG.md
lightning-background-processor/src/lib.rs
lightning-block-sync/Cargo.toml
lightning-block-sync/src/init.rs
lightning-block-sync/src/lib.rs
lightning-block-sync/src/poll.rs
lightning-block-sync/src/test_utils.rs
lightning-invoice/src/de.rs
lightning-invoice/src/lib.rs
lightning-invoice/src/payment.rs
lightning-invoice/src/ser.rs
lightning-invoice/src/utils.rs
lightning-net-tokio/Cargo.toml
lightning-net-tokio/src/lib.rs
lightning-persister/src/lib.rs
lightning-persister/src/util.rs
lightning-rapid-gossip-sync/src/lib.rs
lightning-transaction-sync/Cargo.toml
lightning-transaction-sync/src/esplora.rs
lightning-transaction-sync/src/lib.rs
lightning-transaction-sync/tests/integration_tests.rs
lightning/src/ln/channel.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/functional_test_utils.rs
lightning/src/ln/functional_tests.rs
lightning/src/ln/outbound_payment.rs
lightning/src/util/events.rs
lightning/src/util/ser.rs
lightning/src/util/ser_macros.rs
pending_changelog/2063.txt [new file with mode: 0644]

index 1c1472a1007cd214ff8248e186cbf5cfab1d8d89..100441d2be200cb85e6e70b296691851f9edb818 100644 (file)
@@ -86,6 +86,11 @@ jobs:
         run: cargo update -p tokio --precise "1.14.0" --verbose
         env:
           CARGO_NET_GIT_FETCH_WITH_CLI: "true"
+      - name: Pin tokio to 1.26 for Windows
+        if: "matrix.platform == 'windows-latest'"
+        run: cargo update -p tokio --precise "1.26.0" --verbose
+        env:
+          CARGO_NET_GIT_FETCH_WITH_CLI: "true"
       - name: Build on Rust ${{ matrix.toolchain }} with net-tokio
         if: "matrix.build-net-tokio && !matrix.coverage"
         run: cargo build --verbose --color always
@@ -127,18 +132,21 @@ jobs:
           cd lightning-transaction-sync
           cargo build --verbose --color always --features esplora-blocking
           cargo build --verbose --color always --features esplora-async
+          cargo build --verbose --color always --features esplora-async-https
       - name: Build transaction sync clients on Rust ${{ matrix.toolchain }} with features and full code-linking for coverage generation
         if: "matrix.build-tx-sync && matrix.coverage"
         run: |
           cd lightning-transaction-sync
           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features esplora-blocking
           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features esplora-async
+          RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features esplora-async-https
       - name: Test transaction sync clients on Rust ${{ matrix.toolchain }} with features
         if: "matrix.build-tx-sync"
         run: |
           cd lightning-transaction-sync
           cargo test --verbose --color always --features esplora-blocking
           cargo test --verbose --color always --features esplora-async
+          cargo test --verbose --color always --features esplora-async-https
       - name: Test backtrace-debug builds on Rust ${{ matrix.toolchain }}
         if: "matrix.toolchain == 'stable'"
         shell: bash # Default on Winblows is powershell
index e12c84a6b567240ed9d0e006f1c05f3516fcb885..d8475c003e0b2677f756fa117adf51ab9cc28f85 100644 (file)
@@ -22,7 +22,7 @@
    missing support for blinded path payments (#1927, #1908, #1926).
  * A `lightning-custom-message` crate has been added to make combining multiple
    custom messages into one enum/handler easier (#1832).
- * `Event::PaymentPathFailure` is now generated for failure to send an HTLC
+ * `Event::PaymentPathFailed` is now generated for failure to send an HTLC
    over the first hop on our local channel (#2014, #2043).
  * `lightning-net-tokio` no longer requires an `Arc` on `PeerManager` (#1968).
  * `ChannelManager::list_recent_payments` was added (#1873).
@@ -40,7 +40,7 @@
    if you downgrade prior to receipt (#1878).
  * `Event::PaymentPathFailed::network_update` will always be `None` if an
    0.0.114-generated event is read by a prior version of LDK (#2043).
- * `Event::PaymentPathFailed::all_paths_removed` will always be false if an
+ * `Event::PaymentPathFailed::all_paths_failed` will always be false if an
    0.0.114-generated event is read by a prior version of LDK. Users who rely on
    it to determine payment retries should migrate to `Event::PaymentFailed`, in
    a separate release prior to upgrading to LDK 0.0.114 if downgrading is
index a6de0a62fb07583ae29741b87d209c0e66ee7c5d..e407c4fdb82b27ff5d74f24812e35884ba21c014 100644 (file)
@@ -349,9 +349,9 @@ macro_rules! define_run_body {
                                                log_error!($logger, "Error: Failed to persist network graph, check your disk and permissions {}", e)
                                        }
 
-                                       last_prune_call = $get_timer(NETWORK_PRUNE_TIMER);
                                        have_pruned = true;
                                }
+                               last_prune_call = $get_timer(NETWORK_PRUNE_TIMER);
                        }
 
                        if $timer_elapsed(&mut last_scorer_persist_call, SCORER_PERSIST_TIMER) {
@@ -757,7 +757,7 @@ mod tests {
 
        impl Persister {
                fn new(data_dir: String) -> Self {
-                       let filesystem_persister = FilesystemPersister::new(data_dir.clone());
+                       let filesystem_persister = FilesystemPersister::new(data_dir);
                        Self { graph_error: None, graph_persistence_notifier: None, manager_error: None, scorer_error: None, filesystem_persister }
                }
 
@@ -824,7 +824,7 @@ mod tests {
                }
 
                fn expect(&mut self, expectation: TestResult) {
-                       self.event_expectations.get_or_insert_with(|| VecDeque::new()).push_back(expectation);
+                       self.event_expectations.get_or_insert_with(VecDeque::new).push_back(expectation);
                }
        }
 
@@ -1226,7 +1226,7 @@ mod tests {
                // Set up a background event handler for SpendableOutputs events.
                let (sender, receiver) = std::sync::mpsc::sync_channel(1);
                let event_handler = move |event: Event| match event {
-                       Event::SpendableOutputs { .. } => sender.send(event.clone()).unwrap(),
+                       Event::SpendableOutputs { .. } => sender.send(event).unwrap(),
                        Event::ChannelReady { .. } => {},
                        Event::ChannelClosed { .. } => {},
                        _ => panic!("Unexpected event: {:?}", event),
@@ -1274,7 +1274,7 @@ mod tests {
                let nodes = create_nodes(2, "test_not_pruning_network_graph_until_graph_sync_completion".to_string());
                let data_dir = nodes[0].persister.get_data_dir();
                let (sender, receiver) = std::sync::mpsc::sync_channel(1);
-               let persister = Arc::new(Persister::new(data_dir.clone()).with_graph_persistence_notifier(sender));
+               let persister = Arc::new(Persister::new(data_dir).with_graph_persistence_notifier(sender));
                let network_graph = nodes[0].network_graph.clone();
                let features = ChannelFeatures::empty();
                network_graph.add_channel_from_partial_announcement(42, 53, features, nodes[0].node.get_our_node_id(), nodes[1].node.get_our_node_id())
@@ -1317,7 +1317,7 @@ mod tests {
                // this should have added two channels
                assert_eq!(network_graph.read_only().channels().len(), 3);
 
-               let _ = receiver
+               receiver
                        .recv_timeout(Duration::from_secs(super::FIRST_NETWORK_PRUNE_TIMER * 5))
                        .expect("Network graph not pruned within deadline");
 
@@ -1344,7 +1344,7 @@ mod tests {
 
                let nodes = create_nodes(1, "test_payment_path_scoring".to_string());
                let data_dir = nodes[0].persister.get_data_dir();
-               let persister = Arc::new(Persister::new(data_dir.clone()));
+               let persister = Arc::new(Persister::new(data_dir));
                let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].no_gossip_sync(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), Some(nodes[0].scorer.clone()));
 
                let scored_scid = 4242;
@@ -1369,7 +1369,6 @@ mod tests {
                        failure: PathFailure::OnPath { network_update: None },
                        path: path.clone(),
                        short_channel_id: Some(scored_scid),
-                       retry: None,
                });
                let event = receiver
                        .recv_timeout(Duration::from_secs(EVENT_DEADLINE))
@@ -1389,7 +1388,6 @@ mod tests {
                        failure: PathFailure::OnPath { network_update: None },
                        path: path.clone(),
                        short_channel_id: None,
-                       retry: None,
                });
                let event = receiver
                        .recv_timeout(Duration::from_secs(EVENT_DEADLINE))
@@ -1431,7 +1429,7 @@ mod tests {
                nodes[0].node.push_pending_event(Event::ProbeFailed {
                        payment_id: PaymentId([42; 32]),
                        payment_hash: PaymentHash([42; 32]),
-                       path: path.clone(),
+                       path,
                        short_channel_id: Some(scored_scid),
                });
                let event = receiver
index 69c64a14f1e3006cef97bd484ff28ab18c684e98..894c3b528df83f500683eb0e1c53a8fa7560fffb 100644 (file)
@@ -28,4 +28,4 @@ chunked_transfer = { version = "1.4", optional = true }
 
 [dev-dependencies]
 lightning = { version = "0.0.114", path = "../lightning", features = ["_test_utils"] }
-tokio = { version = "~1.14", features = [ "macros", "rt" ] }
+tokio = { version = "1.14", features = [ "macros", "rt" ] }
index 2807bc877694c42b827d22a80cb2f17ce621edd0..866b247edee0b5e6e4b7a0b1faff0a857bfbfbc8 100644 (file)
@@ -181,7 +181,7 @@ pub async fn synchronize_listeners<B: Deref + Sized + Send + Sync, C: Cache, L:
                let chain_listener = &ChainListenerSet(chain_listeners_at_height);
                let mut chain_notifier = ChainNotifier { header_cache, chain_listener };
                chain_notifier.connect_blocks(common_ancestor, most_connected_blocks, &mut chain_poller)
-                       .await.or_else(|(e, _)| Err(e))?;
+                       .await.map_err(|(e, _)| e)?;
        }
 
        Ok(best_header)
index 0a7c655147ff0c85faf1297a2830d95b1f5746ce..5c7c0dee8c10c4dddaf3ea630238db5e59387650 100644 (file)
@@ -414,15 +414,15 @@ impl<'a, C: Cache, L: Deref> ChainNotifier<'a, C, L> where L::Target: chain::Lis
                        let height = header.height;
                        let block_data = chain_poller
                                .fetch_block(&header).await
-                               .or_else(|e| Err((e, Some(new_tip))))?;
+                               .map_err(|e| (e, Some(new_tip)))?;
                        debug_assert_eq!(block_data.block_hash, header.block_hash);
 
                        match block_data.deref() {
                                BlockData::FullBlock(block) => {
-                                       self.chain_listener.block_connected(&block, height);
+                                       self.chain_listener.block_connected(block, height);
                                },
                                BlockData::HeaderOnly(header) => {
-                                       self.chain_listener.filtered_block_connected(&header, &[], height);
+                                       self.chain_listener.filtered_block_connected(header, &[], height);
                                },
                        }
 
index 05ccd4504fde0d81a76646d91b44d9b2b1653711..9f7e8becf5060c2f62471825a2aa0cfeca573f5e 100644 (file)
@@ -61,7 +61,7 @@ impl Validate for BlockHeaderData {
        fn validate(self, block_hash: BlockHash) -> BlockSourceResult<Self::T> {
                let pow_valid_block_hash = self.header
                        .validate_pow(&self.header.target())
-                       .or_else(|e| Err(BlockSourceError::persistent(e)))?;
+                       .map_err(BlockSourceError::persistent)?;
 
                if pow_valid_block_hash != block_hash {
                        return Err(BlockSourceError::persistent("invalid block hash"));
@@ -82,7 +82,7 @@ impl Validate for BlockData {
 
                let pow_valid_block_hash = header
                        .validate_pow(&header.target())
-                       .or_else(|e| Err(BlockSourceError::persistent(e)))?;
+                       .map_err(BlockSourceError::persistent)?;
 
                if pow_valid_block_hash != block_hash {
                        return Err(BlockSourceError::persistent("invalid block hash"));
index b9bc519b9e84aeacfb5af3cd36c352bcb99915b2..597d2a85fd51ca8fae8274ec1e6b78adcdc5c9b4 100644 (file)
@@ -106,7 +106,7 @@ impl Blockchain {
                BlockHeaderData {
                        chainwork: self.blocks[0].header.work() + Uint256::from_u64(height as u64).unwrap(),
                        height: height as u32,
-                       header: self.blocks[height].header.clone(),
+                       header: self.blocks[height].header,
                }
        }
 
@@ -162,7 +162,7 @@ impl BlockSource for Blockchain {
                                        }
 
                                        if self.filtered_blocks {
-                                               return Ok(BlockData::HeaderOnly(block.header.clone()));
+                                               return Ok(BlockData::HeaderOnly(block.header));
                                        } else {
                                                return Ok(BlockData::FullBlock(block.clone()));
                                        }
index 92c1cb5c28f5385b5eb2f37c2cbbac62b58ac398..ab9fd9cb2bc21446920360759feefec87291f774 100644 (file)
@@ -6,7 +6,6 @@ use core::num::ParseIntError;
 use core::str;
 use core::str::FromStr;
 
-use bech32;
 use bech32::{u5, FromBase32};
 
 use bitcoin_hashes::Hash;
@@ -18,7 +17,6 @@ use lightning::routing::router::{RouteHint, RouteHintHop};
 
 use num_traits::{CheckedAdd, CheckedMul};
 
-use secp256k1;
 use secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
 use secp256k1::PublicKey;
 
@@ -323,9 +321,9 @@ impl FromStr for RawHrp {
                };
 
                Ok(RawHrp {
-                       currency: currency,
+                       currency,
                        raw_amount: amount,
-                       si_prefix: si_prefix,
+                       si_prefix,
                })
        }
 }
@@ -342,7 +340,7 @@ impl FromBase32 for RawDataPart {
                let tagged = parse_tagged_parts(&data[7..])?;
 
                Ok(RawDataPart {
-                       timestamp: timestamp,
+                       timestamp,
                        tagged_fields: tagged,
                })
        }
@@ -515,7 +513,7 @@ impl FromBase32 for ExpiryTime {
 
        fn from_base32(field_data: &[u5]) -> Result<ExpiryTime, ParseError> {
                match parse_int_be::<u64, u5>(field_data, 32)
-                       .map(|t| ExpiryTime::from_seconds(t))
+                       .map(ExpiryTime::from_seconds)
                {
                        Some(t) => Ok(t),
                        None => Err(ParseError::IntegerOverflowError),
@@ -540,7 +538,7 @@ impl FromBase32 for Fallback {
        type Err = ParseError;
 
        fn from_base32(field_data: &[u5]) -> Result<Fallback, ParseError> {
-               if field_data.len() < 1 {
+               if field_data.is_empty() {
                        return Err(ParseError::UnexpectedEndOfTaggedFields);
                }
 
@@ -554,7 +552,7 @@ impl FromBase32 for Fallback {
                                }
 
                                Ok(Fallback::SegWitProgram {
-                                       version: version,
+                                       version,
                                        program: bytes
                                })
                        },
index 17b6e2de2b6efe8582f9f78823289f306c9f4991..37c74922ee6957fcb1a0211808e6e13a62f18fac 100644 (file)
@@ -585,13 +585,13 @@ impl<D: tb::Bool, H: tb::Bool, C: tb::Bool, S: tb::Bool> InvoiceBuilder<D, H, tb
                }).collect::<Vec<_>>();
 
                let data = RawDataPart {
-                       timestamp: timestamp,
-                       tagged_fields: tagged_fields,
+                       timestamp,
+                       tagged_fields,
                };
 
                Ok(RawInvoice {
-                       hrp: hrp,
-                       data: data,
+                       hrp,
+                       data,
                })
        }
 }
@@ -781,7 +781,7 @@ impl SignedRawInvoice {
                        recovered_pub_key = Some(recovered);
                }
 
-               let pub_key = included_pub_key.or_else(|| recovered_pub_key.as_ref())
+               let pub_key = included_pub_key.or(recovered_pub_key.as_ref())
                        .expect("One is always present");
 
                let hash = Message::from_slice(&self.hash[..])
@@ -1014,9 +1014,9 @@ impl PositiveTimestamp {
 }
 
 #[cfg(feature = "std")]
-impl Into<SystemTime> for PositiveTimestamp {
-       fn into(self) -> SystemTime {
-               SystemTime::UNIX_EPOCH + self.0
+impl From<PositiveTimestamp> for SystemTime {
+       fn from(val: PositiveTimestamp) -> Self {
+               SystemTime::UNIX_EPOCH + val.0
        }
 }
 
@@ -1147,7 +1147,7 @@ impl Invoice {
        /// ```
        pub fn from_signed(signed_invoice: SignedRawInvoice) -> Result<Self, SemanticError> {
                let invoice = Invoice {
-                       signed_invoice: signed_invoice,
+                       signed_invoice,
                };
                invoice.check_field_counts()?;
                invoice.check_feature_bits()?;
@@ -1185,9 +1185,9 @@ impl Invoice {
        ///
        /// (C-not exported) because we don't yet export InvoiceDescription
        pub fn description(&self) -> InvoiceDescription {
-               if let Some(ref direct) = self.signed_invoice.description() {
+               if let Some(direct) = self.signed_invoice.description() {
                        return InvoiceDescription::Direct(direct);
-               } else if let Some(ref hash) = self.signed_invoice.description_hash() {
+               } else if let Some(hash) = self.signed_invoice.description_hash() {
                        return InvoiceDescription::Hash(hash);
                }
                unreachable!("ensured by constructor");
@@ -1332,9 +1332,9 @@ impl Description {
        }
 }
 
-impl Into<String> for Description {
-       fn into(self) -> String {
-               self.into_inner()
+impl From<Description> for String {
+       fn from(val: Description) -> Self {
+               val.into_inner()
        }
 }
 
@@ -1398,9 +1398,9 @@ impl PrivateRoute {
        }
 }
 
-impl Into<RouteHint> for PrivateRoute {
-       fn into(self) -> RouteHint {
-               self.into_inner()
+impl From<PrivateRoute> for RouteHint {
+       fn from(val: PrivateRoute) -> Self {
+               val.into_inner()
        }
 }
 
@@ -1766,7 +1766,7 @@ mod test {
 
                // Multiple payment secrets
                let invoice = {
-                       let mut invoice = invoice_template.clone();
+                       let mut invoice = invoice_template;
                        invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
                        invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
                        invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)))
@@ -1792,7 +1792,7 @@ mod test {
                assert_eq!(invoice.hrp.raw_amount, Some(15));
 
 
-               let invoice = builder.clone()
+               let invoice = builder
                        .amount_milli_satoshis(150)
                        .build_raw()
                        .unwrap();
@@ -1846,7 +1846,7 @@ mod test {
                        .build_raw();
                assert_eq!(long_route_res, Err(CreationError::RouteTooLong));
 
-               let sign_error_res = builder.clone()
+               let sign_error_res = builder
                        .description("Test".into())
                        .payment_secret(PaymentSecret([0; 32]))
                        .try_build_signed(|_| {
@@ -1876,7 +1876,7 @@ mod test {
 
                let route_1 = RouteHint(vec![
                        RouteHintHop {
-                               src_node_id: public_key.clone(),
+                               src_node_id: public_key,
                                short_channel_id: de::parse_int_be(&[123; 8], 256).expect("short chan ID slice too big?"),
                                fees: RoutingFees {
                                        base_msat: 2,
@@ -1887,7 +1887,7 @@ mod test {
                                htlc_maximum_msat: None,
                        },
                        RouteHintHop {
-                               src_node_id: public_key.clone(),
+                               src_node_id: public_key,
                                short_channel_id: de::parse_int_be(&[42; 8], 256).expect("short chan ID slice too big?"),
                                fees: RoutingFees {
                                        base_msat: 3,
@@ -1901,7 +1901,7 @@ mod test {
 
                let route_2 = RouteHint(vec![
                        RouteHintHop {
-                               src_node_id: public_key.clone(),
+                               src_node_id: public_key,
                                short_channel_id: 0,
                                fees: RoutingFees {
                                        base_msat: 4,
@@ -1912,7 +1912,7 @@ mod test {
                                htlc_maximum_msat: None,
                        },
                        RouteHintHop {
-                               src_node_id: public_key.clone(),
+                               src_node_id: public_key,
                                short_channel_id: de::parse_int_be(&[1; 8], 256).expect("short chan ID slice too big?"),
                                fees: RoutingFees {
                                        base_msat: 5,
@@ -1927,7 +1927,7 @@ mod test {
                let builder = InvoiceBuilder::new(Currency::BitcoinTestnet)
                        .amount_milli_satoshis(123)
                        .duration_since_epoch(Duration::from_secs(1234567))
-                       .payee_pub_key(public_key.clone())
+                       .payee_pub_key(public_key)
                        .expiry_time(Duration::from_secs(54321))
                        .min_final_cltv_expiry_delta(144)
                        .fallback(Fallback::PubKeyHash([0;20]))
index 981fd2e6ba49225c0e41fb2923ee56e480aea0b7..b1aee9e22b27f45913911adb2cfde4987056d8e9 100644 (file)
@@ -144,11 +144,11 @@ fn pay_invoice_using_amount<P: Deref>(
        invoice: &Invoice, amount_msats: u64, payment_id: PaymentId, retry_strategy: Retry,
        payer: P
 ) -> Result<(), PaymentError> where P::Target: Payer {
-       let payment_hash = PaymentHash(invoice.payment_hash().clone().into_inner());
-       let payment_secret = Some(invoice.payment_secret().clone());
+       let payment_hash = PaymentHash((*invoice.payment_hash()).into_inner());
+       let payment_secret = Some(*invoice.payment_secret());
        let mut payment_params = PaymentParameters::from_node_id(invoice.recover_payee_pub_key(),
                invoice.min_final_cltv_expiry_delta() as u32)
-               .with_expiry_time(expiry_time_from_unix_epoch(&invoice).as_secs())
+               .with_expiry_time(expiry_time_from_unix_epoch(invoice).as_secs())
                .with_route_hints(invoice.route_hints());
        if let Some(features) = invoice.features() {
                payment_params = payment_params.with_features(features.clone());
@@ -203,7 +203,7 @@ where
                payment_id: PaymentId, route_params: RouteParameters, retry_strategy: Retry
        ) -> Result<(), PaymentError> {
                self.send_payment_with_retry(payment_hash, payment_secret, payment_id, route_params, retry_strategy)
-                       .map_err(|e| PaymentError::Sending(e))
+                       .map_err(PaymentError::Sending)
        }
 }
 
@@ -344,7 +344,7 @@ mod tests {
                let invoice = invoice(payment_preimage);
                let amt_msat = 10_000;
 
-               match pay_zero_value_invoice(&invoice, amt_msat, Retry::Attempts(0), &nodes[0].node) {
+               match pay_zero_value_invoice(&invoice, amt_msat, Retry::Attempts(0), nodes[0].node) {
                        Err(PaymentError::Invoice("amount unexpected")) => {},
                        _ => panic!()
                }
index f5742289118ba1e21382ad899770d9fb028831ce..a6ccf873f3d0dd2117714a51fd267f954ca7f91a 100644 (file)
@@ -47,7 +47,7 @@ impl<'a, W: WriteBase32> BytesToBase32<'a, W> {
                        self.writer.write_u5(
                                u5::try_from_u8((self.buffer & 0b11111000) >> 3 ).expect("<32")
                        )?;
-                       self.buffer = self.buffer << 5;
+                       self.buffer <<= 5;
                        self.buffer_bits -= 5;
                }
 
@@ -58,7 +58,7 @@ impl<'a, W: WriteBase32> BytesToBase32<'a, W> {
 
                self.writer.write_u5(u5::try_from_u8(from_buffer | from_byte).expect("<32"))?;
                self.buffer = byte << (5 - self.buffer_bits);
-               self.buffer_bits = 3 + self.buffer_bits;
+               self.buffer_bits += 3;
 
                Ok(())
        }
@@ -75,7 +75,7 @@ impl<'a, W: WriteBase32> BytesToBase32<'a, W> {
                        self.writer.write_u5(
                                u5::try_from_u8((self.buffer & 0b11111000) >> 3).expect("<32")
                        )?;
-                       self.buffer = self.buffer << 5;
+                       self.buffer <<= 5;
                        self.buffer_bits -= 5;
                }
 
index 11a779b1028a8ddceb825cc833cceb57856d52f0..f837502e3e687db86bda72850ed7c2db4c801599 100644 (file)
@@ -141,7 +141,7 @@ where
        L::Target: Logger,
 {
 
-       if phantom_route_hints.len() == 0 {
+       if phantom_route_hints.is_empty() {
                return Err(SignOrCreationError::CreationError(
                        CreationError::MissingRouteHints,
                ));
@@ -549,11 +549,9 @@ fn filter_channels<L: Deref>(
                        }
                }
 
-               if channel.is_usable {
-                       if !online_channel_exists {
-                               log_trace!(logger, "Channel with connected peer exists for invoice route hints");
-                               online_channel_exists = true;
-                       }
+               if channel.is_usable && !online_channel_exists {
+                       log_trace!(logger, "Channel with connected peer exists for invoice route hints");
+                       online_channel_exists = true;
                }
 
                match filtered_channels.entry(channel.counterparty.node_id) {
@@ -660,7 +658,7 @@ mod test {
                create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 10001);
                let non_default_invoice_expiry_secs = 4200;
                let invoice = create_invoice_from_channelmanager_and_duration_since_epoch(
-                       &nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
+                       nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
                        Some(10_000), "test".to_string(), Duration::from_secs(1234567),
                        non_default_invoice_expiry_secs, None).unwrap();
                assert_eq!(invoice.amount_pico_btc(), Some(100_000));
@@ -693,14 +691,14 @@ mod test {
                let scorer = test_utils::TestScorer::new();
                let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
                let route = find_route(
-                       &nodes[0].node.get_our_node_id(), &route_params, &network_graph,
+                       &nodes[0].node.get_our_node_id(), &route_params, network_graph,
                        Some(&first_hops.iter().collect::<Vec<_>>()), &logger, &scorer, &random_seed_bytes
                ).unwrap();
 
                let payment_event = {
                        let mut payment_hash = PaymentHash([0; 32]);
                        payment_hash.0.copy_from_slice(&invoice.payment_hash().as_ref()[0..32]);
-                       nodes[0].node.send_payment(&route, payment_hash, &Some(invoice.payment_secret().clone()), PaymentId(payment_hash.0)).unwrap();
+                       nodes[0].node.send_payment(&route, payment_hash, &Some(*invoice.payment_secret()), PaymentId(payment_hash.0)).unwrap();
                        let mut added_monitors = nodes[0].chain_monitor.added_monitors.lock().unwrap();
                        assert_eq!(added_monitors.len(), 1);
                        added_monitors.clear();
@@ -727,7 +725,7 @@ mod test {
                let custom_min_final_cltv_expiry_delta = Some(50);
 
                let invoice = crate::utils::create_invoice_from_channelmanager_and_duration_since_epoch(
-                       &nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
+                       nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
                        Some(10_000), "".into(), Duration::from_secs(1234567), 3600,
                        if with_custom_delta { custom_min_final_cltv_expiry_delta } else { None },
                ).unwrap();
@@ -750,7 +748,7 @@ mod test {
                let custom_min_final_cltv_expiry_delta = Some(21);
 
                let invoice = crate::utils::create_invoice_from_channelmanager_and_duration_since_epoch(
-                       &nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
+                       nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
                        Some(10_000), "".into(), Duration::from_secs(1234567), 3600,
                        custom_min_final_cltv_expiry_delta,
                ).unwrap();
@@ -765,7 +763,7 @@ mod test {
                let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
                let description_hash = crate::Sha256(Hash::hash("Testing description_hash".as_bytes()));
                let invoice = crate::utils::create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch(
-                       &nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
+                       nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
                        Some(10_000), description_hash, Duration::from_secs(1234567), 3600, None,
                ).unwrap();
                assert_eq!(invoice.amount_pico_btc(), Some(100_000));
@@ -781,7 +779,7 @@ mod test {
                let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
                let payment_hash = PaymentHash([0; 32]);
                let invoice = crate::utils::create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash(
-                       &nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
+                       nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
                        Some(10_000), "test".to_string(), Duration::from_secs(1234567), 3600,
                        payment_hash, None,
                ).unwrap();
@@ -972,7 +970,7 @@ mod test {
                mut chan_ids_to_match: HashSet<u64>
        ) {
                let invoice = create_invoice_from_channelmanager_and_duration_since_epoch(
-                       &invoice_node.node, invoice_node.keys_manager, invoice_node.logger,
+                       invoice_node.node, invoice_node.keys_manager, invoice_node.logger,
                        Currency::BitcoinTestnet, invoice_amt, "test".to_string(), Duration::from_secs(1234567),
                        3600, None).unwrap();
                let hints = invoice.private_routes();
@@ -994,9 +992,9 @@ mod test {
        #[cfg(feature = "std")]
        fn do_test_multi_node_receive(user_generated_pmt_hash: bool) {
                let mut chanmon_cfgs = create_chanmon_cfgs(3);
-               let seed_1 = [42 as u8; 32];
-               let seed_2 = [43 as u8; 32];
-               let cross_node_seed = [44 as u8; 32];
+               let seed_1 = [42u8; 32];
+               let seed_2 = [43u8; 32];
+               let cross_node_seed = [44u8; 32];
                chanmon_cfgs[1].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
                chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
                let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
@@ -1026,7 +1024,7 @@ mod test {
                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,
+                               route_hints, nodes[1].keys_manager, nodes[1].keys_manager, nodes[1].logger,
                                Currency::BitcoinTestnet, None, Duration::from_secs(1234567)
                        ).unwrap();
                let (payment_hash, payment_secret) = (PaymentHash(invoice.payment_hash().into_inner()), *invoice.payment_secret());
@@ -1056,13 +1054,13 @@ mod test {
                let scorer = test_utils::TestScorer::new();
                let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
                let route = find_route(
-                       &nodes[0].node.get_our_node_id(), &params, &network_graph,
+                       &nodes[0].node.get_our_node_id(), &params, network_graph,
                        Some(&first_hops.iter().collect::<Vec<_>>()), &logger, &scorer, &random_seed_bytes
                ).unwrap();
                let (payment_event, fwd_idx) = {
                        let mut payment_hash = PaymentHash([0; 32]);
                        payment_hash.0.copy_from_slice(&invoice.payment_hash().as_ref()[0..32]);
-                       nodes[0].node.send_payment(&route, payment_hash, &Some(invoice.payment_secret().clone()), PaymentId(payment_hash.0)).unwrap();
+                       nodes[0].node.send_payment(&route, payment_hash, &Some(*invoice.payment_secret()), PaymentId(payment_hash.0)).unwrap();
                        let mut added_monitors = nodes[0].chain_monitor.added_monitors.lock().unwrap();
                        assert_eq!(added_monitors.len(), 1);
                        added_monitors.clear();
@@ -1092,7 +1090,7 @@ mod test {
 
                let payment_preimage_opt = if user_generated_pmt_hash { None } else { Some(payment_preimage) };
                expect_payment_claimable!(&nodes[fwd_idx], payment_hash, payment_secret, payment_amt, payment_preimage_opt, route.paths[0].last().unwrap().pubkey);
-               do_claim_payment_along_route(&nodes[0], &vec!(&vec!(&nodes[fwd_idx])[..]), false, payment_preimage);
+               do_claim_payment_along_route(&nodes[0], &[&vec!(&nodes[fwd_idx])[..]], false, payment_preimage);
                let events = nodes[0].node.get_and_clear_pending_events();
                assert_eq!(events.len(), 2);
                match events[0] {
@@ -1115,9 +1113,9 @@ mod test {
        #[cfg(feature = "std")]
        fn test_multi_node_hints_has_htlc_min_max_values() {
                let mut chanmon_cfgs = create_chanmon_cfgs(3);
-               let seed_1 = [42 as u8; 32];
-               let seed_2 = [43 as u8; 32];
-               let cross_node_seed = [44 as u8; 32];
+               let seed_1 = [42u8; 32];
+               let seed_2 = [43u8; 32];
+               let cross_node_seed = [44u8; 32];
                chanmon_cfgs[1].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
                chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
                let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
@@ -1136,8 +1134,8 @@ mod test {
 
                let invoice = crate::utils::create_phantom_invoice::<&test_utils::TestKeysInterface,
                        &test_utils::TestKeysInterface, &test_utils::TestLogger>(Some(payment_amt), Some(payment_hash),
-                               "test".to_string(), 3600, route_hints, &nodes[1].keys_manager, &nodes[1].keys_manager,
-                               &nodes[1].logger, Currency::BitcoinTestnet, None, Duration::from_secs(1234567)).unwrap();
+                               "test".to_string(), 3600, route_hints, nodes[1].keys_manager, nodes[1].keys_manager,
+                               nodes[1].logger, Currency::BitcoinTestnet, None, Duration::from_secs(1234567)).unwrap();
 
                let chan_0_1 = &nodes[1].node.list_usable_channels()[0];
                assert_eq!(invoice.route_hints()[0].0[0].htlc_minimum_msat, chan_0_1.inbound_htlc_minimum_msat);
@@ -1168,7 +1166,7 @@ mod test {
                        &test_utils::TestKeysInterface, &test_utils::TestKeysInterface, &test_utils::TestLogger,
                >(
                        Some(payment_amt), None, non_default_invoice_expiry_secs, description_hash,
-                       route_hints, &nodes[1].keys_manager, &nodes[1].keys_manager, &nodes[1].logger,
+                       route_hints, nodes[1].keys_manager, nodes[1].keys_manager, nodes[1].logger,
                        Currency::BitcoinTestnet, None, Duration::from_secs(1234567),
                )
                .unwrap();
@@ -1198,8 +1196,8 @@ mod test {
                let duration_since_epoch = Duration::from_secs(1234567);
                let invoice = crate::utils::create_phantom_invoice::<&test_utils::TestKeysInterface,
                        &test_utils::TestKeysInterface, &test_utils::TestLogger>(Some(payment_amt), payment_hash,
-                               "".to_string(), non_default_invoice_expiry_secs, route_hints, &nodes[1].keys_manager, &nodes[1].keys_manager,
-                               &nodes[1].logger, Currency::BitcoinTestnet, min_final_cltv_expiry_delta, duration_since_epoch).unwrap();
+                               "".to_string(), non_default_invoice_expiry_secs, route_hints, nodes[1].keys_manager, nodes[1].keys_manager,
+                               nodes[1].logger, Currency::BitcoinTestnet, min_final_cltv_expiry_delta, duration_since_epoch).unwrap();
                assert_eq!(invoice.amount_pico_btc(), Some(200_000));
                assert_eq!(invoice.min_final_cltv_expiry_delta(), (min_final_cltv_expiry_delta.unwrap() + 3) as u64);
                assert_eq!(invoice.expiry_time(), Duration::from_secs(non_default_invoice_expiry_secs.into()));
@@ -1209,9 +1207,9 @@ mod test {
        #[cfg(feature = "std")]
        fn test_multi_node_hints_includes_single_channels_to_participating_nodes() {
                let mut chanmon_cfgs = create_chanmon_cfgs(3);
-               let seed_1 = [42 as u8; 32];
-               let seed_2 = [43 as u8; 32];
-               let cross_node_seed = [44 as u8; 32];
+               let seed_1 = [42u8; 32];
+               let seed_2 = [43u8; 32];
+               let cross_node_seed = [44u8; 32];
                chanmon_cfgs[1].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
                chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
                let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
@@ -1238,9 +1236,9 @@ mod test {
        #[cfg(feature = "std")]
        fn test_multi_node_hints_includes_one_channel_of_each_counterparty_nodes_per_participating_node() {
                let mut chanmon_cfgs = create_chanmon_cfgs(4);
-               let seed_1 = [42 as u8; 32];
-               let seed_2 = [43 as u8; 32];
-               let cross_node_seed = [44 as u8; 32];
+               let seed_1 = [42u8; 32];
+               let seed_2 = [43u8; 32];
+               let cross_node_seed = [44u8; 32];
                chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
                chanmon_cfgs[3].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
                let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
@@ -1269,9 +1267,9 @@ mod test {
        #[cfg(feature = "std")]
        fn test_multi_node_forwarding_info_not_assigned_channel_excluded_from_hints() {
                let mut chanmon_cfgs = create_chanmon_cfgs(4);
-               let seed_1 = [42 as u8; 32];
-               let seed_2 = [43 as u8; 32];
-               let cross_node_seed = [44 as u8; 32];
+               let seed_1 = [42u8; 32];
+               let seed_2 = [43u8; 32];
+               let cross_node_seed = [44u8; 32];
                chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
                chanmon_cfgs[3].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
                let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
@@ -1327,9 +1325,9 @@ mod test {
        #[cfg(feature = "std")]
        fn test_multi_node_with_only_public_channels_hints_includes_only_phantom_route() {
                let mut chanmon_cfgs = create_chanmon_cfgs(3);
-               let seed_1 = [42 as u8; 32];
-               let seed_2 = [43 as u8; 32];
-               let cross_node_seed = [44 as u8; 32];
+               let seed_1 = [42u8; 32];
+               let seed_2 = [43u8; 32];
+               let cross_node_seed = [44u8; 32];
                chanmon_cfgs[1].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
                chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
                let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
@@ -1360,9 +1358,9 @@ mod test {
        #[cfg(feature = "std")]
        fn test_multi_node_with_mixed_public_and_private_channel_hints_includes_only_phantom_route() {
                let mut chanmon_cfgs = create_chanmon_cfgs(4);
-               let seed_1 = [42 as u8; 32];
-               let seed_2 = [43 as u8; 32];
-               let cross_node_seed = [44 as u8; 32];
+               let seed_1 = [42u8; 32];
+               let seed_2 = [43u8; 32];
+               let cross_node_seed = [44u8; 32];
                chanmon_cfgs[1].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
                chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
                let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
@@ -1394,9 +1392,9 @@ mod test {
        #[cfg(feature = "std")]
        fn test_multi_node_hints_has_only_highest_inbound_capacity_channel() {
                let mut chanmon_cfgs = create_chanmon_cfgs(3);
-               let seed_1 = [42 as u8; 32];
-               let seed_2 = [43 as u8; 32];
-               let cross_node_seed = [44 as u8; 32];
+               let seed_1 = [42u8; 32];
+               let seed_2 = [43u8; 32];
+               let cross_node_seed = [44u8; 32];
                chanmon_cfgs[1].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
                chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
                let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
@@ -1425,9 +1423,9 @@ mod test {
        #[cfg(feature = "std")]
        fn test_multi_node_channels_inbound_capacity_lower_than_invoice_amt_filtering() {
                let mut chanmon_cfgs = create_chanmon_cfgs(4);
-               let seed_1 = [42 as u8; 32];
-               let seed_2 = [43 as u8; 32];
-               let cross_node_seed = [44 as u8; 32];
+               let seed_1 = [42u8; 32];
+               let seed_2 = [43u8; 32];
+               let cross_node_seed = [44u8; 32];
                chanmon_cfgs[1].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
                chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
                let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
@@ -1512,8 +1510,8 @@ mod test {
 
                let invoice = crate::utils::create_phantom_invoice::<&test_utils::TestKeysInterface,
                        &test_utils::TestKeysInterface, &test_utils::TestLogger>(invoice_amt, None, "test".to_string(),
-                               3600, phantom_route_hints, &invoice_node.keys_manager, &invoice_node.keys_manager,
-                               &invoice_node.logger, Currency::BitcoinTestnet, None, Duration::from_secs(1234567)).unwrap();
+                               3600, phantom_route_hints, invoice_node.keys_manager, invoice_node.keys_manager,
+                               invoice_node.logger, Currency::BitcoinTestnet, None, Duration::from_secs(1234567)).unwrap();
 
                let invoice_hints = invoice.private_routes();
 
@@ -1544,7 +1542,7 @@ mod test {
                let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
                let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
                let result = crate::utils::create_invoice_from_channelmanager_and_duration_since_epoch(
-                       &nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
+                       nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
                        Some(10_000), "Some description".into(), Duration::from_secs(1234567), 3600, Some(MIN_FINAL_CLTV_EXPIRY_DELTA - 4),
                );
                match result {
index 203fbc9b815c5f96a743eea259eaec656a1d45b0..6250628d24ae8786971ffba6b46e7d3b093a71ad 100644 (file)
@@ -20,5 +20,5 @@ lightning = { version = "0.0.114", path = "../lightning" }
 tokio = { version = "1.0", features = [ "io-util", "macros", "rt", "sync", "net", "time" ] }
 
 [dev-dependencies]
-tokio = { version = "~1.14", features = [ "io-util", "macros", "rt", "rt-multi-thread", "sync", "net", "time" ] }
+tokio = { version = "1.14", features = [ "io-util", "macros", "rt", "rt-multi-thread", "sync", "net", "time" ] }
 lightning = { version = "0.0.114", path = "../lightning", features = ["_test_utils"] }
index 81e6157c656f6e39e76525e33ca09e1b55870325..a513e603efe54d2654bdce1a59a74b59fa9e9b93 100644 (file)
@@ -205,7 +205,7 @@ impl Connection {
                        tokio::select! {
                                v = write_avail_receiver.recv() => {
                                        assert!(v.is_some()); // We can't have dropped the sending end, its in the us Arc!
-                                       if let Err(_) = peer_manager.write_buffer_space_avail(&mut our_descriptor) {
+                                       if peer_manager.write_buffer_space_avail(&mut our_descriptor).is_err() {
                                                break Disconnect::CloseConnection;
                                        }
                                },
@@ -313,7 +313,7 @@ pub fn setup_inbound<PM, CMH, RMH, OMH, L, UMH, NS>(
        #[cfg(test)]
        let last_us = Arc::clone(&us);
 
-       let handle_opt = if let Ok(_) = peer_manager.new_inbound_connection(SocketDescriptor::new(us.clone()), remote_addr) {
+       let handle_opt = if peer_manager.new_inbound_connection(SocketDescriptor::new(us.clone()), remote_addr).is_ok() {
                Some(tokio::spawn(Connection::schedule_read(peer_manager, us, reader, read_receiver, write_receiver)))
        } else {
                // Note that we will skip socket_disconnected here, in accordance with the PeerManager
index aaa3ef73d6c6f0e40f51a4c3684d0b4e1ced054b..488378576e5c24ca22bcc5b5de99514e94c8af6a 100644 (file)
@@ -176,7 +176,7 @@ mod tests {
 
                let chanmon_cfgs = create_chanmon_cfgs(1);
                let mut node_cfgs = create_node_cfgs(1, &chanmon_cfgs);
-               let chain_mon_0 = test_utils::TestChainMonitor::new(Some(&chanmon_cfgs[0].chain_source), &chanmon_cfgs[0].tx_broadcaster, &chanmon_cfgs[0].logger, &chanmon_cfgs[0].fee_estimator, &persister, &node_cfgs[0].keys_manager);
+               let chain_mon_0 = test_utils::TestChainMonitor::new(Some(&chanmon_cfgs[0].chain_source), &chanmon_cfgs[0].tx_broadcaster, &chanmon_cfgs[0].logger, &chanmon_cfgs[0].fee_estimator, &persister, node_cfgs[0].keys_manager);
                node_cfgs[0].chain_monitor = chain_mon_0;
                let node_chanmgrs = create_node_chanmgrs(1, &node_cfgs, &[None]);
                let nodes = create_network(1, &node_cfgs, &node_chanmgrs);
@@ -196,8 +196,8 @@ mod tests {
                let persister_1 = FilesystemPersister::new("test_filesystem_persister_1".to_string());
                let chanmon_cfgs = create_chanmon_cfgs(2);
                let mut node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
-               let chain_mon_0 = test_utils::TestChainMonitor::new(Some(&chanmon_cfgs[0].chain_source), &chanmon_cfgs[0].tx_broadcaster, &chanmon_cfgs[0].logger, &chanmon_cfgs[0].fee_estimator, &persister_0, &node_cfgs[0].keys_manager);
-               let chain_mon_1 = test_utils::TestChainMonitor::new(Some(&chanmon_cfgs[1].chain_source), &chanmon_cfgs[1].tx_broadcaster, &chanmon_cfgs[1].logger, &chanmon_cfgs[1].fee_estimator, &persister_1, &node_cfgs[1].keys_manager);
+               let chain_mon_0 = test_utils::TestChainMonitor::new(Some(&chanmon_cfgs[0].chain_source), &chanmon_cfgs[0].tx_broadcaster, &chanmon_cfgs[0].logger, &chanmon_cfgs[0].fee_estimator, &persister_0, node_cfgs[0].keys_manager);
+               let chain_mon_1 = test_utils::TestChainMonitor::new(Some(&chanmon_cfgs[1].chain_source), &chanmon_cfgs[1].tx_broadcaster, &chanmon_cfgs[1].logger, &chanmon_cfgs[1].fee_estimator, &persister_1, node_cfgs[1].keys_manager);
                node_cfgs[0].chain_monitor = chain_mon_0;
                node_cfgs[1].chain_monitor = chain_mon_1;
                let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
index 4adbb33e5b26fd886fb64d05d3d315efd3f28b16..20c4a8151854a4e2b1b51183487305e374d95f89 100644 (file)
@@ -102,10 +102,10 @@ mod tests {
                let test_writeable = TestWriteable{};
                let filename = "test_readonly_dir_persister_filename".to_string();
                let path = "test_readonly_dir_persister_dir";
-               fs::create_dir_all(path.to_string()).unwrap();
-               let mut perms = fs::metadata(path.to_string()).unwrap().permissions();
+               fs::create_dir_all(path).unwrap();
+               let mut perms = fs::metadata(path).unwrap().permissions();
                perms.set_readonly(true);
-               fs::set_permissions(path.to_string(), perms).unwrap();
+               fs::set_permissions(path, perms).unwrap();
                let mut dest_file = PathBuf::from(path);
                dest_file.push(filename);
                match write_to_file(dest_file, &test_writeable) {
index af235b1c4224d990f2a1d71881ab23e659d61e28..00aac9fd35873a8b31a218c2fa692a1664302c9a 100644 (file)
@@ -183,18 +183,17 @@ mod tests {
                                fs::create_dir_all(graph_sync_test_directory).unwrap();
 
                                let graph_sync_test_file = test.get_test_file_path();
-                               fs::write(&graph_sync_test_file, valid_response).unwrap();
+                               fs::write(graph_sync_test_file, valid_response).unwrap();
 
                                test
                        }
+
                        fn get_test_directory(&self) -> String {
-                               let graph_sync_test_directory = self.directory.clone() + "/graph-sync-tests";
-                               graph_sync_test_directory
+                               self.directory.clone() + "/graph-sync-tests"
                        }
+
                        fn get_test_file_path(&self) -> String {
-                               let graph_sync_test_directory = self.get_test_directory();
-                               let graph_sync_test_file = graph_sync_test_directory.to_owned() + "/test_data.lngossip";
-                               graph_sync_test_file
+                               self.get_test_directory() + "/test_data.lngossip"
                        }
                }
 
index 395410951db5c061f859b17d9fa7790dc4981e20..4ad581947404ea5aa462d1ec740855e2973efad7 100644 (file)
@@ -16,6 +16,7 @@ rustdoc-args = ["--cfg", "docsrs"]
 [features]
 default = []
 esplora-async = ["async-interface", "esplora-client/async", "futures"]
+esplora-async-https = ["esplora-async", "reqwest/rustls-tls"]
 esplora-blocking = ["esplora-client/blocking"]
 async-interface = []
 
@@ -25,6 +26,7 @@ bitcoin = { version = "0.29.0", default-features = false }
 bdk-macros = "0.6"
 futures = { version = "0.3", optional = true }
 esplora-client = { version = "0.3.0", default-features = false, optional = true }
+reqwest = { version = "0.11", optional = true, default-features = false, features = ["json"] }
 
 [dev-dependencies]
 lightning = { version = "0.0.114", path = "../lightning", features = ["std"] }
index 807ef8075005c13ba12a29d99a393aea72328ac3..f68be08a5a6c648e9c61a07aa1171ea420453365 100644 (file)
@@ -2,7 +2,7 @@ use crate::error::{TxSyncError, InternalError};
 use crate::common::{SyncState, FilterQueue, ConfirmedTx};
 
 use lightning::util::logger::Logger;
-use lightning::{log_error, log_given_level, log_info, log_internal, log_debug, log_trace};
+use lightning::{log_error, log_info, log_debug, log_trace};
 use lightning::chain::WatchedOutput;
 use lightning::chain::{Confirm, Filter};
 
index 791490d9dfcf2b90f8bfceae99b6ed31304ba23a..05b71d21bb5faaa05d5b0cebccb252b69e9e8db0 100644 (file)
@@ -7,8 +7,9 @@
 //!
 //! ## Features and Backend Support
 //!
-//!- `esplora_blocking` enables syncing against an Esplora backend based on a blocking client.
-//!- `esplora_async` enables syncing against an Esplora backend based on an async client.
+//!- `esplora-blocking` enables syncing against an Esplora backend based on a blocking client.
+//!- `esplora-async` enables syncing against an Esplora backend based on an async client.
+//!- `esplora-async-https` enables the async Esplora client with support for HTTPS.
 //!
 //! ## Version Compatibility
 //!
index 276aeabf9e049b706b27779e3445078226cdc226..d2f0c70a123c6ff6e935b874296440d78a2451c2 100644 (file)
@@ -348,3 +348,20 @@ async fn test_esplora_syncs() {
                _ => panic!("Unexpected event"),
        }
 }
+
+#[tokio::test]
+#[cfg(any(feature = "esplora-async-https", feature = "esplora-blocking"))]
+async fn test_esplora_connects_to_public_server() {
+       let mut logger = TestLogger {};
+       let esplora_url = "https://blockstream.info/api".to_string();
+       let tx_sync = EsploraSyncClient::new(esplora_url, &mut logger);
+       let confirmable = TestConfirmable::new();
+
+       // Check we connect and pick up on new best blocks
+       assert_eq!(confirmable.best_block.lock().unwrap().1, 0);
+       #[cfg(feature = "esplora-async-https")]
+       tx_sync.sync(vec![&confirmable]).await.unwrap();
+       #[cfg(feature = "esplora-blocking")]
+       tx_sync.sync(vec![&confirmable]).unwrap();
+       assert_ne!(confirmable.best_block.lock().unwrap().1, 0);
+}
index 618c05eecb8e5774bdba7cb58abff8aa0b74521b..1a1409c654d0ac08d1f8464abb44c6a838895171 100644 (file)
@@ -7118,7 +7118,6 @@ mod tests {
                                first_hop_htlc_msat: 548,
                                payment_id: PaymentId([42; 32]),
                                payment_secret: None,
-                               payment_params: None,
                        }
                });
 
index 2be585380058b32ee5115d9e9bfd0d8cc2eb7bc3..c4ebc8bc3fa60aba8092018b64e2459446218bf3 100644 (file)
@@ -53,7 +53,7 @@ use crate::ln::msgs::{ChannelMessageHandler, DecodeError, LightningError, MAX_VA
 use crate::ln::outbound_payment;
 use crate::ln::outbound_payment::{OutboundPayments, PaymentAttempts, PendingOutboundPayment};
 use crate::ln::wire::Encode;
-use crate::chain::keysinterface::{EntropySource, KeysManager, NodeSigner, Recipient, SignerProvider, ChannelSigner};
+use crate::chain::keysinterface::{EntropySource, KeysManager, NodeSigner, Recipient, SignerProvider, ChannelSigner, WriteableEcdsaChannelSigner};
 use crate::util::config::{UserConfig, ChannelConfig};
 use crate::util::events::{Event, EventHandler, EventsProvider, MessageSendEvent, MessageSendEventsProvider, ClosureReason, HTLCDestination};
 use crate::util::events;
@@ -275,11 +275,6 @@ pub(crate) enum HTLCSource {
                first_hop_htlc_msat: u64,
                payment_id: PaymentId,
                payment_secret: Option<PaymentSecret>,
-               /// Note that this is now "deprecated" - we write it for forwards (and read it for
-               /// backwards) compatibility reasons, but prefer to use the data in the
-               /// [`super::outbound_payment`] module, which stores per-payment data once instead of in
-               /// each HTLC.
-               payment_params: Option<PaymentParameters>,
        },
 }
 #[allow(clippy::derive_hash_xor_eq)] // Our Hash is faithful to the data, we just don't have SecretKey::hash
@@ -290,14 +285,13 @@ impl core::hash::Hash for HTLCSource {
                                0u8.hash(hasher);
                                prev_hop_data.hash(hasher);
                        },
-                       HTLCSource::OutboundRoute { path, session_priv, payment_id, payment_secret, first_hop_htlc_msat, payment_params } => {
+                       HTLCSource::OutboundRoute { path, session_priv, payment_id, payment_secret, first_hop_htlc_msat } => {
                                1u8.hash(hasher);
                                path.hash(hasher);
                                session_priv[..].hash(hasher);
                                payment_id.hash(hasher);
                                payment_secret.hash(hasher);
                                first_hop_htlc_msat.hash(hasher);
-                               payment_params.hash(hasher);
                        },
                }
        }
@@ -312,7 +306,6 @@ impl HTLCSource {
                        first_hop_htlc_msat: 0,
                        payment_id: PaymentId([2; 32]),
                        payment_secret: None,
-                       payment_params: None,
                }
        }
 }
@@ -1229,6 +1222,55 @@ impl ChannelDetails {
        pub fn get_outbound_payment_scid(&self) -> Option<u64> {
                self.short_channel_id.or(self.outbound_scid_alias)
        }
+
+       fn from_channel<Signer: WriteableEcdsaChannelSigner>(channel: &Channel<Signer>,
+               best_block_height: u32, latest_features: InitFeatures) -> Self {
+
+               let balance = channel.get_available_balances();
+               let (to_remote_reserve_satoshis, to_self_reserve_satoshis) =
+                       channel.get_holder_counterparty_selected_channel_reserve_satoshis();
+               ChannelDetails {
+                       channel_id: channel.channel_id(),
+                       counterparty: ChannelCounterparty {
+                               node_id: channel.get_counterparty_node_id(),
+                               features: latest_features,
+                               unspendable_punishment_reserve: to_remote_reserve_satoshis,
+                               forwarding_info: channel.counterparty_forwarding_info(),
+                               // Ensures that we have actually received the `htlc_minimum_msat` value
+                               // from the counterparty through the `OpenChannel` or `AcceptChannel`
+                               // message (as they are always the first message from the counterparty).
+                               // Else `Channel::get_counterparty_htlc_minimum_msat` could return the
+                               // default `0` value set by `Channel::new_outbound`.
+                               outbound_htlc_minimum_msat: if channel.have_received_message() {
+                                       Some(channel.get_counterparty_htlc_minimum_msat()) } else { None },
+                               outbound_htlc_maximum_msat: channel.get_counterparty_htlc_maximum_msat(),
+                       },
+                       funding_txo: channel.get_funding_txo(),
+                       // Note that accept_channel (or open_channel) is always the first message, so
+                       // `have_received_message` indicates that type negotiation has completed.
+                       channel_type: if channel.have_received_message() { Some(channel.get_channel_type().clone()) } else { None },
+                       short_channel_id: channel.get_short_channel_id(),
+                       outbound_scid_alias: if channel.is_usable() { Some(channel.outbound_scid_alias()) } else { None },
+                       inbound_scid_alias: channel.latest_inbound_scid_alias(),
+                       channel_value_satoshis: channel.get_value_satoshis(),
+                       unspendable_punishment_reserve: to_self_reserve_satoshis,
+                       balance_msat: balance.balance_msat,
+                       inbound_capacity_msat: balance.inbound_capacity_msat,
+                       outbound_capacity_msat: balance.outbound_capacity_msat,
+                       next_outbound_htlc_limit_msat: balance.next_outbound_htlc_limit_msat,
+                       user_channel_id: channel.get_user_id(),
+                       confirmations_required: channel.minimum_depth(),
+                       confirmations: Some(channel.get_funding_tx_confirmations(best_block_height)),
+                       force_close_spend_delay: channel.get_counterparty_selected_contest_delay(),
+                       is_outbound: channel.is_outbound(),
+                       is_channel_ready: channel.is_usable(),
+                       is_usable: channel.is_live(),
+                       is_public: channel.should_announce(),
+                       inbound_htlc_minimum_msat: Some(channel.get_holder_htlc_minimum_msat()),
+                       inbound_htlc_maximum_msat: channel.get_holder_htlc_maximum_msat(),
+                       config: Some(channel.config()),
+               }
+       }
 }
 
 /// Used by [`ChannelManager::list_recent_payments`] to express the status of recent payments.
@@ -1716,51 +1758,10 @@ where
                        for (_cp_id, peer_state_mutex) in per_peer_state.iter() {
                                let mut peer_state_lock = peer_state_mutex.lock().unwrap();
                                let peer_state = &mut *peer_state_lock;
-                               for (channel_id, channel) in peer_state.channel_by_id.iter().filter(f) {
-                                       let balance = channel.get_available_balances();
-                                       let (to_remote_reserve_satoshis, to_self_reserve_satoshis) =
-                                               channel.get_holder_counterparty_selected_channel_reserve_satoshis();
-                                       res.push(ChannelDetails {
-                                               channel_id: (*channel_id).clone(),
-                                               counterparty: ChannelCounterparty {
-                                                       node_id: channel.get_counterparty_node_id(),
-                                                       features: peer_state.latest_features.clone(),
-                                                       unspendable_punishment_reserve: to_remote_reserve_satoshis,
-                                                       forwarding_info: channel.counterparty_forwarding_info(),
-                                                       // Ensures that we have actually received the `htlc_minimum_msat` value
-                                                       // from the counterparty through the `OpenChannel` or `AcceptChannel`
-                                                       // message (as they are always the first message from the counterparty).
-                                                       // Else `Channel::get_counterparty_htlc_minimum_msat` could return the
-                                                       // default `0` value set by `Channel::new_outbound`.
-                                                       outbound_htlc_minimum_msat: if channel.have_received_message() {
-                                                               Some(channel.get_counterparty_htlc_minimum_msat()) } else { None },
-                                                       outbound_htlc_maximum_msat: channel.get_counterparty_htlc_maximum_msat(),
-                                               },
-                                               funding_txo: channel.get_funding_txo(),
-                                               // Note that accept_channel (or open_channel) is always the first message, so
-                                               // `have_received_message` indicates that type negotiation has completed.
-                                               channel_type: if channel.have_received_message() { Some(channel.get_channel_type().clone()) } else { None },
-                                               short_channel_id: channel.get_short_channel_id(),
-                                               outbound_scid_alias: if channel.is_usable() { Some(channel.outbound_scid_alias()) } else { None },
-                                               inbound_scid_alias: channel.latest_inbound_scid_alias(),
-                                               channel_value_satoshis: channel.get_value_satoshis(),
-                                               unspendable_punishment_reserve: to_self_reserve_satoshis,
-                                               balance_msat: balance.balance_msat,
-                                               inbound_capacity_msat: balance.inbound_capacity_msat,
-                                               outbound_capacity_msat: balance.outbound_capacity_msat,
-                                               next_outbound_htlc_limit_msat: balance.next_outbound_htlc_limit_msat,
-                                               user_channel_id: channel.get_user_id(),
-                                               confirmations_required: channel.minimum_depth(),
-                                               confirmations: Some(channel.get_funding_tx_confirmations(best_block_height)),
-                                               force_close_spend_delay: channel.get_counterparty_selected_contest_delay(),
-                                               is_outbound: channel.is_outbound(),
-                                               is_channel_ready: channel.is_usable(),
-                                               is_usable: channel.is_live(),
-                                               is_public: channel.should_announce(),
-                                               inbound_htlc_minimum_msat: Some(channel.get_holder_htlc_minimum_msat()),
-                                               inbound_htlc_maximum_msat: channel.get_holder_htlc_maximum_msat(),
-                                               config: Some(channel.config()),
-                                       });
+                               for (_channel_id, channel) in peer_state.channel_by_id.iter().filter(f) {
+                                       let details = ChannelDetails::from_channel(channel, best_block_height,
+                                               peer_state.latest_features.clone());
+                                       res.push(details);
                                }
                        }
                }
@@ -1786,6 +1787,24 @@ where
                self.list_channels_with_filter(|&(_, ref channel)| channel.is_live())
        }
 
+       /// Gets the list of channels we have with a given counterparty, in random order.
+       pub fn list_channels_with_counterparty(&self, counterparty_node_id: &PublicKey) -> Vec<ChannelDetails> {
+               let best_block_height = self.best_block.read().unwrap().height();
+               let per_peer_state = self.per_peer_state.read().unwrap();
+
+               if let Some(peer_state_mutex) = per_peer_state.get(counterparty_node_id) {
+                       let mut peer_state_lock = peer_state_mutex.lock().unwrap();
+                       let peer_state = &mut *peer_state_lock;
+                       let features = &peer_state.latest_features;
+                       return peer_state.channel_by_id
+                               .iter()
+                               .map(|(_, channel)|
+                                       ChannelDetails::from_channel(channel, best_block_height, features.clone()))
+                               .collect();
+               }
+               vec![]
+       }
+
        /// Returns in an undefined order recent payments that -- if not fulfilled -- have yet to find a
        /// successful path, or have unresolved HTLCs.
        ///
@@ -2441,12 +2460,12 @@ where
        }
 
        #[cfg(test)]
-       pub(crate) fn test_send_payment_along_path(&self, path: &Vec<RouteHop>, payment_params: &Option<PaymentParameters>, payment_hash: &PaymentHash, payment_secret: &Option<PaymentSecret>, total_value: u64, cur_height: u32, payment_id: PaymentId, keysend_preimage: &Option<PaymentPreimage>, session_priv_bytes: [u8; 32]) -> Result<(), APIError> {
+       pub(crate) fn test_send_payment_along_path(&self, path: &Vec<RouteHop>, payment_hash: &PaymentHash, payment_secret: &Option<PaymentSecret>, total_value: u64, cur_height: u32, payment_id: PaymentId, keysend_preimage: &Option<PaymentPreimage>, session_priv_bytes: [u8; 32]) -> Result<(), APIError> {
                let _lck = self.total_consistency_lock.read().unwrap();
-               self.send_payment_along_path(path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv_bytes)
+               self.send_payment_along_path(path, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv_bytes)
        }
 
-       fn send_payment_along_path(&self, path: &Vec<RouteHop>, payment_params: &Option<PaymentParameters>, payment_hash: &PaymentHash, payment_secret: &Option<PaymentSecret>, total_value: u64, cur_height: u32, payment_id: PaymentId, keysend_preimage: &Option<PaymentPreimage>, session_priv_bytes: [u8; 32]) -> Result<(), APIError> {
+       fn send_payment_along_path(&self, path: &Vec<RouteHop>, payment_hash: &PaymentHash, payment_secret: &Option<PaymentSecret>, total_value: u64, cur_height: u32, payment_id: PaymentId, keysend_preimage: &Option<PaymentPreimage>, session_priv_bytes: [u8; 32]) -> Result<(), APIError> {
                // The top-level caller should hold the total_consistency_lock read lock.
                debug_assert!(self.total_consistency_lock.try_write().is_err());
 
@@ -2485,7 +2504,6 @@ where
                                                first_hop_htlc_msat: htlc_msat,
                                                payment_id,
                                                payment_secret: payment_secret.clone(),
-                                               payment_params: payment_params.clone(),
                                        }, onion_packet, &self.logger);
                                match break_chan_entry!(self, send_res, chan) {
                                        Some(monitor_update) => {
@@ -2591,8 +2609,8 @@ where
                let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier);
                self.pending_outbound_payments
                        .send_payment_with_route(route, payment_hash, payment_secret, payment_id, &self.entropy_source, &self.node_signer, best_block_height,
-                               |path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv|
-                               self.send_payment_along_path(path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv))
+                               |path, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv|
+                               self.send_payment_along_path(path, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv))
        }
 
        /// Similar to [`ChannelManager::send_payment`], but will automatically find a route based on
@@ -2605,8 +2623,8 @@ where
                                &self.router, self.list_usable_channels(), || self.compute_inflight_htlcs(),
                                &self.entropy_source, &self.node_signer, best_block_height, &self.logger,
                                &self.pending_events,
-                               |path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv|
-                               self.send_payment_along_path(path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv))
+                               |path, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv|
+                               self.send_payment_along_path(path, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv))
        }
 
        #[cfg(test)]
@@ -2614,8 +2632,8 @@ where
                let best_block_height = self.best_block.read().unwrap().height();
                let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier);
                self.pending_outbound_payments.test_send_payment_internal(route, payment_hash, payment_secret, keysend_preimage, payment_id, recv_value_msat, onion_session_privs, &self.node_signer, best_block_height,
-                       |path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv|
-                       self.send_payment_along_path(path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv))
+                       |path, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv|
+                       self.send_payment_along_path(path, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv))
        }
 
        #[cfg(test)]
@@ -2667,8 +2685,8 @@ where
                self.pending_outbound_payments.send_spontaneous_payment_with_route(
                        route, payment_preimage, payment_id, &self.entropy_source, &self.node_signer,
                        best_block_height,
-                       |path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv|
-                       self.send_payment_along_path(path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv))
+                       |path, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv|
+                       self.send_payment_along_path(path, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv))
        }
 
        /// Similar to [`ChannelManager::send_spontaneous_payment`], but will automatically find a route
@@ -2685,8 +2703,8 @@ where
                        retry_strategy, route_params, &self.router, self.list_usable_channels(),
                        || self.compute_inflight_htlcs(),  &self.entropy_source, &self.node_signer, best_block_height,
                        &self.logger, &self.pending_events,
-                       |path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv|
-                       self.send_payment_along_path(path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv))
+                       |path, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv|
+                       self.send_payment_along_path(path, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv))
        }
 
        /// Send a payment that is probing the given route for liquidity. We calculate the
@@ -2696,8 +2714,8 @@ where
                let best_block_height = self.best_block.read().unwrap().height();
                let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier);
                self.pending_outbound_payments.send_probe(hops, self.probing_cookie_secret, &self.entropy_source, &self.node_signer, best_block_height,
-                       |path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv|
-                       self.send_payment_along_path(path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv))
+                       |path, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv|
+                       self.send_payment_along_path(path, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv))
        }
 
        /// Returns whether a payment with the given [`PaymentHash`] and [`PaymentId`] is, in fact, a
@@ -3421,8 +3439,8 @@ where
                self.pending_outbound_payments.check_retry_payments(&self.router, || self.list_usable_channels(),
                        || self.compute_inflight_htlcs(), &self.entropy_source, &self.node_signer, best_block_height,
                        &self.pending_events, &self.logger,
-                       |path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv|
-                       self.send_payment_along_path(path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv));
+                       |path, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv|
+                       self.send_payment_along_path(path, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv));
 
                for (htlc_source, payment_hash, failure_reason, destination) in failed_forwards.drain(..) {
                        self.fail_htlc_backwards_internal(&htlc_source, &payment_hash, &failure_reason, destination);
@@ -3808,9 +3826,9 @@ where
                // from block_connected which may run during initialization prior to the chain_monitor
                // being fully configured. See the docs for `ChannelManagerReadArgs` for more.
                match source {
-                       HTLCSource::OutboundRoute { ref path, ref session_priv, ref payment_id, ref payment_params, .. } => {
+                       HTLCSource::OutboundRoute { ref path, ref session_priv, ref payment_id, .. } => {
                                if self.pending_outbound_payments.fail_htlc(source, payment_hash, onion_error, path,
-                                       session_priv, payment_id, payment_params, self.probing_cookie_secret, &self.secp_ctx,
+                                       session_priv, payment_id, self.probing_cookie_secret, &self.secp_ctx,
                                        &self.pending_events, &self.logger)
                                { self.push_pending_forwards_ev(); }
                        },
@@ -6832,7 +6850,6 @@ impl Readable for HTLCSource {
                                        path,
                                        payment_id: payment_id.unwrap(),
                                        payment_secret,
-                                       payment_params,
                                })
                        }
                        1 => Ok(HTLCSource::PreviousHopData(Readable::read(reader)?)),
@@ -6844,7 +6861,7 @@ impl Readable for HTLCSource {
 impl Writeable for HTLCSource {
        fn write<W: Writer>(&self, writer: &mut W) -> Result<(), crate::io::Error> {
                match self {
-                       HTLCSource::OutboundRoute { ref session_priv, ref first_hop_htlc_msat, ref path, payment_id, payment_secret, payment_params } => {
+                       HTLCSource::OutboundRoute { ref session_priv, ref first_hop_htlc_msat, ref path, payment_id, payment_secret } => {
                                0u8.write(writer)?;
                                let payment_id_opt = Some(payment_id);
                                write_tlv_fields!(writer, {
@@ -6853,7 +6870,7 @@ impl Writeable for HTLCSource {
                                        (2, first_hop_htlc_msat, required),
                                        (3, payment_secret, option),
                                        (4, *path, vec_type),
-                                       (5, payment_params, option),
+                                       (5, None::<PaymentParameters>, option), // payment_params in LDK versions prior to 0.0.115
                                 });
                        }
                        HTLCSource::PreviousHopData(ref field) => {
@@ -7854,8 +7871,10 @@ mod tests {
                // to connect messages with new values
                chan.0.contents.fee_base_msat *= 2;
                chan.1.contents.fee_base_msat *= 2;
-               let node_a_chan_info = nodes[0].node.list_channels()[0].clone();
-               let node_b_chan_info = nodes[1].node.list_channels()[0].clone();
+               let node_a_chan_info = nodes[0].node.list_channels_with_counterparty(
+                       &nodes[1].node.get_our_node_id()).pop().unwrap();
+               let node_b_chan_info = nodes[1].node.list_channels_with_counterparty(
+                       &nodes[0].node.get_our_node_id()).pop().unwrap();
 
                // The first two nodes (which opened a channel) should now require fresh persistence
                assert!(nodes[0].node.await_persistable_update_timeout(Duration::from_millis(1)));
@@ -7931,7 +7950,7 @@ mod tests {
                // indicates there are more HTLCs coming.
                let cur_height = CHAN_CONFIRM_DEPTH + 1; // route_payment calls send_payment, which adds 1 to the current height. So we do the same here to match.
                let session_privs = nodes[0].node.test_add_new_pending_payment(our_payment_hash, Some(payment_secret), payment_id, &mpp_route).unwrap();
-               nodes[0].node.test_send_payment_along_path(&mpp_route.paths[0], &route.payment_params, &our_payment_hash, &Some(payment_secret), 200_000, cur_height, payment_id, &None, session_privs[0]).unwrap();
+               nodes[0].node.test_send_payment_along_path(&mpp_route.paths[0], &our_payment_hash, &Some(payment_secret), 200_000, cur_height, payment_id, &None, session_privs[0]).unwrap();
                check_added_monitors!(nodes[0], 1);
                let mut events = nodes[0].node.get_and_clear_pending_msg_events();
                assert_eq!(events.len(), 1);
@@ -7961,7 +7980,7 @@ mod tests {
                expect_payment_failed!(nodes[0], our_payment_hash, true);
 
                // Send the second half of the original MPP payment.
-               nodes[0].node.test_send_payment_along_path(&mpp_route.paths[1], &route.payment_params, &our_payment_hash, &Some(payment_secret), 200_000, cur_height, payment_id, &None, session_privs[1]).unwrap();
+               nodes[0].node.test_send_payment_along_path(&mpp_route.paths[1], &our_payment_hash, &Some(payment_secret), 200_000, cur_height, payment_id, &None, session_privs[1]).unwrap();
                check_added_monitors!(nodes[0], 1);
                let mut events = nodes[0].node.get_and_clear_pending_msg_events();
                assert_eq!(events.len(), 1);
index 1e99a475fe9f1501dd5042c8b4d344e55a7aa5f8..c8d3beb3cba8e3d899e96fc2717c8d4e7893660d 100644 (file)
@@ -1868,20 +1868,13 @@ pub fn expect_payment_failed_conditions_event<'a, 'b, 'c, 'd, 'e>(
 ) {
        if conditions.expected_mpp_parts_remain { assert_eq!(payment_failed_events.len(), 1); } else { assert_eq!(payment_failed_events.len(), 2); }
        let expected_payment_id = match &payment_failed_events[0] {
-               Event::PaymentPathFailed { payment_hash, payment_failed_permanently, path, retry, payment_id, failure, short_channel_id,
+               Event::PaymentPathFailed { payment_hash, payment_failed_permanently, payment_id, failure,
                        #[cfg(test)]
                        error_code,
                        #[cfg(test)]
                        error_data, .. } => {
                        assert_eq!(*payment_hash, expected_payment_hash, "unexpected payment_hash");
                        assert_eq!(*payment_failed_permanently, expected_payment_failed_permanently, "unexpected payment_failed_permanently value");
-                       assert!(retry.is_some(), "expected retry.is_some()");
-                       assert_eq!(retry.as_ref().unwrap().final_value_msat, path.last().unwrap().fee_msat, "Retry amount should match last hop in path");
-                       assert_eq!(retry.as_ref().unwrap().payment_params.payee_pubkey, path.last().unwrap().pubkey, "Retry payee node_id should match last hop in path");
-                       if let Some(scid) = short_channel_id {
-                               assert!(retry.as_ref().unwrap().payment_params.previously_failed_channels.contains(&scid));
-                       }
-
                        #[cfg(test)]
                        {
                                assert!(error_code.is_some(), "expected error_code.is_some() = true");
index 454fbe2b7819889e3246314a90ac82eed17f40f9..4fe5d041028c4a0fefbf8c4ea3dc6e69bda2f88b 100644 (file)
@@ -4083,7 +4083,7 @@ fn do_test_htlc_timeout(send_partial_mpp: bool) {
                let cur_height = CHAN_CONFIRM_DEPTH + 1; // route_payment calls send_payment, which adds 1 to the current height. So we do the same here to match.
                let payment_id = PaymentId([42; 32]);
                let session_privs = nodes[0].node.test_add_new_pending_payment(our_payment_hash, Some(payment_secret), payment_id, &route).unwrap();
-               nodes[0].node.test_send_payment_along_path(&route.paths[0], &route.payment_params, &our_payment_hash, &Some(payment_secret), 200_000, cur_height, payment_id, &None, session_privs[0]).unwrap();
+               nodes[0].node.test_send_payment_along_path(&route.paths[0], &our_payment_hash, &Some(payment_secret), 200_000, cur_height, payment_id, &None, session_privs[0]).unwrap();
                check_added_monitors!(nodes[0], 1);
                let mut events = nodes[0].node.get_and_clear_pending_msg_events();
                assert_eq!(events.len(), 1);
@@ -9130,7 +9130,6 @@ fn test_inconsistent_mpp_params() {
                if path_a[0].pubkey == nodes[1].node.get_our_node_id() {
                        core::cmp::Ordering::Less } else { core::cmp::Ordering::Greater }
        });
-       let payment_params_opt = Some(payment_params);
 
        let (our_payment_preimage, our_payment_hash, our_payment_secret) = get_payment_preimage_hash!(&nodes[3]);
 
@@ -9144,7 +9143,7 @@ fn test_inconsistent_mpp_params() {
                dup_route.paths.push(route.paths[1].clone());
                nodes[0].node.test_add_new_pending_payment(our_payment_hash, Some(our_payment_secret), payment_id, &dup_route).unwrap()
        };
-       nodes[0].node.test_send_payment_along_path(&route.paths[0], &payment_params_opt, &our_payment_hash, &Some(our_payment_secret), 15_000_000, cur_height, payment_id, &None, session_privs[0]).unwrap();
+       nodes[0].node.test_send_payment_along_path(&route.paths[0], &our_payment_hash, &Some(our_payment_secret), 15_000_000, cur_height, payment_id, &None, session_privs[0]).unwrap();
        check_added_monitors!(nodes[0], 1);
 
        {
@@ -9154,7 +9153,7 @@ fn test_inconsistent_mpp_params() {
        }
        assert!(nodes[3].node.get_and_clear_pending_events().is_empty());
 
-       nodes[0].node.test_send_payment_along_path(&route.paths[1], &payment_params_opt, &our_payment_hash, &Some(our_payment_secret), 14_000_000, cur_height, payment_id, &None, session_privs[1]).unwrap();
+       nodes[0].node.test_send_payment_along_path(&route.paths[1], &our_payment_hash, &Some(our_payment_secret), 14_000_000, cur_height, payment_id, &None, session_privs[1]).unwrap();
        check_added_monitors!(nodes[0], 1);
 
        {
@@ -9200,7 +9199,7 @@ fn test_inconsistent_mpp_params() {
 
        expect_payment_failed_conditions(&nodes[0], our_payment_hash, true, PaymentFailedConditions::new().mpp_parts_remain());
 
-       nodes[0].node.test_send_payment_along_path(&route.paths[1], &payment_params_opt, &our_payment_hash, &Some(our_payment_secret), 15_000_000, cur_height, payment_id, &None, session_privs[2]).unwrap();
+       nodes[0].node.test_send_payment_along_path(&route.paths[1], &our_payment_hash, &Some(our_payment_secret), 15_000_000, cur_height, payment_id, &None, session_privs[2]).unwrap();
        check_added_monitors!(nodes[0], 1);
 
        let mut events = nodes[0].node.get_and_clear_pending_msg_events();
index 86b4de768f830172d1caf411b5670667be60923e..6ede956b7d52df3a035d0fd308d505bcf2650bc5 100644 (file)
@@ -79,7 +79,9 @@ impl PendingOutboundPayment {
        }
        fn is_auto_retryable_now(&self) -> bool {
                match self {
-                       PendingOutboundPayment::Retryable { retry_strategy: Some(strategy), attempts, .. } => {
+                       PendingOutboundPayment::Retryable {
+                               retry_strategy: Some(strategy), attempts, payment_params: Some(_), ..
+                       } => {
                                strategy.is_retryable_now(&attempts)
                        },
                        _ => false,
@@ -97,14 +99,6 @@ impl PendingOutboundPayment {
                        _ => false,
                }
        }
-       fn payment_parameters(&mut self) -> Option<&mut PaymentParameters> {
-               match self {
-                       PendingOutboundPayment::Retryable { payment_params: Some(ref mut params), .. } => {
-                               Some(params)
-                       },
-                       _ => None,
-               }
-       }
        pub fn insert_previously_failed_scid(&mut self, scid: u64) {
                if let PendingOutboundPayment::Retryable { payment_params: Some(params), .. } = self {
                        params.previously_failed_channels.push(scid);
@@ -231,7 +225,7 @@ pub enum Retry {
        ///
        /// Each attempt may be multiple HTLCs along multiple paths if the router decides to split up a
        /// retry, and may retry multiple failed HTLCs at once if they failed around the same time and
-       /// were retried along a route from a single call to [`Router::find_route`].
+       /// were retried along a route from a single call to [`Router::find_route_with_id`].
        Attempts(usize),
        #[cfg(not(feature = "no-std"))]
        /// Time elapsed before abandoning retries for a payment. At least one attempt at payment is made;
@@ -436,8 +430,8 @@ impl OutboundPayments {
                NS::Target: NodeSigner,
                L::Target: Logger,
                IH: Fn() -> InFlightHtlcs,
-               SP: Fn(&Vec<RouteHop>, &Option<PaymentParameters>, &PaymentHash, &Option<PaymentSecret>, u64,
-                        u32, PaymentId, &Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>,
+               SP: Fn(&Vec<RouteHop>, &PaymentHash, &Option<PaymentSecret>, u64, u32, PaymentId,
+                       &Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>,
        {
                self.send_payment_internal(payment_id, payment_hash, payment_secret, None, retry_strategy,
                        route_params, router, first_hops, &compute_inflight_htlcs, entropy_source, node_signer,
@@ -452,8 +446,8 @@ impl OutboundPayments {
        where
                ES::Target: EntropySource,
                NS::Target: NodeSigner,
-               F: Fn(&Vec<RouteHop>, &Option<PaymentParameters>, &PaymentHash, &Option<PaymentSecret>, u64,
-                  u32, PaymentId, &Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>
+               F: Fn(&Vec<RouteHop>, &PaymentHash, &Option<PaymentSecret>, u64, u32, PaymentId,
+                       &Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>
        {
                let onion_session_privs = self.add_new_pending_payment(payment_hash, *payment_secret, payment_id, None, route, None, None, entropy_source, best_block_height)?;
                self.pay_route_internal(route, payment_hash, payment_secret, None, payment_id, None,
@@ -474,8 +468,8 @@ impl OutboundPayments {
                NS::Target: NodeSigner,
                L::Target: Logger,
                IH: Fn() -> InFlightHtlcs,
-               SP: Fn(&Vec<RouteHop>, &Option<PaymentParameters>, &PaymentHash, &Option<PaymentSecret>, u64,
-                        u32, PaymentId, &Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>,
+               SP: Fn(&Vec<RouteHop>, &PaymentHash, &Option<PaymentSecret>, u64, u32, PaymentId,
+                       &Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>,
        {
                let preimage = payment_preimage
                        .unwrap_or_else(|| PaymentPreimage(entropy_source.get_secure_random_bytes()));
@@ -493,8 +487,8 @@ impl OutboundPayments {
        where
                ES::Target: EntropySource,
                NS::Target: NodeSigner,
-               F: Fn(&Vec<RouteHop>, &Option<PaymentParameters>, &PaymentHash, &Option<PaymentSecret>, u64,
-                  u32, PaymentId, &Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>
+               F: Fn(&Vec<RouteHop>, &PaymentHash, &Option<PaymentSecret>, u64, u32, PaymentId,
+                       &Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>
        {
                let preimage = payment_preimage
                        .unwrap_or_else(|| PaymentPreimage(entropy_source.get_secure_random_bytes()));
@@ -519,8 +513,8 @@ impl OutboundPayments {
                R::Target: Router,
                ES::Target: EntropySource,
                NS::Target: NodeSigner,
-               SP: Fn(&Vec<RouteHop>, &Option<PaymentParameters>, &PaymentHash, &Option<PaymentSecret>, u64,
-                  u32, PaymentId, &Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>,
+               SP: Fn(&Vec<RouteHop>, &PaymentHash, &Option<PaymentSecret>, u64, u32, PaymentId,
+                       &Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>,
                IH: Fn() -> InFlightHtlcs,
                FH: Fn() -> Vec<ChannelDetails>,
                L::Target: Logger,
@@ -531,20 +525,20 @@ impl OutboundPayments {
                        let mut retry_id_route_params = None;
                        for (pmt_id, pmt) in outbounds.iter_mut() {
                                if pmt.is_auto_retryable_now() {
-                                       if let PendingOutboundPayment::Retryable { pending_amt_msat, total_msat, payment_params: Some(params), .. } = pmt {
+                                       if let PendingOutboundPayment::Retryable { pending_amt_msat, total_msat, payment_params: Some(params), payment_hash, .. } = pmt {
                                                if pending_amt_msat < total_msat {
-                                                       retry_id_route_params = Some((*pmt_id, RouteParameters {
+                                                       retry_id_route_params = Some((*payment_hash, *pmt_id, RouteParameters {
                                                                final_value_msat: *total_msat - *pending_amt_msat,
                                                                payment_params: params.clone(),
                                                        }));
                                                        break
                                                }
-                                       }
+                                       } else { debug_assert!(false); }
                                }
                        }
                        core::mem::drop(outbounds);
-                       if let Some((payment_id, route_params)) = retry_id_route_params {
-                               self.retry_payment_internal(payment_id, route_params, router, first_hops(), &inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, &send_payment_along_path)
+                       if let Some((payment_hash, payment_id, route_params)) = retry_id_route_params {
+                               self.retry_payment_internal(payment_hash, payment_id, route_params, router, first_hops(), &inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, &send_payment_along_path)
                        } else { break }
                }
 
@@ -588,8 +582,8 @@ impl OutboundPayments {
                NS::Target: NodeSigner,
                L::Target: Logger,
                IH: Fn() -> InFlightHtlcs,
-               SP: Fn(&Vec<RouteHop>, &Option<PaymentParameters>, &PaymentHash, &Option<PaymentSecret>, u64,
-                   u32, PaymentId, &Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>
+               SP: Fn(&Vec<RouteHop>, &PaymentHash, &Option<PaymentSecret>, u64, u32, PaymentId,
+                       &Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>
        {
                #[cfg(feature = "std")] {
                        if has_expired(&route_params) {
@@ -597,9 +591,10 @@ impl OutboundPayments {
                        }
                }
 
-               let route = router.find_route(
+               let route = router.find_route_with_id(
                        &node_signer.get_node_id(Recipient::Node).unwrap(), &route_params,
-                       Some(&first_hops.iter().collect::<Vec<_>>()), &inflight_htlcs()
+                       Some(&first_hops.iter().collect::<Vec<_>>()), &inflight_htlcs(),
+                       payment_hash, payment_id,
                ).map_err(|_| RetryableSendFailure::RouteNotFound)?;
 
                let onion_session_privs = self.add_new_pending_payment(payment_hash, *payment_secret,
@@ -617,10 +612,10 @@ impl OutboundPayments {
        }
 
        fn retry_payment_internal<R: Deref, NS: Deref, ES: Deref, IH, SP, L: Deref>(
-               &self, payment_id: PaymentId, route_params: RouteParameters, router: &R,
-               first_hops: Vec<ChannelDetails>, inflight_htlcs: &IH, entropy_source: &ES, node_signer: &NS,
-               best_block_height: u32, logger: &L, pending_events: &Mutex<Vec<events::Event>>,
-               send_payment_along_path: &SP,
+               &self, payment_hash: PaymentHash, payment_id: PaymentId, route_params: RouteParameters,
+               router: &R, first_hops: Vec<ChannelDetails>, inflight_htlcs: &IH, entropy_source: &ES,
+               node_signer: &NS, best_block_height: u32, logger: &L,
+               pending_events: &Mutex<Vec<events::Event>>, send_payment_along_path: &SP,
        )
        where
                R::Target: Router,
@@ -628,8 +623,8 @@ impl OutboundPayments {
                NS::Target: NodeSigner,
                L::Target: Logger,
                IH: Fn() -> InFlightHtlcs,
-               SP: Fn(&Vec<RouteHop>, &Option<PaymentParameters>, &PaymentHash, &Option<PaymentSecret>, u64,
-                   u32, PaymentId, &Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>
+               SP: Fn(&Vec<RouteHop>, &PaymentHash, &Option<PaymentSecret>, u64, u32, PaymentId,
+                       &Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>
        {
                #[cfg(feature = "std")] {
                        if has_expired(&route_params) {
@@ -639,9 +634,10 @@ impl OutboundPayments {
                        }
                }
 
-               let route = match router.find_route(
+               let route = match router.find_route_with_id(
                        &node_signer.get_node_id(Recipient::Node).unwrap(), &route_params,
-                       Some(&first_hops.iter().collect::<Vec<_>>()), &inflight_htlcs()
+                       Some(&first_hops.iter().collect::<Vec<_>>()), &inflight_htlcs(),
+                       payment_hash, payment_id,
                ) {
                        Ok(route) => route,
                        Err(e) => {
@@ -665,32 +661,31 @@ impl OutboundPayments {
                }
 
                macro_rules! abandon_with_entry {
-                       ($payment_id: expr, $payment_hash: expr, $payment: expr, $pending_events: expr) => {
+                       ($payment: expr) => {
                                if $payment.get_mut().mark_abandoned().is_ok() && $payment.get().remaining_parts() == 0 {
-                                       $pending_events.lock().unwrap().push(events::Event::PaymentFailed {
-                                               payment_id: $payment_id,
-                                               payment_hash: $payment_hash,
+                                       pending_events.lock().unwrap().push(events::Event::PaymentFailed {
+                                               payment_id,
+                                               payment_hash,
                                        });
                                        $payment.remove();
                                }
                        }
                }
-               let (total_msat, payment_hash, payment_secret, keysend_preimage) = {
+               let (total_msat, payment_secret, keysend_preimage) = {
                        let mut outbounds = self.pending_outbound_payments.lock().unwrap();
                        match outbounds.entry(payment_id) {
                                hash_map::Entry::Occupied(mut payment) => {
                                        let res = match payment.get() {
                                                PendingOutboundPayment::Retryable {
-                                                       total_msat, payment_hash, keysend_preimage, payment_secret, pending_amt_msat, ..
+                                                       total_msat, keysend_preimage, payment_secret, pending_amt_msat, ..
                                                } => {
                                                        let retry_amt_msat: u64 = route.paths.iter().map(|path| path.last().unwrap().fee_msat).sum();
                                                        if retry_amt_msat + *pending_amt_msat > *total_msat * (100 + RETRY_OVERFLOW_PERCENTAGE) / 100 {
                                                                log_error!(logger, "retry_amt_msat of {} will put pending_amt_msat (currently: {}) more than 10% over total_payment_amt_msat of {}", retry_amt_msat, pending_amt_msat, total_msat);
-                                                               let payment_hash = *payment_hash;
-                                                               abandon_with_entry!(payment_id, payment_hash, payment, pending_events);
+                                                               abandon_with_entry!(payment);
                                                                return
                                                        }
-                                                       (*total_msat, *payment_hash, *payment_secret, *keysend_preimage)
+                                                       (*total_msat, *payment_secret, *keysend_preimage)
                                                },
                                                PendingOutboundPayment::Legacy { .. } => {
                                                        log_error!(logger, "Unable to retry payments that were initially sent on LDK versions prior to 0.0.102");
@@ -707,7 +702,7 @@ impl OutboundPayments {
                                        };
                                        if !payment.get().is_retryable_now() {
                                                log_error!(logger, "Retries exhausted for payment id {}", log_bytes!(payment_id.0));
-                                               abandon_with_entry!(payment_id, res.1, payment, pending_events);
+                                               abandon_with_entry!(payment);
                                                return
                                        }
                                        payment.get_mut().increment_attempts();
@@ -743,20 +738,20 @@ impl OutboundPayments {
                NS::Target: NodeSigner,
                L::Target: Logger,
                IH: Fn() -> InFlightHtlcs,
-               SP: Fn(&Vec<RouteHop>, &Option<PaymentParameters>, &PaymentHash, &Option<PaymentSecret>, u64,
-                   u32, PaymentId, &Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>
+               SP: Fn(&Vec<RouteHop>, &PaymentHash, &Option<PaymentSecret>, u64, u32, PaymentId,
+                       &Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>
        {
                match err {
                        PaymentSendFailure::AllFailedResendSafe(errs) => {
                                Self::push_path_failed_evs_and_scids(payment_id, payment_hash, &mut route_params, route.paths, errs.into_iter().map(|e| Err(e)), pending_events);
-                               self.retry_payment_internal(payment_id, route_params, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, send_payment_along_path);
+                               self.retry_payment_internal(payment_hash, payment_id, route_params, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, send_payment_along_path);
                        },
                        PaymentSendFailure::PartialFailure { failed_paths_retry: Some(mut retry), results, .. } => {
                                Self::push_path_failed_evs_and_scids(payment_id, payment_hash, &mut retry, route.paths, results.into_iter(), pending_events);
                                // Some paths were sent, even if we failed to send the full MPP value our recipient may
                                // misbehave and claim the funds, at which point we have to consider the payment sent, so
                                // return `Ok()` here, ignoring any retry errors.
-                               self.retry_payment_internal(payment_id, retry, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, send_payment_along_path);
+                               self.retry_payment_internal(payment_hash, payment_id, retry, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, send_payment_along_path);
                        },
                        PaymentSendFailure::PartialFailure { failed_paths_retry: None, .. } => {
                                // This may happen if we send a payment and some paths fail, but only due to a temporary
@@ -797,7 +792,6 @@ impl OutboundPayments {
                                        failure: events::PathFailure::InitialSend { err: e },
                                        path,
                                        short_channel_id: failed_scid,
-                                       retry: None,
                                        #[cfg(test)]
                                        error_code: None,
                                        #[cfg(test)]
@@ -814,8 +808,8 @@ impl OutboundPayments {
        where
                ES::Target: EntropySource,
                NS::Target: NodeSigner,
-               F: Fn(&Vec<RouteHop>, &Option<PaymentParameters>, &PaymentHash, &Option<PaymentSecret>, u64,
-                  u32, PaymentId, &Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>
+               F: Fn(&Vec<RouteHop>, &PaymentHash, &Option<PaymentSecret>, u64, u32, PaymentId,
+                       &Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>
        {
                let payment_id = PaymentId(entropy_source.get_secure_random_bytes());
 
@@ -892,8 +886,8 @@ impl OutboundPayments {
        ) -> Result<(), PaymentSendFailure>
        where
                NS::Target: NodeSigner,
-               F: Fn(&Vec<RouteHop>, &Option<PaymentParameters>, &PaymentHash, &Option<PaymentSecret>, u64,
-                  u32, PaymentId, &Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>
+               F: Fn(&Vec<RouteHop>, &PaymentHash, &Option<PaymentSecret>, u64, u32, PaymentId,
+                       &Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>
        {
                if route.paths.len() < 1 {
                        return Err(PaymentSendFailure::ParameterError(APIError::InvalidRoute{err: "There must be at least one path to send over".to_owned()}));
@@ -930,7 +924,7 @@ impl OutboundPayments {
                let mut results = Vec::new();
                debug_assert_eq!(route.paths.len(), onion_session_privs.len());
                for (path, session_priv) in route.paths.iter().zip(onion_session_privs.into_iter()) {
-                       let mut path_res = send_payment_along_path(&path, &route.payment_params, &payment_hash, payment_secret, total_value, cur_height, payment_id, &keysend_preimage, session_priv);
+                       let mut path_res = send_payment_along_path(&path, &payment_hash, payment_secret, total_value, cur_height, payment_id, &keysend_preimage, session_priv);
                        match path_res {
                                Ok(_) => {},
                                Err(APIError::MonitorUpdateInProgress) => {
@@ -997,8 +991,8 @@ impl OutboundPayments {
        ) -> Result<(), PaymentSendFailure>
        where
                NS::Target: NodeSigner,
-               F: Fn(&Vec<RouteHop>, &Option<PaymentParameters>, &PaymentHash, &Option<PaymentSecret>, u64,
-                  u32, PaymentId, &Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>
+               F: Fn(&Vec<RouteHop>, &PaymentHash, &Option<PaymentSecret>, u64, u32, PaymentId,
+                       &Option<PaymentPreimage>, [u8; 32]) -> Result<(), APIError>
        {
                self.pay_route_internal(route, payment_hash, payment_secret, keysend_preimage, payment_id,
                        recv_value_msat, onion_session_privs, node_signer, best_block_height,
@@ -1127,8 +1121,8 @@ impl OutboundPayments {
        pub(super) fn fail_htlc<L: Deref>(
                &self, source: &HTLCSource, payment_hash: &PaymentHash, onion_error: &HTLCFailReason,
                path: &Vec<RouteHop>, session_priv: &SecretKey, payment_id: &PaymentId,
-               payment_params: &Option<PaymentParameters>, probing_cookie_secret: [u8; 32],
-               secp_ctx: &Secp256k1<secp256k1::All>, pending_events: &Mutex<Vec<events::Event>>, logger: &L
+               probing_cookie_secret: [u8; 32], secp_ctx: &Secp256k1<secp256k1::All>,
+               pending_events: &Mutex<Vec<events::Event>>, logger: &L
        ) -> bool where L::Target: Logger {
                #[cfg(test)]
                let (network_update, short_channel_id, payment_retryable, onion_error_code, onion_error_data) = onion_error.decode_onion_failure(secp_ctx, logger, &source);
@@ -1156,7 +1150,6 @@ impl OutboundPayments {
 
                let mut full_failure_ev = None;
                let mut pending_retry_ev = false;
-               let mut retry = None;
                let attempts_remaining = if let hash_map::Entry::Occupied(mut payment) = outbounds.entry(*payment_id) {
                        if !payment.get_mut().remove(&session_priv_bytes, Some(&path)) {
                                log_trace!(logger, "Received duplicative fail for HTLC with payment_hash {}", log_bytes!(payment_hash.0));
@@ -1168,27 +1161,13 @@ impl OutboundPayments {
                        }
                        let mut is_retryable_now = payment.get().is_auto_retryable_now();
                        if let Some(scid) = short_channel_id {
+                               // TODO: If we decided to blame ourselves (or one of our channels) in
+                               // process_onion_failure we should close that channel as it implies our
+                               // next-hop is needlessly blaming us!
                                payment.get_mut().insert_previously_failed_scid(scid);
                        }
 
-                       // We want to move towards only using the `PaymentParameters` in the outbound payments
-                       // map. However, for backwards-compatibility, we still need to support passing the
-                       // `PaymentParameters` data that was shoved in the HTLC (and given to us via
-                       // `payment_params`) back to the user.
-                       let path_last_hop = path.last().expect("Outbound payments must have had a valid path");
-                       if let Some(params) = payment.get_mut().payment_parameters() {
-                               retry = Some(RouteParameters {
-                                       payment_params: params.clone(),
-                                       final_value_msat: path_last_hop.fee_msat,
-                               });
-                       } else if let Some(params) = payment_params {
-                               retry = Some(RouteParameters {
-                                       payment_params: params.clone(),
-                                       final_value_msat: path_last_hop.fee_msat,
-                               });
-                       }
-
-                       if payment_is_probe || !is_retryable_now || !payment_retryable || retry.is_none() {
+                       if payment_is_probe || !is_retryable_now || !payment_retryable {
                                let _ = payment.get_mut().mark_abandoned(); // we'll only Err if it's a legacy payment
                                is_retryable_now = false;
                        }
@@ -1228,12 +1207,6 @@ impl OutboundPayments {
                                        }
                                }
                        } else {
-                               // TODO: If we decided to blame ourselves (or one of our channels) in
-                               // process_onion_failure we should close that channel as it implies our
-                               // next-hop is needlessly blaming us!
-                               if let Some(scid) = short_channel_id {
-                                       retry.as_mut().map(|r| r.payment_params.previously_failed_channels.push(scid));
-                               }
                                // If we miss abandoning the payment above, we *must* generate an event here or else the
                                // payment will sit in our outbounds forever.
                                if attempts_remaining && !already_awaiting_retry {
@@ -1247,7 +1220,6 @@ impl OutboundPayments {
                                        failure: events::PathFailure::OnPath { network_update },
                                        path: path.clone(),
                                        short_channel_id,
-                                       retry,
                                        #[cfg(test)]
                                        error_code: onion_error_code,
                                        #[cfg(test)]
@@ -1384,9 +1356,9 @@ mod tests {
                        &Route { paths: vec![], payment_params: None }, Some(Retry::Attempts(1)),
                        Some(expired_route_params.payment_params.clone()), &&keys_manager, 0).unwrap();
                        outbound_payments.retry_payment_internal(
-                               PaymentId([0; 32]), expired_route_params, &&router, vec![], &|| InFlightHtlcs::new(),
-                               &&keys_manager, &&keys_manager, 0, &&logger, &pending_events,
-                               &|_, _, _, _, _, _, _, _, _| Ok(()));
+                               PaymentHash([0; 32]), PaymentId([0; 32]), expired_route_params, &&router, vec![],
+                               &|| InFlightHtlcs::new(), &&keys_manager, &&keys_manager, 0, &&logger,
+                               &pending_events, &|_, _, _, _, _, _, _, _| Ok(()));
                        let events = pending_events.lock().unwrap();
                        assert_eq!(events.len(), 1);
                        if let Event::PaymentFailed { .. } = events[0] { } else { panic!("Unexpected event"); }
@@ -1394,7 +1366,7 @@ mod tests {
                        let err = outbound_payments.send_payment(
                                PaymentHash([0; 32]), &None, PaymentId([0; 32]), Retry::Attempts(0), expired_route_params,
                                &&router, vec![], || InFlightHtlcs::new(), &&keys_manager, &&keys_manager, 0, &&logger,
-                               &pending_events, |_, _, _, _, _, _, _, _, _| Ok(())).unwrap_err();
+                               &pending_events, |_, _, _, _, _, _, _, _| Ok(())).unwrap_err();
                        if let RetryableSendFailure::PaymentExpired = err { } else { panic!("Unexpected error"); }
                }
        }
@@ -1428,9 +1400,9 @@ mod tests {
                                &Route { paths: vec![], payment_params: None }, Some(Retry::Attempts(1)),
                                Some(route_params.payment_params.clone()), &&keys_manager, 0).unwrap();
                        outbound_payments.retry_payment_internal(
-                               PaymentId([0; 32]), route_params, &&router, vec![], &|| InFlightHtlcs::new(),
-                               &&keys_manager, &&keys_manager, 0, &&logger, &pending_events,
-                               &|_, _, _, _, _, _, _, _, _| Ok(()));
+                               PaymentHash([0; 32]), PaymentId([0; 32]), route_params, &&router, vec![],
+                               &|| InFlightHtlcs::new(), &&keys_manager, &&keys_manager, 0, &&logger,
+                               &pending_events, &|_, _, _, _, _, _, _, _| Ok(()));
                        let events = pending_events.lock().unwrap();
                        assert_eq!(events.len(), 1);
                        if let Event::PaymentFailed { .. } = events[0] { } else { panic!("Unexpected event"); }
@@ -1438,7 +1410,7 @@ mod tests {
                        let err = outbound_payments.send_payment(
                                PaymentHash([0; 32]), &None, PaymentId([0; 32]), Retry::Attempts(0), route_params,
                                &&router, vec![], || InFlightHtlcs::new(), &&keys_manager, &&keys_manager, 0, &&logger,
-                               &pending_events, |_, _, _, _, _, _, _, _, _| Ok(())).unwrap_err();
+                               &pending_events, |_, _, _, _, _, _, _, _| Ok(())).unwrap_err();
                        if let RetryableSendFailure::RouteNotFound = err {
                        } else { panic!("Unexpected error"); }
                }
@@ -1487,7 +1459,7 @@ mod tests {
                        PaymentHash([0; 32]), &None, PaymentId([0; 32]), Retry::Attempts(0), route_params.clone(),
                        &&router, vec![], || InFlightHtlcs::new(), &&keys_manager, &&keys_manager, 0, &&logger,
                        &pending_events,
-                       |_, _, _, _, _, _, _, _, _| Err(APIError::ChannelUnavailable { err: "test".to_owned() }))
+                       |_, _, _, _, _, _, _, _| Err(APIError::ChannelUnavailable { err: "test".to_owned() }))
                        .unwrap();
                let mut events = pending_events.lock().unwrap();
                assert_eq!(events.len(), 2);
@@ -1505,7 +1477,7 @@ mod tests {
                outbound_payments.send_payment(
                        PaymentHash([0; 32]), &None, PaymentId([0; 32]), Retry::Attempts(0), route_params.clone(),
                        &&router, vec![], || InFlightHtlcs::new(), &&keys_manager, &&keys_manager, 0, &&logger,
-                       &pending_events, |_, _, _, _, _, _, _, _, _| Err(APIError::MonitorUpdateInProgress))
+                       &pending_events, |_, _, _, _, _, _, _, _| Err(APIError::MonitorUpdateInProgress))
                        .unwrap();
                {
                        let events = pending_events.lock().unwrap();
@@ -1517,7 +1489,7 @@ mod tests {
                        PaymentHash([0; 32]), &None, PaymentId([1; 32]), Retry::Attempts(0), route_params.clone(),
                        &&router, vec![], || InFlightHtlcs::new(), &&keys_manager, &&keys_manager, 0, &&logger,
                        &pending_events,
-                       |_, _, _, _, _, _, _, _, _| Err(APIError::APIMisuseError { err: "test".to_owned() }))
+                       |_, _, _, _, _, _, _, _| Err(APIError::APIMisuseError { err: "test".to_owned() }))
                        .unwrap();
                let events = pending_events.lock().unwrap();
                assert_eq!(events.len(), 2);
index 5bc8a5084f2924706bf812aad46f4c750f851bc0..8c981fd1c482db6b9c75323b639735e87d4bcac6 100644 (file)
@@ -701,10 +701,6 @@ pub enum Event {
                /// If this is `Some`, then the corresponding channel should be avoided when the payment is
                /// retried. May be `None` for older [`Event`] serializations.
                short_channel_id: Option<u64>,
-               /// Parameters used by LDK to compute a new [`Route`] when retrying the failed payment path.
-               ///
-               /// [`Route`]: crate::routing::router::Route
-               retry: Option<RouteParameters>,
 #[cfg(test)]
                error_code: Option<u16>,
 #[cfg(test)]
@@ -992,7 +988,7 @@ impl Writeable for Event {
                        },
                        &Event::PaymentPathFailed {
                                ref payment_id, ref payment_hash, ref payment_failed_permanently, ref failure,
-                               ref path, ref short_channel_id, ref retry,
+                               ref path, ref short_channel_id,
                                #[cfg(test)]
                                ref error_code,
                                #[cfg(test)]
@@ -1010,7 +1006,7 @@ impl Writeable for Event {
                                        (3, false, required), // all_paths_failed in LDK versions prior to 0.0.114
                                        (5, *path, vec_type),
                                        (7, short_channel_id, option),
-                                       (9, retry, option),
+                                       (9, None::<RouteParameters>, option), // retry in LDK versions prior to 0.0.115
                                        (11, payment_id, option),
                                        (13, failure, required),
                                });
@@ -1227,7 +1223,6 @@ impl MaybeReadable for Event {
                                        let mut network_update = None;
                                        let mut path: Option<Vec<RouteHop>> = Some(vec![]);
                                        let mut short_channel_id = None;
-                                       let mut retry = None;
                                        let mut payment_id = None;
                                        let mut failure_opt = None;
                                        read_tlv_fields!(reader, {
@@ -1236,7 +1231,6 @@ impl MaybeReadable for Event {
                                                (2, payment_failed_permanently, required),
                                                (5, path, vec_type),
                                                (7, short_channel_id, option),
-                                               (9, retry, option),
                                                (11, payment_id, option),
                                                (13, failure_opt, upgradable_option),
                                        });
@@ -1248,7 +1242,6 @@ impl MaybeReadable for Event {
                                                failure,
                                                path: path.unwrap(),
                                                short_channel_id,
-                                               retry,
                                                #[cfg(test)]
                                                error_code,
                                                #[cfg(test)]
index bef192585b5e486696068174b92539c0faa895ff..f0208aad46aebd3a16d242383995073f2de71810 100644 (file)
@@ -1272,4 +1272,46 @@ mod tests {
                hostname.write(&mut buf).unwrap();
                assert_eq!(Hostname::read(&mut buf.as_slice()).unwrap().as_str(), "test");
        }
+
+       #[test]
+       fn bigsize_encoding_decoding() {
+               let values = vec![0, 252, 253, 65535, 65536, 4294967295, 4294967296, 18446744073709551615];
+               let bytes = vec![
+                       "00", 
+                       "fc",
+                       "fd00fd",
+                       "fdffff",
+                       "fe00010000",
+                       "feffffffff",
+                       "ff0000000100000000",
+                       "ffffffffffffffffff"
+               ];
+               for i in 0..=7 {        
+                       let mut stream = crate::io::Cursor::new(::hex::decode(bytes[i]).unwrap());
+                       assert_eq!(super::BigSize::read(&mut stream).unwrap().0, values[i]);
+                       let mut stream = super::VecWriter(Vec::new());
+                       super::BigSize(values[i]).write(&mut stream).unwrap();
+                       assert_eq!(stream.0, ::hex::decode(bytes[i]).unwrap());
+               }
+               let err_bytes = vec![
+                       "fd00fc",
+                       "fe0000ffff",
+                       "ff00000000ffffffff",
+                       "fd00",
+                       "feffff",
+                       "ffffffffff",
+                       "fd",
+                       "fe",
+                       "ff",
+                       ""
+               ];
+               for i in 0..=9 {
+                       let mut stream = crate::io::Cursor::new(::hex::decode(err_bytes[i]).unwrap());
+                       if i < 3 {
+                               assert_eq!(super::BigSize::read(&mut stream).err(), Some(crate::ln::msgs::DecodeError::InvalidValue));
+                       } else {
+                               assert_eq!(super::BigSize::read(&mut stream).err(), Some(crate::ln::msgs::DecodeError::ShortRead));
+                       }
+               }
+       }
 }
index 59402f6acc8e0eab43810eb896a678186e2e9efc..92a43b3fde5282fb4420d4981c1e23b3d9bd0e81 100644 (file)
@@ -874,6 +874,8 @@ macro_rules! tlv_record_ref_type {
        ($type:ty) => { &'a $type };
 }
 
+#[doc(hidden)]
+#[macro_export]
 macro_rules! _impl_writeable_tlv_based_enum_common {
        ($st: ident, $(($variant_id: expr, $variant_name: ident) =>
                {$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}
@@ -885,7 +887,7 @@ macro_rules! _impl_writeable_tlv_based_enum_common {
                                        $($st::$variant_name { $(ref $field),* } => {
                                                let id: u8 = $variant_id;
                                                id.write(writer)?;
-                                               write_tlv_fields!(writer, {
+                                               $crate::write_tlv_fields!(writer, {
                                                        $(($type, *$field, $fieldty)),*
                                                });
                                        }),*
@@ -923,7 +925,7 @@ macro_rules! impl_writeable_tlv_based_enum {
                {$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}
        ),* $(,)*;
        $(($tuple_variant_id: expr, $tuple_variant_name: ident)),*  $(,)*) => {
-               _impl_writeable_tlv_based_enum_common!($st,
+               $crate::_impl_writeable_tlv_based_enum_common!($st,
                        $(($variant_id, $variant_name) => {$(($type, $field, $fieldty)),*}),*;
                        $(($tuple_variant_id, $tuple_variant_name)),*);
 
@@ -935,12 +937,12 @@ macro_rules! impl_writeable_tlv_based_enum {
                                                // Because read_tlv_fields creates a labeled loop, we cannot call it twice
                                                // in the same function body. Instead, we define a closure and call it.
                                                let f = || {
-                                                       _init_and_read_tlv_fields!(reader, {
+                                                       $crate::_init_and_read_tlv_fields!(reader, {
                                                                $(($type, $field, $fieldty)),*
                                                        });
                                                        Ok($st::$variant_name {
                                                                $(
-                                                                       $field: _init_tlv_based_struct_field!($field, $fieldty)
+                                                                       $field: $crate::_init_tlv_based_struct_field!($field, $fieldty)
                                                                ),*
                                                        })
                                                };
@@ -977,7 +979,7 @@ macro_rules! impl_writeable_tlv_based_enum_upgradable {
        ),* $(,)*
        $(;
        $(($tuple_variant_id: expr, $tuple_variant_name: ident)),*  $(,)*)*) => {
-               _impl_writeable_tlv_based_enum_common!($st,
+               $crate::_impl_writeable_tlv_based_enum_common!($st,
                        $(($variant_id, $variant_name) => {$(($type, $field, $fieldty)),*}),*;
                        $($(($tuple_variant_id, $tuple_variant_name)),*)*);
 
@@ -989,12 +991,12 @@ macro_rules! impl_writeable_tlv_based_enum_upgradable {
                                                // Because read_tlv_fields creates a labeled loop, we cannot call it twice
                                                // in the same function body. Instead, we define a closure and call it.
                                                let f = || {
-                                                       _init_and_read_tlv_fields!(reader, {
+                                                       $crate::_init_and_read_tlv_fields!(reader, {
                                                                $(($type, $field, $fieldty)),*
                                                        });
                                                        Ok(Some($st::$variant_name {
                                                                $(
-                                                                       $field: _init_tlv_based_struct_field!($field, $fieldty)
+                                                                       $field: $crate::_init_tlv_based_struct_field!($field, $fieldty)
                                                                ),*
                                                        }))
                                                };
diff --git a/pending_changelog/2063.txt b/pending_changelog/2063.txt
new file mode 100644 (file)
index 0000000..8ac52a4
--- /dev/null
@@ -0,0 +1,4 @@
+## API Updates
+
+- `Event::PaymentPathFailed::retry` will always be `None` if we initiate a payment on 0.0.115
+       then downgrade to an earlier version (#2063)