Skip to content

Commit 370dc64

Browse files
committed
feature: replace setup_nodes.sh with predefined configs. This removes
the extra need to call cargo run --bin cli setup
1 parent fdfeed5 commit 370dc64

38 files changed

+820
-51
lines changed

.github/workflows/integ-tests.yml

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,8 @@ jobs:
101101

102102
- name: Start 12-node stack (docker-compose)
103103
run: |
104-
if [ "${{ github.event_name }}" = "pull_request" ]; then
105-
bash setup_nodes.sh 12 "trieve/threshold:pr-${{ github.event.pull_request.number }}"
106-
else
107-
bash setup_nodes.sh 12 "trieve/threshold:latest"
108-
fi
104+
sed -i "s/trieve\/threshold:latest/trieve\/threshold:pr-${{ github.event.pull_request.number }}/g" docker-compose-12.yaml
105+
docker compose -f docker-compose-12.yaml up -d
109106
110107
- name: Wait for gRPC endpoints
111108
run: |
@@ -177,11 +174,8 @@ jobs:
177174

178175
- name: Start 5-node stack (docker-compose)
179176
run: |
180-
if [ "${{ github.event_name }}" = "pull_request" ]; then
181-
bash setup_nodes.sh 5 "trieve/threshold:pr-${{ github.event.pull_request.number }}"
182-
else
183-
bash setup_nodes.sh 5 "trieve/threshold:latest"
184-
fi
177+
sed -i "s/trieve\/threshold:latest/trieve\/threshold:pr-${{ github.event.pull_request.number }}/g" docker-compose.yaml
178+
docker compose -f docker-compose.yaml up -d
185179
186180
- name: Wait for gRPC endpoint
187181
run: |
@@ -245,18 +239,15 @@ jobs:
245239

246240
- name: Start 5-node stack (docker-compose)
247241
run: |
248-
if [ "${{ github.event_name }}" = "pull_request" ]; then
249-
bash setup_nodes.sh 5 "trieve/threshold:pr-${{ github.event.pull_request.number }}"
250-
else
251-
bash setup_nodes.sh 5 "trieve/threshold:latest"
252-
fi
242+
sed -i "s/trieve\/threshold:latest/trieve\/threshold:pr-${{ github.event.pull_request.number }}/g" docker-compose.yaml
243+
docker compose -f docker-compose.yaml up -d
253244
254245
- name: Wait for gRPC endpoint
255246
run: |
256-
echo "Waiting for node to expose port 50057-50061..."
247+
echo "Waiting for node to expose port 50051-50055..."
257248
for i in {1..30}; do
258-
if nc -z localhost {50057..50061}; then
259-
echo "Port 50057-50061 is open."
249+
if nc -z localhost {50051..50055}; then
250+
echo "Port 50051-50055 is open."
260251
break
261252
fi
262253
echo "Port not ready yet – retry #$i"
@@ -321,26 +312,23 @@ jobs:
321312

322313
- name: Start 5-node stack with network chaos
323314
run: |
324-
if [ "${{ github.event_name }}" = "pull_request" ]; then
325-
bash setup_nodes.sh 5 "trieve/threshold:pr-${{ github.event.pull_request.number }}"
326-
else
327-
bash setup_nodes.sh 5 "trieve/threshold:latest"
328-
fi
315+
sed -i "s/trieve\/threshold:latest/trieve\/threshold:pr-${{ github.event.pull_request.number }}/g" docker-compose.yaml
316+
docker compose -f docker-compose.yaml -f docker-compose.chaos-network.yaml up -d
329317
330318
- name: Wait for gRPC endpoint
331319
run: |
332-
echo "Waiting for node to expose port 50057-50061..."
320+
echo "Waiting for node to expose port 50051-50055..."
333321
for i in {1..30}; do
334-
if nc -z localhost {50057..50061}; then
335-
echo "Port 50057-50061 is open."
322+
if nc -z localhost {50051..50055}; then
323+
echo "Port 50051-50055 is open."
336324
break
337325
fi
338326
echo "Port not ready yet – retry #$i"
339327
sleep 5
340328
done
341329
342330
- name: Run end-to-end integration tests with network chaos
343-
run: cargo run --bin integration-tests check-dkg --port-range 50057-50061
331+
run: cargo run --bin integration-tests check-dkg --port-range 50051-50055
344332

345333
- name: Shutdown stack & print logs
346334
run: |
@@ -394,26 +382,23 @@ jobs:
394382

