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

Upgrade the World #358

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ panic = 'abort' # Abort on panic
default = []

[dependencies]
lightning = { version = "0.0.123", features = ["std"] }
lightning-invoice = { version = "0.31.0" }
lightning-net-tokio = { version = "0.0.123" }
lightning-persister = { version = "0.0.123" }
lightning-background-processor = { version = "0.0.123", features = ["futures"] }
lightning-rapid-gossip-sync = { version = "0.0.123" }
lightning-transaction-sync = { version = "0.0.123", features = ["esplora-async-https", "time"] }
lightning-liquidity = { version = "=0.1.0-alpha.4", features = ["std"] }
lightning = { version = "0.0.124", features = ["std"] }
lightning-invoice = { version = "0.32.0" }
lightning-net-tokio = { version = "0.0.124" }
lightning-persister = { version = "0.0.124" }
lightning-background-processor = { version = "0.0.124", features = ["futures"] }
lightning-rapid-gossip-sync = { version = "0.0.124" }
lightning-transaction-sync = { version = "0.0.124", features = ["esplora-async-https", "time"] }
lightning-liquidity = { version = "0.1.0-alpha.5", features = ["std"] }

#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["std"] }
#lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main" }
Expand All @@ -55,18 +55,20 @@ lightning-liquidity = { version = "=0.1.0-alpha.4", features = ["std"] }
#lightning-transaction-sync = { path = "../rust-lightning/lightning-transaction-sync", features = ["esplora-async"] }
#lightning-liquidity = { path = "../lightning-liquidity", features = ["std"] }

bdk = { version = "0.29.0", default-features = false, features = ["std", "async-interface", "use-esplora-async", "sqlite-bundled", "keys-bip39"]}
bdk_chain = { version = "=0.19.0", default-features = false, features = ["std"] }
bdk_esplora = { version = "=0.18.0", default-features = false, features = ["async-https-rustls"]}
bdk_wallet = { version = "=1.0.0-beta.4", default-features = false, features = ["std", "keys-bip39"]}

reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls"] }
rusqlite = { version = "0.28.0", features = ["bundled"] }
bitcoin = "0.30.2"
bitcoin = "0.32.2"
bip39 = "2.0.0"
bip21 = { version = "0.3.1", features = ["std"], default-features = false }
bip21 = { version = "0.5", features = ["std"], default-features = false }

rand = "0.8.5"
chrono = { version = "0.4", default-features = false, features = ["clock"] }
tokio = { version = "1.37", default-features = false, features = [ "rt-multi-thread", "time", "sync" ] }
esplora-client = { version = "0.6", default-features = false }
tokio = { version = "1.37", default-features = false, features = [ "rt-multi-thread", "time", "sync", "macros" ] }
esplora-client = { version = "0.9", default-features = false }
libc = "0.2"
uniffi = { version = "0.26.0", features = ["build"], optional = true }

Expand All @@ -78,18 +80,18 @@ prost = { version = "0.11.6", default-features = false}
winapi = { version = "0.3", features = ["winbase"] }

[dev-dependencies]
lightning = { version = "0.0.123", features = ["std", "_test_utils"] }
lightning = { version = "0.0.124", features = ["std", "_test_utils"] }
#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["std", "_test_utils"] }
electrum-client = { version = "0.15.1", default-features = true }
bitcoincore-rpc = { version = "0.17.0", default-features = false }
electrum-client = { version = "0.21.0", default-features = true }
bitcoincore-rpc = { version = "0.19.0", default-features = false }
proptest = "1.0.0"
regex = "1.5.6"

[target.'cfg(not(no_download))'.dev-dependencies]
electrsd = { version = "0.26.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_25_0"] }
electrsd = { version = "0.29.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_25_0"] }

[target.'cfg(no_download)'.dev-dependencies]
electrsd = { version = "0.26.0", features = ["legacy"] }
electrsd = { version = "0.29.0", features = ["legacy"] }

