Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ldk 121, bdk alpha5, bitcoin 0.30 #1002

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
839 changes: 480 additions & 359 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ opt-level = "z"
opt-level = "z"

[patch.crates-io]
lightning = { git = 'https://github.com/MutinyWallet/rust-lightning.git', rev = "686a84236f54bf8d7270a5fbec07801e5281691f" }
lightning-invoice = { git = 'https://github.com/MutinyWallet/rust-lightning.git', rev = "686a84236f54bf8d7270a5fbec07801e5281691f" }
lightning-rapid-gossip-sync = { git = 'https://github.com/MutinyWallet/rust-lightning.git', rev = "686a84236f54bf8d7270a5fbec07801e5281691f" }
lightning-background-processor = { git = 'https://github.com/MutinyWallet/rust-lightning.git', rev = "686a84236f54bf8d7270a5fbec07801e5281691f" }
lightning-transaction-sync = { git = 'https://github.com/MutinyWallet/rust-lightning.git', rev = "686a84236f54bf8d7270a5fbec07801e5281691f" }
lightning = { git = 'https://github.com/MutinyWallet/rust-lightning.git', rev = "e82635b32458a77d28a5a23b664696422eb526e4" }
TonyGiorgio marked this conversation as resolved.
Show resolved Hide resolved
lightning-invoice = { git = 'https://github.com/MutinyWallet/rust-lightning.git', rev = "e82635b32458a77d28a5a23b664696422eb526e4" }
lightning-rapid-gossip-sync = { git = 'https://github.com/MutinyWallet/rust-lightning.git', rev = "e82635b32458a77d28a5a23b664696422eb526e4" }
lightning-background-processor = { git = 'https://github.com/MutinyWallet/rust-lightning.git', rev = "e82635b32458a77d28a5a23b664696422eb526e4" }
lightning-transaction-sync = { git = 'https://github.com/MutinyWallet/rust-lightning.git', rev = "e82635b32458a77d28a5a23b664696422eb526e4" }
26 changes: 13 additions & 13 deletions mutiny-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@ homepage = "https://mutinywallet.com"
repository = "https://github.com/mutinywallet/mutiny-node"

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

cfg-if = "1.0.0"
bip39 = { version = "2.0.0" }
bitcoin = { version = "0.29.2", default-features = false, features = ["std", "serde", "secp-recovery", "rand"] }
bdk = { version = "=1.0.0-alpha.1" }
bdk_esplora = { version = "=0.3.0", default-features = false, features = ["std", "async-https"] }
bdk_chain = { version = "=0.5.0", features = ["std"] }
bitcoin = { version = "0.30.2", default-features = false, features = ["std", "serde", "secp-recovery", "rand"] }
bdk = { version = "1.0.0-alpha.5" }
bdk_esplora = { version = "0.7.0", default-features = false, features = ["std", "async-https"] }
bdk_chain = { version = "0.9.0", features = ["std"] }
bdk-macros = "0.6.0"
getrandom = { version = "0.2" }
itertools = "0.11.0"
serde = { version = "^1.0", features = ["derive"] }
serde_json = { version = "^1.0" }
uuid = { version = "1.1.2", features = ["v4"] }
esplora-client = { version = "0.5", default-features = false }
lightning = { version = "0.0.118", default-features = false, features = ["max_level_trace", "grind_signatures", "std"] }
lightning-invoice = { version = "0.26.0", features = ["serde"] }
lightning-rapid-gossip-sync = { version = "0.0.118" }
lightning-background-processor = { version = "0.0.118", features = ["futures"] }
lightning-transaction-sync = { version = "0.0.118", features = ["esplora-async-https"] }
lightning-liquidity = { git = "https://github.com/johncantrell97/ldk-lsp-client.git", rev = "9e01757d20c04aa31c28de8c4ffab5442d547edc" }
esplora-client = { version = "0.6", default-features = false }
lightning = { version = "0.0.121", default-features = false, features = ["max_level_trace", "grind_signatures", "std"] }
lightning-invoice = { version = "0.29.0", features = ["serde"] }
lightning-rapid-gossip-sync = { version = "0.0.121" }
lightning-background-processor = { version = "0.0.121", features = ["futures"] }
lightning-transaction-sync = { version = "0.0.121", default-features = false, features = ["esplora-async-https"] }
lightning-liquidity = { git = "https://github.com/lightningdevkit/lightning-liquidity.git", rev = "478ccf9324e2650d200ea289a0ba8905afe420b6" }
chrono = "0.4.22"
futures-util = { version = "0.3", default-features = false }
reqwest = { version = "0.11", default-features = false, features = ["json"] }
Expand All @@ -46,7 +46,7 @@ jwt-compact = { version = "0.8.0-beta.1", features = ["es256k"] }
argon2 = { version = "0.5.0", features = ["password-hash", "alloc"] }
payjoin = { version = "0.13.0", features = ["send", "base64"] }
bincode = "1.3.3"
hex = "0.4.3"
hex-conservative = "0.1.1"
async-lock = "3.2.0"

