Skip to content

Commit c9c1b38

Browse files
Compatibility changes. DO NOT REVIEW
1 parent a2d4c1e commit c9c1b38

File tree

17 files changed

+1277
-556
lines changed

17 files changed

+1277
-556
lines changed

Cargo.toml

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,28 @@ panic = 'abort' # Abort on panic
2828
default = []
2929

3030
[dependencies]
31-
lightning = { version = "0.1.0", features = ["std"] }
32-
lightning-types = { version = "0.2.0" }
33-
lightning-invoice = { version = "0.33.0", features = ["std"] }
34-
lightning-net-tokio = { version = "0.1.0" }
35-
lightning-persister = { version = "0.1.0" }
36-
lightning-background-processor = { version = "0.1.0", features = ["futures"] }
37-
lightning-rapid-gossip-sync = { version = "0.1.0" }
38-
lightning-block-sync = { version = "0.1.0", features = ["rpc-client", "tokio"] }
39-
lightning-transaction-sync = { version = "0.1.0", features = ["esplora-async-https", "time", "electrum"] }
40-
lightning-liquidity = { version = "0.1.0", features = ["std"] }
41-
42-
#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", features = ["std"] }
43-
#lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
44-
#lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", features = ["std"] }
45-
#lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
46-
#lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
47-
#lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", features = ["futures"] }
48-
#lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
49-
#lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", features = ["rpc-client", "tokio"] }
50-
#lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", features = ["esplora-async-https", "electrum", "time"] }
51-
#lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
31+
#lightning = { version = "0.1.0", features = ["std"] }
32+
#lightning-types = { version = "0.2.0" }
33+
#lightning-invoice = { version = "0.33.0", features = ["std"] }
34+
#lightning-net-tokio = { version = "0.1.0" }
35+
#lightning-persister = { version = "0.1.0" }
36+
#lightning-background-processor = { version = "0.1.0", features = ["futures"] }
37+
#lightning-rapid-gossip-sync = { version = "0.1.0" }
38+
#lightning-block-sync = { version = "0.1.0", features = ["rpc-client", "tokio"] }
39+
#lightning-transaction-sync = { version = "0.1.0", features = ["esplora-async-https", "time", "electrum"] }
40+
#lightning-liquidity = { version = "0.1.0", features = ["std"] }
41+
42+
lightning = { git = "https://github.com/martinsaposnic/rust-lightning", branch = "client-trusts-lsp", features = ["std"] }
43+
lightning-types = { git = "https://github.com/martinsaposnic/rust-lightning", branch = "client-trusts-lsp" }
44+
lightning-invoice = { git = "https://github.com/martinsaposnic/rust-lightning", branch = "client-trusts-lsp", features = ["std"] }
45+
lightning-net-tokio = { git = "https://github.com/martinsaposnic/rust-lightning", branch = "client-trusts-lsp" }
46+
lightning-persister = { git = "https://github.com/martinsaposnic/rust-lightning", branch = "client-trusts-lsp" }
47+
lightning-background-processor = { git = "https://github.com/martinsaposnic/rust-lightning", branch = "client-trusts-lsp" }
48+
lightning-rapid-gossip-sync = { git = "https://github.com/martinsaposnic/rust-lightning", branch = "client-trusts-lsp" }
49+
lightning-block-sync = { git = "https://github.com/martinsaposnic/rust-lightning", branch = "client-trusts-lsp", features = ["rpc-client", "tokio"] }
50+
lightning-transaction-sync = { git = "https://github.com/martinsaposnic/rust-lightning", branch = "client-trusts-lsp", features = ["esplora-async-https", "electrum", "time"] }
51+
lightning-liquidity = { git = "https://github.com/martinsaposnic/rust-lightning", branch = "client-trusts-lsp" }
52+
lightning-macros = { git = "https://github.com/martinsaposnic/rust-lightning", branch = "client-trusts-lsp" }
5253

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

9899
[dev-dependencies]
99-
lightning = { version = "0.1.0", features = ["std", "_test_utils"] }
100-
#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["std", "_test_utils"] }
100+
#lightning = { version = "0.1.0", features = ["std", "_test_utils"] }
101+
lightning = { git = "https://github.com/martinsaposnic/rust-lightning", branch="client-trusts-lsp", features = ["std", "_test_utils"] }
101102
#lightning = { path = "../rust-lightning/lightning", features = ["std", "_test_utils"] }
102103
proptest = "1.0.0"
103104
regex = "1.5.6"

bindings/ldk_node.udl

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ dictionary Config {
1212
sequence<PublicKey> trusted_peers_0conf;
1313
u64 probing_liquidity_limit_multiplier;
1414
AnchorChannelsConfig? anchor_channels_config;
15-
SendingParameters? sending_parameters;
15+
RouteParametersConfig? route_parameters;
1616
};
1717

