Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit 57ccd46

Browse files
committed
LDK 0.0.118
1 parent 10ea76e commit 57ccd46

File tree

8 files changed

+97
-84
lines changed

8 files changed

+97
-84
lines changed

mutiny-core/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ serde = { version = "^1.0", features = ["derive"] }
2626
serde_json = { version = "^1.0" }
2727
uuid = { version = "1.1.2", features = ["v4"] }
2828
esplora-client = { version = "0.5", default-features = false }
29-
lightning = { version = "0.0.117", default-features = false, features = ["max_level_trace", "grind_signatures", "no-std"] }
30-
lightning-invoice = { version = "0.25.0", default-features = false, features = ["no-std", "serde"] }
31-
lightning-rapid-gossip-sync = { version = "0.0.117", default-features = false, features = ["no-std"] }
29+
lightning = { version = "0.0.118", default-features = false, features = ["max_level_trace", "grind_signatures", "no-std"] }
30+
lightning-invoice = { version = "0.26.0", default-features = false, features = ["no-std", "serde"] }
31+
lightning-rapid-gossip-sync = { version = "0.0.118", default-features = false, features = ["no-std"] }
3232
chrono = "0.4.22"
3333
futures-util = { version = "0.3", default-features = false }
3434
reqwest = { version = "0.11", default-features = false, features = ["json"] }

mutiny-core/src/event.rs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ use core::fmt;
1717
use lightning::events::{Event, PaymentPurpose};
1818
use lightning::sign::SpendableOutputDescriptor;
1919
use lightning::{
20-
chain::chaininterface::{ConfirmationTarget, FeeEstimator},
21-
log_debug, log_error, log_info, log_warn,
22-
util::errors::APIError,
23-
util::logger::Logger,
20+
log_debug, log_error, log_info, log_warn, util::errors::APIError, util::logger::Logger,
2421
};
2522
use lightning_invoice::Bolt11Invoice;
2623
use serde::{Deserialize, Serialize};
@@ -571,6 +568,36 @@ impl<S: MutinyStorage> EventHandler<S> {
571568
}
572569
Event::HTLCIntercepted { .. } => {}
573570
Event::BumpTransaction(event) => self.bump_tx_event_handler.handle_event(&event),
571+
Event::InvoiceRequestFailed { payment_id } => {
572+
log_warn!(self.logger, "EVENT: InvoiceRequestFailed: {payment_id}");
573+
match self
574+
.persister
575+
.read_payment_info(&payment_id.0, false, &self.logger)
576+
{
577+
Some(mut saved_payment_info) => {
578+
saved_payment_info.status = HTLCStatus::Failed;
579+
saved_payment_info.last_update = crate::utils::now().as_secs();
580+
match self.persister.persist_payment_info(
581+
&payment_id.0,
582+
&saved_payment_info,
583+
false,
584+
) {
585+
Ok(_) => (),
586+
Err(e) => log_error!(
587+
self.logger,
588+
"ERROR: could not persist payment info: {e}"
589+
),
590+
}
591+
}
592+
None => {
593+
// we failed in an invoice request that we didn't have saved? ...
594+
log_warn!(
595+
self.logger,
596+
"WARN: invoice request failed but we did not have it stored"
597+
);
598+
}
599+
}
600+
}
574601
}
575602
}
576603

@@ -604,9 +631,7 @@ impl<S: MutinyStorage> EventHandler<S> {
604631
output_descriptors.len()
605632
);
606633

607-
let tx_feerate = self
608-
.fee_estimator
609-
.get_est_sat_per_1000_weight(ConfirmationTarget::Normal);
634+
let tx_feerate = self.fee_estimator.get_normal_fee_rate();
610635

611636
// We set nLockTime to the current height to discourage fee sniping.
612637
// Occasionally randomly pick a nLockTime even further back, so

