Skip to content

Commit e4da11e

Browse files
committed
Switch to new sigs-based auth in VSS integration tests
When we added the trivial sigs-based authentication scheme in VSS, we made it the default if no other authentication scheme was configured and default features are enabled. This broke our integration tests as we were expecting no authentication to be required in such a case. Here we fix this by switching to the new sigs-based auth scheme, removing `store_id`s to demonstrate client isolation while we're at it. Sadly, because we don't currently have a test framework for LNURL-auth-based VSS, and because VSS no longer defaults to no-auth, the upgrade-from-0.6 test has to be moved to a separate CI job which runs VSS server with the noop auth.
1 parent 927ce68 commit e4da11e

File tree

5 files changed

+164
-114
lines changed

5 files changed

+164
-114
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: CI Checks - VSS No-Auth Integration Tests
2+
3+
on: [push, pull_request]
4+
5+
concurrency:
6+
group: ${{ github.workflow }}-${{ github.ref }}
7+
cancel-in-progress: true
8+
9+
jobs:
10+
build-and-test:
11+
runs-on: ubuntu-latest
12+
13+
services:
14+
postgres:
15+
image: postgres:latest
16+
ports:
17+
- 5432:5432
18+
env:
19+
POSTGRES_DB: postgres
20+
POSTGRES_USER: postgres
21+
POSTGRES_PASSWORD: postgres
22+
options: >-
23+
--health-cmd pg_isready
24+
--health-interval 10s
25+
--health-timeout 5s
26+
--health-retries 5
27+
28+
steps:
29+
- name: Checkout code
30+
uses: actions/checkout@v3
31+
with:
32+
path: ldk-node
33+
- name: Checkout VSS
34+
uses: actions/checkout@v3
35+
with:
36+
repository: lightningdevkit/vss-server
37+
path: vss-server
38+
39+
- name: Build and Deploy VSS Server
40+
run: |
41+
cd vss-server/rust
42+
RUSTFLAGS=--cfg=noop_authorizer cargo run --no-default-features server/vss-server-config.toml&
43+
- name: Run VSS Integration tests
44+
run: |
45+
cd ldk-node
46+
export TEST_VSS_BASE_URL="http://localhost:8080/vss"
47+
RUSTFLAGS="--cfg vss_test --cfg cycle_tests" cargo test --test integration_tests_vss_no_auth

