Skip to content
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
312 changes: 228 additions & 84 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ enum Commands {
description: String,
#[arg(long)]
amount_msat: Option<u64>,
#[arg(long)]
expiry_secs: Option<u32>,
#[arg(long)]
quantity: Option<u64>,
},
Bolt12Send {
#[arg(short, long)]
Expand Down Expand Up @@ -95,9 +99,16 @@ async fn main() {
Commands::Bolt11Send { invoice, amount_msat } => {
handle_response(client.bolt11_send(Bolt11SendRequest { invoice, amount_msat }).await);
},
Commands::Bolt12Receive { description, amount_msat } => {
Commands::Bolt12Receive { description, amount_msat, expiry_secs, quantity } => {
handle_response(
client.bolt12_receive(Bolt12ReceiveRequest { description, amount_msat }).await,
client
.bolt12_receive(Bolt12ReceiveRequest {
description,
amount_msat,
expiry_secs,
quantity,
})
.await,
);
},
Commands::Bolt12Send { offer, amount_msat, quantity, payer_note } => {
Expand Down
19 changes: 14 additions & 5 deletions protos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ pub struct GetNodeInfoResponse {
/// Should be always set, will never be `None`.
#[prost(message, optional, tag = "3")]
pub current_best_block: ::core::option::Option<BestBlock>,
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet
/// to the chain tip.
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet to
/// the chain tip.
///
/// Will be `None` if the wallet hasnt been synced since the node was initialized.
/// Will be `None` if the wallet hasn't been synced yet.
#[prost(uint64, optional, tag = "4")]
pub latest_wallet_sync_timestamp: ::core::option::Option<u64>,
pub latest_lightning_wallet_sync_timestamp: ::core::option::Option<u64>,
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our on-chain
/// wallet to the chain tip.
///
Expand Down Expand Up @@ -152,6 +152,12 @@ pub struct Bolt12ReceiveRequest {
/// The amount in millisatoshi to send. If unset, a "zero-amount" or variable-amount offer is returned.
#[prost(uint64, optional, tag = "2")]
pub amount_msat: ::core::option::Option<u64>,
/// Offer expiry time in seconds.
#[prost(uint32, optional, tag = "3")]
pub expiry_secs: ::core::option::Option<u32>,
/// If set, it represents the number of items requested, can only be set for fixed-amount offers.
#[prost(uint64, optional, tag = "4")]
pub quantity: ::core::option::Option<u64>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down Expand Up @@ -297,6 +303,9 @@ pub struct CloseChannelRequest {
/// Whether to force close the specified channel.
#[prost(bool, optional, tag = "3")]
pub force_close: ::core::option::Option<bool>,
/// The reason for force-closing, can only be set while force closing a channel.
#[prost(string, optional, tag = "4")]
pub force_close_reason: ::core::option::Option<::prost::alloc::string::String>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down Expand Up @@ -391,7 +400,7 @@ pub struct Channel {
pub is_usable: bool,
/// Is `true` if this channel is (or will be) publicly-announced
#[prost(bool, tag = "15")]
pub is_public: bool,
pub is_announced: bool,
/// Set of configurable parameters set by self that affect channel operation.
#[prost(message, optional, tag = "16")]
pub channel_config: ::core::option::Option<ChannelConfig>,
Expand Down
21 changes: 14 additions & 7 deletions protos/src/proto/ldk_node_server.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ message GetNodeInfoResponse {
// Should be always set, will never be `None`.
BestBlock current_best_block = 3;

// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet
// to the chain tip.
// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet to
// the chain tip.
//
// Will be `None` if the wallet hasnt been synced since the node was initialized.
optional uint64 latest_wallet_sync_timestamp = 4;
// Will be `None` if the wallet hasn't been synced yet.
optional uint64 latest_lightning_wallet_sync_timestamp = 4;

// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our on-chain
// wallet to the chain tip.
Expand Down Expand Up @@ -147,6 +147,12 @@ message Bolt12ReceiveRequest {

// The amount in millisatoshi to send. If unset, a "zero-amount" or variable-amount offer is returned.
optional uint64 amount_msat = 2;

// Offer expiry time in seconds.
optional uint32 expiry_secs = 3;

// If set, it represents the number of items requested, can only be set for fixed-amount offers.
optional uint64 quantity = 4;
}

message Bolt12ReceiveResponse {
Expand Down Expand Up @@ -273,6 +279,9 @@ message CloseChannelRequest {

// Whether to force close the specified channel.
optional bool force_close = 3;

// The reason for force-closing, can only be set while force closing a channel.
optional string force_close_reason = 4;
}

message CloseChannelResponse {
Expand Down Expand Up @@ -364,7 +373,7 @@ message Channel {
bool is_usable = 14;

// Is `true` if this channel is (or will be) publicly-announced
bool is_public = 15;
bool is_announced = 15;

// Set of configurable parameters set by self that affect channel operation.
ChannelConfig channel_config = 16;
Expand Down Expand Up @@ -427,11 +436,9 @@ message OutPoint {
}

message BestBlock {

// The block’s hash
string block_hash = 1;

// The height at which the block was confirmed.
uint32 height = 2;

}
2 changes: 1 addition & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
ldk-node = { git = "https://github.com/lightningdevkit/ldk-node.git", branch = "main" }
ldk-node = { version = "0.4.0", default-features = false }
serde = { version = "1.0.203", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.118", default-features = false }
hyper = { version = "1", default-features = false, features = ["server", "http1"] }
Expand Down
4 changes: 2 additions & 2 deletions server/src/api/bolt11_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub(crate) fn handle_bolt11_send_request(
.map_err(|_| ldk_node::NodeError::InvalidInvoice)?;

let payment_id = match request.amount_msat {
None => node.bolt11_payment().send(&invoice),
Some(amount_msat) => node.bolt11_payment().send_using_amount(&invoice, amount_msat),
None => node.bolt11_payment().send(&invoice, None),
Some(amount_msat) => node.bolt11_payment().send_using_amount(&invoice, amount_msat, None),
}?;

let response = Bolt11SendResponse { payment_id: Bytes::from(payment_id.0.to_vec()) };
Expand Down
11 changes: 9 additions & 2 deletions server/src/api/bolt12_receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ pub(crate) fn handle_bolt12_receive_request(
node: Arc<Node>, request: Bolt12ReceiveRequest,
) -> Result<Bolt12ReceiveResponse, ldk_node::NodeError> {
let offer = match request.amount_msat {
Some(amount_msat) => node.bolt12_payment().receive(amount_msat, &request.description)?,
None => node.bolt12_payment().receive_variable_amount(&request.description)?,
Some(amount_msat) => node.bolt12_payment().receive(
amount_msat,
&request.description,
request.expiry_secs,
request.quantity,
)?,
None => node
.bolt12_payment()
.receive_variable_amount(&request.description, request.expiry_secs)?,
};

let response = Bolt12ReceiveResponse { offer: offer.to_string() };
Expand Down
11 changes: 7 additions & 4 deletions server/src/api/bolt12_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ pub(crate) fn handle_bolt12_send_request(
Offer::from_str(&request.offer.as_str()).map_err(|_| ldk_node::NodeError::InvalidOffer)?;

let payment_id = match request.amount_msat {
None => node.bolt12_payment().send(&offer, request.payer_note),
Some(amount_msat) => {
node.bolt12_payment().send_using_amount(&offer, request.payer_note, amount_msat)
},
None => node.bolt12_payment().send(&offer, request.quantity, request.payer_note),
Some(amount_msat) => node.bolt12_payment().send_using_amount(
&offer,
amount_msat,
request.quantity,
request.payer_note,
),
}?;

let response = Bolt12SendResponse { payment_id: Bytes::from(payment_id.0.to_vec()) };
Expand Down
6 changes: 5 additions & 1 deletion server/src/api/close_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ pub(crate) fn handle_close_channel_request(
.map_err(|_| ldk_node::NodeError::InvalidPublicKey)?;

match request.force_close {
Some(true) => node.force_close_channel(&user_channel_id, counterparty_node_id)?,
Some(true) => node.force_close_channel(
&user_channel_id,
counterparty_node_id,
request.force_close_reason,
)?,
_ => node.close_channel(&user_channel_id, counterparty_node_id)?,
};

Expand Down
2 changes: 1 addition & 1 deletion server/src/api/get_node_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub(crate) fn handle_get_node_info_request(
let response = GetNodeInfoResponse {
node_id: node.node_id().to_string(),
current_best_block: Some(best_block),
latest_wallet_sync_timestamp: node_status.latest_wallet_sync_timestamp,
latest_lightning_wallet_sync_timestamp: node_status.latest_lightning_wallet_sync_timestamp,
latest_onchain_wallet_sync_timestamp: node_status.latest_onchain_wallet_sync_timestamp,
latest_fee_rate_cache_update_timestamp: node_status.latest_fee_rate_cache_update_timestamp,
latest_rgs_snapshot_timestamp: node_status.latest_rgs_snapshot_timestamp,
Expand Down
29 changes: 20 additions & 9 deletions server/src/api/open_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,26 @@ pub(crate) fn handle_open_channel(
.map_err(|_| ldk_node::NodeError::InvalidPublicKey)?;
let address = SocketAddress::from_str(&request.address)
.map_err(|_| ldk_node::NodeError::InvalidSocketAddress)?;
let user_channel_id = node.connect_open_channel(
node_id,
address,
request.channel_amount_sats,
request.push_to_counterparty_msat,
// TODO: Allow setting ChannelConfig in open-channel.
None,
request.announce_channel,
)?;

let user_channel_id = if request.announce_channel {
node.open_announced_channel(
node_id,
address,
request.channel_amount_sats,
request.push_to_counterparty_msat,
// TODO: Allow setting ChannelConfig in open-channel.
None,
)?
} else {
node.open_channel(
node_id,
address,
request.channel_amount_sats,
request.push_to_counterparty_msat,
None,
)?
};

let response = OpenChannelResponse {
user_channel_id: Bytes::from(user_channel_id.0.to_be_bytes().to_vec()),
};
Expand Down
5 changes: 3 additions & 2 deletions server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ use crate::service::NodeService;

use ldk_node::bitcoin::Network;
use ldk_node::lightning::ln::msgs::SocketAddress;
use ldk_node::{Builder, Config, Event, LogLevel};
use ldk_node::{Builder, Event, LogLevel};

use tokio::net::TcpListener;
use tokio::signal::unix::SignalKind;

use hyper::server::conn::http1;
use hyper_util::rt::TokioIo;

use ldk_node::config::Config;
use std::net::SocketAddr;
use std::str::FromStr;
use std::sync::Arc;
Expand Down Expand Up @@ -58,7 +59,7 @@ fn main() {
};

let mut builder = Builder::from_config(config);
builder.set_esplora_server(args[5].clone());
builder.set_chain_source_esplora(args[5].clone(), None);

let runtime = match tokio::runtime::Builder::new_multi_thread().enable_all().build() {
Ok(runtime) => Arc::new(runtime),
Expand Down
30 changes: 19 additions & 11 deletions server/src/util/proto_adapter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use hex::prelude::*;
use ldk_node::{ChannelConfig, ChannelDetails};
use ldk_node::config::{ChannelConfig, MaxDustHTLCExposure};
use ldk_node::ChannelDetails;
use protos::{Channel, OutPoint};

pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
Channel {
channel_id: channel.channel_id.0.to_lower_hex_string(),
Expand All @@ -19,8 +21,8 @@ pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
is_outbound: channel.is_outbound,
is_channel_ready: channel.is_channel_ready,
is_usable: channel.is_usable,
is_public: channel.is_public,
channel_config: Some(channel_config_to_proto(channel.config.as_ref())),
is_announced: channel.is_announced,
channel_config: Some(channel_config_to_proto(channel.config)),
next_outbound_htlc_limit_msat: channel.next_outbound_htlc_limit_msat,
next_outbound_htlc_minimum_msat: channel.next_outbound_htlc_minimum_msat,
force_close_spend_delay: channel.force_close_spend_delay.map(|x| x as u32),
Expand All @@ -38,18 +40,24 @@ pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
}
}

pub(crate) fn channel_config_to_proto(channel_config: &ChannelConfig) -> protos::ChannelConfig {
pub(crate) fn channel_config_to_proto(channel_config: ChannelConfig) -> protos::ChannelConfig {
protos::ChannelConfig {
forwarding_fee_proportional_millionths: Some(
channel_config.forwarding_fee_proportional_millionths(),
channel_config.forwarding_fee_proportional_millionths,
),
forwarding_fee_base_msat: Some(channel_config.forwarding_fee_base_msat()),
cltv_expiry_delta: Some(channel_config.cltv_expiry_delta() as u32),
forwarding_fee_base_msat: Some(channel_config.forwarding_fee_base_msat),
cltv_expiry_delta: Some(channel_config.cltv_expiry_delta as u32),
force_close_avoidance_max_fee_satoshis: Some(
channel_config.force_close_avoidance_max_fee_satoshis(),
channel_config.force_close_avoidance_max_fee_satoshis,
),
accept_underpaying_htlcs: Some(channel_config.accept_underpaying_htlcs()),
// FIXME: Pending ldk-node upgrade.
max_dust_htlc_exposure: None,
accept_underpaying_htlcs: Some(channel_config.accept_underpaying_htlcs),
max_dust_htlc_exposure: match channel_config.max_dust_htlc_exposure {
MaxDustHTLCExposure::FixedLimit { limit_msat } => {
Some(protos::channel_config::MaxDustHtlcExposure::FixedLimitMsat(limit_msat))
},
MaxDustHTLCExposure::FeeRateMultiplier { multiplier } => {
Some(protos::channel_config::MaxDustHtlcExposure::FeeRateMultiplier(multiplier))
},
},
}
}