mutiny-core/src/fees.rs

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ impl<S: MutinyStorage> MutinyFeeEstimator<S> {
5353
sats_per_kw: Option<u32>,
5454
) -> u64 {
5555
// if no fee rate is provided, use the normal confirmation target
56-
let sats_per_kw = sats_per_kw
57-
.unwrap_or_else(|| self.get_est_sat_per_1000_weight(ConfirmationTarget::Normal));
56+
let sats_per_kw = sats_per_kw.unwrap_or_else(|| self.get_normal_fee_rate());
5857
let expected_weight = {
5958
// Calculate the non-witness and witness data sizes
6059
let non_witness_size = TX_OVERHEAD
@@ -144,14 +143,29 @@ impl<S: MutinyStorage> MutinyFeeEstimator<S> {
144143

145144
Ok(())
146145
}
146+
147+
pub fn get_low_fee_rate(&self) -> u32 {
148+
// MinAllowedNonAnchorChannelRemoteFee is a fee rate we expect to get slowly
149+
self.get_est_sat_per_1000_weight(ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee)
150+
}
151+
152+
pub fn get_normal_fee_rate(&self) -> u32 {
153+
// NonAnchorChannelFee is a fee rate we expect to be confirmed in 6 blocks
154+
self.get_est_sat_per_1000_weight(ConfirmationTarget::NonAnchorChannelFee)
155+
}
156+
157+
pub fn get_high_fee_rate(&self) -> u32 {
158+
// OnChainSweep is the highest fee rate we have, so use that
159+
self.get_est_sat_per_1000_weight(ConfirmationTarget::OnChainSweep)
160+
}
147161
}
148162

149163
impl<S: MutinyStorage> FeeEstimator for MutinyFeeEstimator<S> {
150164
fn get_est_sat_per_1000_weight(&self, confirmation_target: ConfirmationTarget) -> u32 {
151165
let num_blocks = num_blocks_from_conf_target(confirmation_target);
152166
let fallback_fee = fallback_fee_from_conf_target(confirmation_target);
153167

154-
match self.storage.get_fee_estimates() {
168+
let fee = match self.storage.get_fee_estimates() {
155169
Err(_) | Ok(None) => fallback_fee,
156170
Ok(Some(estimates)) => {
157171
let found = estimates.get(&num_blocks.to_string());
@@ -160,43 +174,46 @@ impl<S: MutinyStorage> FeeEstimator for MutinyFeeEstimator<S> {
160174
log_trace!(self.logger, "Got fee rate from saved cache!");
161175
let sats_vbyte = num.to_owned();
162176
// convert to sats per kw
163-
let mut fee_rate = sats_vbyte * 250.0;
164-
165-
// if we're using the high priority target, multiply by 3
166-
// this should help prevent force closures from fee disputes
167-
if confirmation_target == ConfirmationTarget::HighPriority {
168-
fee_rate *= 3.0;
169-
}
177+
let fee_rate = sats_vbyte * 250.0;
170178

171179
// return the fee rate, but make sure it's not lower than the floor
172180
(fee_rate as u32).max(FEERATE_FLOOR_SATS_PER_KW)
173181
}
174182
None => fallback_fee,
175183
}
176184
}
185+
};
186+
187+
// any post processing we do after the we get the fee rate from the cache
188+
match confirmation_target {
189+
ConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee => fee * 30, // multiply by 30 to help prevent force closes
190+
ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee => fee - 250, // helps with rounding errors
191+
_ => fee,
177192
}
178193
}
179194
}
180195

181196
fn num_blocks_from_conf_target(confirmation_target: ConfirmationTarget) -> usize {
182197
match confirmation_target {
183-
// MempoolMinimum is only used for anchor channels, we just set the target to 1008
184-
// as that is esplora's highest block target available
185-
ConfirmationTarget::MempoolMinimum => 1008,
186-
// Background is VERY lax and may never confirm if used directly
187-
// it is only meant for lower ranges of transaction to enter mempool
188-
ConfirmationTarget::Background => 1008,
189-
ConfirmationTarget::Normal => 6,
190-
ConfirmationTarget::HighPriority => 1,
198+
ConfirmationTarget::AnchorChannelFee => 1008,
199+
ConfirmationTarget::MinAllowedAnchorChannelRemoteFee => 1008,
200+
ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee => 1008,
201+
ConfirmationTarget::ChannelCloseMinimum => 1008,
202+
ConfirmationTarget::NonAnchorChannelFee => 6,
203+
ConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee => 1,
204+
ConfirmationTarget::OnChainSweep => 1,
191205
}
192206
}
193207

194208
fn fallback_fee_from_conf_target(confirmation_target: ConfirmationTarget) -> u32 {
195209
match confirmation_target {
196-
ConfirmationTarget::MempoolMinimum => 3 * 250,
197-
ConfirmationTarget::Background => 10 * 250,
198-
ConfirmationTarget::Normal => 20 * 250,
199-
ConfirmationTarget::HighPriority => 50 * 250,
210+
ConfirmationTarget::MinAllowedAnchorChannelRemoteFee => 3 * 250,
211+
ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee => 3 * 250,
212+
ConfirmationTarget::ChannelCloseMinimum => 10 * 250,
213+
ConfirmationTarget::AnchorChannelFee => 10 * 250,
214+
ConfirmationTarget::NonAnchorChannelFee => 20 * 250,
215+
ConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee => 50 * 250,
216+
ConfirmationTarget::OnChainSweep => 50 * 250,
200217
}
201218
}
202219

@@ -229,28 +246,31 @@ mod test {
229246
#[test]
230247
fn test_num_blocks_from_conf_target() {
231248
assert_eq!(
232-
num_blocks_from_conf_target(ConfirmationTarget::Background),
249+
num_blocks_from_conf_target(ConfirmationTarget::ChannelCloseMinimum),
233250
1008
234251
);
235-
assert_eq!(num_blocks_from_conf_target(ConfirmationTarget::Normal), 6);
236252
assert_eq!(
237-
num_blocks_from_conf_target(ConfirmationTarget::HighPriority),
253+
num_blocks_from_conf_target(ConfirmationTarget::NonAnchorChannelFee),
254+
6
255+
);
256+
assert_eq!(
257+
num_blocks_from_conf_target(ConfirmationTarget::OnChainSweep),
238258
1
239259
);
240260
}
241261

242262
#[test]
243263
fn test_fallback_fee_from_conf_target() {
244264
assert_eq!(
245-
fallback_fee_from_conf_target(ConfirmationTarget::Background),
265+
fallback_fee_from_conf_target(ConfirmationTarget::ChannelCloseMinimum),
246266
2_500
247267
);
248268
assert_eq!(
249-
fallback_fee_from_conf_target(ConfirmationTarget::Normal),
269+
fallback_fee_from_conf_target(ConfirmationTarget::NonAnchorChannelFee),
250270
5_000
251271
);
252272
assert_eq!(
253-
fallback_fee_from_conf_target(ConfirmationTarget::HighPriority),
273+
fallback_fee_from_conf_target(ConfirmationTarget::OnChainSweep),
254274
12_500
255275
);
256276
}
@@ -288,17 +308,17 @@ mod test {
288308

289309
// test that we get the fee rate from the cache
290310
assert_eq!(
291-
fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::Normal),
311+
fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::NonAnchorChannelFee),
292312
2500
293313
);
294314

295315
// test that we get the fallback fee rate
296316
assert_eq!(
297-
fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::Background),
317+
fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::ChannelCloseMinimum),
298318
2_500
299319
);
300320
assert_eq!(
301-
fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::HighPriority),
321+
fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::OnChainSweep),
302322
12_500
303323
);
304324
}

