Skip to content

Client trusts lsp #572

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
47 changes: 24 additions & 23 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,28 @@ panic = 'abort' # Abort on panic
default = []

[dependencies]
lightning = { version = "0.1.0", features = ["std"] }
lightning-types = { version = "0.2.0" }
lightning-invoice = { version = "0.33.0", features = ["std"] }
lightning-net-tokio = { version = "0.1.0" }
lightning-persister = { version = "0.1.0" }
lightning-background-processor = { version = "0.1.0", features = ["futures"] }
lightning-rapid-gossip-sync = { version = "0.1.0" }
lightning-block-sync = { version = "0.1.0", features = ["rpc-client", "tokio"] }
lightning-transaction-sync = { version = "0.1.0", features = ["esplora-async-https", "time", "electrum"] }
lightning-liquidity = { version = "0.1.0", features = ["std"] }

#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", features = ["std"] }
#lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
#lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", features = ["std"] }
#lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
#lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
#lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", features = ["futures"] }
#lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
#lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", features = ["rpc-client", "tokio"] }
#lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", features = ["esplora-async-https", "electrum", "time"] }
#lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
#lightning = { version = "0.1.0", features = ["std"] }
#lightning-types = { version = "0.2.0" }
#lightning-invoice = { version = "0.33.0", features = ["std"] }
#lightning-net-tokio = { version = "0.1.0" }
#lightning-persister = { version = "0.1.0" }
#lightning-background-processor = { version = "0.1.0", features = ["futures"] }
#lightning-rapid-gossip-sync = { version = "0.1.0" }
#lightning-block-sync = { version = "0.1.0", features = ["rpc-client", "tokio"] }
#lightning-transaction-sync = { version = "0.1.0", features = ["esplora-async-https", "time", "electrum"] }
#lightning-liquidity = { version = "0.1.0", features = ["std"] }

lightning = { git = "https://github.com/martinsaposnic/rust-lightning", branch = "client-trusts-lsp", features = ["std"] }
lightning-types = { git = "https://github.com/martinsaposnic/rust-lightning", branch = "client-trusts-lsp" }
lightning-invoice = { git = "https://github.com/martinsaposnic/rust-lightning", branch = "client-trusts-lsp", features = ["std"] }
lightning-net-tokio = { git = "https://github.com/martinsaposnic/rust-lightning", branch = "client-trusts-lsp" }
lightning-persister = { git = "https://github.com/martinsaposnic/rust-lightning", branch = "client-trusts-lsp" }
lightning-background-processor = { git = "https://github.com/martinsaposnic/rust-lightning", branch = "client-trusts-lsp" }
lightning-rapid-gossip-sync = { git = "https://github.com/martinsaposnic/rust-lightning", branch = "client-trusts-lsp" }
lightning-block-sync = { git = "https://github.com/martinsaposnic/rust-lightning", branch = "client-trusts-lsp", features = ["rpc-client", "tokio"] }
lightning-transaction-sync = { git = "https://github.com/martinsaposnic/rust-lightning", branch = "client-trusts-lsp", features = ["esplora-async-https", "electrum", "time"] }
lightning-liquidity = { git = "https://github.com/martinsaposnic/rust-lightning", branch = "client-trusts-lsp" }
lightning-macros = { git = "https://github.com/martinsaposnic/rust-lightning", branch = "client-trusts-lsp" }

#lightning = { path = "../rust-lightning/lightning", features = ["std"] }
#lightning-types = { path = "../rust-lightning/lightning-types" }
Expand Down Expand Up @@ -96,8 +97,8 @@ prost = { version = "0.11.6", default-features = false}
winapi = { version = "0.3", features = ["winbase"] }

[dev-dependencies]
lightning = { version = "0.1.0", features = ["std", "_test_utils"] }
#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["std", "_test_utils"] }
#lightning = { version = "0.1.0", features = ["std", "_test_utils"] }
lightning = { git = "https://github.com/martinsaposnic/rust-lightning", branch="client-trusts-lsp", features = ["std", "_test_utils"] }
#lightning = { path = "../rust-lightning/lightning", features = ["std", "_test_utils"] }
proptest = "1.0.0"
regex = "1.5.6"
Expand Down
76 changes: 35 additions & 41 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dictionary Config {
sequence<PublicKey> trusted_peers_0conf;
u64 probing_liquidity_limit_multiplier;
AnchorChannelsConfig? anchor_channels_config;
SendingParameters? sending_parameters;
RouteParametersConfig? route_parameters;
};

