]> git.bitcoin.ninja Git - ldk-sample/commitdiff
Upgrade LDK to 0.0.118
authorMatt Corallo <git@bluematt.me>
Sat, 30 Sep 2023 01:06:13 +0000 (01:06 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 13 Nov 2023 23:20:22 +0000 (23:20 +0000)
Cargo.toml
src/bitcoind_client.rs
src/cli.rs
src/main.rs
src/sweep.rs

index d73ce6de274f3878edce7a3bd837304a55455244..e814e5f4e6b42dc6bcb2a636b69a368caad3c6d1 100644 (file)
@@ -8,13 +8,13 @@ edition = "2018"
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
-lightning = { version = "0.0.117", features = ["max_level_trace"] }
-lightning-block-sync = { version = "0.0.117", features = [ "rpc-client", "tokio" ] }
-lightning-invoice = { version = "0.25.0" }
-lightning-net-tokio = { version = "0.0.117" }
-lightning-persister = { version = "0.0.117" }
-lightning-background-processor = { version = "0.0.117", features = [ "futures" ] }
-lightning-rapid-gossip-sync = { version = "0.0.117" }
+lightning = { version = "0.0.118", features = ["max_level_trace"] }
+lightning-block-sync = { version = "0.0.118", features = [ "rpc-client", "tokio" ] }
+lightning-invoice = { version = "0.26.0" }
+lightning-net-tokio = { version = "0.0.118" }
+lightning-persister = { version = "0.0.118" }
+lightning-background-processor = { version = "0.0.118", features = [ "futures" ] }
+lightning-rapid-gossip-sync = { version = "0.0.118" }
 
 base64 = "0.13.0"
 bitcoin = "0.29.0"
index 67b42ef6c5a82b69aad12e10110ed8d4f989a2d4..17ea74c1e4e8b644487a7ecd12c84a141d81f609 100644 (file)
@@ -75,10 +75,23 @@ impl BitcoindClient {
                                "Failed to make initial call to bitcoind - please check your RPC user/password and access settings")
                        })?;
                let mut fees: HashMap<ConfirmationTarget, AtomicU32> = HashMap::new();
-               fees.insert(ConfirmationTarget::MempoolMinimum, AtomicU32::new(MIN_FEERATE));
-               fees.insert(ConfirmationTarget::Background, AtomicU32::new(MIN_FEERATE));
-               fees.insert(ConfirmationTarget::Normal, AtomicU32::new(2000));
-               fees.insert(ConfirmationTarget::HighPriority, AtomicU32::new(5000));
+               fees.insert(ConfirmationTarget::OnChainSweep, AtomicU32::new(5000));
+               fees.insert(
+                       ConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee,
+                       AtomicU32::new(25 * 250),
+               );
+               fees.insert(
+                       ConfirmationTarget::MinAllowedAnchorChannelRemoteFee,
+                       AtomicU32::new(MIN_FEERATE),
+               );
+               fees.insert(
+                       ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee,
+                       AtomicU32::new(MIN_FEERATE),
+               );
+               fees.insert(ConfirmationTarget::AnchorChannelFee, AtomicU32::new(MIN_FEERATE));
+               fees.insert(ConfirmationTarget::NonAnchorChannelFee, AtomicU32::new(2000));
+               fees.insert(ConfirmationTarget::ChannelCloseMinimum, AtomicU32::new(MIN_FEERATE));
+
                let client = Self {
                        bitcoind_rpc_client: Arc::new(bitcoind_rpc_client),
                        host,
@@ -162,18 +175,28 @@ impl BitcoindClient {
                                        }
                                };
 
-                               fees.get(&ConfirmationTarget::MempoolMinimum)
+                               fees.get(&ConfirmationTarget::OnChainSweep)
+                                       .unwrap()
+                                       .store(high_prio_estimate, Ordering::Release);
+                               fees.get(&ConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee)
+                                       .unwrap()
+                                       .store(std::cmp::max(25 * 250, high_prio_estimate * 10), Ordering::Release);
+                               fees.get(&ConfirmationTarget::MinAllowedAnchorChannelRemoteFee)
                                        .unwrap()
                                        .store(mempoolmin_estimate, Ordering::Release);
-                               fees.get(&ConfirmationTarget::Background)
+                               fees.get(&ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee)
+                                       .unwrap()
+                                       .store(background_estimate - 250, Ordering::Release);
+                               fees.get(&ConfirmationTarget::AnchorChannelFee)
                                        .unwrap()
                                        .store(background_estimate, Ordering::Release);
-                               fees.get(&ConfirmationTarget::Normal)
+                               fees.get(&ConfirmationTarget::NonAnchorChannelFee)
                                        .unwrap()
                                        .store(normal_estimate, Ordering::Release);
-                               fees.get(&ConfirmationTarget::HighPriority)
+                               fees.get(&ConfirmationTarget::ChannelCloseMinimum)
                                        .unwrap()
-                                       .store(high_prio_estimate, Ordering::Release);
+                                       .store(background_estimate, Ordering::Release);
+
                                tokio::time::sleep(Duration::from_secs(60)).await;
                        }
                });
