Skip to content

Upgrade to LDK 0.0.117 #151

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

Merged
merged 2 commits into from
Oct 24, 2023
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
33 changes: 18 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ panic = 'abort' # Abort on panic
default = []

[dependencies]
lightning = { version = "0.0.116", features = ["max_level_trace", "std"] }
lightning-invoice = { version = "0.24.0" }
lightning-net-tokio = { version = "0.0.116" }
lightning-persister = { version = "0.0.116" }
lightning-background-processor = { version = "0.0.116", features = ["futures"] }
lightning-rapid-gossip-sync = { version = "0.0.116" }
lightning-transaction-sync = { version = "0.0.116", features = ["esplora-async-https"] }

#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["max_level_trace", "std"] }
#lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main" }
#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-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["esplora-async"] }
lightning = { version = "0.0.117", features = ["max_level_trace", "std"] }
lightning-invoice = { version = "0.25.0" }
lightning-net-tokio = { version = "0.0.117" }
lightning-persister = { version = "0.0.117" }
lightning-background-processor = { version = "0.0.117", features = ["futures"] }
lightning-rapid-gossip-sync = { version = "0.0.117" }
lightning-transaction-sync = { version = "0.0.117", features = ["esplora-async-https"] }

# lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["max_level_trace", "std"] }
# lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main" }
# 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-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["esplora-async"] }

