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

Commit 517ebce

Browse files
authored
Merge pull request #1002 from MutinyWallet/ldk-121
2 parents 1957174 + bfca73f commit 517ebce

32 files changed

Lines changed: 1300 additions & 1041 deletions

Cargo.lock

Lines changed: 480 additions & 359 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ opt-level = "z"
1515
opt-level = "z"
1616

1717
[patch.crates-io]
18-
lightning = { git = 'https://github.com/MutinyWallet/rust-lightning.git', rev = "686a84236f54bf8d7270a5fbec07801e5281691f" }
19-
lightning-invoice = { git = 'https://github.com/MutinyWallet/rust-lightning.git', rev = "686a84236f54bf8d7270a5fbec07801e5281691f" }
20-
lightning-rapid-gossip-sync = { git = 'https://github.com/MutinyWallet/rust-lightning.git', rev = "686a84236f54bf8d7270a5fbec07801e5281691f" }
21-
lightning-background-processor = { git = 'https://github.com/MutinyWallet/rust-lightning.git', rev = "686a84236f54bf8d7270a5fbec07801e5281691f" }
22-
lightning-transaction-sync = { git = 'https://github.com/MutinyWallet/rust-lightning.git', rev = "686a84236f54bf8d7270a5fbec07801e5281691f" }
18+
lightning = { git = 'https://github.com/MutinyWallet/rust-lightning.git', rev = "e82635b32458a77d28a5a23b664696422eb526e4" }
19+
lightning-invoice = { git = 'https://github.com/MutinyWallet/rust-lightning.git', rev = "e82635b32458a77d28a5a23b664696422eb526e4" }
20+
lightning-rapid-gossip-sync = { git = 'https://github.com/MutinyWallet/rust-lightning.git', rev = "e82635b32458a77d28a5a23b664696422eb526e4" }
21+
lightning-background-processor = { git = 'https://github.com/MutinyWallet/rust-lightning.git', rev = "e82635b32458a77d28a5a23b664696422eb526e4" }
22+
lightning-transaction-sync = { git = 'https://github.com/MutinyWallet/rust-lightning.git', rev = "e82635b32458a77d28a5a23b664696422eb526e4" }

mutiny-core/Cargo.toml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@ homepage = "https://mutinywallet.com"
1212
repository = "https://github.com/mutinywallet/mutiny-node"
1313

1414
[dependencies]
15-
lnurl-rs = { version = "0.3.1", default-features = false, features = ["async", "async-https"] }
15+
lnurl-rs = { version = "0.4.0", default-features = false, features = ["async", "async-https"] }
1616

1717
cfg-if = "1.0.0"
1818
bip39 = { version = "2.0.0" }
19-
bitcoin = { version = "0.29.2", default-features = false, features = ["std", "serde", "secp-recovery", "rand"] }
20-
bdk = { version = "=1.0.0-alpha.1" }
21-
bdk_esplora = { version = "=0.3.0", default-features = false, features = ["std", "async-https"] }
22-
bdk_chain = { version = "=0.5.0", features = ["std"] }
19+
bitcoin = { version = "0.30.2", default-features = false, features = ["std", "serde", "secp-recovery", "rand"] }
20+
bdk = { version = "1.0.0-alpha.5" }
21+
bdk_esplora = { version = "0.7.0", default-features = false, features = ["std", "async-https"] }
22+
bdk_chain = { version = "0.9.0", features = ["std"] }
2323
bdk-macros = "0.6.0"
2424
getrandom = { version = "0.2" }
2525
itertools = "0.11.0"
2626
serde = { version = "^1.0", features = ["derive"] }
2727
serde_json = { version = "^1.0" }
2828
uuid = { version = "1.1.2", features = ["v4"] }
29-
esplora-client = { version = "0.5", default-features = false }
30-
lightning = { version = "0.0.118", default-features = false, features = ["max_level_trace", "grind_signatures", "std"] }
31-
lightning-invoice = { version = "0.26.0", features = ["serde"] }
32-
lightning-rapid-gossip-sync = { version = "0.0.118" }
33-
lightning-background-processor = { version = "0.0.118", features = ["futures"] }
34-
lightning-transaction-sync = { version = "0.0.118", features = ["esplora-async-https"] }
35-
lightning-liquidity = { git = "https://github.com/johncantrell97/ldk-lsp-client.git", rev = "9e01757d20c04aa31c28de8c4ffab5442d547edc" }
29+
esplora-client = { version = "0.6", default-features = false }
30+
lightning = { version = "0.0.121", default-features = false, features = ["max_level_trace", "grind_signatures", "std"] }
31+
lightning-invoice = { version = "0.29.0", features = ["serde"] }
32+
lightning-rapid-gossip-sync = { version = "0.0.121" }
33+
lightning-background-processor = { version = "0.0.121", features = ["futures"] }
34+
lightning-transaction-sync = { version = "0.0.121", default-features = false, features = ["esplora-async-https"] }
35+
lightning-liquidity = { git = "https://github.com/lightningdevkit/lightning-liquidity.git", rev = "478ccf9324e2650d200ea289a0ba8905afe420b6" }
3636
chrono = "0.4.22"
3737
futures-util = { version = "0.3", default-features = false }
3838
reqwest = { version = "0.11", default-features = false, features = ["json"] }
@@ -46,7 +46,7 @@ jwt-compact = { version = "0.8.0-beta.1", features = ["es256k"] }
4646
argon2 = { version = "0.5.0", features = ["password-hash", "alloc"] }
4747
payjoin = { version = "0.13.0", features = ["send", "base64"] }
4848
bincode = "1.3.3"
49-
hex = "0.4.3"
49+
hex-conservative = "0.1.1"
5050
async-lock = "3.2.0"
5151