1818
dictionary AnchorChannelsConfig {
@@ -160,19 +160,19 @@ interface Node {
160160

161161
[Enum]
162162
interface Bolt11InvoiceDescription {
163-
Hash(string hash);
164-
Direct(string description);
163+
Hash(string hash);
164+
Direct(string description);
165165
};
166166

167167
interface Bolt11Payment {
168168
[Throws=NodeError]
169-
PaymentId send([ByRef]Bolt11Invoice invoice, SendingParameters? sending_parameters);
169+
PaymentId send([ByRef]Bolt11Invoice invoice, RouteParametersConfig? route_parameters);
170170
[Throws=NodeError]
171-
PaymentId send_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat, SendingParameters? sending_parameters);
171+
PaymentId send_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat, RouteParametersConfig? route_parameters);
172172
[Throws=NodeError]
173-
void send_probes([ByRef]Bolt11Invoice invoice);
173+
void send_probes([ByRef]Bolt11Invoice invoice, RouteParametersConfig? route_parameters);
174174
[Throws=NodeError]
175-
void send_probes_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat);
175+
void send_probes_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat, RouteParametersConfig? route_parameters);
176176
[Throws=NodeError]
177177
void claim_for_hash(PaymentHash payment_hash, u64 claimable_amount_msat, PaymentPreimage preimage);
178178
[Throws=NodeError]
@@ -208,9 +208,9 @@ interface Bolt12Payment {
208208

209209
interface SpontaneousPayment {
210210
[Throws=NodeError]
211-
PaymentId send(u64 amount_msat, PublicKey node_id, SendingParameters? sending_parameters);
211+
PaymentId send(u64 amount_msat, PublicKey node_id, RouteParametersConfig? route_parameters);
212212
[Throws=NodeError]
213-
PaymentId send_with_custom_tlvs(u64 amount_msat, PublicKey node_id, SendingParameters? sending_parameters, sequence<CustomTlvRecord> custom_tlvs);
213+
PaymentId send_with_custom_tlvs(u64 amount_msat, PublicKey node_id, RouteParametersConfig? route_parameters, sequence<CustomTlvRecord> custom_tlvs);
214214
[Throws=NodeError]
215215
void send_probes(u64 amount_msat, PublicKey node_id);
216216
};
@@ -245,7 +245,7 @@ interface LSPS1Liquidity {
245245
[Throws=NodeError]
246246
LSPS1OrderStatus request_channel(u64 lsp_balance_sat, u64 client_balance_sat, u32 channel_expiry_blocks, boolean announce_channel);
247247
[Throws=NodeError]
248-
LSPS1OrderStatus check_order_status(OrderId order_id);
248+
LSPS1OrderStatus check_order_status(LSPS1OrderId order_id);
249249
};
250250

251251
[Error]
@@ -446,11 +446,11 @@ dictionary PaymentDetails {
446446
u64 latest_update_timestamp;
447447
};
448448

449-
dictionary SendingParameters {
450-
MaxTotalRoutingFeeLimit? max_total_routing_fee_msat;
451-
u32? max_total_cltv_expiry_delta;
452-
u8? max_path_count;
453-
u8? max_channel_saturation_power_of_half;
449+
dictionary RouteParametersConfig {
450+
u64? max_total_routing_fee_msat;
451+
u32 max_total_cltv_expiry_delta;
452+
u8 max_path_count;
453+
u8 max_channel_saturation_power_of_half;
454454
};
455455

456456
dictionary CustomTlvRecord {
@@ -459,13 +459,13 @@ dictionary CustomTlvRecord {
459459
};
460460

461461
dictionary LSPS1OrderStatus {
462-
OrderId order_id;
463-
OrderParameters order_params;
464-
PaymentInfo payment_options;
465-
ChannelOrderInfo? channel_state;
462+
LSPS1OrderId order_id;
463+
LSPS1OrderParams order_params;
464+
LSPS1PaymentInfo payment_options;
465+
LSPS1ChannelInfo? channel_state;
466466
};
467467

468-
dictionary OrderParameters {
468+
dictionary LSPS1OrderParams {
469469
u64 lsp_balance_sat;
470470
u64 client_balance_sat;
471471
u16 required_channel_confirmations;
@@ -475,22 +475,22 @@ dictionary OrderParameters {
475475
boolean announce_channel;
476476
};
477477

478-
dictionary PaymentInfo {
479-
Bolt11PaymentInfo? bolt11;
480-
OnchainPaymentInfo? onchain;
478+
dictionary LSPS1PaymentInfo {
479+
LSPS1Bolt11PaymentInfo? bolt11;
480+
LSPS1OnchainPaymentInfo? onchain;
481481
};
482482

483-
dictionary Bolt11PaymentInfo {
484-
PaymentState state;
485-
DateTime expires_at;
483+
dictionary LSPS1Bolt11PaymentInfo {
484+
LSPS1PaymentState state;
485+
LSPSDateTime expires_at;
486486
u64 fee_total_sat;
487487
u64 order_total_sat;
488488
Bolt11Invoice invoice;
489489
};
490490

491-
dictionary OnchainPaymentInfo {
492-
PaymentState state;
493-
DateTime expires_at;
491+
dictionary LSPS1OnchainPaymentInfo {
492+
LSPS1PaymentState state;
493+
LSPSDateTime expires_at;
494494
u64 fee_total_sat;
495495
u64 order_total_sat;
496496
Address address;
@@ -499,24 +499,18 @@ dictionary OnchainPaymentInfo {
499499
Address? refund_onchain_address;
500500
};
501501

502-
dictionary ChannelOrderInfo {
503-
DateTime funded_at;
502+
dictionary LSPS1ChannelInfo {
503+
LSPSDateTime funded_at;
504504
OutPoint funding_outpoint;
505-
DateTime expires_at;
505+
LSPSDateTime expires_at;
506506
};
507507

508-
enum PaymentState {
508+
enum LSPS1PaymentState {
509509
"ExpectPayment",
510510
"Paid",
511511
"Refunded",
512512
};
513513

514-
[Enum]
515-
interface MaxTotalRoutingFeeLimit {
516-
None ();
517-
Some ( u64 amount_msat );
518-
};
519-
520514
[NonExhaustive]
521515
enum Network {
522516
"Bitcoin",
@@ -851,7 +845,7 @@ typedef string UntrustedString;
851845
typedef string NodeAlias;
852846

853847
[Custom]
854-
typedef string OrderId;
848+
typedef string LSPS1OrderId;
855849

856850
[Custom]
857-
typedef string DateTime;
851+
typedef string LSPSDateTime;

src/builder.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,17 +1187,6 @@ fn build_with_store_internal(
11871187
};
11881188

11891189
let mut user_config = default_user_config(&config);
1190-
if liquidity_source_config.and_then(|lsc| lsc.lsps2_client.as_ref()).is_some() {
1191-
// Generally allow claiming underpaying HTLCs as the LSP will skim off some fee. We'll
1192-
// check that they don't take too much before claiming.
1193-
user_config.channel_config.accept_underpaying_htlcs = true;
1194-
1195-
// FIXME: When we're an LSPS2 client, set maximum allowed inbound HTLC value in flight
1196-
// to 100%. We should eventually be able to set this on a per-channel basis, but for
1197-
// now we just bump the default for all channels.
1198-
user_config.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel =
1199-
100;
1200-
}
12011190

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

12761265
// Give ChannelMonitors to ChainMonitor
12771266
for (_blockhash, channel_monitor) in channel_monitors.into_iter() {
1278-
let funding_outpoint = channel_monitor.get_funding_txo().0;
1279-
chain_monitor.watch_channel(funding_outpoint, channel_monitor).map_err(|e| {
1267+
let channel_id = channel_monitor.channel_id();
1268+
chain_monitor.watch_channel(channel_id, channel_monitor).map_err(|e| {
12801269
log_error!(logger, "Failed to watch channel monitor: {:?}", e);
12811270
BuildError::InvalidChannelMonitor
12821271
})?;

src/chain/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ impl ChainSource {
452452
if let Some(worst_channel_monitor_block_hash) = chain_monitor
453453
.list_monitors()
454454
.iter()
455-
.flat_map(|(txo, _)| chain_monitor.get_monitor(*txo))
455+
.flat_map(|channel_id| chain_monitor.get_monitor(*channel_id))
456456
.map(|m| m.current_best_block())
457457
.min_by_key(|b| b.height)
458458
.map(|b| b.block_hash)

src/config.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
//! Objects for configuring the node.
99
1010
use crate::logger::LogLevel;
11-
use crate::payment::SendingParameters;
1211

1312
use lightning::ln::msgs::SocketAddress;
1413
use lightning::routing::gossip::NodeAlias;
14+
use lightning::routing::router::RouteParametersConfig;
1515
use lightning::util::config::ChannelConfig as LdkChannelConfig;
1616
use lightning::util::config::MaxDustHTLCExposure as LdkMaxDustHTLCExposure;
1717
use lightning::util::config::UserConfig;
@@ -102,9 +102,9 @@ pub const WALLET_KEYS_SEED_LEN: usize = 64;
102102
/// | `probing_liquidity_limit_multiplier` | 3 |
103103
/// | `log_level` | Debug |
104104
/// | `anchor_channels_config` | Some(..) |
105-
/// | `sending_parameters` | None |
105+
/// | `route_parameters` | None |
106106
///
107-
/// See [`AnchorChannelsConfig`] and [`SendingParameters`] for more information regarding their
107+
/// See [`AnchorChannelsConfig`] and [`RouteParametersConfig`] for more information regarding their
108108
/// respective default values.
109109
///
110110
/// [`Node`]: crate::Node
@@ -161,12 +161,12 @@ pub struct Config {
161161
pub anchor_channels_config: Option<AnchorChannelsConfig>,
162162
/// Configuration options for payment routing and pathfinding.
163163
///
164-
/// Setting the `SendingParameters` provides flexibility to customize how payments are routed,
164+
/// Setting the [`RouteParametersConfig`] provides flexibility to customize how payments are routed,
165165
/// including setting limits on routing fees, CLTV expiry, and channel utilization.
166166
///
167167
/// **Note:** If unset, default parameters will be used, and you will be able to override the
168168
/// parameters on a per-payment basis in the corresponding method calls.
169-
pub sending_parameters: Option<SendingParameters>,
169+
pub route_parameters: Option<RouteParametersConfig>,
170170
}
171171

172172
impl Default for Config {
@@ -179,7 +179,7 @@ impl Default for Config {
179179
trusted_peers_0conf: Vec::new(),
180180
probing_liquidity_limit_multiplier: DEFAULT_PROBING_LIQUIDITY_LIMIT_MULTIPLIER,
181181
anchor_channels_config: Some(AnchorChannelsConfig::default()),
182-
sending_parameters: None,
182+
route_parameters: None,
183183
node_alias: None,
184184
}
185185
}

src/event.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,9 +1040,9 @@ where
10401040
LdkEvent::PaymentPathFailed { .. } => {},
10411041
LdkEvent::ProbeSuccessful { .. } => {},
10421042
LdkEvent::ProbeFailed { .. } => {},
1043-
LdkEvent::HTLCHandlingFailed { failed_next_destination, .. } => {
1043+
LdkEvent::HTLCHandlingFailed { failure_type, .. } => {
10441044
if let Some(liquidity_source) = self.liquidity_source.as_ref() {
1045-
liquidity_source.handle_htlc_handling_failed(failed_next_destination);
1045+
liquidity_source.handle_htlc_handling_failed(failure_type);
10461046
}
10471047
},
10481048
LdkEvent::PendingHTLCsForwardable { time_forwardable } => {
@@ -1159,17 +1159,44 @@ where
11591159

11601160
let user_channel_id: u128 = rand::thread_rng().gen::<u128>();
11611161
let allow_0conf = self.config.trusted_peers_0conf.contains(&counterparty_node_id);
1162+
let mut channel_override_config = None;
1163+
if let Some((lsp_node_id, _)) = self
1164+
.liquidity_source
1165+
.as_ref()
1166+
.and_then(|ls| ls.as_ref().get_lsps2_lsp_details())
1167+
{
1168+
if lsp_node_id == counterparty_node_id {
1169+
// When we're an LSPS2 client, allow claiming underpaying HTLCs as the LSP will skim off some fee. We'll
1170+
// check that they don't take too much before claiming.
1171+
//
1172+
// We also set maximum allowed inbound HTLC value in flight
1173+
// to 100%. We should eventually be able to set this on a per-channel basis, but for
1174+
// now we just bump the default for all channels.
1175+
channel_override_config = Some(ChannelConfigOverrides {
1176+
handshake_overrides: Some(ChannelHandshakeConfigUpdate {
1177+
max_inbound_htlc_value_in_flight_percent_of_channel: Some(100),
1178+
..Default::default()
1179+
}),
1180+
update_overrides: Some(ChannelConfigUpdate {
1181+
accept_underpaying_htlcs: Some(true),
1182+
..Default::default()
1183+
}),
1184+
});
1185+
}
1186+
}
11621187
let res = if allow_0conf {
11631188
self.channel_manager.accept_inbound_channel_from_trusted_peer_0conf(
11641189
&temporary_channel_id,
11651190
&counterparty_node_id,
11661191
user_channel_id,
1192+
channel_override_config,
11671193
)
11681194
} else {
11691195
self.channel_manager.accept_inbound_channel(
11701196
&temporary_channel_id,
11711197
&counterparty_node_id,
11721198
user_channel_id,
1199+
channel_override_config,
11731200
)
11741201
};
11751202

0 commit comments

Comments
 (0)