395383
- name: Start 5-node stack with node chaos
396384
run: |
397-
if [ "${{ github.event_name }}" = "pull_request" ]; then
398-
bash setup_nodes.sh 5 "trieve/threshold:pr-${{ github.event.pull_request.number }}"
399-
else
400-
bash setup_nodes.sh 5 "trieve/threshold:latest"
401-
fi
385+
sed -i "s/trieve\/threshold:latest/trieve\/threshold:pr-${{ github.event.pull_request.number }}/g" docker-compose.yaml
386+
docker compose -f docker-compose.yaml -f docker-compose.chaos-nodes.yaml up -d
402387
403388
- name: Wait for gRPC endpoint
404389
run: |
405-
echo "Waiting for node to expose port 50057-50061..."
390+
echo "Waiting for node to expose port 50051-50055..."
406391
for i in {1..30}; do
407-
if nc -z localhost {50057..50061}; then
408-
echo "Port 50057-50061 is open."
392+
if nc -z localhost {50051..50055}; then
393+
echo "Port 50051-50055 is open."
409394
break
410395
fi
411396
echo "Port not ready yet – retry #$i"
412397
sleep 5
413398
done
414399
415400
- name: Run end-to-end integration tests with node chaos
416-
run: cargo run --bin integration-tests check-dkg --port-range 50057-50061
401+
run: cargo run --bin integration-tests check-dkg --port-range 50051-50055
417402

418403
- name: Shutdown stack & print logs
419404
run: |
@@ -476,7 +461,7 @@ jobs:
476461
echo "Waiting for node to expose port 50051-50055..."
477462
for i in {1..30}; do
478463
if nc -z localhost {50051..50055}; then
479-
echo "Port 50057-50061 is open."
464+
echo "Port 50051-50055 is open."
480465
break
481466
fi
482467
echo "Port not ready yet – retry #$i"
@@ -542,10 +527,10 @@ jobs:
542527
543528
- name: Wait for gRPC endpoint
544529
run: |
545-
echo "Waiting for node to expose port 50057-50061..."
530+
echo "Waiting for node to expose port 50051-50055..."
546531
for i in {1..30}; do
547-
if nc -z localhost {50057..50061}; then
548-
echo "Port 50057-50061 is open."
532+
if nc -z localhost {50051..50055}; then
533+
echo "Port 50051-50055 is open."
549534
break
550535
fi
551536
echo "Port not ready yet – retry #$i"

crates/node/src/config.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub struct NodeConfig {
3333
pub monitor_start_block: u32,
3434
pub min_signers: Option<u16>,
3535
pub max_signers: Option<u16>,
36+
pub save_keys: bool,
3637
}
3738

3839
#[derive(Serialize, Deserialize)]
@@ -54,6 +55,7 @@ pub struct ConfigStore {
5455
pub monitor_start_block: u32,
5556
pub min_signers: Option<u16>,
5657
pub max_signers: Option<u16>,
58+
pub save_keys: bool,
5759
}
5860

5961
#[derive(Clone, Serialize, Deserialize)]
@@ -147,6 +149,7 @@ impl NodeConfig {
147149
monitor_start_block: 0,
148150
min_signers: None,
149151
max_signers: None,
152+
save_keys: true,
150153
})
151154
}
152155

@@ -189,6 +192,7 @@ impl NodeConfig {
189192
monitor_start_block: self.monitor_start_block,
190193
min_signers: self.min_signers,
191194
max_signers: self.max_signers,
195+
save_keys: self.save_keys,
192196
};
193197

194198
let config_str: String = serde_yaml::to_string(&config_store).unwrap();
@@ -271,6 +275,7 @@ impl NodeConfig {
271275
monitor_start_block: config_store.monitor_start_block,
272276
min_signers: config_store.min_signers,
273277
max_signers: config_store.max_signers,
278+
save_keys: config_store.save_keys,
274279
};
275280

276281
Ok(node_config)
@@ -312,7 +317,9 @@ impl NodeConfig {
312317
};
313318

314319
self.dkg_keys = Some(dkg_keys);
315-
self.save_to_keys_file()?;
320+
if self.save_keys {
321+
self.save_to_keys_file()?;
322+
}
316323

317324
Ok(())
318325
}
@@ -370,6 +377,7 @@ pub struct NodeConfigBuilder {
370377
monitor_start_block: Option<u32>,
371378
min_signers: Option<u16>,
372379
max_signers: Option<u16>,
380+
save_keys: Option<bool>,
373381
}
374382

375383
impl Default for NodeConfigBuilder {
@@ -398,6 +406,7 @@ impl NodeConfigBuilder {
398406
monitor_start_block: None,
399407
min_signers: None,
400408
max_signers: None,
409+
save_keys: None,
401410
}
402411
}
403412
#[must_use]
@@ -490,6 +499,12 @@ impl NodeConfigBuilder {
490499
self
491500
}
492501

502+
#[must_use]
503+
pub const fn save_keys(mut self, save_keys: bool) -> Self {
504+
self.save_keys = Some(save_keys);
505+
self
506+
}
507+
493508
pub fn build(self) -> Result<NodeConfig, NodeError> {
494509
let key_file_path = self.key_file_path.ok_or_else(|| {
495510
NodeError::Error("key_file_path must be provided when building NodeConfig".into())
@@ -511,6 +526,10 @@ impl NodeConfigBuilder {
511526
)
512527
.map_err(|e| NodeError::Error(format!("Failed to create NodeConfig: {e}")))?;
513528

529+
if let Some(save_keys) = self.save_keys {
530+
cfg.save_keys = save_keys;
531+
}
532+
514533
if let Some(data) = self.key_data {
515534
cfg.key_data = data;
516535
}

0 commit comments

Comments
 (0)