@@ -203,7 +226,8 @@ impl BitcoindClient {
                        // LDK gives us feerates in satoshis per KW but Bitcoin Core here expects fees
                        // denominated in satoshis per vB. First we need to multiply by 4 to convert weight
                        // units to virtual bytes, then divide by 1000 to convert KvB to vB.
-                       "fee_rate": self.get_est_sat_per_1000_weight(ConfirmationTarget::Normal) as f64 / 250.0,
+                       "fee_rate": self
+                               .get_est_sat_per_1000_weight(ConfirmationTarget::NonAnchorChannelFee) as f64 / 250.0,
                        // While users could "cancel" a channel open by RBF-bumping and paying back to
                        // themselves, we don't allow it here as its easy to have users accidentally RBF bump
                        // and pay to the channel funding address, which results in loss of funds. Real
index 66af9ee6f320d0b7acc38b03fef72c598111d724..297900a0db7cf15b6ce59480336a91afaefe0bba 100644 (file)
@@ -12,7 +12,7 @@ use lightning::ln::channelmanager::{PaymentId, RecipientOnionFields, Retry};
 use lightning::ln::msgs::SocketAddress;
 use lightning::ln::{ChannelId, PaymentHash, PaymentPreimage};
 use lightning::onion_message::OnionMessagePath;
-use lightning::onion_message::{CustomOnionMessageContents, Destination, OnionMessageContents};
+use lightning::onion_message::{Destination, OnionMessageContents};
 use lightning::routing::gossip::NodeId;
 use lightning::routing::router::{PaymentParameters, RouteParameters};
 use lightning::sign::{EntropySource, KeysManager};
@@ -48,7 +48,7 @@ struct UserOnionMessageContents {
        data: Vec<u8>,
 }
 
-impl CustomOnionMessageContents for UserOnionMessageContents {
+impl OnionMessageContents for UserOnionMessageContents {
        fn tlv_type(&self) -> u64 {
                self.tlv_type
        }
@@ -445,7 +445,7 @@ pub(crate) fn poll_for_user_input(
                                        let message_path = OnionMessagePath { intermediate_nodes, destination };
                                        match onion_messenger.send_onion_message(
                                                message_path,
-                                               OnionMessageContents::Custom(UserOnionMessageContents { tlv_type, data }),
+                                               UserOnionMessageContents { tlv_type, data },
                                                None,
                                        ) {
                                                Ok(()) => println!("SUCCESS: forwarded onion message to first hop"),
index 50edb22ed54449d47d1f168c252ab05ff0ff7a6a..a33d667653291169fa87cc7eeed9faaa62580ced 100644 (file)
@@ -139,7 +139,7 @@ pub(crate) type GossipVerifier = lightning_block_sync::gossip::GossipVerifier<
        Arc<FilesystemLogger>,
        SocketDescriptor,
        Arc<ChannelManager>,
-       Arc<SimpleArcOnionMessenger<FilesystemLogger>>,
+       Arc<OnionMessenger>,
        IgnoringMessageHandler,
        Arc<KeysManager>,
 >;
@@ -158,7 +158,8 @@ pub(crate) type ChannelManager =
 
 pub(crate) type NetworkGraph = gossip::NetworkGraph<Arc<FilesystemLogger>>;
 
-type OnionMessenger = SimpleArcOnionMessenger<FilesystemLogger>;
+type OnionMessenger =
+       SimpleArcOnionMessenger<ChainMonitor, BitcoindClient, BitcoindClient, FilesystemLogger>;
 
 pub(crate) type BumpTxEventHandler = BumpTransactionEventHandler<
        Arc<BitcoindClient>,
@@ -358,6 +359,13 @@ async fn handle_ldk_events(
                        }
                        fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound.encode()).unwrap();
                }
+               Event::InvoiceRequestFailed { payment_id } => {
+                       print!("\nEVENT: Failed to request invoice to send payment with id {}", payment_id);
+                       print!("> ");
+                       io::stdout().flush().unwrap();
+
+                       // TODO: mark the payment as failed
+               }
                Event::PaymentForwarded {
                        prev_channel_id,
                        next_channel_id,
@@ -754,7 +762,7 @@ async fn start_ldk() {
                Arc::clone(&keys_manager),
                Arc::clone(&logger),
                Arc::new(DefaultMessageRouter {}),
-               IgnoringMessageHandler {},
+               Arc::clone(&channel_manager),
                IgnoringMessageHandler {},
        ));
        let mut ephemeral_bytes = [0; 32];
index 01cea9d32bbc7c042d4a7b457015b23a01409d4d..87577df752424d59041844ff8080b1c9e8311ec1 100644 (file)
@@ -109,8 +109,8 @@ pub(crate) async fn periodic_sweep(
                                }
                                let destination_address = bitcoind_client.get_new_address().await;
                                let output_descriptors = &outputs.iter().map(|a| a).collect::<Vec<_>>();
-                               let tx_feerate =
-                                       bitcoind_client.get_est_sat_per_1000_weight(ConfirmationTarget::Background);
+                               let tx_feerate = bitcoind_client
+                                       .get_est_sat_per_1000_weight(ConfirmationTarget::ChannelCloseMinimum);
 
                                // We set nLockTime to the current height to discourage fee sniping.
                                // Occasionally randomly pick a nLockTime even further back, so