dictionary AnchorChannelsConfig {
Expand Down Expand Up @@ -160,19 +160,19 @@ interface Node {

[Enum]
interface Bolt11InvoiceDescription {
Hash(string hash);
Direct(string description);
Hash(string hash);
Direct(string description);
};

interface Bolt11Payment {
[Throws=NodeError]
PaymentId send([ByRef]Bolt11Invoice invoice, SendingParameters? sending_parameters);
PaymentId send([ByRef]Bolt11Invoice invoice, RouteParametersConfig? route_parameters);
[Throws=NodeError]
PaymentId send_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat, SendingParameters? sending_parameters);
PaymentId send_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void send_probes([ByRef]Bolt11Invoice invoice);
void send_probes([ByRef]Bolt11Invoice invoice, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void send_probes_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat);
void send_probes_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void claim_for_hash(PaymentHash payment_hash, u64 claimable_amount_msat, PaymentPreimage preimage);
[Throws=NodeError]
Expand Down Expand Up @@ -208,9 +208,9 @@ interface Bolt12Payment {

interface SpontaneousPayment {
[Throws=NodeError]
PaymentId send(u64 amount_msat, PublicKey node_id, SendingParameters? sending_parameters);
PaymentId send(u64 amount_msat, PublicKey node_id, RouteParametersConfig? route_parameters);
[Throws=NodeError]
PaymentId send_with_custom_tlvs(u64 amount_msat, PublicKey node_id, SendingParameters? sending_parameters, sequence<CustomTlvRecord> custom_tlvs);
PaymentId send_with_custom_tlvs(u64 amount_msat, PublicKey node_id, RouteParametersConfig? route_parameters, sequence<CustomTlvRecord> custom_tlvs);
[Throws=NodeError]
void send_probes(u64 amount_msat, PublicKey node_id);
};
Expand Down Expand Up @@ -245,7 +245,7 @@ interface LSPS1Liquidity {
[Throws=NodeError]
LSPS1OrderStatus request_channel(u64 lsp_balance_sat, u64 client_balance_sat, u32 channel_expiry_blocks, boolean announce_channel);
[Throws=NodeError]
LSPS1OrderStatus check_order_status(OrderId order_id);
LSPS1OrderStatus check_order_status(LSPS1OrderId order_id);
};

[Error]
Expand Down Expand Up @@ -446,11 +446,11 @@ dictionary PaymentDetails {
u64 latest_update_timestamp;
};

dictionary SendingParameters {
MaxTotalRoutingFeeLimit? max_total_routing_fee_msat;
u32? max_total_cltv_expiry_delta;
u8? max_path_count;
u8? max_channel_saturation_power_of_half;
dictionary RouteParametersConfig {
u64? max_total_routing_fee_msat;
u32 max_total_cltv_expiry_delta;
u8 max_path_count;
u8 max_channel_saturation_power_of_half;
};

dictionary CustomTlvRecord {
Expand All @@ -459,13 +459,13 @@ dictionary CustomTlvRecord {
};

dictionary LSPS1OrderStatus {
OrderId order_id;
OrderParameters order_params;
PaymentInfo payment_options;
ChannelOrderInfo? channel_state;
LSPS1OrderId order_id;
LSPS1OrderParams order_params;
LSPS1PaymentInfo payment_options;
LSPS1ChannelInfo? channel_state;
};

dictionary OrderParameters {
dictionary LSPS1OrderParams {
u64 lsp_balance_sat;
u64 client_balance_sat;
u16 required_channel_confirmations;
Expand All @@ -475,22 +475,22 @@ dictionary OrderParameters {
boolean announce_channel;
};

dictionary PaymentInfo {
Bolt11PaymentInfo? bolt11;
OnchainPaymentInfo? onchain;
dictionary LSPS1PaymentInfo {
LSPS1Bolt11PaymentInfo? bolt11;
LSPS1OnchainPaymentInfo? onchain;
};

dictionary Bolt11PaymentInfo {
PaymentState state;
DateTime expires_at;
dictionary LSPS1Bolt11PaymentInfo {
LSPS1PaymentState state;
LSPSDateTime expires_at;
u64 fee_total_sat;
u64 order_total_sat;
Bolt11Invoice invoice;
};

dictionary OnchainPaymentInfo {
PaymentState state;
DateTime expires_at;
dictionary LSPS1OnchainPaymentInfo {
LSPS1PaymentState state;
LSPSDateTime expires_at;
u64 fee_total_sat;
u64 order_total_sat;
Address address;
Expand All @@ -499,24 +499,18 @@ dictionary OnchainPaymentInfo {
Address? refund_onchain_address;
};

dictionary ChannelOrderInfo {
DateTime funded_at;
dictionary LSPS1ChannelInfo {
LSPSDateTime funded_at;
OutPoint funding_outpoint;
DateTime expires_at;
LSPSDateTime expires_at;
};

enum PaymentState {
enum LSPS1PaymentState {
"ExpectPayment",
"Paid",
"Refunded",
};

[Enum]
interface MaxTotalRoutingFeeLimit {
None ();
Some ( u64 amount_msat );
};

[NonExhaustive]
enum Network {
"Bitcoin",
Expand Down Expand Up @@ -851,7 +845,7 @@ typedef string UntrustedString;
typedef string NodeAlias;

[Custom]
typedef string OrderId;
typedef string LSPS1OrderId;

[Custom]
typedef string DateTime;
typedef string LSPSDateTime;
15 changes: 2 additions & 13 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1187,17 +1187,6 @@ fn build_with_store_internal(
};

let mut user_config = default_user_config(&config);
if liquidity_source_config.and_then(|lsc| lsc.lsps2_client.as_ref()).is_some() {
// Generally allow claiming underpaying HTLCs as the LSP will skim off some fee. We'll
// check that they don't take too much before claiming.
user_config.channel_config.accept_underpaying_htlcs = true;

// FIXME: When we're an LSPS2 client, set maximum allowed inbound HTLC value in flight
// to 100%. We should eventually be able to set this on a per-channel basis, but for
// now we just bump the default for all channels.
user_config.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel =
100;
}

if liquidity_source_config.and_then(|lsc| lsc.lsps2_service.as_ref()).is_some() {
// If we act as an LSPS2 service, we need to to be able to intercept HTLCs and forward the
Expand Down Expand Up @@ -1275,8 +1264,8 @@ fn build_with_store_internal(

// Give ChannelMonitors to ChainMonitor
for (_blockhash, channel_monitor) in channel_monitors.into_iter() {
let funding_outpoint = channel_monitor.get_funding_txo().0;
chain_monitor.watch_channel(funding_outpoint, channel_monitor).map_err(|e| {
let channel_id = channel_monitor.channel_id();
chain_monitor.watch_channel(channel_id, channel_monitor).map_err(|e| {
log_error!(logger, "Failed to watch channel monitor: {:?}", e);
BuildError::InvalidChannelMonitor
})?;
Expand Down
2 changes: 1 addition & 1 deletion src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ impl ChainSource {
if let Some(worst_channel_monitor_block_hash) = chain_monitor
.list_monitors()
.iter()
.flat_map(|(txo, _)| chain_monitor.get_monitor(*txo))
.flat_map(|channel_id| chain_monitor.get_monitor(*channel_id))
.map(|m| m.current_best_block())
.min_by_key(|b| b.height)
.map(|b| b.block_hash)
Expand Down
12 changes: 6 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
//! Objects for configuring the node.

use crate::logger::LogLevel;
use crate::payment::SendingParameters;

use lightning::ln::msgs::SocketAddress;
use lightning::routing::gossip::NodeAlias;
use lightning::routing::router::RouteParametersConfig;
use lightning::util::config::ChannelConfig as LdkChannelConfig;
use lightning::util::config::MaxDustHTLCExposure as LdkMaxDustHTLCExposure;
use lightning::util::config::UserConfig;
Expand Down Expand Up @@ -102,9 +102,9 @@ pub const WALLET_KEYS_SEED_LEN: usize = 64;
/// | `probing_liquidity_limit_multiplier` | 3 |
/// | `log_level` | Debug |
/// | `anchor_channels_config` | Some(..) |
/// | `sending_parameters` | None |
/// | `route_parameters` | None |
///
/// See [`AnchorChannelsConfig`] and [`SendingParameters`] for more information regarding their
/// See [`AnchorChannelsConfig`] and [`RouteParametersConfig`] for more information regarding their
/// respective default values.
///
/// [`Node`]: crate::Node
Expand Down Expand Up @@ -161,12 +161,12 @@ pub struct Config {
pub anchor_channels_config: Option<AnchorChannelsConfig>,
/// Configuration options for payment routing and pathfinding.
///
/// Setting the `SendingParameters` provides flexibility to customize how payments are routed,
/// Setting the [`RouteParametersConfig`] provides flexibility to customize how payments are routed,
/// including setting limits on routing fees, CLTV expiry, and channel utilization.
///
/// **Note:** If unset, default parameters will be used, and you will be able to override the
/// parameters on a per-payment basis in the corresponding method calls.
pub sending_parameters: Option<SendingParameters>,
pub route_parameters: Option<RouteParametersConfig>,
}

impl Default for Config {
Expand All @@ -179,7 +179,7 @@ impl Default for Config {
trusted_peers_0conf: Vec::new(),
probing_liquidity_limit_multiplier: DEFAULT_PROBING_LIQUIDITY_LIMIT_MULTIPLIER,
anchor_channels_config: Some(AnchorChannelsConfig::default()),
sending_parameters: None,
route_parameters: None,
node_alias: None,
}
}
Expand Down
Loading
Loading