Skip to content

Commit

Permalink
feat(polka-storage-provider-server): implement config file
Browse files Browse the repository at this point in the history
  • Loading branch information
jmg-duarte committed Jan 13, 2025
1 parent 31533cd commit cfbb98d
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 120 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ thiserror = { version = "2.0.3", default-features = false }
tokio = "1.37.0"
tokio-stream = "0.1.15"
tokio-util = "0.7.11"
toml = "0.8.19"
tower = "0.4.13"
tower-http = "0.5.2"
tracing = "0.1.40"
Expand Down
Empty file added examples/sp.config.json
Empty file.
10 changes: 9 additions & 1 deletion examples/start_sp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,12 @@ RUST_LOG=debug target/release/storagext-cli --sr25519-key "//Alice" proofs set-p
RUST_LOG=debug target/release/storagext-cli --sr25519-key "//Bob" proofs set-post-verifying-key @2KiB.post.vk.scale &
wait

RUST_LOG=debug target/release/polka-storage-provider-server --sr25519-key "$PROVIDER" --seal-proof "2KiB" --post-proof "2KiB" --porep-parameters 2KiB.porep.params --post-parameters 2KiB.post.params
echo '{
"seal_proof": "2KiB",
"post_proof": "2KiB",
"porep_parameters": "2KiB.porep.params",
"post_parameters": "2KiB.post.params"
}' > /tmp/storage_provider.config.json
RUST_LOG=debug target/release/polka-storage-provider-server \
--sr25519-key "$PROVIDER" \
--config /tmp/storage_provider.config.json
3 changes: 2 additions & 1 deletion storage-provider/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ tempfile = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true }
tokio-util = { workspace = true, features = ["rt"] }
toml = { workspace = true }
tower = { workspace = true }
tower-http = { workspace = true, features = ["trace"] }
tracing = { workspace = true }
tracing-appender = { workspace = true }
tracing-subscriber = { workspace = true, features = ["env-filter"] }
url = { workspace = true }
url = { workspace = true, features = ["serde"] }
uuid = { workspace = true, features = ["v4"] }

[lints]
Expand Down
99 changes: 99 additions & 0 deletions storage-provider/server/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
use std::{
net::{IpAddr, Ipv4Addr, SocketAddr},
num::NonZero,
path::PathBuf,
};

use clap::Args;
use primitives::proofs::{RegisteredPoStProof, RegisteredSealProof};
use serde::{Deserialize, Serialize};
use url::Url;

use crate::DEFAULT_NODE_ADDRESS;

/// Default address to bind the RPC server to.
const fn default_rpc_listen_address() -> SocketAddr {
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8000)
}

/// Default address to bind the RPC server to.
const fn default_upload_listen_address() -> SocketAddr {
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8001)
}

/// Default number of parallel prove commits.
const fn default_parallel_prove_commits() -> NonZero<usize> {
// SAFETY: 2 != 0
unsafe { NonZero::new_unchecked(2) }
}

fn default_node_address() -> Url {
Url::parse(DEFAULT_NODE_ADDRESS).expect("DEFAULT_NODE_ADDRESS must be a valid Url")
}

#[derive(Debug, Clone, Deserialize, Serialize, Args)]
#[group(multiple = true, conflicts_with = "config")]
#[serde(deny_unknown_fields)]
pub struct ConfigurationArgs {
/// The server's listen address.
#[serde(default = "default_upload_listen_address")]
#[arg(long, default_value_t = default_upload_listen_address())]
pub(crate) upload_listen_address: SocketAddr,

/// The server's listen address.
#[serde(default = "default_rpc_listen_address")]
#[arg(long, default_value_t = default_rpc_listen_address())]
pub(crate) rpc_listen_address: SocketAddr,

/// The target parachain node's address.
#[serde(default = "default_node_address")]
#[arg(long, default_value_t = default_node_address())]
pub(crate) node_url: Url,

/// RocksDB storage directory.
/// Defaults to a temporary random directory, like `/tmp/<random>/deals_database`.
#[arg(long)]
pub(crate) database_directory: Option<PathBuf>,

/// Piece storage directory.
/// Defaults to a temporary random directory, like `/tmp/<random>/...`.
#[arg(long)]
pub(crate) storage_directory: Option<PathBuf>,

/// The number of prove commits to be run in parallel.
/// MUST BE > 0 or the pipeline will not progress.
///
/// Creating a replica is memory-heavy process.
/// E.g. With 2KiB sector sizes and 16GiB of RAM, it goes OOM at 4 parallel.
#[serde(default = "default_parallel_prove_commits")]
#[arg(long, default_value_t = default_parallel_prove_commits())]
pub(crate) parallel_prove_commits: NonZero<usize>,

// NOTE: the following parameters are marked as "not required" so the CLI doesn't require them
// when --config is used, otherwise, they're very much required
/// Proof of Replication proof type.
#[arg(long, required = false)]
pub(crate) seal_proof: RegisteredSealProof,

/// Proof of Spacetime proof type.
#[arg(long, required = false)]
pub(crate) post_proof: RegisteredPoStProof,

/// Proving Parameters for PoRep proof, corresponding to given `seal_proof` sector size.
/// They are shared across all of the nodes in the network, as the chain stores corresponding Verifying Key parameters.
///
/// Testing/temporary parameters can be generated via `polka-storage-provider-client proofs porep-params` command.
/// Note that when you generate keys, for local testnet,
/// **they need to be set** via an extrinsic pallet-proofs::set_porep_verifyingkey.
#[arg(long, required = false)]
pub(crate) porep_parameters: PathBuf,

/// Proving Parameters for PoSt proof, corresponding to given `post_proof` sector size.
/// They are shared across all of the nodes in the network, as the chain stores corresponding Verifying Key parameters.
///
/// Testing/temporary parameters can be generated via `polka-storage-provider-client proofs post-params` command.
/// Note that when you generate keys, for local testnet,
/// **they need to be set** via an extrinsic pallet-proofs::set_post_verifyingkey.
#[arg(long, required = false)]
pub(crate) post_parameters: PathBuf,
}
Loading

0 comments on commit cfbb98d

Please sign in to comment.