Skip to content

Commit c2f7e23

Browse files
committed
Switch to upstreamed VssStore from lightning-persister
Delete the local `VssStore`/`VssStoreBuilder` implementation and consume the upstreamed version from `lightning-persister` instead. The `Builder` now derives the VSS `Xpriv` inline before passing it to the upstream `VssStoreBuilder`, which no longer takes `NodeEntropy` directly. Also switch all `vss_client` imports to the re-export from `lightning_persister::vss_client` and drop the direct `vss-client-ng` dependency to avoid version mismatches. Co-Authored-By: HAL 9000 Signed-off-by: Elias Rohrer <dev@tnull.de>
1 parent 9e0a812 commit c2f7e23

File tree

6 files changed

+54
-1081
lines changed

6 files changed

+54
-1081
lines changed

Cargo.toml

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "
4343
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204" }
4444
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204", features = ["std"] }
4545
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204" }
46-
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204", features = ["tokio"] }
46+
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204", features = ["tokio", "vss"] }
4747
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204" }
4848
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204" }
4949
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204", features = ["rest-client", "rpc-client", "tokio"] }
@@ -76,7 +76,6 @@ serde_json = { version = "1.0.128", default-features = false, features = ["std"]
7676
log = { version = "0.4.22", default-features = false, features = ["std"]}
7777

7878
async-trait = { version = "0.1", default-features = false }
79-
vss-client = { package = "vss-client-ng", version = "0.5" }
8079
prost = { version = "0.11.6", default-features = false}
8180
#bitcoin-payment-instructions = { version = "0.6" }
8281
bitcoin-payment-instructions = { git = "https://github.com/jkczyz/bitcoin-payment-instructions", rev = "0138feb7acefb1e49102a6fb46d7b776bf43265e" }
@@ -131,18 +130,18 @@ check-cfg = [
131130
name = "payments"
132131
harness = false
133132

134-
#[patch.crates-io]
135-
#lightning = { path = "../rust-lightning/lightning" }
136-
#lightning-types = { path = "../rust-lightning/lightning-types" }
137-
#lightning-invoice = { path = "../rust-lightning/lightning-invoice" }
138-
#lightning-net-tokio = { path = "../rust-lightning/lightning-net-tokio" }
139-
#lightning-persister = { path = "../rust-lightning/lightning-persister" }
140-
#lightning-background-processor = { path = "../rust-lightning/lightning-background-processor" }
141-
#lightning-rapid-gossip-sync = { path = "../rust-lightning/lightning-rapid-gossip-sync" }
142-
#lightning-block-sync = { path = "../rust-lightning/lightning-block-sync" }
143-
#lightning-transaction-sync = { path = "../rust-lightning/lightning-transaction-sync" }
144-
#lightning-liquidity = { path = "../rust-lightning/lightning-liquidity" }
145-
#lightning-macros = { path = "../rust-lightning/lightning-macros" }
133+
[patch.crates-io]
134+
lightning = { path = "../rust-lightning/lightning" }
135+
lightning-types = { path = "../rust-lightning/lightning-types" }
136+
lightning-invoice = { path = "../rust-lightning/lightning-invoice" }
137+
lightning-net-tokio = { path = "../rust-lightning/lightning-net-tokio" }
138+
lightning-persister = { path = "../rust-lightning/lightning-persister" }
139+
lightning-background-processor = { path = "../rust-lightning/lightning-background-processor" }
140+
lightning-rapid-gossip-sync = { path = "../rust-lightning/lightning-rapid-gossip-sync" }
141+
lightning-block-sync = { path = "../rust-lightning/lightning-block-sync" }
142+
lightning-transaction-sync = { path = "../rust-lightning/lightning-transaction-sync" }
143+
lightning-liquidity = { path = "../rust-lightning/lightning-liquidity" }
144+
lightning-macros = { path = "../rust-lightning/lightning-macros" }
146145

147146
#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
148147
#lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
@@ -171,7 +170,7 @@ harness = false
171170
#vss-client-ng = { path = "../vss-client" }
172171
#vss-client-ng = { git = "https://github.com/lightningdevkit/vss-client", branch = "main" }
173172
#
174-
#[patch."https://github.com/lightningdevkit/rust-lightning"]
173+
[patch."https://github.com/lightningdevkit/rust-lightning"]
175174
#lightning = { path = "../rust-lightning/lightning" }
176175
#lightning-types = { path = "../rust-lightning/lightning-types" }
177176
#lightning-invoice = { path = "../rust-lightning/lightning-invoice" }
@@ -183,3 +182,14 @@ harness = false
183182
#lightning-transaction-sync = { path = "../rust-lightning/lightning-transaction-sync" }
184183
#lightning-liquidity = { path = "../rust-lightning/lightning-liquidity" }
185184
#lightning-macros = { path = "../rust-lightning/lightning-macros" }
185+
lightning = { git = "https://github.com/tnull/rust-lightning", rev = "a343406d14de4d9086e38b48038b66cae3326a4f" }
186+
lightning-types = { git = "https://github.com/tnull/rust-lightning", rev = "a343406d14de4d9086e38b48038b66cae3326a4f" }
187+
lightning-invoice = { git = "https://github.com/tnull/rust-lightning", rev = "a343406d14de4d9086e38b48038b66cae3326a4f" }
188+
lightning-net-tokio = { git = "https://github.com/tnull/rust-lightning", rev = "a343406d14de4d9086e38b48038b66cae3326a4f" }
189+
lightning-persister = { git = "https://github.com/tnull/rust-lightning", rev = "a343406d14de4d9086e38b48038b66cae3326a4f" }
190+
lightning-background-processor = { git = "https://github.com/tnull/rust-lightning", rev = "a343406d14de4d9086e38b48038b66cae3326a4f" }
191+
lightning-rapid-gossip-sync = { git = "https://github.com/tnull/rust-lightning", rev = "a343406d14de4d9086e38b48038b66cae3326a4f" }
192+
lightning-block-sync = { git = "https://github.com/tnull/rust-lightning", rev = "a343406d14de4d9086e38b48038b66cae3326a4f" }
193+
lightning-transaction-sync = { git = "https://github.com/tnull/rust-lightning", rev = "a343406d14de4d9086e38b48038b66cae3326a4f" }
194+
lightning-liquidity = { git = "https://github.com/tnull/rust-lightning", rev = "a343406d14de4d9086e38b48038b66cae3326a4f" }
195+
lightning-macros = { git = "https://github.com/tnull/rust-lightning", rev = "a343406d14de4d9086e38b48038b66cae3326a4f" }

src/builder.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ use lightning::util::persist::{
4040
use lightning::util::ser::ReadableArgs;
4141
use lightning::util::sweep::OutputSweeper;
4242
use lightning_persister::fs_store::v1::FilesystemStore;
43-
use vss_client::headers::VssHeaderProvider;
43+
use lightning_persister::vss_client::headers::VssHeaderProvider;
44+
use lightning_persister::vss_store::VssStoreBuilder;
4445

4546
use crate::chain::ChainSource;
4647
use crate::config::{
@@ -59,7 +60,6 @@ use crate::io::utils::{
5960
read_node_metrics, read_output_sweeper, read_payments, read_peer_info, read_pending_payments,
6061
read_scorer, write_node_metrics,
6162
};
62-
use crate::io::vss_store::VssStoreBuilder;
6363
use crate::io::{
6464
self, PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE, PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE,
6565
PENDING_PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE,
@@ -84,6 +84,7 @@ use crate::wallet::persist::KVStoreWalletPersister;
8484
use crate::wallet::Wallet;
8585
use crate::{Node, NodeMetrics};
8686

87+
const VSS_HARDENED_CHILD_INDEX: u32 = 877;
8788
const LSPS_HARDENED_CHILD_INDEX: u32 = 577;
8889
const PERSISTER_MAX_PENDING_UPDATES: u64 = 100;
8990

@@ -663,7 +664,8 @@ impl NodeBuilder {
663664
fixed_headers: HashMap<String, String>,
664665
) -> Result<Node, BuildError> {
665666
let logger = setup_logger(&self.log_writer_config, &self.config)?;
666-
let builder = VssStoreBuilder::new(node_entropy, vss_url, store_id, self.config.network);
667+
let vss_xprv = derive_vss_xprv(&node_entropy, self.config.network)?;
668+
let builder = VssStoreBuilder::new(vss_xprv, vss_url, store_id);
667669
let vss_store = builder.build_with_sigs_auth(fixed_headers).map_err(|e| {
668670
log_error!(logger, "Failed to setup VSS store: {}", e);
669671
BuildError::KVStoreSetupFailed
@@ -699,7 +701,8 @@ impl NodeBuilder {
699701
lnurl_auth_server_url: String, fixed_headers: HashMap<String, String>,
700702
) -> Result<Node, BuildError> {
701703
let logger = setup_logger(&self.log_writer_config, &self.config)?;
702-
let builder = VssStoreBuilder::new(node_entropy, vss_url, store_id, self.config.network);
704+
let vss_xprv = derive_vss_xprv(&node_entropy, self.config.network)?;
705+
let builder = VssStoreBuilder::new(vss_xprv, vss_url, store_id);
703706
let vss_store =
704707
builder.build_with_lnurl(lnurl_auth_server_url, fixed_headers).map_err(|e| {
705708
log_error!(logger, "Failed to setup VSS store: {}", e);
@@ -721,13 +724,14 @@ impl NodeBuilder {
721724
/// unrecoverable, i.e., if they remain unresolved after internal retries are exhausted.
722725
///
723726
/// [VSS]: https://github.com/lightningdevkit/vss-server/blob/main/README.md
724-
/// [`FixedHeaders`]: vss_client::headers::FixedHeaders
727+
/// [`FixedHeaders`]: lightning_persister::vss_client::headers::FixedHeaders
725728
pub fn build_with_vss_store_and_fixed_headers(
726729
&self, node_entropy: NodeEntropy, vss_url: String, store_id: String,
727730
fixed_headers: HashMap<String, String>,
728731
) -> Result<Node, BuildError> {
729732
let logger = setup_logger(&self.log_writer_config, &self.config)?;
730-
let builder = VssStoreBuilder::new(node_entropy, vss_url, store_id, self.config.network);
733+
let vss_xprv = derive_vss_xprv(&node_entropy, self.config.network)?;
734+
let builder = VssStoreBuilder::new(vss_xprv, vss_url, store_id);
731735
let vss_store = builder.build_with_fixed_headers(fixed_headers).map_err(|e| {
732736
log_error!(logger, "Failed to setup VSS store: {}", e);
733737
BuildError::KVStoreSetupFailed
@@ -752,7 +756,8 @@ impl NodeBuilder {
752756
header_provider: Arc<dyn VssHeaderProvider>,
753757
) -> Result<Node, BuildError> {
754758
let logger = setup_logger(&self.log_writer_config, &self.config)?;
755-
let builder = VssStoreBuilder::new(node_entropy, vss_url, store_id, self.config.network);
759+
let vss_xprv = derive_vss_xprv(&node_entropy, self.config.network)?;
760+
let builder = VssStoreBuilder::new(vss_xprv, vss_url, store_id);
756761
let vss_store = builder.build_with_header_provider(header_provider).map_err(|e| {
757762
log_error!(logger, "Failed to setup VSS store: {}", e);
758763
BuildError::KVStoreSetupFailed
@@ -2023,6 +2028,19 @@ fn optionally_install_rustls_cryptoprovider() {
20232028
});
20242029
}
20252030

2031+
fn derive_vss_xprv(node_entropy: &NodeEntropy, network: Network) -> Result<Xpriv, BuildError> {
2032+
let seed_bytes = node_entropy.to_seed_bytes();
2033+
let secp_ctx = Secp256k1::new();
2034+
Xpriv::new_master(network, &seed_bytes)
2035+
.and_then(|master| {
2036+
master.derive_priv(
2037+
&secp_ctx,
2038+
&[ChildNumber::Hardened { index: VSS_HARDENED_CHILD_INDEX }],
2039+
)
2040+
})
2041+
.map_err(|_| BuildError::KVStoreSetupFailed)
2042+
}
2043+
20262044
/// Sets up the node logger.
20272045
fn setup_logger(
20282046
log_writer_config: &Option<LogWriterConfig>, config: &Config,

src/ffi/types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ pub use lightning_liquidity::lsps0::ser::LSPSDateTime;
4343
pub use lightning_liquidity::lsps1::msgs::{
4444
LSPS1ChannelInfo, LSPS1OrderId, LSPS1OrderParams, LSPS1PaymentState,
4545
};
46-
pub use lightning_types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
47-
pub use lightning_types::string::UntrustedString;
48-
use vss_client::headers::{
46+
use lightning_persister::vss_client::headers::{
4947
VssHeaderProvider as VssClientHeaderProvider,
5048
VssHeaderProviderError as VssClientHeaderProviderError,
5149
};
50+
pub use lightning_types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
51+
pub use lightning_types::string::UntrustedString;
5252

5353
/// Errors around providing headers for each VSS request.
5454
#[derive(Debug, uniffi::Error)]

src/io/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ pub mod sqlite_store;
1111
#[cfg(test)]
1212
pub(crate) mod test_utils;
1313
pub(crate) mod utils;
14-
pub mod vss_store;
1514

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

0 commit comments

Comments
 (0)