Skip to content

Commit 3dee645

Browse files
committed
Initial implementation of LDK Node
1 parent adfdc24 commit 3dee645

15 files changed

+2308
-324
lines changed

.github/workflows/build.yml

+2
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ jobs:
2525
- name: Check formatting
2626
if: matrix.check-fmt
2727
run: rustup component add rustfmt && cargo fmt --all -- --check
28+
- name: Test on Rust ${{ matrix.toolchain }}
29+
run: cargo test

Cargo.toml

+44-11
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,63 @@
11
[package]
2-
name = "ldk-lite"
2+
name = "ldk-node"
33
version = "0.1.0"
44
authors = ["Elias Rohrer <[email protected]>"]
55
license = "MIT OR Apache-2.0"
66
edition = "2018"
7+
description = "A ready-to-go node implementation built using LDK."
78

89
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
910

1011
[dependencies]
11-
lightning = { version = "0.0.110", features = ["max_level_trace", "std"] }
12-
lightning-invoice = { version = "0.18" }
13-
lightning-net-tokio = { version = "0.0.110" }
14-
lightning-persister = { version = "0.0.110" }
15-
lightning-background-processor = { version = "0.0.110" }
16-
lightning-rapid-gossip-sync = { version = "0.0.110" }
12+
#lightning = { version = "0.0.114", features = ["max_level_trace", "std"] }
13+
#lightning-invoice = { version = "0.22" }
14+
#lightning-net-tokio = { version = "0.0.114" }
15+
#lightning-persister = { version = "0.0.114" }
16+
#lightning-background-processor = { version = "0.0.114" }
17+
#lightning-rapid-gossip-sync = { version = "0.0.114" }
18+
#lightning-transaction-sync = { version = "0.0.114", features = ["esplora-async"] }
1719

18-
#bdk = "0.20.0"
19-
bdk = { git = "https://github.com/tnull/bdk", branch="feat/use-external-esplora-client", features = ["use-esplora-ureq", "key-value-db"]}
20-
bitcoin = "0.28.1"
20+
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["max_level_trace", "std"] }
21+
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main" }
22+
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main" }
23+
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main" }
24+
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main" }
25+
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main" }
26+
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["esplora-async"] }
27+
28+
#lightning = { git = "https://github.com/tnull/rust-lightning", branch="2023-03-expose-impl-writeable-tlv-based-enum-common", features = ["max_level_trace", "std"] }
29+
#lightning-invoice = { git = "https://github.com/tnull/rust-lightning", branch="2023-03-expose-impl-writeable-tlv-based-enum-common" }
30+
#lightning-net-tokio = { git = "https://github.com/tnull/rust-lightning", branch="2023-03-expose-impl-writeable-tlv-based-enum-common" }
31+
#lightning-persister = { git = "https://github.com/tnull/rust-lightning", branch="2023-03-expose-impl-writeable-tlv-based-enum-common" }
32+
#lightning-background-processor = { git = "https://github.com/tnull/rust-lightning", branch="2023-03-expose-impl-writeable-tlv-based-enum-common" }
33+
#lightning-rapid-gossip-sync = { git = "https://github.com/tnull/rust-lightning", branch="2023-03-expose-impl-writeable-tlv-based-enum-common" }
34+
#lightning-transaction-sync = { git = "https://github.com/tnull/rust-lightning", branch="2023-03-expose-impl-writeable-tlv-based-enum-common", features = ["esplora-async"] }
35+
36+
#lightning = { path = "../rust-lightning/lightning", features = ["max_level_trace", "std"] }
37+
#lightning-invoice = { path = "../rust-lightning/lightning-invoice" }
38+
#lightning-net-tokio = { path = "../rust-lightning/lightning-net-tokio" }
39+
#lightning-persister = { path = "../rust-lightning/lightning-persister" }
40+
#lightning-background-processor = { path = "../rust-lightning/lightning-background-processor" }
41+
#lightning-rapid-gossip-sync = { path = "../rust-lightning/lightning-rapid-gossip-sync" }
42+
#lightning-transaction-sync = { path = "../rust-lightning/lightning-transaction-sync", features = ["esplora-async"] }
43+
44+
bdk = { version = "=0.27.1", default-features = false, features = ["async-interface", "use-esplora-async", "sqlite-bundled"]}
45+
reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls"] }
46+
rusqlite = { version = "0.28.0", features = ["bundled"] }
47+
bitcoin = "0.29.2"
2148

2249
rand = "0.8.5"
2350
chrono = "0.4"
2451
futures = "0.3"
2552
serde_json = { version = "1.0" }
26-
tokio = { version = "1", features = [ "io-util", "macros", "rt", "rt-multi-thread", "sync", "net", "time" ] }
53+
tokio = { version = "1", default-features = false, features = [ "rt-multi-thread", "time", "sync" ] }
54+
esplora-client = { version = "=0.3", default-features = false }
2755

