Skip to content

Commit 160347c

Browse files
authored
Merge pull request #151 from tnull/2023-08-upgrade-to-LDK-0.0.117
Upgrade to LDK 0.0.117
2 parents d9a8c8a + acf76e3 commit 160347c

21 files changed

+1473
-1234
lines changed

Cargo.toml

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,21 @@ panic = 'abort' # Abort on panic
3232
default = []
3333

3434
[dependencies]
35-
lightning = { version = "0.0.116", features = ["max_level_trace", "std"] }
36-
lightning-invoice = { version = "0.24.0" }
37-
lightning-net-tokio = { version = "0.0.116" }
38-
lightning-persister = { version = "0.0.116" }
39-
lightning-background-processor = { version = "0.0.116", features = ["futures"] }
40-
lightning-rapid-gossip-sync = { version = "0.0.116" }
41-
lightning-transaction-sync = { version = "0.0.116", features = ["esplora-async-https"] }
42-
43-
#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["max_level_trace", "std"] }
44-
#lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main" }
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-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["esplora-async"] }
35+
lightning = { version = "0.0.117", features = ["max_level_trace", "std"] }
36+
lightning-invoice = { version = "0.25.0" }
37+
lightning-net-tokio = { version = "0.0.117" }
38+
lightning-persister = { version = "0.0.117" }
39+
lightning-background-processor = { version = "0.0.117", features = ["futures"] }
40+
lightning-rapid-gossip-sync = { version = "0.0.117" }
41+
lightning-transaction-sync = { version = "0.0.117", features = ["esplora-async-https"] }
42+
43+
# lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["max_level_trace", "std"] }
44+
# lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main" }
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-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["esplora-async"] }
5050

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

5959
bdk = { version = "0.28.0", default-features = false, features = ["std", "async-interface", "use-esplora-async", "sqlite-bundled", "keys-bip39"]}
60+
6061
reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls"] }
6162
rusqlite = { version = "0.28.0", features = ["bundled"] }
6263
bitcoin = "0.29.2"
@@ -74,6 +75,8 @@ uniffi = { version = "0.23.0", features = ["build"], optional = true }
7475
winapi = { version = "0.3", features = ["winbase"] }
7576

7677
[dev-dependencies]
78+
lightning = { version = "0.0.117", features = ["max_level_trace", "std", "_test_utils"] }
79+
#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["max_level_trace", "std", "_test_utils"] }
7780
electrsd = { version = "0.22.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_23_0"] }
7881
electrum-client = "0.12.0"
7982
proptest = "1.0.0"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LDK Node is a self-custodial Lightning node in library form. Its central goal is
1111
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.
1212

