Skip to content

Commit ec34f23

Browse files
authored
chore: update for merged curio and synapse-sdk PRs (#27)
Plus some additional fixes that seem to work for me
1 parent f4b60ce commit ec34f23

File tree

7 files changed

+141
-53
lines changed

7 files changed

+141
-53
lines changed

src/commands/start/curio/daemon.rs

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::commands::start::curio::constants::CURIO_LAYERS;
99
use crate::docker::command_logger::run_and_log_command_strings;
1010
use crate::docker::network::{lotus_network_name, pdp_miner_network_name};
1111
use crate::docker::{container_exists, stop_and_remove_container};
12+
use crate::docker::init::set_volume_ownership;
1213
use crate::paths::{
1314
foc_devnet_bin, foc_devnet_curio_sp_volume, foc_devnet_genesis_sectors_pdp_sp,
1415
foc_devnet_proof_parameters, CONTAINER_FILECOIN_PROOF_PARAMS_PATH,
@@ -46,7 +47,7 @@ pub fn start_curio_daemon(
4647
create_curio_directories(context, sp_index)?;
4748

4849
// Step 2: Create and start container
49-
let docker_args = build_docker_run_args(context, sp_index, &container_name)?;
50+
let docker_args = build_docker_create_args(context, sp_index, &container_name)?;
5051
start_curio_container(context, &container_name, docker_args)?;
5152

5253
Ok(())
@@ -63,31 +64,38 @@ fn create_curio_directories(context: &SetupContext, sp_index: usize) -> Result<(
6364
curio_sp_dir.join("long-term-storage"),
6465
];
6566

66-
for dir in dirs {
67-
fs::create_dir_all(&dir)?;
67+
for dir in &dirs {
68+
fs::create_dir_all(dir)?;
6869
}
6970

71+
set_volume_ownership(&curio_sp_dir)?;
72+
7073
Ok(())
7174
}
7275

7376
/// Create and start Curio container
77+
///
78+
/// Uses docker create + network connect + start pattern so that:
79+
/// 1. Container is created but not started
80+
/// 2. Networks are connected while container is stopped
81+
/// 3. Container is started with Curio as PID 1 (logs work properly)
7482
fn start_curio_container(
7583
context: &SetupContext,
7684
container_name: &str,
7785
mut docker_args: Vec<String>,
7886
) -> Result<(), Box<dyn Error>> {
7987
info!("Creating container {}...", container_name);
8088

81-
// Add image and command - run curio directly as the main process
89+
// Add image and command - Curio as main process
8290
docker_args.push(crate::constants::CURIO_DOCKER_IMAGE.to_string());
8391
docker_args.push("/usr/local/bin/lotus-bins/curio".to_string());
8492
docker_args.push("run".to_string());
8593
docker_args.push("--nosync".to_string());
8694
docker_args.push("--layers".to_string());
8795
docker_args.push(CURIO_LAYERS.to_string());
8896

89-
// Execute docker run
90-
let key = format!("curio_daemon_start_{}", container_name);
97+
// Execute docker create (not run)
98+
let key = format!("curio_daemon_create_{}", container_name);
9199
let output = run_and_log_command_strings("docker", &docker_args, context, &key)?;
92100

93101
if !output.status.success() {
@@ -98,7 +106,7 @@ fn start_curio_container(
98106
.into());
99107
}
100108

101-
// Connect to filecoin network
109+
// Connect to filecoin network before starting
102110
let lotus_network = lotus_network_name(context.run_id());
103111
let network_args = vec![
104112
"network".to_string(),
@@ -109,13 +117,26 @@ fn start_curio_container(
109117
let key = format!("curio_network_connect_{}", container_name);
110118
let _ = run_and_log_command_strings("docker", &network_args, context, &key); // Ignore errors if already connected
111119

112-
info!("Container created");
120+
// Start the container
121+
let start_args = vec!["start".to_string(), container_name.to_string()];
122+
let key = format!("curio_daemon_start_{}", container_name);
123+
let output = run_and_log_command_strings("docker", &start_args, context, &key)?;
124+
125+
if !output.status.success() {
126+
return Err(format!(
127+
"Failed to start curio container: {}",
128+
String::from_utf8_lossy(&output.stderr)
129+
)
130+
.into());
131+
}
132+
133+
info!("Container created and started");
113134

114135
Ok(())
115136
}
116137

117-
/// Build docker run arguments for Curio
118-
fn build_docker_run_args(
138+
/// Build docker create arguments for Curio
139+
fn build_docker_create_args(
119140
context: &SetupContext,
120141
sp_index: usize,
121142
container_name: &str,
@@ -127,8 +148,7 @@ fn build_docker_run_args(
127148
let genesis_sectors_dir = foc_devnet_genesis_sectors_pdp_sp(run_id, sp_index);
128149

129150
let mut docker_args = vec![
130-
"run".to_string(),
131-
"-d".to_string(),
151+
"create".to_string(),
132152
"--name".to_string(),
133153
container_name.to_string(),
134154
"--network".to_string(),

src/commands/start/curio/db_setup.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,40 @@ pub fn build_foc_contract_env_vars(context: &SetupContext) -> Result<Vec<String>
3333

3434
// Get standard contracts
3535
if let Some(usdfc) = addresses.contracts.get("usdfc") {
36-
env_vars.push(format!("CURIO_USDFC={}", usdfc));
36+
env_vars.push(format!("CURIO_DEVNET_USDFC_ADDRESS={}", usdfc));
3737
}
3838

3939
// Get FOC service contracts
4040
if let Some(payment) = addresses.foc_contracts.get("payment_contract") {
41-
env_vars.push(format!("CURIO_PAYMENT_CONTRACT={}", payment));
41+
env_vars.push(format!("CURIO_DEVNET_PAYMENTS_ADDRESS={}", payment));
4242
}
4343
if let Some(multicall) = addresses.foc_contracts.get("multicall_address") {
44-
env_vars.push(format!("CURIO_MULTICALL_ADDRESS={}", multicall));
44+
env_vars.push(format!("CURIO_DEVNET_MULTICALL_ADDRESS={}", multicall));
4545
}
4646
if let Some(pdp) = addresses.foc_contracts.get("p_d_p_verifier_proxy") {
47-
env_vars.push(format!("CURIO_PDP_VERIFIER={}", pdp));
47+
env_vars.push(format!("CURIO_DEVNET_PDP_VERIFIER_ADDRESS={}", pdp));
4848
}
4949
if let Some(fwss) = addresses
5050
.foc_contracts
5151
.get("filecoin_warm_storage_service_proxy")
5252
{
53-
env_vars.push(format!("CURIO_FWS_SERVICE={}", fwss));
53+
env_vars.push(format!("CURIO_DEVNET_FWSS_ADDRESS={}", fwss));
5454
}
5555
if let Some(sp_registry) = addresses
5656
.foc_contracts
5757
.get("service_provider_registry_proxy")
5858
{
59-
env_vars.push(format!("CURIO_SERVICE_REGISTRY={}", sp_registry));
59+
env_vars.push(format!(
60+
"CURIO_DEVNET_SERVICE_REGISTRY_ADDRESS={}",
61+
sp_registry
62+
));
6063
}
6164

6265
// Simple record keeper is always zero address
63-
env_vars
64-
.push("CURIO_SIMPLE_RECORD_KEEPER=0x0000000000000000000000000000000000000000".to_string());
66+
env_vars.push(
67+
"CURIO_DEVNET_RECORD_KEEPER_SIMPLE_ADDRESS=0x0000000000000000000000000000000000000000"
68+
.to_string(),
69+
);
6570

6671
Ok(env_vars)
6772
}

src/commands/start/curio/storage.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,39 @@ use std::thread;
1212
use std::time::Duration;
1313
use tracing::info;
1414

15+
/// Wait for Curio RPC to be ready using the built-in wait-api command.
16+
fn wait_for_curio_rpc(context: &SetupContext, container_name: &str) -> Result<(), Box<dyn Error>> {
17+
info!("Waiting for Curio RPC to be ready...");
18+
19+
let machine_addr = format!("{}:12300", container_name);
20+
let key = format!("curio_wait_api_{}", container_name);
21+
let output = run_and_log_command(
22+
"docker",
23+
&[
24+
"exec",
25+
container_name,
26+
"/usr/local/bin/lotus-bins/curio",
27+
"cli",
28+
"--machine",
29+
&machine_addr,
30+
"wait-api",
31+
],
32+
context,
33+
&key,
34+
)?;
35+
36+
if !output.status.success() {
37+
return Err(format!(
38+
"Curio RPC failed to become ready: {}",
39+
String::from_utf8_lossy(&output.stderr)
40+
)
41+
.into());
42+
}
43+
44+
info!("Curio RPC is ready");
45+
Ok(())
46+
}
47+
1548
/// Attach storage locations for a specific PDP SP.
1649
///
1750
/// Attaches:
@@ -26,6 +59,9 @@ pub fn attach_storage_locations(
2659
let run_id = context.run_id();
2760
let container_name = format!("foc-{}-curio-{}", run_id, sp_index);
2861

62+
// Wait for RPC to be ready before attaching storage
63+
wait_for_curio_rpc(context, &container_name)?;
64+
2965
// Attach fast storage
3066
attach_fast_storage(context, &container_name)?;
3167

src/commands/start/foc_deploy/deployment.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ pub fn perform_deployment(
4343
) -> Result<(), Box<dyn Error>> {
4444
info!("Deploying FOC service contracts...");
4545

46+
// Clear cached devnet addresses so contracts are actually deployed
47+
super::helpers::clear_cached_devnet_deployments()?;
48+
4649
// Get required addresses from context
4750
let (foc_deployer, foc_deployer_eth, mock_usdfc_address, _global_faucet) =
4851
super::helpers::check_required_addresses(context)?;

src/commands/start/foc_deploy/helpers.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
//! including repository path resolution and deployment checks.
55
66
use crate::config::{Config, Location};
7+
use crate::constants::LOCAL_NETWORK_CHAIN_ID;
78
use crate::docker::containers::lotus_container_name;
89
use crate::docker::core::container_is_running;
910
use crate::paths::{foc_devnet_config, foc_devnet_filecoin_services_repo};
1011
use std::error::Error;
1112
use std::fs;
1213
use std::path::PathBuf;
14+
use tracing::info;
1315

1416
/// Get the filecoin-services repository path based on configuration
1517
///
@@ -93,3 +95,39 @@ pub fn check_required_addresses(
9395
global_faucet.clone(),
9496
))
9597
}
98+
99+
/// Clear cached devnet deployment addresses from deployments.json
100+
///
101+
/// The filecoin-services deployment script reads deployments.json and skips
102+
/// deployment if addresses already exist for the chain ID. This causes issues
103+
/// when starting a fresh devnet because the cached addresses point to contracts
104+
/// that don't exist on the new chain. This function removes the devnet entry
105+
/// so that contracts are actually deployed.
106+
pub fn clear_cached_devnet_deployments() -> Result<(), Box<dyn Error>> {
107+
let services_repo = get_filecoin_services_repo_path()?;
108+
let deployments_file = services_repo.join("service_contracts/deployments.json");
109+
110+
if !deployments_file.exists() {
111+
info!("No deployments.json found, skipping cache clear");
112+
return Ok(());
113+
}
114+
115+
let content = fs::read_to_string(&deployments_file)?;
116+
let mut deployments: serde_json::Value = serde_json::from_str(&content)?;
117+
118+
let chain_id_str = LOCAL_NETWORK_CHAIN_ID.to_string();
119+
if let Some(obj) = deployments.as_object_mut() {
120+
if obj.remove(&chain_id_str).is_some() {
121+
info!(
122+
"Cleared cached devnet (chain {}) addresses from deployments.json",
123+
chain_id_str
124+
);
125+
let updated = serde_json::to_string_pretty(&deployments)?;
126+
fs::write(&deployments_file, updated)?;
127+
} else {
128+
info!("No cached devnet addresses found in deployments.json");
129+
}
130+
}
131+
132+
Ok(())
133+
}

src/commands/start/synapse_test_e2e/synapse_test_step.rs

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ struct DockerTestParams<'a> {
2828
user_key: &'a str,
2929
lotus_rpc_url: &'a str,
3030
warm_storage_addr: &'a str,
31+
multicall3_addr: &'a str,
32+
usdfc_addr: &'a str,
3133
sp_registry_addr: &'a str,
3234
}
3335

@@ -119,6 +121,8 @@ impl Step for SynapseTestE2EStep {
119121
user_key: &user_key,
120122
lotus_rpc_url: &lotus_rpc_url,
121123
warm_storage_addr: &warm_storage_addr,
124+
multicall3_addr: &multicall3_addr,
125+
usdfc_addr: &usdfc_addr,
122126
sp_registry_addr: &sp_registry_addr,
123127
})
124128
}
@@ -163,15 +167,14 @@ fn build_docker_command(params: &DockerTestParams) -> Result<Vec<String>, Box<dy
163167
];
164168

165169
// Add environment variables required by synapse-sdk scripts
170+
// Note: example-storage-e2e.js uses env vars, not CLI flags
166171
let env_vars = vec![
167172
("CLIENT_PRIVATE_KEY", params.user_key.to_string()),
168173
("PRIVATE_KEY", params.user_key.to_string()),
169-
("NETWORK", "devnet".to_string()),
170174
("RPC_URL", params.lotus_rpc_url.to_string()),
171-
(
172-
"WARM_STORAGE_CONTRACT_ADDRESS",
173-
params.warm_storage_addr.to_string(),
174-
),
175+
("WARM_STORAGE_ADDRESS", params.warm_storage_addr.to_string()),
176+
("MULTICALL3_ADDRESS", params.multicall3_addr.to_string()),
177+
("USDFC_ADDRESS", params.usdfc_addr.to_string()),
175178
("SP_REGISTRY_ADDRESS", params.sp_registry_addr.to_string()),
176179
("CI", "true".to_string()),
177180
];
@@ -281,7 +284,7 @@ fn create_random_test_file(run_dir: &Path) -> Result<PathBuf, Box<dyn Error>> {
281284
Ok(random_file_path)
282285
}
283286

284-
/// Generate the shell script using CLI flags expected by synapse-sdk.
287+
/// Generate the shell script for synapse-sdk E2E testing.
285288
fn generate_test_script(
286289
lotus_rpc_url: &str,
287290
warm_storage_addr: &str,
@@ -299,12 +302,7 @@ fn generate_test_script(
299302
sp_registry_addr,
300303
));
301304
lines.extend(wait_commands());
302-
lines.push(build_storage_e2e_command(
303-
lotus_rpc_url,
304-
warm_storage_addr,
305-
multicall3_addr,
306-
usdfc_addr,
307-
));
305+
lines.push(build_storage_e2e_command());
308306

309307
lines.join("\n")
310308
}
@@ -363,21 +361,9 @@ fn wait_commands() -> Vec<String> {
363361
}
364362

365363
/// CLI invocation for the storage E2E test.
366-
fn build_storage_e2e_command(
367-
lotus_rpc_url: &str,
368-
warm_storage_addr: &str,
369-
multicall3_addr: &str,
370-
usdfc_addr: &str,
371-
) -> String {
372-
format!(
373-
"echo \"Running storage E2E test...\"\n\
374-
node utils/example-storage-e2e.js \\\n\
375-
--network devnet \\\n\
376-
--rpc-url {} \\\n\
377-
--warm-storage {} \\\n\
378-
--multicall3 {} \\\n\
379-
--usdfc {} \\\n\
380-
/tmp/random_test_file.txt",
381-
lotus_rpc_url, warm_storage_addr, multicall3_addr, usdfc_addr
382-
)
364+
/// The script uses environment variables for configuration (set via Docker -e flags).
365+
fn build_storage_e2e_command() -> String {
366+
"echo \"Running storage E2E test...\"\n\
367+
node utils/example-storage-e2e.js /tmp/random_test_file.txt"
368+
.to_string()
383369
}

src/config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,20 +209,20 @@ impl Default for Config {
209209
tag: "v1.34.4-rc1".to_string(),
210210
},
211211
curio: Location::GitBranch {
212-
url: "https://github.com/redpanda-f/curio.git".to_string(),
213-
branch: "feat/pdpv0/redpanda/localnet-setup".to_string(),
212+
url: "https://github.com/filecoin-project/curio.git".to_string(),
213+
branch: "pdpv0".to_string(),
214214
},
215215
filecoin_services: Location::GitBranch {
216216
url: "https://github.com/FilOzone/filecoin-services.git".to_string(),
217-
branch: "feat/redpanda/localnet-deployment-aware".to_string(),
217+
branch: "main".to_string(),
218218
},
219219
multicall3: Location::GitBranch {
220220
url: "https://github.com/mds1/multicall3.git".to_string(),
221221
branch: "main".to_string(),
222222
},
223223
synapse_sdk: Location::GitBranch {
224224
url: "https://github.com/FilOzone/synapse-sdk.git".to_string(),
225-
branch: "feat/redpanda/localnet-support".to_string(),
225+
branch: "master".to_string(),
226226
},
227227
yugabyte_download_url: "https://software.yugabyte.com/releases/2.25.1.0/yugabyte-2.25.1.0-b381-linux-x86_64.tar.gz".to_string(),
228228
approved_pdp_sp_count: 1,

0 commit comments

Comments
 (0)