Skip to content
Draft
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
49 changes: 24 additions & 25 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ default = []
#lightning-liquidity = { version = "0.2.0", features = ["std"] }
#lightning-macros = { version = "0.2.0" }

lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204", features = ["std"] }
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204" }
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204", features = ["std"] }
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204" }
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204", features = ["tokio"] }
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204" }
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204" }
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204", features = ["rest-client", "rpc-client", "tokio"] }
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204", features = ["std"] }
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204" }
lightning = { git = "https://github.com/tnull/rust-lightning", rev = "dd583b0b99999080fd770f50a38ec1277c53950a", features = ["std"] }
lightning-types = { git = "https://github.com/tnull/rust-lightning", rev = "dd583b0b99999080fd770f50a38ec1277c53950a" }
lightning-invoice = { git = "https://github.com/tnull/rust-lightning", rev = "dd583b0b99999080fd770f50a38ec1277c53950a", features = ["std"] }
lightning-net-tokio = { git = "https://github.com/tnull/rust-lightning", rev = "dd583b0b99999080fd770f50a38ec1277c53950a" }
lightning-persister = { git = "https://github.com/tnull/rust-lightning", rev = "dd583b0b99999080fd770f50a38ec1277c53950a", features = ["tokio", "vss"] }
lightning-background-processor = { git = "https://github.com/tnull/rust-lightning", rev = "dd583b0b99999080fd770f50a38ec1277c53950a" }
lightning-rapid-gossip-sync = { git = "https://github.com/tnull/rust-lightning", rev = "dd583b0b99999080fd770f50a38ec1277c53950a" }
lightning-block-sync = { git = "https://github.com/tnull/rust-lightning", rev = "dd583b0b99999080fd770f50a38ec1277c53950a", features = ["rest-client", "rpc-client", "tokio"] }
lightning-transaction-sync = { git = "https://github.com/tnull/rust-lightning", rev = "dd583b0b99999080fd770f50a38ec1277c53950a", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
lightning-liquidity = { git = "https://github.com/tnull/rust-lightning", rev = "dd583b0b99999080fd770f50a38ec1277c53950a", features = ["std"] }
lightning-macros = { git = "https://github.com/tnull/rust-lightning", rev = "dd583b0b99999080fd770f50a38ec1277c53950a" }

bdk_chain = { version = "0.23.0", default-features = false, features = ["std"] }
bdk_esplora = { version = "0.22.0", default-features = false, features = ["async-https-rustls", "tokio"]}
Expand All @@ -76,7 +76,6 @@ serde_json = { version = "1.0.128", default-features = false, features = ["std"]
log = { version = "0.4.22", default-features = false, features = ["std"]}

async-trait = { version = "0.1", default-features = false }
vss-client = { package = "vss-client-ng", version = "0.5" }
prost = { version = "0.11.6", default-features = false}
#bitcoin-payment-instructions = { version = "0.6" }
bitcoin-payment-instructions = { git = "https://github.com/jkczyz/bitcoin-payment-instructions", rev = "0138feb7acefb1e49102a6fb46d7b776bf43265e" }
Expand All @@ -85,7 +84,7 @@ bitcoin-payment-instructions = { git = "https://github.com/jkczyz/bitcoin-paymen
winapi = { version = "0.3", features = ["winbase"] }

[dev-dependencies]
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204", features = ["std", "_test_utils"] }
lightning = { git = "https://github.com/tnull/rust-lightning", rev = "dd583b0b99999080fd770f50a38ec1277c53950a", features = ["std", "_test_utils"] }
rand = { version = "0.9.2", default-features = false, features = ["std", "thread_rng", "os_rng"] }
proptest = "1.0.0"
regex = "1.5.6"
Expand Down Expand Up @@ -131,18 +130,18 @@ check-cfg = [
name = "payments"
harness = false

#[patch.crates-io]
#lightning = { path = "../rust-lightning/lightning" }
#lightning-types = { path = "../rust-lightning/lightning-types" }
#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-block-sync = { path = "../rust-lightning/lightning-block-sync" }
#lightning-transaction-sync = { path = "../rust-lightning/lightning-transaction-sync" }
#lightning-liquidity = { path = "../rust-lightning/lightning-liquidity" }
#lightning-macros = { path = "../rust-lightning/lightning-macros" }
[patch.crates-io]
lightning = { path = "../rust-lightning/lightning" }
lightning-types = { path = "../rust-lightning/lightning-types" }
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-block-sync = { path = "../rust-lightning/lightning-block-sync" }
lightning-transaction-sync = { path = "../rust-lightning/lightning-transaction-sync" }
lightning-liquidity = { path = "../rust-lightning/lightning-liquidity" }
lightning-macros = { path = "../rust-lightning/lightning-macros" }

#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
#lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
Expand Down
32 changes: 25 additions & 7 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ use lightning::util::persist::{
use lightning::util::ser::ReadableArgs;
use lightning::util::sweep::OutputSweeper;
use lightning_persister::fs_store::v1::FilesystemStore;
use vss_client::headers::VssHeaderProvider;
use lightning_persister::vss_client::headers::VssHeaderProvider;
use lightning_persister::vss_store::VssStoreBuilder;

use crate::chain::ChainSource;
use crate::config::{
Expand All @@ -59,7 +60,6 @@ use crate::io::utils::{
read_node_metrics, read_output_sweeper, read_payments, read_peer_info, read_pending_payments,
read_scorer, write_node_metrics,
};
use crate::io::vss_store::VssStoreBuilder;
use crate::io::{
self, PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE, PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE,
PENDING_PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE,
Expand All @@ -84,6 +84,7 @@ use crate::wallet::persist::KVStoreWalletPersister;
use crate::wallet::Wallet;
use crate::{Node, NodeMetrics};

const VSS_HARDENED_CHILD_INDEX: u32 = 877;
const LSPS_HARDENED_CHILD_INDEX: u32 = 577;
const PERSISTER_MAX_PENDING_UPDATES: u64 = 100;

Expand Down Expand Up @@ -663,7 +664,8 @@ impl NodeBuilder {
fixed_headers: HashMap<String, String>,
) -> Result<Node, BuildError> {
let logger = setup_logger(&self.log_writer_config, &self.config)?;
let builder = VssStoreBuilder::new(node_entropy, vss_url, store_id, self.config.network);
let vss_xprv = derive_vss_xprv(&node_entropy, self.config.network)?;
let builder = VssStoreBuilder::new(vss_xprv, vss_url, store_id);
let vss_store = builder.build_with_sigs_auth(fixed_headers).map_err(|e| {
log_error!(logger, "Failed to setup VSS store: {}", e);
BuildError::KVStoreSetupFailed
Expand Down Expand Up @@ -699,7 +701,8 @@ impl NodeBuilder {
lnurl_auth_server_url: String, fixed_headers: HashMap<String, String>,
) -> Result<Node, BuildError> {
let logger = setup_logger(&self.log_writer_config, &self.config)?;
let builder = VssStoreBuilder::new(node_entropy, vss_url, store_id, self.config.network);
let vss_xprv = derive_vss_xprv(&node_entropy, self.config.network)?;
let builder = VssStoreBuilder::new(vss_xprv, vss_url, store_id);
let vss_store =
builder.build_with_lnurl(lnurl_auth_server_url, fixed_headers).map_err(|e| {
log_error!(logger, "Failed to setup VSS store: {}", e);
Expand All @@ -721,13 +724,14 @@ impl NodeBuilder {
/// unrecoverable, i.e., if they remain unresolved after internal retries are exhausted.
///
/// [VSS]: https://github.com/lightningdevkit/vss-server/blob/main/README.md
/// [`FixedHeaders`]: vss_client::headers::FixedHeaders
/// [`FixedHeaders`]: lightning_persister::vss_client::headers::FixedHeaders
pub fn build_with_vss_store_and_fixed_headers(
&self, node_entropy: NodeEntropy, vss_url: String, store_id: String,
fixed_headers: HashMap<String, String>,
) -> Result<Node, BuildError> {
let logger = setup_logger(&self.log_writer_config, &self.config)?;
let builder = VssStoreBuilder::new(node_entropy, vss_url, store_id, self.config.network);
let vss_xprv = derive_vss_xprv(&node_entropy, self.config.network)?;
let builder = VssStoreBuilder::new(vss_xprv, vss_url, store_id);
let vss_store = builder.build_with_fixed_headers(fixed_headers).map_err(|e| {
log_error!(logger, "Failed to setup VSS store: {}", e);
BuildError::KVStoreSetupFailed
Expand All @@ -752,7 +756,8 @@ impl NodeBuilder {
header_provider: Arc<dyn VssHeaderProvider>,
) -> Result<Node, BuildError> {
let logger = setup_logger(&self.log_writer_config, &self.config)?;
let builder = VssStoreBuilder::new(node_entropy, vss_url, store_id, self.config.network);
let vss_xprv = derive_vss_xprv(&node_entropy, self.config.network)?;
let builder = VssStoreBuilder::new(vss_xprv, vss_url, store_id);
let vss_store = builder.build_with_header_provider(header_provider).map_err(|e| {
log_error!(logger, "Failed to setup VSS store: {}", e);
BuildError::KVStoreSetupFailed
Expand Down Expand Up @@ -2023,6 +2028,19 @@ fn optionally_install_rustls_cryptoprovider() {
});
}

fn derive_vss_xprv(node_entropy: &NodeEntropy, network: Network) -> Result<Xpriv, BuildError> {
let seed_bytes = node_entropy.to_seed_bytes();
let secp_ctx = Secp256k1::new();
Xpriv::new_master(network, &seed_bytes)
.and_then(|master| {
master.derive_priv(
&secp_ctx,
&[ChildNumber::Hardened { index: VSS_HARDENED_CHILD_INDEX }],
)
})
.map_err(|_| BuildError::KVStoreSetupFailed)
}

/// Sets up the node logger.
fn setup_logger(
log_writer_config: &Option<LogWriterConfig>, config: &Config,
Expand Down
6 changes: 3 additions & 3 deletions src/ffi/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ pub use lightning_liquidity::lsps0::ser::LSPSDateTime;
pub use lightning_liquidity::lsps1::msgs::{
LSPS1ChannelInfo, LSPS1OrderId, LSPS1OrderParams, LSPS1PaymentState,
};
pub use lightning_types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
pub use lightning_types::string::UntrustedString;
use vss_client::headers::{
use lightning_persister::vss_client::headers::{
VssHeaderProvider as VssClientHeaderProvider,
VssHeaderProviderError as VssClientHeaderProviderError,
};
pub use lightning_types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
pub use lightning_types::string::UntrustedString;

/// Errors around providing headers for each VSS request.
#[derive(Debug, uniffi::Error)]
Expand Down
1 change: 0 additions & 1 deletion src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub mod sqlite_store;
#[cfg(test)]
pub(crate) mod test_utils;
pub(crate) mod utils;
pub mod vss_store;

/// The event queue will be persisted under this key.
pub(crate) const EVENT_QUEUE_PERSISTENCE_PRIMARY_NAMESPACE: &str = "";
Expand Down
Loading
Loading