Skip to content

Upgrade to LDK 0.2 #462

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

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
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
39 changes: 26 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,46 @@ 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 = { 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" }
#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-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
#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 = { git = "https://github.com/tnull/rust-lightning", rev = "ab6acc9bd1b3b976fe878d49054116f781635878", features = ["std"] }
lightning-types = { git = "https://github.com/tnull/rust-lightning", rev = "ab6acc9bd1b3b976fe878d49054116f781635878" }
lightning-invoice = { git = "https://github.com/tnull/rust-lightning", rev = "ab6acc9bd1b3b976fe878d49054116f781635878", features = ["std"] }
lightning-net-tokio = { git = "https://github.com/tnull/rust-lightning", rev = "ab6acc9bd1b3b976fe878d49054116f781635878" }
lightning-persister = { git = "https://github.com/tnull/rust-lightning", rev = "ab6acc9bd1b3b976fe878d49054116f781635878" }
lightning-background-processor = { git = "https://github.com/tnull/rust-lightning", rev = "ab6acc9bd1b3b976fe878d49054116f781635878" }
lightning-rapid-gossip-sync = { git = "https://github.com/tnull/rust-lightning", rev = "ab6acc9bd1b3b976fe878d49054116f781635878" }
lightning-block-sync = { git = "https://github.com/tnull/rust-lightning", rev = "ab6acc9bd1b3b976fe878d49054116f781635878", features = ["rpc-client", "tokio"] }
lightning-transaction-sync = { git = "https://github.com/tnull/rust-lightning", rev = "ab6acc9bd1b3b976fe878d49054116f781635878", features = ["esplora-async-https", "electrum", "time"] }
lightning-liquidity = { git = "https://github.com/tnull/rust-lightning", rev = "ab6acc9bd1b3b976fe878d49054116f781635878" }
lightning-macros = { git = "https://github.com/tnull/rust-lightning", rev = "ab6acc9bd1b3b976fe878d49054116f781635878" }

#lightning = { path = "../rust-lightning/lightning", features = ["std"] }
#lightning-types = { path = "../rust-lightning/lightning-types" }
#lightning-invoice = { path = "../rust-lightning/lightning-invoice", features = ["std"] }
#lightning-net-tokio = { path = "../rust-lightning/lightning-net-tokio" }
#lightning-persister = { path = "../rust-lightning/lightning-persister" }
#lightning-background-processor = { path = "../rust-lightning/lightning-background-processor", features = ["futures"] }
#lightning-background-processor = { path = "../rust-lightning/lightning-background-processor" }
#lightning-rapid-gossip-sync = { path = "../rust-lightning/lightning-rapid-gossip-sync" }
#lightning-block-sync = { path = "../rust-lightning/lightning-block-sync", features = ["rpc-client", "tokio"] }
#lightning-transaction-sync = { path = "../rust-lightning/lightning-transaction-sync", features = ["esplora-async-https", "electrum", "time"] }
Expand Down Expand Up @@ -91,8 +103,9 @@ 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 = { version = "0.1.0", features = ["std", "_test_utils"] }
#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["std", "_test_utils"] }
lightning = { git = "https://github.com/tnull/rust-lightning", rev = "ab6acc9bd1b3b976fe878d49054116f781635878", features = ["std", "_test_utils"] }
#lightning = { path = "../rust-lightning/lightning", features = ["std", "_test_utils"] }
proptest = "1.0.0"
regex = "1.5.6"
Expand Down
46 changes: 23 additions & 23 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ interface Node {

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

interface Bolt11Payment {
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 @@ -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,13 +499,13 @@ 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",
Expand Down Expand Up @@ -794,7 +794,7 @@ typedef string UntrustedString;
typedef string NodeAlias;

[Custom]
typedef string OrderId;
typedef string LSPS1OrderId;

[Custom]
typedef string DateTime;
typedef string LSPSDateTime;
17 changes: 2 additions & 15 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,17 +1181,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 @@ -1269,8 +1258,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 Expand Up @@ -1411,8 +1400,6 @@ fn build_with_store_internal(
Arc::clone(&keys_manager),
));

liquidity_source.as_ref().map(|l| l.set_peer_manager(Arc::clone(&peer_manager)));

gossip_source.set_gossip_verifier(
Arc::clone(&chain_source),
Arc::clone(&peer_manager),
Expand Down
2 changes: 1 addition & 1 deletion src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,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
39 changes: 33 additions & 6 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ use lightning::impl_writeable_tlv_based_enum;
use lightning::ln::channelmanager::PaymentId;
use lightning::ln::types::ChannelId;
use lightning::routing::gossip::NodeId;
use lightning::util::config::{
ChannelConfigOverrides, ChannelConfigUpdate, ChannelHandshakeConfigUpdate,
};
use lightning::util::errors::APIError;
use lightning::util::ser::{Readable, ReadableArgs, Writeable, Writer};

Expand Down Expand Up @@ -563,13 +566,10 @@ where
payment_hash,
purpose,
amount_msat,
receiver_node_id: _,
via_channel_id: _,
via_user_channel_id: _,
claim_deadline,
onion_fields,
counterparty_skimmed_fee_msat,
payment_id: _,
..
} => {
let payment_id = PaymentId(payment_hash.0);
if let Some(info) = self.payment_store.get(&payment_id) {
Expand Down Expand Up @@ -1041,9 +1041,9 @@ where
LdkEvent::PaymentPathFailed { .. } => {},
LdkEvent::ProbeSuccessful { .. } => {},
LdkEvent::ProbeFailed { .. } => {},
LdkEvent::HTLCHandlingFailed { failed_next_destination, .. } => {
LdkEvent::HTLCHandlingFailed { failure_type, .. } => {
if let Some(liquidity_source) = self.liquidity_source.as_ref() {
liquidity_source.handle_htlc_handling_failed(failed_next_destination);
liquidity_source.handle_htlc_handling_failed(failure_type);
}
},
LdkEvent::PendingHTLCsForwardable { time_forwardable } => {
Expand Down Expand Up @@ -1158,17 +1158,44 @@ where

let user_channel_id: u128 = rand::thread_rng().gen::<u128>();
let allow_0conf = self.config.trusted_peers_0conf.contains(&counterparty_node_id);
let mut channel_override_config = None;
if let Some((lsp_node_id, _)) = self
.liquidity_source
.as_ref()
.and_then(|ls| ls.as_ref().get_lsps2_lsp_details())
{
if lsp_node_id == counterparty_node_id {
// When we're an LSPS2 client, allow claiming underpaying HTLCs as the LSP will skim off some fee. We'll
// check that they don't take too much before claiming.
//
// We also 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.
channel_override_config = Some(ChannelConfigOverrides {
handshake_overrides: Some(ChannelHandshakeConfigUpdate {
max_inbound_htlc_value_in_flight_percent_of_channel: Some(100),
..Default::default()
}),
update_overrides: Some(ChannelConfigUpdate {
accept_underpaying_htlcs: Some(true),
..Default::default()
}),
});
}
}
let res = if allow_0conf {
self.channel_manager.accept_inbound_channel_from_trusted_peer_0conf(
&temporary_channel_id,
&counterparty_node_id,
user_channel_id,
channel_override_config,
)
} else {
self.channel_manager.accept_inbound_channel(
&temporary_channel_id,
&counterparty_node_id,
user_channel_id,
channel_override_config,
)
};

Expand Down
13 changes: 8 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,9 @@ impl Node {
let background_chan_man = Arc::clone(&self.channel_manager);
let background_gossip_sync = self.gossip_source.as_gossip_sync();
let background_peer_man = Arc::clone(&self.peer_manager);
let background_liquidity_man_opt =
self.liquidity_source.as_ref().map(|ls| Arc::clone(&ls.liquidity_manager()));
let background_sweeper = Arc::clone(&self.output_sweeper);
let background_onion_messenger = Arc::clone(&self.onion_messenger);
let background_logger = Arc::clone(&self.logger);
let background_error_logger = Arc::clone(&self.logger);
Expand Down Expand Up @@ -587,6 +590,8 @@ impl Node {
Some(background_onion_messenger),
background_gossip_sync,
background_peer_man,
background_liquidity_man_opt,
Some(background_sweeper),
background_logger,
Some(background_scorer),
sleeper,
Expand Down Expand Up @@ -1426,12 +1431,10 @@ impl Node {

let mut total_lightning_balance_sats = 0;
let mut lightning_balances = Vec::new();
for (funding_txo, channel_id) in self.chain_monitor.list_monitors() {
match self.chain_monitor.get_monitor(funding_txo) {
for channel_id in self.chain_monitor.list_monitors() {
match self.chain_monitor.get_monitor(channel_id) {
Ok(monitor) => {
// unwrap safety: `get_counterparty_node_id` will always be `Some` after 0.0.110 and
// LDK Node 0.1 depended on 0.0.115 already.
let counterparty_node_id = monitor.get_counterparty_node_id().unwrap();
let counterparty_node_id = monitor.get_counterparty_node_id();
for ldk_balance in monitor.get_claimable_balances() {
total_lightning_balance_sats += ldk_balance.claimable_amount_satoshis();
lightning_balances.push(LightningBalance::from_ldk_balance(
Expand Down
Loading
Loading