mutiny-core/src/node.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use core::time::Duration;
3232
use lightning::chain::channelmonitor::ChannelMonitor;
3333
use lightning::util::ser::{ReadableArgs, Writeable};
3434
use lightning::{
35-
chain::chaininterface::{ConfirmationTarget, FeeEstimator},
3635
ln::channelmanager::{RecipientOnionFields, RetryableSendFailure},
3736
routing::scoring::ProbabilisticScoringFeeParameters,
3837
util::config::ChannelConfig,
@@ -1409,10 +1408,7 @@ impl<S: MutinyStorage> Node<S> {
14091408
let sats_per_vbyte = if let Some(sats_vbyte) = fee_rate {
14101409
sats_vbyte
14111410
} else {
1412-
let sats_per_kw = self
1413-
.wallet
1414-
.fees
1415-
.get_est_sat_per_1000_weight(ConfirmationTarget::Normal);
1411+
let sats_per_kw = self.wallet.fees.get_normal_fee_rate();
14161412

14171413
FeeRate::from_sat_per_kwu(sats_per_kw as f32).as_sat_per_vb()
14181414
};
@@ -1483,10 +1479,8 @@ impl<S: MutinyStorage> Node<S> {
14831479
total
14841480
};
14851481

1486-
let sats_per_kw = self
1487-
.wallet
1488-
.fees
1489-
.get_est_sat_per_1000_weight(ConfirmationTarget::Normal);
1482+
let sats_per_kw = self.wallet.fees.get_normal_fee_rate();
1483+
14901484
// Calculate the expected transaction fee
14911485
let expected_fee = self.wallet.fees.calculate_expected_fee(
14921486
utxos.len(),

mutiny-core/src/nodemanager.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ use bitcoin::{Address, Network, OutPoint, Transaction, Txid};
4141
use core::time::Duration;
4242
use esplora_client::Builder;
4343
use futures::{future::join_all, lock::Mutex};
44-
use lightning::chain::chaininterface::{ConfirmationTarget, FeeEstimator};
4544
use lightning::chain::Confirm;
4645
use lightning::events::ClosureReason;
4746
use lightning::io::Read;
@@ -1460,25 +1459,19 @@ impl<S: MutinyStorage> NodeManager<S> {
14601459
/// Gets a fee estimate for a very low priority transaction.
14611460
/// Value is in sat/vbyte.
14621461
pub fn estimate_fee_low(&self) -> u32 {
1463-
self.fee_estimator
1464-
.get_est_sat_per_1000_weight(ConfirmationTarget::Background)
1465-
/ 250
1462+
self.fee_estimator.get_low_fee_rate() / 250
14661463
}
14671464

14681465
/// Gets a fee estimate for an average priority transaction.
14691466
/// Value is in sat/vbyte.
14701467
pub fn estimate_fee_normal(&self) -> u32 {
1471-
self.fee_estimator
1472-
.get_est_sat_per_1000_weight(ConfirmationTarget::Normal)
1473-
/ 250
1468+
self.fee_estimator.get_normal_fee_rate() / 250
14741469
}
14751470

14761471
/// Gets a fee estimate for an high priority transaction.
14771472
/// Value is in sat/vbyte.
14781473
pub fn estimate_fee_high(&self) -> u32 {
1479-
self.fee_estimator
1480-
.get_est_sat_per_1000_weight(ConfirmationTarget::HighPriority)
1481-
/ 250
1474+
self.fee_estimator.get_high_fee_rate() / 250
14821475
}
14831476

14841477
/// Creates a new lightning node and adds it to the manager.
@@ -2077,9 +2070,7 @@ impl<S: MutinyStorage> NodeManager<S> {
20772070

20782071
// ldk uses background fee rate for closing channels which can be very slow
20792072
// so we use normal fee rate instead
2080-
let fee_rate = self
2081-
.fee_estimator
2082-
.get_est_sat_per_1000_weight(ConfirmationTarget::Normal);
2073+
let fee_rate = self.wallet.fees.get_normal_fee_rate();
20832074

20842075
node.channel_manager
20852076
.close_channel_with_feerate_and_script(

mutiny-core/src/onchain.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use bitcoin::hashes::hex::ToHex;
1515
use bitcoin::psbt::PartiallySignedTransaction;
1616
use bitcoin::util::bip32::{ChildNumber, DerivationPath, ExtendedPrivKey};
1717
use bitcoin::{Address, Network, OutPoint, Script, Transaction, Txid};
18-
use lightning::chain::chaininterface::{ConfirmationTarget, FeeEstimator};
1918
use lightning::events::bump_transaction::{Utxo, WalletSource};
2019
use lightning::util::logger::Logger;
2120
use lightning::{log_debug, log_error, log_info, log_warn};
@@ -447,9 +446,7 @@ impl<S: MutinyStorage> OnChainWallet<S> {
447446
let fee_rate = if let Some(rate) = fee_rate {
448447
FeeRate::from_sat_per_vb(rate)
449448
} else {
450-
let sat_per_kwu = self
451-
.fees
452-
.get_est_sat_per_1000_weight(ConfirmationTarget::Normal);
449+
let sat_per_kwu = self.fees.get_normal_fee_rate();
453450
FeeRate::from_sat_per_kwu(sat_per_kwu as f32)
454451
};
455452
let (mut psbt, details) = {
@@ -495,9 +492,7 @@ impl<S: MutinyStorage> OnChainWallet<S> {
495492
let fee_rate = if let Some(rate) = fee_rate {
496493
FeeRate::from_sat_per_vb(rate)
497494
} else {
498-
let sat_per_kwu = self
499-
.fees
500-
.get_est_sat_per_1000_weight(ConfirmationTarget::Normal);
495+
let sat_per_kwu = self.fees.get_normal_fee_rate();
501496
FeeRate::from_sat_per_kwu(sat_per_kwu as f32)
502497
};
503498
let (mut psbt, details) = {

mutiny-core/src/peermanager.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use std::{net::SocketAddr, sync::atomic::AtomicBool};
1313

1414
use crate::networking::socket::{schedule_descriptor_read, MutinySocketDescriptor};
1515
use crate::scb::message_handler::SCBMessageHandler;
16-
use bitcoin::BlockHash;
1716
use lightning::events::{MessageSendEvent, MessageSendEventsProvider};
1817
use lightning::ln::features::{InitFeatures, NodeFeatures};
1918
use lightning::ln::msgs;
@@ -22,7 +21,6 @@ use lightning::ln::peer_handler::PeerHandleError;
2221
use lightning::ln::peer_handler::{IgnoringMessageHandler, PeerManager as LdkPeerManager};
2322
use lightning::log_warn;
2423
use lightning::routing::gossip::NodeId;
25-
use lightning::routing::utxo::{UtxoLookup, UtxoLookupError, UtxoResult};
2624
use lightning::util::logger::Logger;
2725
use std::sync::Arc;
2826

@@ -179,16 +177,6 @@ impl<S: MutinyStorage> MessageSendEventsProvider for GossipMessageHandler<S> {
179177
}
180178
}
181179

182-
// I needed some type to implement RoutingMessageHandler, but I don't want to implement it
183-
// we don't need to lookup UTXOs, so we can just return an error
184-
// This should never actually be called because we are passing in None for the UTXO lookup
185-
struct ErroringUtxoLookup {}
186-
impl UtxoLookup for ErroringUtxoLookup {
187-
fn get_utxo(&self, _genesis_hash: &BlockHash, _short_channel_id: u64) -> UtxoResult {
188-
UtxoResult::Sync(Err(UtxoLookupError::UnknownTx))
189-
}
190-
}
191-
192180
impl<S: MutinyStorage> RoutingMessageHandler for GossipMessageHandler<S> {
193181
fn handle_node_announcement(
194182
&self,

mutiny-wasm/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ wasm-bindgen-futures = "0.4.33"
2424
serde = { version = "^1.0", features = ["derive"] }
2525
serde_json = { version = "^1.0" }
2626
bitcoin = { version = "0.29.2", default-features = false, features = ["serde", "secp-recovery", "rand"] }
27-
lightning = { version = "0.0.117", default-features = false, features = ["no-std"] }
28-
lightning-invoice = { version = "0.25.0", default-features = false, features = ["no-std"] }
27+
lightning = { version = "0.0.118", default-features = false, features = ["no-std"] }
28+
lightning-invoice = { version = "0.26.0", default-features = false, features = ["no-std"] }
2929
thiserror = "1.0"
3030
instant = { version = "0.1", features = ["wasm-bindgen"] }
3131
lnurl-rs = { version = "0.2.6", default-features = false }

0 commit comments

Comments
 (0)