src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ impl NodeBuilder {
591591
///
592592
/// Uses a simple authentication scheme proving knowledge of a secret key.
593593
///
594-
/// `fixed_headers` are included as it is in all the requests made to VSS and LNURL auth server.
594+
/// `fixed_headers` are included as it is in all the requests made to VSS.
595595
///
596596
/// **Caution**: VSS support is in **alpha** and is considered experimental.
597597
/// Using VSS (or any remote persistence) may cause LDK to panic if persistence failures are

src/io/vss_store.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,6 @@ mod tests {
10161016

10171017
use rand::distr::Alphanumeric;
10181018
use rand::{rng, Rng, RngCore};
1019-
use vss_client::headers::FixedHeaders;
10201019

10211020
use super::*;
10221021
use crate::io::test_utils::do_read_write_remove_list_persist;
@@ -1026,11 +1025,13 @@ mod tests {
10261025
let vss_base_url = std::env::var("TEST_VSS_BASE_URL").unwrap();
10271026
let mut rng = rng();
10281027
let rand_store_id: String = (0..7).map(|_| rng.sample(Alphanumeric) as char).collect();
1029-
let mut vss_seed = [0u8; 32];
1030-
rng.fill_bytes(&mut vss_seed);
1031-
let header_provider = Arc::new(FixedHeaders::new(HashMap::new()));
1028+
let mut node_seed = [0u8; 64];
1029+
rng.fill_bytes(&mut node_seed);
1030+
let entropy = NodeEntropy::from_seed_bytes(node_seed);
10321031
let vss_store =
1033-
VssStore::new(vss_base_url, rand_store_id, vss_seed, header_provider).unwrap();
1032+
VssStoreBuilder::new(entropy, vss_base_url, rand_store_id, Network::Testnet)
1033+
.build_with_sigs_auth(HashMap::new())
1034+
.unwrap();
10341035
do_read_write_remove_list_persist(&vss_store);
10351036
}
10361037

@@ -1039,11 +1040,13 @@ mod tests {
10391040
let vss_base_url = std::env::var("TEST_VSS_BASE_URL").unwrap();
10401041
let mut rng = rng();
10411042
let rand_store_id: String = (0..7).map(|_| rng.sample(Alphanumeric) as char).collect();
1042-
let mut vss_seed = [0u8; 32];
1043-
rng.fill_bytes(&mut vss_seed);
1044-
let header_provider = Arc::new(FixedHeaders::new(HashMap::new()));
1043+
let mut node_seed = [0u8; 64];
1044+
rng.fill_bytes(&mut node_seed);
1045+
let entropy = NodeEntropy::from_seed_bytes(node_seed);
10451046
let vss_store =
1046-
VssStore::new(vss_base_url, rand_store_id, vss_seed, header_provider).unwrap();
1047+
VssStoreBuilder::new(entropy, vss_base_url, rand_store_id, Network::Testnet)
1048+
.build_with_sigs_auth(HashMap::new())
1049+
.unwrap();
10471050

10481051
do_read_write_remove_list_persist(&vss_store);
10491052
drop(vss_store)

tests/integration_tests_vss.rs

Lines changed: 8 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::collections::HashMap;
1313

1414
use ldk_node::entropy::NodeEntropy;
1515
use ldk_node::Builder;
16-
use rand::{rng, Rng};
16+
use rand::RngCore;
1717

1818
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1919
async fn channel_full_cycle_with_vss_store() {
@@ -25,10 +25,10 @@ async fn channel_full_cycle_with_vss_store() {
2525
builder_a.set_chain_source_esplora(esplora_url.clone(), None);
2626
let vss_base_url = std::env::var("TEST_VSS_BASE_URL").unwrap();
2727
let node_a = builder_a
28-
.build_with_vss_store_and_fixed_headers(
28+
.build_with_vss_store(
2929
config_a.node_entropy,
3030
vss_base_url.clone(),
31-
"node_1_store".to_string(),
31+
"".to_owned(),
3232
HashMap::new(),
3333
)
3434
.unwrap();
@@ -39,12 +39,7 @@ async fn channel_full_cycle_with_vss_store() {
3939
let mut builder_b = Builder::from_config(config_b.node_config);
4040
builder_b.set_chain_source_esplora(esplora_url.clone(), None);
4141
let node_b = builder_b
42-
.build_with_vss_store_and_fixed_headers(
43-
config_b.node_entropy,
44-
vss_base_url,
45-
"node_2_store".to_string(),
46-
HashMap::new(),
47-
)
42+
.build_with_vss_store(config_b.node_entropy, vss_base_url, "".to_owned(), HashMap::new())
4843
.unwrap();
4944
node_b.start().unwrap();
5045

@@ -60,96 +55,15 @@ async fn channel_full_cycle_with_vss_store() {
6055
.await;
6156
}
6257

63-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
64-
async fn vss_v0_schema_backwards_compatibility() {
65-
let (bitcoind, electrsd) = common::setup_bitcoind_and_electrsd();
66-
let esplora_url = format!("http://{}", electrsd.esplora_url.as_ref().unwrap());
67-
let vss_base_url = std::env::var("TEST_VSS_BASE_URL").unwrap();
68-
69-
let rand_suffix: String =
70-
(0..7).map(|_| rng().sample(rand::distr::Alphanumeric) as char).collect();
71-
let store_id = format!("v0_compat_test_{}", rand_suffix);
72-
let storage_path = common::random_storage_path().to_str().unwrap().to_owned();
73-
let seed_bytes = [42u8; 64];
74-
let node_entropy = NodeEntropy::from_seed_bytes(seed_bytes);
75-
76-
// Setup a v0.6.2 `Node` persisted with the v0 scheme.
77-
let (old_balance, old_node_id) = {
78-
let mut builder_old = ldk_node_062::Builder::new();
79-
builder_old.set_network(bitcoin::Network::Regtest);
80-
builder_old.set_storage_dir_path(storage_path.clone());
81-
builder_old.set_entropy_seed_bytes(seed_bytes);
82-
builder_old.set_chain_source_esplora(esplora_url.clone(), None);
83-
let node_old = builder_old
84-
.build_with_vss_store_and_fixed_headers(
85-
vss_base_url.clone(),
86-
store_id.clone(),
87-
HashMap::new(),
88-
)
89-
.unwrap();
90-
91-
node_old.start().unwrap();
92-
let addr_old = node_old.onchain_payment().new_address().unwrap();
93-
common::premine_and_distribute_funds(
94-
&bitcoind.client,
95-
&electrsd.client,
96-
vec![addr_old],
97-
bitcoin::Amount::from_sat(100_000),
98-
)
99-
.await;
100-
node_old.sync_wallets().unwrap();
101-
102-
let balance = node_old.list_balances().spendable_onchain_balance_sats;
103-
assert!(balance > 0);
104-
let node_id = node_old.node_id();
105-
106-
// Workaround necessary as v0.6.2's VSS runtime wasn't dropsafe in a tokio context.
107-
tokio::task::block_in_place(move || {
108-
node_old.stop().unwrap();
109-
drop(node_old);
110-
});
111-
112-
(balance, node_id)
113-
};
114-
115-
// Now ensure we can still reinit from the same backend.
116-
let mut builder_new = Builder::new();
117-
builder_new.set_network(bitcoin::Network::Regtest);
118-
builder_new.set_storage_dir_path(storage_path);
119-
builder_new.set_chain_source_esplora(esplora_url, None);
120-
121-
let node_new = builder_new
122-
.build_with_vss_store_and_fixed_headers(
123-
node_entropy,
124-
vss_base_url,
125-
store_id,
126-
HashMap::new(),
127-
)
128-
.unwrap();
129-
130-
node_new.start().unwrap();
131-
node_new.sync_wallets().unwrap();
132-
133-
let new_balance = node_new.list_balances().spendable_onchain_balance_sats;
134-
let new_node_id = node_new.node_id();
135-
136-
assert_eq!(old_node_id, new_node_id);
137-
assert_eq!(old_balance, new_balance);
138-
139-
node_new.stop().unwrap();
140-
}
141-
14258
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
14359
async fn vss_node_restart() {
14460
let (bitcoind, electrsd) = common::setup_bitcoind_and_electrsd();
14561
let esplora_url = format!("http://{}", electrsd.esplora_url.as_ref().unwrap());
14662
let vss_base_url = std::env::var("TEST_VSS_BASE_URL").unwrap();
14763

148-
let rand_suffix: String =
149-
(0..7).map(|_| rng().sample(rand::distr::Alphanumeric) as char).collect();
150-
let store_id = format!("restart_test_{}", rand_suffix);
15164
let storage_path = common::random_storage_path().to_str().unwrap().to_owned();
152-
let seed_bytes = [42u8; 64];
65+
let mut seed_bytes = [42u8; 64];
66+
rand::rng().fill_bytes(&mut seed_bytes);
15367
let node_entropy = NodeEntropy::from_seed_bytes(seed_bytes);
15468

15569
// Setup initial node and fund it.
@@ -159,12 +73,7 @@ async fn vss_node_restart() {
15973
builder.set_storage_dir_path(storage_path.clone());
16074
builder.set_chain_source_esplora(esplora_url.clone(), None);
16175
let node = builder
162-
.build_with_vss_store_and_fixed_headers(
163-
node_entropy,
164-
vss_base_url.clone(),
165-
store_id.clone(),
166-
HashMap::new(),
167-
)
76+
.build_with_vss_store(node_entropy, vss_base_url.clone(), "".to_owned(), HashMap::new())
16877
.unwrap();
16978

17079
node.start().unwrap();
@@ -193,12 +102,7 @@ async fn vss_node_restart() {
193102
builder.set_chain_source_esplora(esplora_url, None);
194103

195104
let node = builder
196-
.build_with_vss_store_and_fixed_headers(
197-
node_entropy,
198-
vss_base_url,
199-
store_id,
200-
HashMap::new(),
201-
)
105+
.build_with_vss_store(node_entropy, vss_base_url, "".to_owned(), HashMap::new())
202106
.unwrap();
203107

204108
node.start().unwrap();
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// This file is Copyright its original authors, visible in version control history.
2+
//
3+
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5+
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
6+
// accordance with one or both of these licenses.
7+
8+
#![cfg(vss_test)]
9+
10+
mod common;
11+
12+
use std::collections::HashMap;
13+
14+
use ldk_node::entropy::NodeEntropy;
15+
use ldk_node::Builder;
16+
use rand::{rng, Rng, RngCore};
17+
18+
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
19+
async fn vss_v0_schema_backwards_compatibility() {
20+
let (bitcoind, electrsd) = common::setup_bitcoind_and_electrsd();
21+
let esplora_url = format!("http://{}", electrsd.esplora_url.as_ref().unwrap());
22+
let vss_base_url = std::env::var("TEST_VSS_BASE_URL").unwrap();
23+
24+
let rand_suffix: String =
25+
(0..7).map(|_| rng().sample(rand::distr::Alphanumeric) as char).collect();
26+
let store_id = format!("v0_compat_test_{}", rand_suffix);
27+
let storage_path = common::random_storage_path().to_str().unwrap().to_owned();
28+
let mut seed_bytes = [42u8; 64];
29+
rand::thread_rng().fill_bytes(&mut seed_bytes);
30+
let node_entropy = NodeEntropy::from_seed_bytes(seed_bytes);
31+
32+
// Setup a v0.6.2 `Node` persisted with the v0 scheme.
33+
let (old_balance, old_node_id) = {
34+
let mut builder_old = ldk_node_062::Builder::new();
35+
builder_old.set_network(bitcoin::Network::Regtest);
36+
builder_old.set_storage_dir_path(storage_path.clone());
37+
builder_old.set_entropy_seed_bytes(seed_bytes);
38+
builder_old.set_chain_source_esplora(esplora_url.clone(), None);
39+
let node_old = builder_old
40+
.build_with_vss_store_and_fixed_headers(
41+
vss_base_url.clone(),
42+
store_id.clone(),
43+
HashMap::new(),
44+
)
45+
.unwrap();
46+
47+
node_old.start().unwrap();
48+
let addr_old = node_old.onchain_payment().new_address().unwrap();
49+
common::premine_and_distribute_funds(
50+
&bitcoind.client,
51+
&electrsd.client,
52+
vec![addr_old],
53+
bitcoin::Amount::from_sat(100_000),
54+
)
55+
.await;
56+
node_old.sync_wallets().unwrap();
57+
58+
let balance = node_old.list_balances().spendable_onchain_balance_sats;
59+
assert!(balance > 0);
60+
let node_id = node_old.node_id();
61+
62+
// Workaround necessary as v0.6.2's VSS runtime wasn't dropsafe in a tokio context.
63+
tokio::task::block_in_place(move || {
64+
node_old.stop().unwrap();
65+
drop(node_old);
66+
});
67+
68+
(balance, node_id)
69+
};
70+
71+
// Now ensure we can still reinit from the same backend.
72+
let mut builder_new = Builder::new();
73+
builder_new.set_network(bitcoin::Network::Regtest);
74+
builder_new.set_storage_dir_path(storage_path);
75+
builder_new.set_chain_source_esplora(esplora_url, None);
76+
77+
let node_new = builder_new
78+
.build_with_vss_store_and_fixed_headers(
79+
node_entropy,
80+
vss_base_url,
81+
store_id,
82+
HashMap::new(),
83+
)
84+
.unwrap();
85+
86+
node_new.start().unwrap();
87+
node_new.sync_wallets().unwrap();
88+
89+
let new_balance = node_new.list_balances().spendable_onchain_balance_sats;
90+
let new_node_id = node_new.node_id();
91+
92+
assert_eq!(old_node_id, new_node_id);
93+
assert_eq!(old_balance, new_balance);
94+
95+
node_new.stop().unwrap();
96+
}

0 commit comments

Comments
 (0)