5252
fedimint-client = { git = "https://github.com/fedimint/fedimint", rev = "6a923ee10c3a578cd835044e3fdd94aa5123735a" }

mutiny-core/src/error.rs

Lines changed: 69 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use aes::cipher::block_padding::UnpadError;
2-
use bitcoin::Network;
2+
use bdk::signer::SignerError;
3+
use bdk::wallet::error::BuildFeeBumpError;
4+
use bdk::wallet::tx_builder::AddUtxoError;
35
use lightning::ln::channelmanager::RetryableSendFailure;
46
use lightning::ln::peer_handler::PeerHandleError;
5-
use lightning_invoice::payment::PaymentError;
67
use lightning_invoice::ParseOrSemanticError;
78
use lightning_rapid_gossip_sync::GraphSyncError;
89
use lightning_transaction_sync::TxSyncError;
@@ -36,7 +37,7 @@ pub enum MutinyError {
3637
ConnectionFailed,
3738
/// The invoice or address is on a different network
3839
#[error("The invoice or address is on a different network.")]
39-
IncorrectNetwork(Network),
40+
IncorrectNetwork,
4041
/// Payment of the given invoice has already been initiated.
4142
#[error("An invoice must not get payed twice.")]
4243
NonUniquePaymentHash,
@@ -201,10 +202,11 @@ impl PartialEq for MutinyError {
201202
(Self::NotFound, Self::NotFound) => true,
202203
(Self::FundingTxCreationFailed, Self::FundingTxCreationFailed) => true,
203204
(Self::ConnectionFailed, Self::ConnectionFailed) => true,
204-
(Self::IncorrectNetwork(net), Self::IncorrectNetwork(net2)) => net == net2,
205+
(Self::IncorrectNetwork, Self::IncorrectNetwork) => true,
205206
(Self::NonUniquePaymentHash, Self::NonUniquePaymentHash) => true,
206207
(Self::PaymentTimeout, Self::PaymentTimeout) => true,
207208
(Self::InvoiceInvalid, Self::InvoiceInvalid) => true,
209+
(Self::InvoiceExpired, Self::InvoiceExpired) => true,
208210
(Self::InvoiceCreationFailed, Self::InvoiceCreationFailed) => true,
209211
(Self::ReserveAmountError, Self::ReserveAmountError) => true,
210212
(Self::InsufficientBalance, Self::InsufficientBalance) => true,
@@ -285,14 +287,9 @@ impl From<aes_gcm::aes::cipher::InvalidLength> for MutinyError {
285287
}
286288
}
287289

288-
impl From<bdk::Error> for MutinyError {
289-
fn from(e: bdk::Error) -> Self {
290-
match e {
291-
bdk::Error::Signer(_) => Self::WalletSigningFailed,
292-
bdk::Error::InsufficientFunds { .. } => Self::InsufficientBalance,
293-
bdk::Error::TransactionNotFound => Self::NotFound,
294-
_ => Self::WalletOperationFailed,
295-
}
290+
impl From<bdk_chain::local_chain::AlterCheckPointError> for MutinyError {
291+
fn from(_e: bdk_chain::local_chain::AlterCheckPointError) -> Self {
292+
Self::WalletOperationFailed
296293
}
297294
}
298295

@@ -305,20 +302,39 @@ impl From<bdk::descriptor::error::Error> for MutinyError {
305302
impl From<bdk::wallet::NewError<MutinyError>> for MutinyError {
306303
fn from(e: bdk::wallet::NewError<MutinyError>) -> Self {
307304
match e {
308-
bdk::wallet::NewError::Persist(e) => e,
305+
bdk::wallet::NewError::Write(e) => e,
309306
bdk::wallet::NewError::Descriptor(e) => e.into(),
307+
bdk::wallet::NewError::NonEmptyDatabase => Self::WalletOperationFailed,
308+
}
309+
}
310+
}
311+
312+
impl From<bdk::wallet::LoadError<MutinyError>> for MutinyError {
313+
fn from(e: bdk::wallet::LoadError<MutinyError>) -> Self {
314+
match e {
315+
bdk::wallet::LoadError::Descriptor(e) => e.into(),
316+
bdk::wallet::LoadError::Load(e) => e,
317+
bdk::wallet::LoadError::MissingGenesis => Self::WalletOperationFailed,
318+
bdk::wallet::LoadError::MissingNetwork => Self::WalletOperationFailed,
319+
bdk::wallet::LoadError::NotInitialized => Self::WalletOperationFailed,
310320
}
311321
}
312322
}
313323

324+
impl From<AddUtxoError> for MutinyError {
325+
fn from(_: AddUtxoError) -> Self {
326+
Self::WalletOperationFailed
327+
}
328+
}
329+
314330
impl From<bip39::Error> for MutinyError {
315331
fn from(_e: bip39::Error) -> Self {
316332
Self::InvalidMnemonic
317333
}
318334
}
319335

320-
impl From<bitcoin::util::bip32::Error> for MutinyError {
321-
fn from(_e: bitcoin::util::bip32::Error) -> Self {
336+
impl From<bitcoin::bip32::Error> for MutinyError {
337+
fn from(_e: bitcoin::bip32::Error) -> Self {
322338
Self::InvalidMnemonic
323339
}
324340
}
@@ -366,15 +382,12 @@ impl From<PeerHandleError> for MutinyError {
366382
}
367383
}
368384

369-
impl From<PaymentError> for MutinyError {
370-
fn from(e: PaymentError) -> Self {
371-
match e {
372-
PaymentError::Invoice(_) => Self::InvoiceInvalid,
373-
PaymentError::Sending(s) => match s {
374-
RetryableSendFailure::PaymentExpired => Self::InvoiceExpired,
375-
RetryableSendFailure::RouteNotFound => Self::RoutingFailed,
376-
RetryableSendFailure::DuplicatePayment => Self::NonUniquePaymentHash,
377-
},
385+
impl From<RetryableSendFailure> for MutinyError {
386+
fn from(s: RetryableSendFailure) -> Self {
387+
match s {
388+
RetryableSendFailure::PaymentExpired => Self::InvoiceExpired,
389+
RetryableSendFailure::RouteNotFound => Self::RoutingFailed,
390+
RetryableSendFailure::DuplicatePayment => Self::NonUniquePaymentHash,
378391
}
379392
}
380393
}
@@ -427,10 +440,15 @@ impl From<bitcoin::hashes::hex::Error> for MutinyError {
427440
}
428441
}
429442

430-
impl From<bitcoin::util::address::Error> for MutinyError {
431-
fn from(_e: bitcoin::util::address::Error) -> Self {
432-
MutinyError::ReadError {
433-
source: MutinyStorageError::Other(anyhow::anyhow!("Failed to decode address")),
443+
impl From<bitcoin::address::Error> for MutinyError {
444+
fn from(e: bitcoin::address::Error) -> Self {
445+
match e {
446+
bitcoin::address::Error::NetworkValidation { .. } => MutinyError::IncorrectNetwork,
447+
bitcoin::address::Error::UnrecognizedScript => MutinyError::InvalidArgumentsError,
448+
bitcoin::address::Error::UnknownAddressType(_) => MutinyError::InvalidArgumentsError,
449+
_ => MutinyError::ReadError {
450+
source: MutinyStorageError::Other(anyhow::anyhow!("Failed to decode address")),
451+
},
434452
}
435453
}
436454
}
@@ -442,15 +460,33 @@ impl From<esplora_client::Error> for MutinyError {
442460
}
443461
}
444462

445-
impl From<bdk_chain::local_chain::InsertBlockNotMatchingError> for MutinyError {
446-
fn from(_e: bdk_chain::local_chain::InsertBlockNotMatchingError) -> Self {
463+
impl From<bdk::wallet::InsertTxError> for MutinyError {
464+
fn from(_e: bdk::wallet::InsertTxError) -> Self {
447465
Self::WalletSyncError
448466
}
449467
}
450468

451-
impl From<bdk::wallet::InsertTxError> for MutinyError {
452-
fn from(_e: bdk::wallet::InsertTxError) -> Self {
453-
Self::WalletSyncError
469+
impl<S> From<bdk::wallet::error::CreateTxError<S>> for MutinyError {
470+
fn from(_e: bdk::wallet::error::CreateTxError<S>) -> Self {
471+
Self::WalletOperationFailed
472+
}
473+
}
474+
475+
impl From<BuildFeeBumpError> for MutinyError {
476+
fn from(e: BuildFeeBumpError) -> Self {
477+
match e {
478+
BuildFeeBumpError::UnknownUtxo(_) => Self::NotFound,
479+
BuildFeeBumpError::TransactionNotFound(_) => Self::NotFound,
480+
BuildFeeBumpError::TransactionConfirmed(_) => Self::NotFound,
481+
BuildFeeBumpError::IrreplaceableTransaction(_) => Self::InvalidArgumentsError,
482+
BuildFeeBumpError::FeeRateUnavailable => Self::WalletOperationFailed,
483+
}
484+
}
485+
}
486+
487+
impl From<SignerError> for MutinyError {
488+
fn from(_: SignerError) -> Self {
489+
Self::WalletOperationFailed
454490
}
455491
}
456492

mutiny-core/src/event.rs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ use crate::utils::sleep;
99
use crate::{fees::MutinyFeeEstimator, storage::read_payment_info};
1010
use crate::{keymanager::PhantomKeysManager, storage::persist_payment_info};
1111
use anyhow::anyhow;
12-
use bitcoin::hashes::hex::ToHex;
12+
use bitcoin::absolute::LockTime;
1313
use bitcoin::secp256k1::PublicKey;
1414
use bitcoin::secp256k1::Secp256k1;
15-
use bitcoin::{LockTime, PackedLockTime};
1615
use core::fmt;
1716
use lightning::events::{Event, PaymentPurpose};
1817
use lightning::sign::SpendableOutputDescriptor;
@@ -175,7 +174,7 @@ impl<S: MutinyStorage> EventHandler<S> {
175174
}
176175
};
177176

178-
let label = format!("LN Channel: {}", counterparty_node_id.to_hex());
177+
let label = format!("LN Channel: {}", counterparty_node_id);
179178
let labels = params_opt
180179
.as_ref()
181180
.and_then(|p| p.labels.clone())
@@ -238,7 +237,7 @@ impl<S: MutinyStorage> EventHandler<S> {
238237
counterparty_skimmed_fee_msat,
239238
..
240239
} => {
241-
log_debug!(self.logger, "EVENT: PaymentReceived received payment from payment hash {} of {amount_msat} millisatoshis to {receiver_node_id:?}", payment_hash.0.to_hex());
240+
log_debug!(self.logger, "EVENT: PaymentReceived received payment from payment hash {} of {amount_msat} millisatoshis to {receiver_node_id:?}", payment_hash);
242241

243242
let expected_skimmed_fee_msat = self
244243
.lsp_client
@@ -272,7 +271,7 @@ impl<S: MutinyStorage> EventHandler<S> {
272271
htlcs,
273272
sender_intended_total_msat,
274273
} => {
275-
log_debug!(self.logger, "EVENT: PaymentClaimed claimed payment from payment hash {} of {} millisatoshis ({sender_intended_total_msat:?} intended) from {} htlcs", payment_hash.0.to_hex(), amount_msat, htlcs.len());
274+
log_debug!(self.logger, "EVENT: PaymentClaimed claimed payment from payment hash {} of {} millisatoshis ({sender_intended_total_msat:?} intended) from {} htlcs", payment_hash, amount_msat, htlcs.len());
276275

277276
let (payment_preimage, payment_secret) = match purpose {
278277
PaymentPurpose::InvoicePayment {
@@ -345,11 +344,7 @@ impl<S: MutinyStorage> EventHandler<S> {
345344
fee_paid_msat,
346345
..
347346
} => {
348-
log_debug!(
349-
self.logger,
350-
"EVENT: PaymentSent: {}",
351-
payment_hash.0.to_hex()
352-
);
347+
log_debug!(self.logger, "EVENT: PaymentSent: {}", payment_hash);
353348

354349
match read_payment_info(
355350
&self.persister.storage,
@@ -446,11 +441,7 @@ impl<S: MutinyStorage> EventHandler<S> {
446441
log_debug!(self.logger, "EVENT: ProbeFailed, ignored");
447442
}
448443
Event::PaymentFailed { payment_hash, .. } => {
449-
log_error!(
450-
self.logger,
451-
"EVENT: PaymentFailed: {}",
452-
payment_hash.0.to_hex()
453-
);
444+
log_error!(self.logger, "EVENT: PaymentFailed: {}", payment_hash);
454445

455446
match read_payment_info(
456447
&self.persister.storage,
@@ -518,6 +509,7 @@ impl<S: MutinyStorage> EventHandler<S> {
518509
user_channel_id,
519510
counterparty_node_id: node_id,
520511
channel_capacity_sats,
512+
..
521513
} => {
522514
// if we still have channel open params, then it was just a failed channel open
523515
// we should not persist this as a closed channel and just delete the channel open params
@@ -529,7 +521,7 @@ impl<S: MutinyStorage> EventHandler<S> {
529521
log_debug!(
530522
self.logger,
531523
"EVENT: Channel {} of size {} closed due to: {:?}",
532-
channel_id.to_hex(),
524+
channel_id,
533525
channel_capacity_sats
534526
.map(|s| s.to_string())
535527
.unwrap_or_else(|| "unknown".to_string()),
@@ -558,9 +550,9 @@ impl<S: MutinyStorage> EventHandler<S> {
558550
log_debug!(
559551
self.logger,
560552
"EVENT: ChannelReady channel_id: {}, user_channel_id: {}, counterparty_node_id: {}, channel_type: {}",
561-
channel_id.to_hex(),
553+
channel_id,
562554
user_channel_id,
563-
counterparty_node_id.to_hex(),
555+
counterparty_node_id,
564556
channel_type);
565557
}
566558
Event::ChannelPending {
@@ -572,9 +564,9 @@ impl<S: MutinyStorage> EventHandler<S> {
572564
log_debug!(
573565
self.logger,
574566
"EVENT: ChannelPending channel_id: {}, user_channel_id: {}, counterparty_node_id: {}",
575-
channel_id.to_hex(),
567+
channel_id,
576568
user_channel_id,
577-
counterparty_node_id.to_hex());
569+
counterparty_node_id);
578570

579571
if let Err(e) = self.persister.delete_channel_open_params(user_channel_id) {
580572
log_warn!(
@@ -592,6 +584,13 @@ impl<S: MutinyStorage> EventHandler<S> {
592584
// we don't support bolt 12 yet
593585
log_warn!(self.logger, "EVENT: InvoiceRequestFailed: {payment_id}");
594586
}
587+
Event::ConnectionNeeded { node_id, addresses } => {
588+
// we don't support bolt 12 yet, and we won't have the connection info anyways
589+
log_debug!(
590+
self.logger,
591+
"EVENT: ConnectionNeeded: {node_id} @ {addresses:?}"
592+
);
593+
}
595594
}
596595
}
597596

@@ -644,7 +643,7 @@ impl<S: MutinyStorage> EventHandler<S> {
644643
height -= u32::from_be_bytes(rand) % 100;
645644
}
646645

647-
let locktime = LockTime::from_height(height).map(PackedLockTime::from).ok();
646+
let locktime = LockTime::from_height(height).ok();
648647

649648
let spending_tx = self
650649
.keys_manager

0 commit comments

Comments
 (0)