Skip to content

Initial implementation of LDK Node #11

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 1 commit into from
Mar 16, 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
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ jobs:
- name: Check formatting
if: matrix.check-fmt
run: rustup component add rustfmt && cargo fmt --all -- --check
- name: Test on Rust ${{ matrix.toolchain }}
run: cargo test
55 changes: 44 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,30 +1,63 @@
[package]
name = "ldk-lite"
name = "ldk-node"
version = "0.1.0"
authors = ["Elias Rohrer <[email protected]>"]
license = "MIT OR Apache-2.0"
edition = "2018"
description = "A ready-to-go node implementation built using LDK."

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

[dependencies]
lightning = { version = "0.0.110", features = ["max_level_trace", "std"] }
lightning-invoice = { version = "0.18" }
lightning-net-tokio = { version = "0.0.110" }
lightning-persister = { version = "0.0.110" }
lightning-background-processor = { version = "0.0.110" }
lightning-rapid-gossip-sync = { version = "0.0.110" }
#lightning = { version = "0.0.114", features = ["max_level_trace", "std"] }
#lightning-invoice = { version = "0.22" }
#lightning-net-tokio = { version = "0.0.114" }
#lightning-persister = { version = "0.0.114" }
#lightning-background-processor = { version = "0.0.114" }
#lightning-rapid-gossip-sync = { version = "0.0.114" }
#lightning-transaction-sync = { version = "0.0.114", features = ["esplora-async"] }

#bdk = "0.20.0"
bdk = { git = "https://github.com/tnull/bdk", branch="feat/use-external-esplora-client", features = ["use-esplora-ureq", "key-value-db"]}
bitcoin = "0.28.1"
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" }
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 = { git = "https://github.com/tnull/rust-lightning", branch="2023-03-expose-impl-writeable-tlv-based-enum-common", features = ["max_level_trace", "std"] }
#lightning-invoice = { git = "https://github.com/tnull/rust-lightning", branch="2023-03-expose-impl-writeable-tlv-based-enum-common" }
#lightning-net-tokio = { git = "https://github.com/tnull/rust-lightning", branch="2023-03-expose-impl-writeable-tlv-based-enum-common" }
#lightning-persister = { git = "https://github.com/tnull/rust-lightning", branch="2023-03-expose-impl-writeable-tlv-based-enum-common" }
#lightning-background-processor = { git = "https://github.com/tnull/rust-lightning", branch="2023-03-expose-impl-writeable-tlv-based-enum-common" }
#lightning-rapid-gossip-sync = { git = "https://github.com/tnull/rust-lightning", branch="2023-03-expose-impl-writeable-tlv-based-enum-common" }
#lightning-transaction-sync = { git = "https://github.com/tnull/rust-lightning", branch="2023-03-expose-impl-writeable-tlv-based-enum-common", features = ["esplora-async"] }

#lightning = { path = "../rust-lightning/lightning", features = ["max_level_trace", "std"] }
#lightning-invoice = { path = "../rust-lightning/lightning-invoice" }
#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" }
#lightning-rapid-gossip-sync = { path = "../rust-lightning/lightning-rapid-gossip-sync" }
#lightning-transaction-sync = { path = "../rust-lightning/lightning-transaction-sync", features = ["esplora-async"] }

bdk = { version = "=0.27.1", default-features = false, features = ["async-interface", "use-esplora-async", "sqlite-bundled"]}
reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls"] }
rusqlite = { version = "0.28.0", features = ["bundled"] }
bitcoin = "0.29.2"

rand = "0.8.5"
chrono = "0.4"
futures = "0.3"
serde_json = { version = "1.0" }
tokio = { version = "1", features = [ "io-util", "macros", "rt", "rt-multi-thread", "sync", "net", "time" ] }
tokio = { version = "1", default-features = false, features = [ "rt-multi-thread", "time", "sync" ] }
esplora-client = { version = "=0.3", default-features = false }

[dev-dependencies]
electrsd = { version = "0.22.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_23_0"] }
electrum-client = "0.12.0"
once_cell = "1.16.0"
proptest = "1.0.0"

[profile.release]
panic = "abort"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# LDK Node
A ready-to-go node implementation based on LDK.
A ready-to-go node implementation built using LDK.
157 changes: 56 additions & 101 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,130 +1,85 @@
use bdk::blockchain::esplora;
use lightning::ln::msgs;
use lightning::util::errors;
use lightning_invoice::payment;
use std::fmt;
use std::io;
use std::time;

