Skip to content
Merged
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
1 change: 1 addition & 0 deletions src/commands/start/endorsement/endorsement_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ impl Step for EndorsementStep {

// Get all endorsed provider IDs in one call
let params = GetProviderIdsParams {
run_id: context.run_id().to_string(),
endorsements_contract_address: endorsements_address,
lotus_rpc_url,
};
Expand Down
39 changes: 18 additions & 21 deletions src/commands/start/endorsement/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use super::constants::{
use crate::commands::start::step::SetupContext;
use crate::constants::BUILDER_DOCKER_IMAGE;
use crate::docker::command_logger::run_and_log_command_strings;
use crate::docker::shell::ephemeral_run_args;
use std::error::Error;
use std::thread;
use std::time::Duration;
Expand Down Expand Up @@ -74,7 +75,13 @@ pub fn endorse_provider(
info!("Endorsement transaction: {}", tx_hash);
thread::sleep(Duration::from_secs(ENDORSEMENT_TX_WAIT_SECS));

verify_transaction_status(&params.lotus_rpc_url, &tx_hash, params.provider_id, context)?;
verify_transaction_status(
&params.lotus_rpc_url,
&tx_hash,
params.provider_id,
&params.run_id,
context,
)?;

info!("{} endorsed successfully", label);

Expand All @@ -99,25 +106,20 @@ fn verify_transaction_status(
rpc_url: &str,
tx_hash: &str,
provider_id: u64,
run_id: &str,
context: &SetupContext,
) -> Result<(), Box<dyn Error>> {
let container_name = format!("foc-verify-endorse-{}", provider_id);
let container_name = format!("foc-verify-endorse-{}-{}", run_id, provider_id);

let cast_cmd = format!(r#"cast receipt {} --rpc-url {} --json"#, tx_hash, rpc_url);

let args: Vec<String> = vec![
"run".to_string(),
"--name".to_string(),
container_name.clone(),
"-u".to_string(),
"foc-user".to_string(),
"--network".to_string(),
"host".to_string(),
let mut args = ephemeral_run_args(&container_name, "foc-user");
args.extend([
BUILDER_DOCKER_IMAGE.to_string(),
"bash".to_string(),
"-c".to_string(),
cast_cmd,
];
]);

let key = format!("pdp_verify_endorse_tx_{}", provider_id);
let output = run_and_log_command_strings("docker", &args, context, &key)?;
Expand Down Expand Up @@ -146,6 +148,7 @@ fn verify_transaction_status(

/// Parameters for getting all provider IDs
pub struct GetProviderIdsParams {
pub run_id: String,
pub endorsements_contract_address: String,
pub lotus_rpc_url: String,
}
Expand All @@ -156,26 +159,20 @@ pub fn get_all_provider_ids(
params: GetProviderIdsParams,
context: &SetupContext,
) -> Result<Vec<u64>, Box<dyn Error>> {
let container_name = "foc-get-provider-ids";
let container_name = format!("foc-get-provider-ids-{}", params.run_id);

let cast_cmd = format!(
r#"cast call {} "getProviderIds()(uint256[])" --rpc-url {}"#,
params.endorsements_contract_address, params.lotus_rpc_url
);

let args: Vec<String> = vec![
"run".to_string(),
"--name".to_string(),
container_name.to_string(),
"-u".to_string(),
"foc-user".to_string(),
"--network".to_string(),
"host".to_string(),
let mut args = ephemeral_run_args(&container_name, "foc-user");
args.extend([
BUILDER_DOCKER_IMAGE.to_string(),
"bash".to_string(),
"-c".to_string(),
cast_cmd,
];
]);

let key = "pdp_get_all_provider_ids";
let output = run_and_log_command_strings("docker", &args, context, key)?;
Expand Down
37 changes: 10 additions & 27 deletions src/commands/start/pdp_service_provider/registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use super::constants::*;
use crate::commands::start::step::SetupContext;
use crate::constants::BUILDER_DOCKER_IMAGE;
use crate::docker::command_logger::run_and_log_command_strings;
use crate::docker::shell::ephemeral_run_args;
use crate::utils::retry::{retry_with_fixed_delay, DEFAULT_MAX_RETRIES, DEFAULT_RETRY_DELAY_SECS};
use std::error::Error;

Expand Down Expand Up @@ -321,22 +322,16 @@ pub fn verify_provider_count(
|| {
let container_name = format!("foc-{}-pdp-verify-count", run_id);

let args: Vec<String> = vec![
"run".to_string(),
"--name".to_string(),
container_name,
"-u".to_string(),
"foc-user".to_string(),
"--network".to_string(),
"host".to_string(),
let mut args = ephemeral_run_args(&container_name, "foc-user");
args.extend([
BUILDER_DOCKER_IMAGE.to_string(),
"cast".to_string(),
"call".to_string(),
registry_address.to_string(),
"getProviderCount()(uint256)".to_string(),
"--rpc-url".to_string(),
lotus_rpc_url.to_string(),
];
]);

let key = "pdp_verify_provider_count".to_string();
let output = run_and_log_command_strings("docker", &args, context, &key)?;
Expand Down Expand Up @@ -371,14 +366,8 @@ pub fn verify_provider_id_by_address(
|| {
let container_name = format!("foc-{}-pdp-verify-id-{}", run_id, provider_address);

let args: Vec<String> = vec![
"run".to_string(),
"--name".to_string(),
container_name,
"-u".to_string(),
"foc-user".to_string(),
"--network".to_string(),
"host".to_string(),
let mut args = ephemeral_run_args(&container_name, "foc-user");
args.extend([
BUILDER_DOCKER_IMAGE.to_string(),
"cast".to_string(),
"call".to_string(),
Expand All @@ -387,7 +376,7 @@ pub fn verify_provider_id_by_address(
provider_address.to_string(),
"--rpc-url".to_string(),
lotus_rpc_url.to_string(),
];
]);

let key = format!("pdp_verify_provider_id_{}", provider_address);
let output = run_and_log_command_strings("docker", &args, context, &key)?;
Expand Down Expand Up @@ -424,14 +413,8 @@ pub fn verify_approved_provider(
// Use isProviderApproved function on StateView contract
let provider_id_str = provider_id.to_string();
let container_name = format!("foc-{}-pdp-verify-approved-{}", run_id, provider_id);
let args: Vec<String> = vec![
"run".to_string(),
"--name".to_string(),
container_name,
"-u".to_string(),
"foc-user".to_string(),
"--network".to_string(),
"host".to_string(),
let mut args = ephemeral_run_args(&container_name, "foc-user");
args.extend([
BUILDER_DOCKER_IMAGE.to_string(),
"cast".to_string(),
"call".to_string(),
Expand All @@ -440,7 +423,7 @@ pub fn verify_approved_provider(
provider_id_str,
"--rpc-url".to_string(),
lotus_rpc_url.to_string(),
];
]);

let key = format!("pdp_verify_approved_provider_{}", provider_id);
let output = run_and_log_command_strings("docker", &args, context, &key)?;
Expand Down
32 changes: 11 additions & 21 deletions src/commands/start/usdfc_deploy/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use crate::commands::start::step::SetupContext;
use crate::docker::bind_mount;
use crate::docker::command_logger::run_and_log_command;
use crate::docker::command_logger::run_and_log_command_strings;
use crate::utils::retry::{retry_with_fixed_delay, DEFAULT_MAX_RETRIES, DEFAULT_RETRY_DELAY_SECS};
use std::error::Error;
use std::path::Path;
Expand Down Expand Up @@ -46,26 +46,16 @@ pub fn verify_mock_usdfc(

let key = format!("usdfc_verify_{}", run_id);
let container_name = format!("foc-{}-usdfc-verify", run_id);
let output = run_and_log_command(
"docker",
&[
"run",
"--name",
&container_name,
"-u",
"foc-user",
"--network",
"host",
"--mount",
&contract_mount,
crate::constants::BUILDER_DOCKER_IMAGE,
"bash",
"-c",
&verify_cmd,
],
context,
&key,
)?;
let mut args = crate::docker::shell::ephemeral_run_args(&container_name, "foc-user");
args.extend([
"--mount".to_string(),
contract_mount.clone(),
crate::constants::BUILDER_DOCKER_IMAGE.to_string(),
"bash".to_string(),
"-c".to_string(),
verify_cmd,
]);
let output = run_and_log_command_strings("docker", &args, context, &key)?;

let _stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);
Expand Down
4 changes: 3 additions & 1 deletion src/docker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@ pub use network::{
lotus_miner_network_name, lotus_network_name, pdp_miner_network_name,
};
pub use portainer::{start_portainer, stop_portainer};
pub use shell::{cast_command, forge_command, lotus_command, lotus_wallet_command};
pub use shell::{
cast_command, ephemeral_run_args, forge_command, lotus_command, lotus_wallet_command,
};
pub use status::{get_container_uptime, get_running_foc_containers, get_system_start_time};
40 changes: 40 additions & 0 deletions src/docker/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,26 @@ pub fn docker_run_host_network(image: &str, args: &[&str]) -> Result<Output, Box
docker_command(&full_args)
}

/// Build `docker run` arguments for a short-lived container that may reuse its name.
///
/// Read-only checks run inside retry loops that reuse a fixed `--name`. Without
/// `--rm`, a failed attempt leaves a stopped container behind and the next
/// attempt fails with "container name is already in use". `--network host` lets
/// `cast` reach the Lotus RPC. Callers append `--mount` pairs, the image, and
/// the command.
pub fn ephemeral_run_args(container_name: &str, user: &str) -> Vec<String> {
vec![
"run".to_string(),
"--rm".to_string(),
"--name".to_string(),
container_name.to_string(),
"-u".to_string(),
user.to_string(),
"--network".to_string(),
"host".to_string(),
]
}

/// Run a Docker container with prepared `--mount` specifications.
///
/// Note: Does not use `--rm` to allow log inspection after container exits.
Expand Down Expand Up @@ -153,3 +173,23 @@ pub fn forge_script_deploy(
args.extend_from_slice(extra_args);
forge_command(&args)
}

#[cfg(test)]
mod tests {
use super::ephemeral_run_args;

#[test]
fn test_ephemeral_run_args_remove_container_on_exit() {
let args = ephemeral_run_args("foc-run-verify", "foc-user");

assert_eq!(args.first().map(String::as_str), Some("run"));
// Without --rm a retry reusing the same --name fails on the leftover container.
assert!(args.iter().any(|a| a == "--rm"));
assert!(args
.windows(2)
.any(|w| w[0] == "--name" && w[1] == "foc-run-verify"));
assert!(args
.windows(2)
.any(|w| w[0] == "--network" && w[1] == "host"));
}
}