fedimint-client = { git = "https://github.com/fedimint/fedimint", rev = "6a923ee10c3a578cd835044e3fdd94aa5123735a" }
Expand Down
102 changes: 69 additions & 33 deletions mutiny-core/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use aes::cipher::block_padding::UnpadError;
use bitcoin::Network;
use bdk::signer::SignerError;
use bdk::wallet::error::BuildFeeBumpError;
use bdk::wallet::tx_builder::AddUtxoError;
use lightning::ln::channelmanager::RetryableSendFailure;
use lightning::ln::peer_handler::PeerHandleError;
use lightning_invoice::payment::PaymentError;
use lightning_invoice::ParseOrSemanticError;
use lightning_rapid_gossip_sync::GraphSyncError;
use lightning_transaction_sync::TxSyncError;
Expand Down Expand Up @@ -36,7 +37,7 @@ pub enum MutinyError {
ConnectionFailed,
/// The invoice or address is on a different network
#[error("The invoice or address is on a different network.")]
IncorrectNetwork(Network),
IncorrectNetwork,
/// Payment of the given invoice has already been initiated.
#[error("An invoice must not get payed twice.")]
NonUniquePaymentHash,
Expand Down Expand Up @@ -201,10 +202,11 @@ impl PartialEq for MutinyError {
(Self::NotFound, Self::NotFound) => true,
(Self::FundingTxCreationFailed, Self::FundingTxCreationFailed) => true,
(Self::ConnectionFailed, Self::ConnectionFailed) => true,
(Self::IncorrectNetwork(net), Self::IncorrectNetwork(net2)) => net == net2,
(Self::IncorrectNetwork, Self::IncorrectNetwork) => true,
(Self::NonUniquePaymentHash, Self::NonUniquePaymentHash) => true,
(Self::PaymentTimeout, Self::PaymentTimeout) => true,
(Self::InvoiceInvalid, Self::InvoiceInvalid) => true,
(Self::InvoiceExpired, Self::InvoiceExpired) => true,
(Self::InvoiceCreationFailed, Self::InvoiceCreationFailed) => true,
(Self::ReserveAmountError, Self::ReserveAmountError) => true,
(Self::InsufficientBalance, Self::InsufficientBalance) => true,
Expand Down Expand Up @@ -285,14 +287,9 @@ impl From<aes_gcm::aes::cipher::InvalidLength> for MutinyError {
}
}

impl From<bdk::Error> for MutinyError {
fn from(e: bdk::Error) -> Self {
match e {
bdk::Error::Signer(_) => Self::WalletSigningFailed,
bdk::Error::InsufficientFunds { .. } => Self::InsufficientBalance,
bdk::Error::TransactionNotFound => Self::NotFound,
_ => Self::WalletOperationFailed,
}
impl From<bdk_chain::local_chain::AlterCheckPointError> for MutinyError {
fn from(_e: bdk_chain::local_chain::AlterCheckPointError) -> Self {
Self::WalletOperationFailed
}
}

Expand All @@ -305,20 +302,39 @@ impl From<bdk::descriptor::error::Error> for MutinyError {
impl From<bdk::wallet::NewError<MutinyError>> for MutinyError {
fn from(e: bdk::wallet::NewError<MutinyError>) -> Self {
match e {
bdk::wallet::NewError::Persist(e) => e,
bdk::wallet::NewError::Write(e) => e,
bdk::wallet::NewError::Descriptor(e) => e.into(),
bdk::wallet::NewError::NonEmptyDatabase => Self::WalletOperationFailed,
}
}
}

impl From<bdk::wallet::LoadError<MutinyError>> for MutinyError {
fn from(e: bdk::wallet::LoadError<MutinyError>) -> Self {
match e {
bdk::wallet::LoadError::Descriptor(e) => e.into(),
bdk::wallet::LoadError::Load(e) => e,
bdk::wallet::LoadError::MissingGenesis => Self::WalletOperationFailed,
bdk::wallet::LoadError::MissingNetwork => Self::WalletOperationFailed,
bdk::wallet::LoadError::NotInitialized => Self::WalletOperationFailed,
}
}
}

impl From<AddUtxoError> for MutinyError {
fn from(_: AddUtxoError) -> Self {
Self::WalletOperationFailed
}
}

impl From<bip39::Error> for MutinyError {
fn from(_e: bip39::Error) -> Self {
Self::InvalidMnemonic
}
}

impl From<bitcoin::util::bip32::Error> for MutinyError {
fn from(_e: bitcoin::util::bip32::Error) -> Self {
impl From<bitcoin::bip32::Error> for MutinyError {
fn from(_e: bitcoin::bip32::Error) -> Self {
Self::InvalidMnemonic
}
}
Expand Down Expand Up @@ -366,15 +382,12 @@ impl From<PeerHandleError> for MutinyError {
}
}

impl From<PaymentError> for MutinyError {
fn from(e: PaymentError) -> Self {
match e {
PaymentError::Invoice(_) => Self::InvoiceInvalid,
PaymentError::Sending(s) => match s {
RetryableSendFailure::PaymentExpired => Self::InvoiceExpired,
RetryableSendFailure::RouteNotFound => Self::RoutingFailed,
RetryableSendFailure::DuplicatePayment => Self::NonUniquePaymentHash,
},
impl From<RetryableSendFailure> for MutinyError {
fn from(s: RetryableSendFailure) -> Self {
match s {
RetryableSendFailure::PaymentExpired => Self::InvoiceExpired,
RetryableSendFailure::RouteNotFound => Self::RoutingFailed,
RetryableSendFailure::DuplicatePayment => Self::NonUniquePaymentHash,
}
}
}
Expand Down Expand Up @@ -427,10 +440,15 @@ impl From<bitcoin::hashes::hex::Error> for MutinyError {
}
}

impl From<bitcoin::util::address::Error> for MutinyError {
fn from(_e: bitcoin::util::address::Error) -> Self {
MutinyError::ReadError {
source: MutinyStorageError::Other(anyhow::anyhow!("Failed to decode address")),
impl From<bitcoin::address::Error> for MutinyError {
fn from(e: bitcoin::address::Error) -> Self {
match e {
bitcoin::address::Error::NetworkValidation { .. } => MutinyError::IncorrectNetwork,
bitcoin::address::Error::UnrecognizedScript => MutinyError::InvalidArgumentsError,
bitcoin::address::Error::UnknownAddressType(_) => MutinyError::InvalidArgumentsError,
_ => MutinyError::ReadError {
source: MutinyStorageError::Other(anyhow::anyhow!("Failed to decode address")),
},
}
}
}
Expand All @@ -442,15 +460,33 @@ impl From<esplora_client::Error> for MutinyError {
}
}

impl From<bdk_chain::local_chain::InsertBlockNotMatchingError> for MutinyError {
fn from(_e: bdk_chain::local_chain::InsertBlockNotMatchingError) -> Self {
impl From<bdk::wallet::InsertTxError> for MutinyError {
fn from(_e: bdk::wallet::InsertTxError) -> Self {
Self::WalletSyncError
}
}

impl From<bdk::wallet::InsertTxError> for MutinyError {
fn from(_e: bdk::wallet::InsertTxError) -> Self {
Self::WalletSyncError
impl<S> From<bdk::wallet::error::CreateTxError<S>> for MutinyError {
fn from(_e: bdk::wallet::error::CreateTxError<S>) -> Self {
Self::WalletOperationFailed
}
}

impl From<BuildFeeBumpError> for MutinyError {
fn from(e: BuildFeeBumpError) -> Self {
match e {
BuildFeeBumpError::UnknownUtxo(_) => Self::NotFound,
BuildFeeBumpError::TransactionNotFound(_) => Self::NotFound,
BuildFeeBumpError::TransactionConfirmed(_) => Self::NotFound,
BuildFeeBumpError::IrreplaceableTransaction(_) => Self::InvalidArgumentsError,
BuildFeeBumpError::FeeRateUnavailable => Self::WalletOperationFailed,
}
}
}

impl From<SignerError> for MutinyError {
fn from(_: SignerError) -> Self {
Self::WalletOperationFailed
}
}

Expand Down
41 changes: 20 additions & 21 deletions mutiny-core/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ use crate::utils::sleep;
use crate::{fees::MutinyFeeEstimator, storage::read_payment_info};
use crate::{keymanager::PhantomKeysManager, storage::persist_payment_info};
use anyhow::anyhow;
use bitcoin::hashes::hex::ToHex;
use bitcoin::absolute::LockTime;
use bitcoin::secp256k1::PublicKey;
use bitcoin::secp256k1::Secp256k1;
use bitcoin::{LockTime, PackedLockTime};
use core::fmt;
use lightning::events::{Event, PaymentPurpose};
use lightning::sign::SpendableOutputDescriptor;
Expand Down Expand Up @@ -175,7 +174,7 @@ impl<S: MutinyStorage> EventHandler<S> {
}
};

let label = format!("LN Channel: {}", counterparty_node_id.to_hex());
let label = format!("LN Channel: {}", counterparty_node_id);
let labels = params_opt
.as_ref()
.and_then(|p| p.labels.clone())
Expand Down Expand Up @@ -238,7 +237,7 @@ impl<S: MutinyStorage> EventHandler<S> {
counterparty_skimmed_fee_msat,
..
} => {
log_debug!(self.logger, "EVENT: PaymentReceived received payment from payment hash {} of {amount_msat} millisatoshis to {receiver_node_id:?}", payment_hash.0.to_hex());
log_debug!(self.logger, "EVENT: PaymentReceived received payment from payment hash {} of {amount_msat} millisatoshis to {receiver_node_id:?}", payment_hash);

let expected_skimmed_fee_msat = self
.lsp_client
Expand Down Expand Up @@ -272,7 +271,7 @@ impl<S: MutinyStorage> EventHandler<S> {
htlcs,
sender_intended_total_msat,
} => {
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());
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());

let (payment_preimage, payment_secret) = match purpose {
PaymentPurpose::InvoicePayment {
Expand Down Expand Up @@ -345,11 +344,7 @@ impl<S: MutinyStorage> EventHandler<S> {
fee_paid_msat,
..
} => {
log_debug!(
self.logger,
"EVENT: PaymentSent: {}",
payment_hash.0.to_hex()
);
log_debug!(self.logger, "EVENT: PaymentSent: {}", payment_hash);

match read_payment_info(
&self.persister.storage,
Expand Down Expand Up @@ -446,11 +441,7 @@ impl<S: MutinyStorage> EventHandler<S> {
log_debug!(self.logger, "EVENT: ProbeFailed, ignored");
}
Event::PaymentFailed { payment_hash, .. } => {
log_error!(
self.logger,
"EVENT: PaymentFailed: {}",
payment_hash.0.to_hex()
);
log_error!(self.logger, "EVENT: PaymentFailed: {}", payment_hash);

match read_payment_info(
&self.persister.storage,
Expand Down Expand Up @@ -518,6 +509,7 @@ impl<S: MutinyStorage> EventHandler<S> {
user_channel_id,
counterparty_node_id: node_id,
channel_capacity_sats,
..
} => {
// if we still have channel open params, then it was just a failed channel open
// we should not persist this as a closed channel and just delete the channel open params
Expand All @@ -529,7 +521,7 @@ impl<S: MutinyStorage> EventHandler<S> {
log_debug!(
self.logger,
"EVENT: Channel {} of size {} closed due to: {:?}",
channel_id.to_hex(),
channel_id,
channel_capacity_sats
.map(|s| s.to_string())
.unwrap_or_else(|| "unknown".to_string()),
Expand Down Expand Up @@ -558,9 +550,9 @@ impl<S: MutinyStorage> EventHandler<S> {
log_debug!(
self.logger,
"EVENT: ChannelReady channel_id: {}, user_channel_id: {}, counterparty_node_id: {}, channel_type: {}",
channel_id.to_hex(),
channel_id,
user_channel_id,
counterparty_node_id.to_hex(),
counterparty_node_id,
channel_type);
}
Event::ChannelPending {
Expand All @@ -572,9 +564,9 @@ impl<S: MutinyStorage> EventHandler<S> {
log_debug!(
self.logger,
"EVENT: ChannelPending channel_id: {}, user_channel_id: {}, counterparty_node_id: {}",
channel_id.to_hex(),
channel_id,
user_channel_id,
counterparty_node_id.to_hex());
counterparty_node_id);

if let Err(e) = self.persister.delete_channel_open_params(user_channel_id) {
log_warn!(
Expand All @@ -592,6 +584,13 @@ impl<S: MutinyStorage> EventHandler<S> {
// we don't support bolt 12 yet
log_warn!(self.logger, "EVENT: InvoiceRequestFailed: {payment_id}");
}
Event::ConnectionNeeded { node_id, addresses } => {
// we don't support bolt 12 yet, and we won't have the connection info anyways
log_debug!(
self.logger,
"EVENT: ConnectionNeeded: {node_id} @ {addresses:?}"
);
}
}
}

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

let locktime = LockTime::from_height(height).map(PackedLockTime::from).ok();
let locktime = LockTime::from_height(height).ok();

let spending_tx = self
.keys_manager
Expand Down