#[derive(Debug)]
#[derive(Debug, PartialEq, Eq)]
/// An error that possibly needs to be handled by the user.
pub enum LdkLiteError {
/// Returned when trying to start LdkLite while it is already running.
pub enum Error {
/// Returned when trying to start [`crate::Node`] while it is already running.
AlreadyRunning,
/// Returned when trying to stop LdkLite while it is not running.
/// Returned when trying to stop [`crate::Node`] while it is not running.
NotRunning,
/// The funding transaction could not be created.
FundingTxCreationFailed,
/// A network connection has been closed.
ConnectionFailed,
/// Payment of the given invoice has already been intiated.
NonUniquePaymentHash,
/// The given amount is invalid.
InvalidAmount,
/// The given invoice is invalid.
InvalidInvoice,
/// Invoice creation failed.
InvoiceCreationFailed,
/// There are insufficient funds to complete the given operation.
InsufficientFunds,
/// An attempted payment has failed.
PaymentFailed,
/// A given peer info could not be parsed.
PeerInfoParse(&'static str),
/// A wrapped LDK `APIError`
LdkApi(errors::APIError),
/// A wrapped LDK `DecodeError`
LdkDecode(msgs::DecodeError),
/// A wrapped LDK `PaymentError`
LdkPayment(payment::PaymentError),
/// A wrapped LDK `SignOrCreationError`
LdkInvoiceCreation(lightning_invoice::SignOrCreationError),
/// A wrapped BDK error
Bdk(bdk::Error),
/// A wrapped `EsploraError`
Esplora(esplora::EsploraError),
/// A wrapped `Bip32` error
Bip32(bitcoin::util::bip32::Error),
/// A wrapped `std::io::Error`
StdIo(io::Error),
/// A wrapped `SystemTimeError`
StdTime(time::SystemTimeError),
PeerInfoParseFailed,
/// A channel could not be opened.
ChannelCreationFailed,
/// A channel could not be closed.
ChannelClosingFailed,
/// Persistence failed.
PersistenceFailed,
/// A wallet operation failed.
WalletOperationFailed,
/// A siging operation failed.
WalletSigningFailed,
/// A transaction sync operation failed.
TxSyncFailed,
}

impl fmt::Display for LdkLiteError {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
LdkLiteError::AlreadyRunning => write!(f, "LDKLite is already running."),
LdkLiteError::NotRunning => write!(f, "LDKLite is not running."),
LdkLiteError::FundingTxCreationFailed => {
write!(f, "the funding transaction could not be created")
Self::AlreadyRunning => write!(f, "Node is already running."),
Self::NotRunning => write!(f, "Node is not running."),
Self::FundingTxCreationFailed => {
write!(f, "Funding transaction could not be created.")
}
LdkLiteError::ConnectionFailed => write!(f, "network connection closed"),
LdkLiteError::NonUniquePaymentHash => write!(f, "an invoice must not get payed twice."),
LdkLiteError::PeerInfoParse(ref e) => {
write!(f, "given peer info could not be parsed: {}", e)
Self::ConnectionFailed => write!(f, "Network connection closed."),
Self::NonUniquePaymentHash => write!(f, "An invoice must not get payed twice."),
Self::InvalidAmount => write!(f, "The given amount is invalid."),
Self::InvalidInvoice => write!(f, "The given invoice is invalid."),
Self::InvoiceCreationFailed => write!(f, "Failed to create invoice."),
Self::InsufficientFunds => {
write!(f, "There are insufficient funds to complete the given operation.")
}
LdkLiteError::LdkDecode(ref e) => write!(f, "LDK decode error: {}", e),
LdkLiteError::LdkApi(ref e) => write!(f, "LDK API error: {:?}", e),
LdkLiteError::LdkPayment(ref e) => write!(f, "LDK payment error: {:?}", e),
LdkLiteError::LdkInvoiceCreation(ref e) => {
write!(f, "LDK invoice sign or creation error: {:?}", e)
}
LdkLiteError::Bdk(ref e) => write!(f, "BDK error: {}", e),
LdkLiteError::Esplora(ref e) => write!(f, "Esplora error: {}", e),
LdkLiteError::Bip32(ref e) => write!(f, "Bitcoin error: {}", e),
LdkLiteError::StdIo(ref e) => write!(f, "IO error: {}", e),
LdkLiteError::StdTime(ref e) => write!(f, "time error: {}", e),
Self::PaymentFailed => write!(f, "Failed to send the given payment."),
Self::PeerInfoParseFailed => write!(f, "Failed to parse the given peer information."),
Self::ChannelCreationFailed => write!(f, "Failed to create channel."),
Self::ChannelClosingFailed => write!(f, "Failed to close channel."),
Self::PersistenceFailed => write!(f, "Failed to persist data."),
Self::WalletOperationFailed => write!(f, "Failed to conduct wallet operation."),
Self::WalletSigningFailed => write!(f, "Failed to sign given transaction."),
Self::TxSyncFailed => write!(f, "Failed to sync transactions."),
}
}
}

impl From<errors::APIError> for LdkLiteError {
fn from(e: errors::APIError) -> Self {
Self::LdkApi(e)
}
}
impl std::error::Error for Error {}

impl From<msgs::DecodeError> for LdkLiteError {
fn from(e: msgs::DecodeError) -> Self {
Self::LdkDecode(e)
}
}

impl From<payment::PaymentError> for LdkLiteError {
fn from(e: payment::PaymentError) -> Self {
Self::LdkPayment(e)
}
}

impl From<lightning_invoice::SignOrCreationError> for LdkLiteError {
fn from(e: lightning_invoice::SignOrCreationError) -> Self {
Self::LdkInvoiceCreation(e)
}
}

impl From<bdk::Error> for LdkLiteError {
impl From<bdk::Error> for Error {
fn from(e: bdk::Error) -> Self {
Self::Bdk(e)
}
}

impl From<bdk::sled::Error> for LdkLiteError {
fn from(e: bdk::sled::Error) -> Self {
Self::Bdk(bdk::Error::Sled(e))
}
}

impl From<bitcoin::util::bip32::Error> for LdkLiteError {
fn from(e: bitcoin::util::bip32::Error) -> Self {
Self::Bip32(e)
}
}

impl From<io::Error> for LdkLiteError {
fn from(e: io::Error) -> Self {
Self::StdIo(e)
}
}

impl From<time::SystemTimeError> for LdkLiteError {
fn from(e: time::SystemTimeError) -> Self {
Self::StdTime(e)
match e {
bdk::Error::Signer(_) => Self::WalletSigningFailed,
_ => Self::WalletOperationFailed,
}
}
}

impl From<esplora::EsploraError> for LdkLiteError {
fn from(e: esplora::EsploraError) -> Self {
Self::Esplora(e)
impl From<lightning_transaction_sync::TxSyncError> for Error {
fn from(_e: lightning_transaction_sync::TxSyncError) -> Self {
Self::TxSyncFailed
}
}
Loading