[target.'cfg(cln_test)'.dev-dependencies]
clightningrpc = { version = "0.3.0-beta.8", default-features = false }
Expand Down
76 changes: 62 additions & 14 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ interface Node {
[Throws=NodeError]
void close_channel([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id);
[Throws=NodeError]
void force_close_channel([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id);
void force_close_channel([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, string? reason);
[Throws=NodeError]
void update_channel_config([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, ChannelConfig channel_config);
[Throws=NodeError]
Expand All @@ -92,7 +92,6 @@ interface Node {
sequence<PeerDetails> list_peers();
sequence<ChannelDetails> list_channels();
NetworkGraph network_graph();
[Throws=NodeError]
string sign_message([ByRef]sequence<u8> msg);
boolean verify_signature([ByRef]sequence<u8> msg, [ByRef]string sig, [ByRef]PublicKey pkey);
};
Expand Down Expand Up @@ -130,9 +129,9 @@ interface Bolt12Payment {
[Throws=NodeError]
PaymentId send_using_amount([ByRef]Offer offer, u64 amount_msat, u64? quantity, string? payer_note);
[Throws=NodeError]
Offer receive(u64 amount_msat, [ByRef]string description, u64? quantity);
Offer receive(u64 amount_msat, [ByRef]string description, u32? expiry_secs, u64? quantity);
[Throws=NodeError]
Offer receive_variable_amount([ByRef]string description);
Offer receive_variable_amount([ByRef]string description, u32? expiry_secs);
[Throws=NodeError]
Bolt12Invoice request_refund_payment([ByRef]Refund refund);
[Throws=NodeError]
Expand Down Expand Up @@ -183,7 +182,6 @@ enum NodeError {
"WalletOperationFailed",
"WalletOperationTimeout",
"OnchainTxSigningFailed",
"MessageSigningFailed",
"TxSyncFailed",
"TxSyncTimeout",
"GossipUpdateFailed",
Expand Down Expand Up @@ -251,7 +249,7 @@ enum BuildError {
[Enum]
interface Event {
PaymentSuccessful(PaymentId? payment_id, PaymentHash payment_hash, u64? fee_paid_msat);
PaymentFailed(PaymentId? payment_id, PaymentHash payment_hash, PaymentFailureReason? reason);
PaymentFailed(PaymentId? payment_id, PaymentHash? payment_hash, PaymentFailureReason? reason);
PaymentReceived(PaymentId? payment_id, PaymentHash payment_hash, u64 amount_msat);
PaymentClaimable(PaymentId payment_id, PaymentHash payment_hash, u64 claimable_amount_msat, u32? claim_deadline);
ChannelPending(ChannelId channel_id, UserChannelId user_channel_id, ChannelId former_temporary_channel_id, PublicKey counterparty_node_id, OutPoint funding_txo);
Expand All @@ -266,12 +264,15 @@ enum PaymentFailureReason {
"PaymentExpired",
"RouteNotFound",
"UnexpectedError",
"UnknownRequiredFeatures",
"InvoiceRequestExpired",
"InvoiceRequestRejected",
};

[Enum]
interface ClosureReason {
CounterpartyForceClosed(UntrustedString peer_msg);
HolderForceClosed();
HolderForceClosed(boolean? broadcasted_latest_txn);
LegacyCooperativeClosure();
CounterpartyInitiatedCooperativeClosure();
LocallyInitiatedCooperativeClosure();
Expand All @@ -283,6 +284,7 @@ interface ClosureReason {
CounterpartyCoopClosedUnfundedChannel();
FundingBatchClosure();
HTLCsTimedOut();
PeerFeerateTooLow(u32 peer_feerate_sat_per_kw, u32 required_feerate_sat_per_kw);
};

[Enum]
Expand Down Expand Up @@ -368,7 +370,7 @@ dictionary ChannelDetails {
boolean is_outbound;
boolean is_channel_ready;
boolean is_usable;
boolean is_public;
boolean is_announced;
u16? cltv_expiry_delta;
u64 counterparty_unspendable_punishment_reserve;
u64? counterparty_outbound_htlc_minimum_msat;
Expand All @@ -393,12 +395,58 @@ dictionary PeerDetails {

[Enum]
interface LightningBalance {
ClaimableOnChannelClose ( ChannelId channel_id, PublicKey counterparty_node_id, u64 amount_satoshis );
ClaimableAwaitingConfirmations ( ChannelId channel_id, PublicKey counterparty_node_id, u64 amount_satoshis, u32 confirmation_height );
ContentiousClaimable ( ChannelId channel_id, PublicKey counterparty_node_id, u64 amount_satoshis, u32 timeout_height, PaymentHash payment_hash, PaymentPreimage payment_preimage );
MaybeTimeoutClaimableHTLC ( ChannelId channel_id, PublicKey counterparty_node_id, u64 amount_satoshis, u32 claimable_height, PaymentHash payment_hash);
MaybePreimageClaimableHTLC ( ChannelId channel_id, PublicKey counterparty_node_id, u64 amount_satoshis, u32 expiry_height, PaymentHash payment_hash);
CounterpartyRevokedOutputClaimable ( ChannelId channel_id, PublicKey counterparty_node_id, u64 amount_satoshis );
ClaimableOnChannelClose (
ChannelId channel_id,
PublicKey counterparty_node_id,
u64 amount_satoshis,
u64 transaction_fee_satoshis,
u64 outbound_payment_htlc_rounded_msat,
u64 outbound_forwarded_htlc_rounded_msat,
u64 inbound_claiming_htlc_rounded_msat,
u64 inbound_htlc_rounded_msat
);
ClaimableAwaitingConfirmations (
ChannelId channel_id,
PublicKey counterparty_node_id,
u64 amount_satoshis,
u32 confirmation_height,
BalanceSource source
);
ContentiousClaimable (
ChannelId channel_id,
PublicKey counterparty_node_id,
u64 amount_satoshis,
u32 timeout_height,
PaymentHash payment_hash,
PaymentPreimage payment_preimage
);
MaybeTimeoutClaimableHTLC (
ChannelId channel_id,
PublicKey counterparty_node_id,
u64 amount_satoshis,
u32 claimable_height,
PaymentHash payment_hash,
boolean outbound_payment
);
MaybePreimageClaimableHTLC (
ChannelId channel_id,
PublicKey counterparty_node_id,
u64 amount_satoshis,
u32 expiry_height,
PaymentHash payment_hash
);
CounterpartyRevokedOutputClaimable (
ChannelId channel_id,
PublicKey counterparty_node_id,
u64 amount_satoshis
);
};

enum BalanceSource {
"HolderForceClosed",
"CounterpartyForceClosed",
"CoopClose",
"Htlc",
};

[Enum]
Expand Down
100 changes: 84 additions & 16 deletions src/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
// accordance with one or both of these licenses.

use crate::sweep::value_satoshis_from_descriptor;
use crate::sweep::value_from_descriptor;

use lightning::chain::channelmonitor::Balance as LdkBalance;
use lightning::ln::{ChannelId, PaymentHash, PaymentPreimage};
use lightning::chain::channelmonitor::BalanceSource;
use lightning::ln::types::ChannelId;
use lightning::ln::{PaymentHash, PaymentPreimage};
use lightning::util::sweep::{OutputSpendStatus, TrackedSpendableOutput};

use bitcoin::secp256k1::PublicKey;
Expand Down Expand Up @@ -80,6 +82,49 @@ pub enum LightningBalance {
/// The amount available to claim, in satoshis, excluding the on-chain fees which will be
/// required to do so.
Comment on lines 82 to 83
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this mention other amounts no longer included here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mh, I left the docs to mirror LDK's docs, and there they seem unchanged?

amount_satoshis: u64,
/// The transaction fee we pay for the closing commitment transaction. This amount is not
/// included in the `amount_satoshis` value.
///
/// Note that if this channel is inbound (and thus our counterparty pays the commitment
/// transaction fee) this value will be zero. For channels created prior to LDK Node 0.4
/// the channel is always treated as outbound (and thus this value is never zero).
Comment on lines +89 to +90
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the channel is always treated as outbound (and thus this value is never zero).

Not sure what is meant by this. Is because LDK Node only allowed outbound channels? If so, why do we need to say this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it has nothing to do with LDK Node per se. This too is directly copied from the LDK docs to account for the behavior change:

Note that if this channel is inbound (and thus our counterparty pays the commitment transaction fee) this value will be zero. For ChannelMonitors created prior to LDK 0.0.124, the channel is always treated as outbound (and thus this value is never zero).

transaction_fee_satoshis: u64,
/// The amount of millisatoshis which has been burned to fees from HTLCs which are outbound
/// from us and are related to a payment which was sent by us. This is the sum of the
/// millisatoshis part of all HTLCs which are otherwise represented by
/// [`LightningBalance::MaybeTimeoutClaimableHTLC`] with their
/// [`LightningBalance::MaybeTimeoutClaimableHTLC::outbound_payment`] flag set, as well as
/// any dust HTLCs which would otherwise be represented the same.
///
/// This amount (rounded up to a whole satoshi value) will not be included in `amount_satoshis`.
outbound_payment_htlc_rounded_msat: u64,
/// The amount of millisatoshis which has been burned to fees from HTLCs which are outbound
/// from us and are related to a forwarded HTLC. This is the sum of the millisatoshis part
/// of all HTLCs which are otherwise represented by
/// [`LightningBalance::MaybeTimeoutClaimableHTLC`] with their
/// [`LightningBalance::MaybeTimeoutClaimableHTLC::outbound_payment`] flag *not* set, as
/// well as any dust HTLCs which would otherwise be represented the same.
///
/// This amount (rounded up to a whole satoshi value) will not be included in `amount_satoshis`.
outbound_forwarded_htlc_rounded_msat: u64,
/// The amount of millisatoshis which has been burned to fees from HTLCs which are inbound
/// to us and for which we know the preimage. This is the sum of the millisatoshis part of
/// all HTLCs which would be represented by [`LightningBalance::ContentiousClaimable`] on
/// channel close, but whose current value is included in `amount_satoshis`, as well as any
/// dust HTLCs which would otherwise be represented the same.
///
/// This amount (rounded up to a whole satoshi value) will not be included in the counterparty's
/// `amount_satoshis`.
inbound_claiming_htlc_rounded_msat: u64,
/// The amount of millisatoshis which has been burned to fees from HTLCs which are inbound
/// to us and for which we do not know the preimage. This is the sum of the millisatoshis
/// part of all HTLCs which would be represented by
/// [`LightningBalance::MaybePreimageClaimableHTLC`] on channel close, as well as any dust
/// HTLCs which would otherwise be represented the same.
///
/// This amount (rounded up to a whole satoshi value) will not be included in the
/// counterparty's `amount_satoshis`.
inbound_htlc_rounded_msat: u64,
},
/// The channel has been closed, and the given balance is ours but awaiting confirmations until
/// we consider it spendable.
Expand All @@ -96,6 +141,8 @@ pub enum LightningBalance {
///
/// [`Event::SpendableOutputs`]: lightning::events::Event::SpendableOutputs
confirmation_height: u32,
/// Whether this balance is a result of cooperative close, a force-close, or an HTLC.
source: BalanceSource,
},
/// The channel has been closed, and the given balance should be ours but awaiting spending
/// transaction confirmation. If the spending transaction does not confirm in time, it is
Expand Down Expand Up @@ -136,6 +183,8 @@ pub enum LightningBalance {
claimable_height: u32,
/// The payment hash whose preimage our counterparty needs to claim this HTLC.
payment_hash: PaymentHash,
/// Indicates whether this HTLC represents a payment which was sent outbound from us.
outbound_payment: bool,
},
/// HTLCs which we received from our counterparty which are claimable with a preimage which we
/// do not currently have. This will only be claimable if we receive the preimage from the node
Expand Down Expand Up @@ -174,16 +223,33 @@ impl LightningBalance {
channel_id: ChannelId, counterparty_node_id: PublicKey, balance: LdkBalance,
) -> Self {
match balance {
LdkBalance::ClaimableOnChannelClose { amount_satoshis } => {
Self::ClaimableOnChannelClose { channel_id, counterparty_node_id, amount_satoshis }
LdkBalance::ClaimableOnChannelClose {
amount_satoshis,
transaction_fee_satoshis,
outbound_payment_htlc_rounded_msat,
outbound_forwarded_htlc_rounded_msat,
inbound_claiming_htlc_rounded_msat,
inbound_htlc_rounded_msat,
} => Self::ClaimableOnChannelClose {
channel_id,
counterparty_node_id,
amount_satoshis,
transaction_fee_satoshis,
outbound_payment_htlc_rounded_msat,
outbound_forwarded_htlc_rounded_msat,
inbound_claiming_htlc_rounded_msat,
inbound_htlc_rounded_msat,
},
LdkBalance::ClaimableAwaitingConfirmations { amount_satoshis, confirmation_height } => {
Self::ClaimableAwaitingConfirmations {
channel_id,
counterparty_node_id,
amount_satoshis,
confirmation_height,
}
LdkBalance::ClaimableAwaitingConfirmations {
amount_satoshis,
confirmation_height,
source,
} => Self::ClaimableAwaitingConfirmations {
channel_id,
counterparty_node_id,
amount_satoshis,
confirmation_height,
source,
},
LdkBalance::ContentiousClaimable {
amount_satoshis,
Expand All @@ -202,12 +268,14 @@ impl LightningBalance {
amount_satoshis,
claimable_height,
payment_hash,
outbound_payment,
} => Self::MaybeTimeoutClaimableHTLC {
channel_id,
counterparty_node_id,
amount_satoshis,
claimable_height,
payment_hash,
outbound_payment,
},
LdkBalance::MaybePreimageClaimableHTLC {
amount_satoshis,
Expand Down Expand Up @@ -278,7 +346,7 @@ impl PendingSweepBalance {
match output_info.status {
OutputSpendStatus::PendingInitialBroadcast { .. } => {
let channel_id = output_info.channel_id;
let amount_satoshis = value_satoshis_from_descriptor(&output_info.descriptor);
let amount_satoshis = value_from_descriptor(&output_info.descriptor).to_sat();
Self::PendingBroadcast { channel_id, amount_satoshis }
},
OutputSpendStatus::PendingFirstConfirmation {
Expand All @@ -287,8 +355,8 @@ impl PendingSweepBalance {
..
} => {
let channel_id = output_info.channel_id;
let amount_satoshis = value_satoshis_from_descriptor(&output_info.descriptor);
let latest_spending_txid = latest_spending_tx.txid();
let amount_satoshis = value_from_descriptor(&output_info.descriptor).to_sat();
let latest_spending_txid = latest_spending_tx.compute_txid();
Self::BroadcastAwaitingConfirmation {
channel_id,
latest_broadcast_height,
Expand All @@ -303,8 +371,8 @@ impl PendingSweepBalance {
..
} => {
let channel_id = output_info.channel_id;
let amount_satoshis = value_satoshis_from_descriptor(&output_info.descriptor);
let latest_spending_txid = latest_spending_tx.txid();
let amount_satoshis = value_from_descriptor(&output_info.descriptor).to_sat();
let latest_spending_txid = latest_spending_tx.compute_txid();
Self::AwaitingThresholdConfirmations {
channel_id,
latest_spending_txid,
Expand Down
Loading
Loading