1313
```rust
14-
use ldk_node::{Builder, NetAddress};
14+
use ldk_node::{Builder, SocketAddress};
1515
use ldk_node::lightning_invoice::Invoice;
1616
use ldk_node::bitcoin::secp256k1::PublicKey;
1717
use ldk_node::bitcoin::Network;
@@ -32,7 +32,7 @@ fn main() {
3232
// .. fund address ..
3333

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

3838
let event = node.wait_next_event();

bindings/ldk_node.udl

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ dictionary Config {
66
string storage_dir_path = "/tmp/ldk_node/";
77
string? log_dir_path = null;
88
Network network = "Bitcoin";
9-
NetAddress? listening_address = null;
9+
SocketAddress? listening_address = null;
1010
u32 default_cltv_expiry_delta = 144;
1111
u64 onchain_wallet_sync_interval_secs = 80;
1212
u64 wallet_sync_interval_secs = 30;
@@ -29,7 +29,7 @@ interface Builder {
2929
void set_gossip_source_rgs(string rgs_server_url);
3030
void set_storage_dir_path(string storage_dir_path);
3131
void set_network(Network network);
32-
void set_listening_address(NetAddress listening_address);
32+
void set_listening_address(SocketAddress listening_address);
3333
[Throws=BuildError]
3434
LDKNode build();
3535
};
@@ -43,7 +43,7 @@ interface LDKNode {
4343
Event wait_next_event();
4444
void event_handled();
4545
PublicKey node_id();
46-
NetAddress? listening_address();
46+
SocketAddress? listening_address();
4747
[Throws=NodeError]
4848
Address new_onchain_address();
4949
[Throws=NodeError]
@@ -55,11 +55,11 @@ interface LDKNode {
5555
[Throws=NodeError]
5656
u64 total_onchain_balance_sats();
5757
[Throws=NodeError]
58-
void connect(PublicKey node_id, NetAddress address, boolean persist);
58+
void connect(PublicKey node_id, SocketAddress address, boolean persist);
5959
[Throws=NodeError]
6060
void disconnect(PublicKey node_id);
6161
[Throws=NodeError]
62-
void connect_open_channel(PublicKey node_id, NetAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config, boolean announce_channel);
62+
void connect_open_channel(PublicKey node_id, SocketAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config, boolean announce_channel);
6363
[Throws=NodeError]
6464
void close_channel([ByRef]ChannelId channel_id, PublicKey counterparty_node_id);
6565
[Throws=NodeError]
@@ -73,9 +73,11 @@ interface LDKNode {
7373
[Throws=NodeError]
7474
PaymentHash send_spontaneous_payment(u64 amount_msat, PublicKey node_id);
7575
[Throws=NodeError]
76-
void send_payment_probe([ByRef]Bolt11Invoice invoice);
76+
void send_payment_probes([ByRef]Bolt11Invoice invoice);
7777
[Throws=NodeError]
78-
void send_spontaneous_payment_probe(u64 amount_msat, PublicKey node_id);
78+
void send_spontaneous_payment_probes(u64 amount_msat, PublicKey node_id);
79+
[Throws=NodeError]
80+
void send_payment_probes_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat);
7981
[Throws=NodeError]
8082
Bolt11Invoice receive_payment(u64 amount_msat, [ByRef]string description, u32 expiry_secs);
8183
[Throws=NodeError]
@@ -111,7 +113,7 @@ enum NodeError {
111113
"TxSyncFailed",
112114
"GossipUpdateFailed",
113115
"InvalidAddress",
114-
"InvalidNetAddress",
116+
"InvalidSocketAddress",
115117
"InvalidPublicKey",
116118
"InvalidSecretKey",
117119
"InvalidPaymentHash",
@@ -130,9 +132,11 @@ enum BuildError {
130132
"InvalidSeedBytes",
131133
"InvalidSeedFile",
132134
"InvalidSystemTime",
135+
"InvalidChannelMonitor",
133136
"ReadFailed",
134137
"WriteFailed",
135138
"StoragePathAccessFailed",
139+
"KVStoreSetupFailed",
136140
"WalletSetupFailed",
137141
"LoggerSetupFailed",
138142
};
@@ -143,8 +147,8 @@ interface Event {
143147
PaymentFailed( PaymentHash payment_hash );
144148
PaymentReceived( PaymentHash payment_hash, u64 amount_msat);
145149
ChannelPending ( ChannelId channel_id, UserChannelId user_channel_id, ChannelId former_temporary_channel_id, PublicKey counterparty_node_id, OutPoint funding_txo );
146-
ChannelReady ( ChannelId channel_id, UserChannelId user_channel_id );
147-
ChannelClosed ( ChannelId channel_id, UserChannelId user_channel_id );
150+
ChannelReady ( ChannelId channel_id, UserChannelId user_channel_id, PublicKey? counterparty_node_id );
151+
ChannelClosed ( ChannelId channel_id, UserChannelId user_channel_id, PublicKey? counterparty_node_id );
148152
};
149153

150154
enum PaymentDirection {
@@ -213,7 +217,7 @@ dictionary ChannelDetails {
213217

214218
dictionary PeerDetails {
215219
PublicKey node_id;
216-
NetAddress address;
220+
SocketAddress address;
217221
boolean is_persisted;
218222
boolean is_connected;
219223
};
@@ -247,7 +251,7 @@ enum LogLevel {
247251
typedef string Txid;
248252

249253
[Custom]
250-
typedef string NetAddress;
254+
typedef string SocketAddress;
251255

252256
[Custom]
253257
typedef string PublicKey;

src/builder.rs

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
use crate::event::EventQueue;
22
use crate::gossip::GossipSource;
33
use crate::io;
4-
use crate::io::fs_store::FilesystemStore;
54
use crate::io::sqlite_store::SqliteStore;
6-
use crate::io::{KVStore, CHANNEL_MANAGER_PERSISTENCE_KEY, CHANNEL_MANAGER_PERSISTENCE_NAMESPACE};
75
use crate::logger::{log_error, FilesystemLogger, Logger};
86
use crate::payment_store::PaymentStore;
97
use crate::peer_store::PeerStore;
108
use crate::types::{
11-
ChainMonitor, ChannelManager, FakeMessageRouter, GossipSync, KeysManager, NetAddress,
12-
NetworkGraph, OnionMessenger, PeerManager,
9+
ChainMonitor, ChannelManager, FakeMessageRouter, GossipSync, KeysManager, NetworkGraph,
10+
OnionMessenger, PeerManager, SocketAddress,
1311
};
1412
use crate::wallet::Wallet;
1513
use crate::LogLevel;
@@ -29,8 +27,14 @@ use lightning::routing::scoring::{
2927
use lightning::sign::EntropySource;
3028

3129
use lightning::util::config::UserConfig;
30+
use lightning::util::persist::{
31+
read_channel_monitors, KVStore, CHANNEL_MANAGER_PERSISTENCE_KEY,
32+
CHANNEL_MANAGER_PERSISTENCE_PRIMARY_NAMESPACE, CHANNEL_MANAGER_PERSISTENCE_SECONDARY_NAMESPACE,
33+
};
3234
use lightning::util::ser::ReadableArgs;
3335

36+
use lightning_persister::fs_store::FilesystemStore;
37+
3438
use lightning_transaction_sync::EsploraSyncClient;
3539

3640
use bdk::bitcoin::secp256k1::Secp256k1;
@@ -48,6 +52,8 @@ use std::convert::TryInto;
4852
use std::default::Default;
4953
use std::fmt;
5054
use std::fs;
55+
use std::io::Cursor;
56+
use std::path::PathBuf;
5157
use std::sync::{Arc, Mutex, RwLock};
5258
use std::time::SystemTime;
5359

@@ -80,12 +86,16 @@ pub enum BuildError {
8086
InvalidSeedFile,
8187
/// The current system time is invalid, clocks might have gone backwards.
8288
InvalidSystemTime,
89+
/// The a read channel monitor is invalid.
90+
InvalidChannelMonitor,
8391
/// We failed to read data from the [`KVStore`].
8492
ReadFailed,
8593
/// We failed to write data to the [`KVStore`].
8694
WriteFailed,
8795
/// We failed to access the given `storage_dir_path`.
8896
StoragePathAccessFailed,
97+
/// We failed to setup our [`KVStore`].
98+
KVStoreSetupFailed,
8999
/// We failed to setup the onchain wallet.
90100
WalletSetupFailed,
91101
/// We failed to setup the logger.
@@ -100,9 +110,13 @@ impl fmt::Display for BuildError {
100110
Self::InvalidSystemTime => {
101111
write!(f, "System time is invalid. Clocks might have gone back in time.")
102112
}
113+
Self::InvalidChannelMonitor => {
114+
write!(f, "Failed to watch a deserialzed ChannelMonitor")
115+
}
103116
Self::ReadFailed => write!(f, "Failed to read from store."),
104117
Self::WriteFailed => write!(f, "Failed to write to store."),
105118
Self::StoragePathAccessFailed => write!(f, "Failed to access the given storage path."),
119+
Self::KVStoreSetupFailed => write!(f, "Failed to setup KVStore."),
106120
Self::WalletSetupFailed => write!(f, "Failed to setup onchain wallet."),
107121
Self::LoggerSetupFailed => write!(f, "Failed to setup the logger."),
108122
}
@@ -155,8 +169,6 @@ impl NodeBuilder {
155169
}
156170

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

219231
/// Sets the IP address and TCP port on which [`Node`] will listen for incoming network connections.
220-
pub fn set_listening_address(&mut self, listening_address: NetAddress) -> &mut Self {
232+
pub fn set_listening_address(&mut self, listening_address: SocketAddress) -> &mut Self {
221233
self.config.listening_address = Some(listening_address);
222234
self
223235
}
@@ -234,17 +246,26 @@ impl NodeBuilder {
234246
let storage_dir_path = self.config.storage_dir_path.clone();
235247
fs::create_dir_all(storage_dir_path.clone())
236248
.map_err(|_| BuildError::StoragePathAccessFailed)?;
237-
let kv_store = Arc::new(SqliteStore::new(storage_dir_path.into()));
249+
let kv_store = Arc::new(
250+
SqliteStore::new(
251+
storage_dir_path.into(),
252+
Some(io::sqlite_store::SQLITE_DB_FILE_NAME.to_string()),
253+
Some(io::sqlite_store::KV_TABLE_NAME.to_string()),
254+
)
255+
.map_err(|_| BuildError::KVStoreSetupFailed)?,
256+
);
238257
self.build_with_store(kv_store)
239258
}
240259

241260
/// Builds a [`Node`] instance with a [`FilesystemStore`] backend and according to the options
242261
/// previously configured.
243262
pub fn build_with_fs_store(&self) -> Result<Node<FilesystemStore>, BuildError> {
244-
let storage_dir_path = self.config.storage_dir_path.clone();
263+
let mut storage_dir_path: PathBuf = self.config.storage_dir_path.clone().into();
264+
storage_dir_path.push("fs_store");
265+
245266
fs::create_dir_all(storage_dir_path.clone())
246267
.map_err(|_| BuildError::StoragePathAccessFailed)?;
247-
let kv_store = Arc::new(FilesystemStore::new(storage_dir_path.into()));
268+
let kv_store = Arc::new(FilesystemStore::new(storage_dir_path));
248269
self.build_with_store(kv_store)
249270
}
250271

@@ -353,7 +374,7 @@ impl ArcedNodeBuilder {
353374
}
354375

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

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

512533
// Read ChannelMonitor state from store
513-
let mut channel_monitors = match io::utils::read_channel_monitors(
534+
let mut channel_monitors = match read_channel_monitors(
514535
Arc::clone(&kv_store),
515536
Arc::clone(&keys_manager),
516537
Arc::clone(&keys_manager),
@@ -536,9 +557,12 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
536557
user_config.manually_accept_inbound_channels = true;
537558
}
538559
let channel_manager = {
539-
if let Ok(mut reader) =
540-
kv_store.read(CHANNEL_MANAGER_PERSISTENCE_NAMESPACE, CHANNEL_MANAGER_PERSISTENCE_KEY)
541-
{
560+
if let Ok(res) = kv_store.read(
561+
CHANNEL_MANAGER_PERSISTENCE_PRIMARY_NAMESPACE,
562+
CHANNEL_MANAGER_PERSISTENCE_SECONDARY_NAMESPACE,
563+
CHANNEL_MANAGER_PERSISTENCE_KEY,
564+
) {
565+
let mut reader = Cursor::new(res);
542566
let channel_monitor_references =
543567
channel_monitors.iter_mut().map(|(_, chanmon)| chanmon).collect();
544568
let read_args = ChannelManagerReadArgs::new(
@@ -589,7 +613,10 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
589613
// Give ChannelMonitors to ChainMonitor
590614
for (_blockhash, channel_monitor) in channel_monitors.into_iter() {
591615
let funding_outpoint = channel_monitor.get_funding_txo().0;
592-
chain_monitor.watch_channel(funding_outpoint, channel_monitor);
616+
chain_monitor.watch_channel(funding_outpoint, channel_monitor).map_err(|e| {
617+
log_error!(logger, "Failed to watch channel monitor: {:?}", e);
618+
BuildError::InvalidChannelMonitor
619+
})?;
593620
}
594621

595622
// Initialize the PeerManager
@@ -726,7 +753,7 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
726753
gossip_source,
727754
kv_store,
728755
logger,
729-
router,
756+
_router: router,
730757
scorer,
731758
peer_store,
732759
payment_store,

src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub enum Error {
3838
/// The given address is invalid.
3939
InvalidAddress,
4040
/// The given network address is invalid.
41-
InvalidNetAddress,
41+
InvalidSocketAddress,
4242
/// The given public key is invalid.
4343
InvalidPublicKey,
4444
/// The given secret key is invalid.
@@ -85,7 +85,7 @@ impl fmt::Display for Error {
8585
Self::TxSyncFailed => write!(f, "Failed to sync transactions."),
8686
Self::GossipUpdateFailed => write!(f, "Failed to update gossip data."),
8787
Self::InvalidAddress => write!(f, "The given address is invalid."),
88-
Self::InvalidNetAddress => write!(f, "The given network address is invalid."),
88+
Self::InvalidSocketAddress => write!(f, "The given network address is invalid."),
8989
Self::InvalidPublicKey => write!(f, "The given public key is invalid."),
9090
Self::InvalidSecretKey => write!(f, "The given secret key is invalid."),
9191
Self::InvalidPaymentHash => write!(f, "The given payment hash is invalid."),

0 commit comments

Comments
 (0)