#lightning = { path = "../rust-lightning/lightning", features = ["max_level_trace", "std"] }
#lightning-invoice = { path = "../rust-lightning/lightning-invoice" }
Expand All @@ -57,6 +57,7 @@ lightning-transaction-sync = { version = "0.0.116", features = ["esplora-async-h
#lightning-transaction-sync = { path = "../rust-lightning/lightning-transaction-sync", features = ["esplora-async"] }

bdk = { version = "0.28.0", default-features = false, features = ["std", "async-interface", "use-esplora-async", "sqlite-bundled", "keys-bip39"]}

reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls"] }
rusqlite = { version = "0.28.0", features = ["bundled"] }
bitcoin = "0.29.2"
Expand All @@ -74,6 +75,8 @@ uniffi = { version = "0.23.0", features = ["build"], optional = true }
winapi = { version = "0.3", features = ["winbase"] }

[dev-dependencies]
lightning = { version = "0.0.117", features = ["max_level_trace", "std", "_test_utils"] }
#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["max_level_trace", "std", "_test_utils"] }
electrsd = { version = "0.22.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_23_0"] }
electrum-client = "0.12.0"
proptest = "1.0.0"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ LDK Node is a self-custodial Lightning node in library form. Its central goal is
The primary abstraction of the library is the [`Node`][api_docs_node], which can be retrieved by setting up and configuring a [`Builder`][api_docs_builder] to your liking and calling one of the `build` methods. `Node` can then be controlled via commands such as `start`, `stop`, `connect_open_channel`, `send_payment`, etc.

```rust
use ldk_node::{Builder, NetAddress};
use ldk_node::{Builder, SocketAddress};
use ldk_node::lightning_invoice::Invoice;
use ldk_node::bitcoin::secp256k1::PublicKey;
use ldk_node::bitcoin::Network;
Expand All @@ -32,7 +32,7 @@ fn main() {
// .. fund address ..

let node_id = PublicKey::from_str("NODE_ID").unwrap();
let node_addr = NetAddress::from_str("IP_ADDR:PORT").unwrap();
let node_addr = SocketAddress::from_str("IP_ADDR:PORT").unwrap();
node.connect_open_channel(node_id, node_addr, 10000, None, None, false).unwrap();

let event = node.wait_next_event();
Expand Down
28 changes: 16 additions & 12 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dictionary Config {
string storage_dir_path = "/tmp/ldk_node/";
string? log_dir_path = null;
Network network = "Bitcoin";
NetAddress? listening_address = null;
SocketAddress? listening_address = null;
u32 default_cltv_expiry_delta = 144;
u64 onchain_wallet_sync_interval_secs = 80;
u64 wallet_sync_interval_secs = 30;
Expand All @@ -29,7 +29,7 @@ interface Builder {
void set_gossip_source_rgs(string rgs_server_url);
void set_storage_dir_path(string storage_dir_path);
void set_network(Network network);
void set_listening_address(NetAddress listening_address);
void set_listening_address(SocketAddress listening_address);
[Throws=BuildError]
LDKNode build();
};
Expand All @@ -43,7 +43,7 @@ interface LDKNode {
Event wait_next_event();
void event_handled();
PublicKey node_id();
NetAddress? listening_address();
SocketAddress? listening_address();
[Throws=NodeError]
Address new_onchain_address();
[Throws=NodeError]
Expand All @@ -55,11 +55,11 @@ interface LDKNode {
[Throws=NodeError]
u64 total_onchain_balance_sats();
[Throws=NodeError]
void connect(PublicKey node_id, NetAddress address, boolean persist);
void connect(PublicKey node_id, SocketAddress address, boolean persist);
[Throws=NodeError]
void disconnect(PublicKey node_id);
[Throws=NodeError]
void connect_open_channel(PublicKey node_id, NetAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config, boolean announce_channel);
void connect_open_channel(PublicKey node_id, SocketAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config, boolean announce_channel);
[Throws=NodeError]
void close_channel([ByRef]ChannelId channel_id, PublicKey counterparty_node_id);
[Throws=NodeError]
Expand All @@ -73,9 +73,11 @@ interface LDKNode {
[Throws=NodeError]
PaymentHash send_spontaneous_payment(u64 amount_msat, PublicKey node_id);
[Throws=NodeError]
void send_payment_probe([ByRef]Bolt11Invoice invoice);
void send_payment_probes([ByRef]Bolt11Invoice invoice);
[Throws=NodeError]
void send_spontaneous_payment_probe(u64 amount_msat, PublicKey node_id);
void send_spontaneous_payment_probes(u64 amount_msat, PublicKey node_id);
[Throws=NodeError]
void send_payment_probes_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat);
[Throws=NodeError]
Bolt11Invoice receive_payment(u64 amount_msat, [ByRef]string description, u32 expiry_secs);
[Throws=NodeError]
Expand Down Expand Up @@ -111,7 +113,7 @@ enum NodeError {
"TxSyncFailed",
"GossipUpdateFailed",
"InvalidAddress",
"InvalidNetAddress",
"InvalidSocketAddress",
"InvalidPublicKey",
"InvalidSecretKey",
"InvalidPaymentHash",
Expand All @@ -130,9 +132,11 @@ enum BuildError {
"InvalidSeedBytes",
"InvalidSeedFile",
"InvalidSystemTime",
"InvalidChannelMonitor",
"ReadFailed",
"WriteFailed",
"StoragePathAccessFailed",
"KVStoreSetupFailed",
"WalletSetupFailed",
"LoggerSetupFailed",
};
Expand All @@ -143,8 +147,8 @@ interface Event {
PaymentFailed( PaymentHash payment_hash );
PaymentReceived( PaymentHash payment_hash, u64 amount_msat);
ChannelPending ( ChannelId channel_id, UserChannelId user_channel_id, ChannelId former_temporary_channel_id, PublicKey counterparty_node_id, OutPoint funding_txo );
ChannelReady ( ChannelId channel_id, UserChannelId user_channel_id );
ChannelClosed ( ChannelId channel_id, UserChannelId user_channel_id );
ChannelReady ( ChannelId channel_id, UserChannelId user_channel_id, PublicKey? counterparty_node_id );
ChannelClosed ( ChannelId channel_id, UserChannelId user_channel_id, PublicKey? counterparty_node_id );
};

enum PaymentDirection {
Expand Down Expand Up @@ -201,7 +205,7 @@ dictionary ChannelDetails {

dictionary PeerDetails {
PublicKey node_id;
NetAddress address;
SocketAddress address;
boolean is_persisted;
boolean is_connected;
};
Expand Down Expand Up @@ -235,7 +239,7 @@ enum LogLevel {
typedef string Txid;

[Custom]
typedef string NetAddress;
typedef string SocketAddress;

[Custom]
typedef string PublicKey;
Expand Down
61 changes: 44 additions & 17 deletions src/builder.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use crate::event::EventQueue;
use crate::gossip::GossipSource;
use crate::io;
use crate::io::fs_store::FilesystemStore;
use crate::io::sqlite_store::SqliteStore;
use crate::io::{KVStore, CHANNEL_MANAGER_PERSISTENCE_KEY, CHANNEL_MANAGER_PERSISTENCE_NAMESPACE};
use crate::logger::{log_error, FilesystemLogger, Logger};
use crate::payment_store::PaymentStore;
use crate::peer_store::PeerStore;
use crate::types::{
ChainMonitor, ChannelManager, FakeMessageRouter, GossipSync, KeysManager, NetAddress,
NetworkGraph, OnionMessenger, PeerManager,
ChainMonitor, ChannelManager, FakeMessageRouter, GossipSync, KeysManager, NetworkGraph,
OnionMessenger, PeerManager, SocketAddress,
};
use crate::wallet::Wallet;
use crate::LogLevel;
Expand All @@ -29,8 +27,14 @@ use lightning::routing::scoring::{
use lightning::sign::EntropySource;

use lightning::util::config::UserConfig;
use lightning::util::persist::{
read_channel_monitors, KVStore, CHANNEL_MANAGER_PERSISTENCE_KEY,
CHANNEL_MANAGER_PERSISTENCE_PRIMARY_NAMESPACE, CHANNEL_MANAGER_PERSISTENCE_SECONDARY_NAMESPACE,
};
use lightning::util::ser::ReadableArgs;

use lightning_persister::fs_store::FilesystemStore;

use lightning_transaction_sync::EsploraSyncClient;

use bdk::bitcoin::secp256k1::Secp256k1;
Expand All @@ -48,6 +52,8 @@ use std::convert::TryInto;
use std::default::Default;
use std::fmt;
use std::fs;
use std::io::Cursor;
use std::path::PathBuf;
use std::sync::{Arc, Mutex, RwLock};
use std::time::SystemTime;

Expand Down Expand Up @@ -80,12 +86,16 @@ pub enum BuildError {
InvalidSeedFile,
/// The current system time is invalid, clocks might have gone backwards.
InvalidSystemTime,
/// The a read channel monitor is invalid.
InvalidChannelMonitor,
/// We failed to read data from the [`KVStore`].
ReadFailed,
/// We failed to write data to the [`KVStore`].
WriteFailed,
/// We failed to access the given `storage_dir_path`.
StoragePathAccessFailed,
/// We failed to setup our [`KVStore`].
KVStoreSetupFailed,
/// We failed to setup the onchain wallet.
WalletSetupFailed,
/// We failed to setup the logger.
Expand All @@ -100,9 +110,13 @@ impl fmt::Display for BuildError {
Self::InvalidSystemTime => {
write!(f, "System time is invalid. Clocks might have gone back in time.")
}
Self::InvalidChannelMonitor => {
write!(f, "Failed to watch a deserialzed ChannelMonitor")
}
Self::ReadFailed => write!(f, "Failed to read from store."),
Self::WriteFailed => write!(f, "Failed to write to store."),
Self::StoragePathAccessFailed => write!(f, "Failed to access the given storage path."),
Self::KVStoreSetupFailed => write!(f, "Failed to setup KVStore."),
Self::WalletSetupFailed => write!(f, "Failed to setup onchain wallet."),
Self::LoggerSetupFailed => write!(f, "Failed to setup the logger."),
}
Expand Down Expand Up @@ -155,8 +169,6 @@ impl NodeBuilder {
}

/// Configures the [`Node`] instance to source its wallet entropy from the given 64 seed bytes.
///
/// **Note:** Panics if the length of the given `seed_bytes` differs from 64.
pub fn set_entropy_seed_bytes(&mut self, seed_bytes: Vec<u8>) -> Result<&mut Self, BuildError> {
if seed_bytes.len() != WALLET_KEYS_SEED_LEN {
return Err(BuildError::InvalidSeedBytes);
Expand Down Expand Up @@ -217,7 +229,7 @@ impl NodeBuilder {
}

/// Sets the IP address and TCP port on which [`Node`] will listen for incoming network connections.
pub fn set_listening_address(&mut self, listening_address: NetAddress) -> &mut Self {
pub fn set_listening_address(&mut self, listening_address: SocketAddress) -> &mut Self {
self.config.listening_address = Some(listening_address);
self
}
Expand All @@ -234,17 +246,26 @@ impl NodeBuilder {
let storage_dir_path = self.config.storage_dir_path.clone();
fs::create_dir_all(storage_dir_path.clone())
.map_err(|_| BuildError::StoragePathAccessFailed)?;
let kv_store = Arc::new(SqliteStore::new(storage_dir_path.into()));
let kv_store = Arc::new(
SqliteStore::new(
storage_dir_path.into(),
Some(io::sqlite_store::SQLITE_DB_FILE_NAME.to_string()),
Some(io::sqlite_store::KV_TABLE_NAME.to_string()),
)
.map_err(|_| BuildError::KVStoreSetupFailed)?,
);
self.build_with_store(kv_store)
}

/// Builds a [`Node`] instance with a [`FilesystemStore`] backend and according to the options
/// previously configured.
pub fn build_with_fs_store(&self) -> Result<Node<FilesystemStore>, BuildError> {
let storage_dir_path = self.config.storage_dir_path.clone();
let mut storage_dir_path: PathBuf = self.config.storage_dir_path.clone().into();
storage_dir_path.push("fs_store");

fs::create_dir_all(storage_dir_path.clone())
.map_err(|_| BuildError::StoragePathAccessFailed)?;
let kv_store = Arc::new(FilesystemStore::new(storage_dir_path.into()));
let kv_store = Arc::new(FilesystemStore::new(storage_dir_path));
self.build_with_store(kv_store)
}

Expand Down Expand Up @@ -353,7 +374,7 @@ impl ArcedNodeBuilder {
}

/// Sets the IP address and TCP port on which [`Node`] will listen for incoming network connections.
pub fn set_listening_address(&self, listening_address: NetAddress) {
pub fn set_listening_address(&self, listening_address: SocketAddress) {
self.inner.write().unwrap().set_listening_address(listening_address);
}

Expand Down Expand Up @@ -510,7 +531,7 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
));

// Read ChannelMonitor state from store
let mut channel_monitors = match io::utils::read_channel_monitors(
let mut channel_monitors = match read_channel_monitors(
Arc::clone(&kv_store),
Arc::clone(&keys_manager),
Arc::clone(&keys_manager),
Expand All @@ -536,9 +557,12 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
user_config.manually_accept_inbound_channels = true;
}
let channel_manager = {
if let Ok(mut reader) =
kv_store.read(CHANNEL_MANAGER_PERSISTENCE_NAMESPACE, CHANNEL_MANAGER_PERSISTENCE_KEY)
{
if let Ok(res) = kv_store.read(
CHANNEL_MANAGER_PERSISTENCE_PRIMARY_NAMESPACE,
CHANNEL_MANAGER_PERSISTENCE_SECONDARY_NAMESPACE,
CHANNEL_MANAGER_PERSISTENCE_KEY,
) {
let mut reader = Cursor::new(res);
let channel_monitor_references =
channel_monitors.iter_mut().map(|(_, chanmon)| chanmon).collect();
let read_args = ChannelManagerReadArgs::new(
Expand Down Expand Up @@ -589,7 +613,10 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
// 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);
chain_monitor.watch_channel(funding_outpoint, channel_monitor).map_err(|e| {
log_error!(logger, "Failed to watch channel monitor: {:?}", e);
BuildError::InvalidChannelMonitor
})?;
}

// Initialize the PeerManager
Expand Down Expand Up @@ -726,7 +753,7 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
gossip_source,
kv_store,
logger,
router,
_router: router,
scorer,
peer_store,
payment_store,
Expand Down
4 changes: 2 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub enum Error {
/// The given address is invalid.
InvalidAddress,
/// The given network address is invalid.
InvalidNetAddress,
InvalidSocketAddress,
/// The given public key is invalid.
InvalidPublicKey,
/// The given secret key is invalid.
Expand Down Expand Up @@ -85,7 +85,7 @@ impl fmt::Display for Error {
Self::TxSyncFailed => write!(f, "Failed to sync transactions."),
Self::GossipUpdateFailed => write!(f, "Failed to update gossip data."),
Self::InvalidAddress => write!(f, "The given address is invalid."),
Self::InvalidNetAddress => write!(f, "The given network address is invalid."),
Self::InvalidSocketAddress => write!(f, "The given network address is invalid."),
Self::InvalidPublicKey => write!(f, "The given public key is invalid."),
Self::InvalidSecretKey => write!(f, "The given secret key is invalid."),
Self::InvalidPaymentHash => write!(f, "The given payment hash is invalid."),
Expand Down
Loading