56+
[dev-dependencies]
57+
electrsd = { version = "0.22.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_23_0"] }
58+
electrum-client = "0.12.0"
59+
once_cell = "1.16.0"
60+
proptest = "1.0.0"
2861

2962
[profile.release]
3063
panic = "abort"

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# LDK Node
2-
A ready-to-go node implementation based on LDK.
2+
A ready-to-go node implementation built using LDK.

src/error.rs

+56-101
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,85 @@
1-
use bdk::blockchain::esplora;
2-
use lightning::ln::msgs;
3-
use lightning::util::errors;
4-
use lightning_invoice::payment;
51
use std::fmt;
6-
use std::io;
7-
use std::time;
82

9-
#[derive(Debug)]
3+
#[derive(Debug, PartialEq, Eq)]
104
/// An error that possibly needs to be handled by the user.
11-
pub enum LdkLiteError {
12-
/// Returned when trying to start LdkLite while it is already running.
5+
pub enum Error {
6+
/// Returned when trying to start [`crate::Node`] while it is already running.
137
AlreadyRunning,
14-
/// Returned when trying to stop LdkLite while it is not running.
8+
/// Returned when trying to stop [`crate::Node`] while it is not running.
159
NotRunning,
1610
/// The funding transaction could not be created.
1711
FundingTxCreationFailed,
1812
/// A network connection has been closed.
1913
ConnectionFailed,
2014
/// Payment of the given invoice has already been intiated.
2115
NonUniquePaymentHash,
16+
/// The given amount is invalid.
17+
InvalidAmount,
18+
/// The given invoice is invalid.
19+
InvalidInvoice,
20+
/// Invoice creation failed.
21+
InvoiceCreationFailed,
22+
/// There are insufficient funds to complete the given operation.
23+
InsufficientFunds,
24+
/// An attempted payment has failed.
25+
PaymentFailed,
2226
/// A given peer info could not be parsed.
23-
PeerInfoParse(&'static str),
24-
/// A wrapped LDK `APIError`
25-
LdkApi(errors::APIError),
26-
/// A wrapped LDK `DecodeError`
27-
LdkDecode(msgs::DecodeError),
28-
/// A wrapped LDK `PaymentError`
29-
LdkPayment(payment::PaymentError),
30-
/// A wrapped LDK `SignOrCreationError`
31-
LdkInvoiceCreation(lightning_invoice::SignOrCreationError),
32-
/// A wrapped BDK error
33-
Bdk(bdk::Error),
34-
/// A wrapped `EsploraError`
35-
Esplora(esplora::EsploraError),
36-
/// A wrapped `Bip32` error
37-
Bip32(bitcoin::util::bip32::Error),
38-
/// A wrapped `std::io::Error`
39-
StdIo(io::Error),
40-
/// A wrapped `SystemTimeError`
41-
StdTime(time::SystemTimeError),
27+
PeerInfoParseFailed,
28+
/// A channel could not be opened.
29+
ChannelCreationFailed,
30+
/// A channel could not be closed.
31+
ChannelClosingFailed,
32+
/// Persistence failed.
33+
PersistenceFailed,
34+
/// A wallet operation failed.
35+
WalletOperationFailed,
36+
/// A siging operation failed.
37+
WalletSigningFailed,
38+
/// A transaction sync operation failed.
39+
TxSyncFailed,
4240
}
4341

44-
impl fmt::Display for LdkLiteError {
42+
impl fmt::Display for Error {
4543
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4644
match *self {
47-
LdkLiteError::AlreadyRunning => write!(f, "LDKLite is already running."),
48-
LdkLiteError::NotRunning => write!(f, "LDKLite is not running."),
49-
LdkLiteError::FundingTxCreationFailed => {
50-
write!(f, "the funding transaction could not be created")
45+
Self::AlreadyRunning => write!(f, "Node is already running."),
46+
Self::NotRunning => write!(f, "Node is not running."),
47+
Self::FundingTxCreationFailed => {
48+
write!(f, "Funding transaction could not be created.")
5149
}
52-
LdkLiteError::ConnectionFailed => write!(f, "network connection closed"),
53-
LdkLiteError::NonUniquePaymentHash => write!(f, "an invoice must not get payed twice."),
54-
LdkLiteError::PeerInfoParse(ref e) => {
55-
write!(f, "given peer info could not be parsed: {}", e)
50+
Self::ConnectionFailed => write!(f, "Network connection closed."),
51+
Self::NonUniquePaymentHash => write!(f, "An invoice must not get payed twice."),
52+
Self::InvalidAmount => write!(f, "The given amount is invalid."),
53+
Self::InvalidInvoice => write!(f, "The given invoice is invalid."),
54+
Self::InvoiceCreationFailed => write!(f, "Failed to create invoice."),
55+
Self::InsufficientFunds => {
56+
write!(f, "There are insufficient funds to complete the given operation.")
5657
}
57-
LdkLiteError::LdkDecode(ref e) => write!(f, "LDK decode error: {}", e),
58-
LdkLiteError::LdkApi(ref e) => write!(f, "LDK API error: {:?}", e),
59-
LdkLiteError::LdkPayment(ref e) => write!(f, "LDK payment error: {:?}", e),
60-
LdkLiteError::LdkInvoiceCreation(ref e) => {
61-
write!(f, "LDK invoice sign or creation error: {:?}", e)
62-
}
63-
LdkLiteError::Bdk(ref e) => write!(f, "BDK error: {}", e),
64-
LdkLiteError::Esplora(ref e) => write!(f, "Esplora error: {}", e),
65-
LdkLiteError::Bip32(ref e) => write!(f, "Bitcoin error: {}", e),
66-
LdkLiteError::StdIo(ref e) => write!(f, "IO error: {}", e),
67-
LdkLiteError::StdTime(ref e) => write!(f, "time error: {}", e),
58+
Self::PaymentFailed => write!(f, "Failed to send the given payment."),
59+
Self::PeerInfoParseFailed => write!(f, "Failed to parse the given peer information."),
60+
Self::ChannelCreationFailed => write!(f, "Failed to create channel."),
61+
Self::ChannelClosingFailed => write!(f, "Failed to close channel."),
62+
Self::PersistenceFailed => write!(f, "Failed to persist data."),
63+
Self::WalletOperationFailed => write!(f, "Failed to conduct wallet operation."),
64+
Self::WalletSigningFailed => write!(f, "Failed to sign given transaction."),
65+
Self::TxSyncFailed => write!(f, "Failed to sync transactions."),
6866
}
6967
}
7068
}
7169

72-
impl From<errors::APIError> for LdkLiteError {
73-
fn from(e: errors::APIError) -> Self {
74-
Self::LdkApi(e)
75-
}
76-
}
70+
impl std::error::Error for Error {}
7771

78-
impl From<msgs::DecodeError> for LdkLiteError {
79-
fn from(e: msgs::DecodeError) -> Self {
80-
Self::LdkDecode(e)
81-
}
82-
}
83-
84-
impl From<payment::PaymentError> for LdkLiteError {
85-
fn from(e: payment::PaymentError) -> Self {
86-
Self::LdkPayment(e)
87-
}
88-
}
89-
90-
impl From<lightning_invoice::SignOrCreationError> for LdkLiteError {
91-
fn from(e: lightning_invoice::SignOrCreationError) -> Self {
92-
Self::LdkInvoiceCreation(e)
93-
}
94-
}
95-
96-
impl From<bdk::Error> for LdkLiteError {
72+
impl From<bdk::Error> for Error {
9773
fn from(e: bdk::Error) -> Self {
98-
Self::Bdk(e)
99-
}
100-
}
101-
102-
impl From<bdk::sled::Error> for LdkLiteError {
103-
fn from(e: bdk::sled::Error) -> Self {
104-
Self::Bdk(bdk::Error::Sled(e))
105-
}
106-
}
107-
108-
impl From<bitcoin::util::bip32::Error> for LdkLiteError {
109-
fn from(e: bitcoin::util::bip32::Error) -> Self {
110-
Self::Bip32(e)
111-
}
112-
}
113-
114-
impl From<io::Error> for LdkLiteError {
115-
fn from(e: io::Error) -> Self {
116-
Self::StdIo(e)
117-
}
118-
}
119-
120-
impl From<time::SystemTimeError> for LdkLiteError {
121-
fn from(e: time::SystemTimeError) -> Self {
122-
Self::StdTime(e)
74+
match e {
75+
bdk::Error::Signer(_) => Self::WalletSigningFailed,
76+
_ => Self::WalletOperationFailed,
77+
}
12378
}
12479
}
12580

126-
impl From<esplora::EsploraError> for LdkLiteError {
127-
fn from(e: esplora::EsploraError) -> Self {
128-
Self::Esplora(e)
81+
impl From<lightning_transaction_sync::TxSyncError> for Error {
82+
fn from(_e: lightning_transaction_sync::TxSyncError) -> Self {
83+
Self::TxSyncFailed
12984
}
13085
}

0 commit comments

Comments
 (0)