diff --git a/README.md b/README.md index bce6fad6..dd8a3622 100644 --- a/README.md +++ b/README.md @@ -340,3 +340,4 @@ These environment variables will be useful if there was ever a snag hit: - `NEAR_RPC_TIMEOUT_SECS`: The default is 10 seconds, but this is the amount of time beforing timing out waiting for a RPC service when talking to the sandbox or any other network such as testnet. - `NEAR_SANDBOX_BIN_PATH`: Set this to our own prebuilt `neard-sandbox` bin path if we want to use a non-default version of the sandbox or configure nearcore with our own custom features that we want to test in workspaces. - `NEAR_SANDBOX_MAX_PAYLOAD_SIZE`: Sets the max payload size for sending transaction commits to sandbox. The default is 1gb and is necessary for patching large states. +- `NEAR_SANDBOX_MAX_FILES`: Set the max amount of files that can be opened at a time in the sandbox. If none is specified, the default size of 4096 will be used. The actual near chain will use over 10,000 in pratice, but for testing this should be much lower since we do not have a constantly running blockchain unless our tests take up that much time. diff --git a/workspaces/src/network/config.rs b/workspaces/src/network/config.rs index 697d72cf..258504b3 100644 --- a/workspaces/src/network/config.rs +++ b/workspaces/src/network/config.rs @@ -38,20 +38,22 @@ fn overwrite(home_dir: impl AsRef, value: Value) -> Result<()> { Ok(()) } -/// Limit how much nearcore/sandbox can receive per payload. The default set by nearcore is not -/// enough for certain sandbox operations like patching contract state in the case of contracts -/// larger than 10mb. -fn max_sandbox_json_payload_size() -> Result { - let max_files = match std::env::var("NEAR_SANDBOX_MAX_PAYLOAD_SIZE") { - Ok(val) => val - .parse::() - .map_err(|err| ErrorKind::DataConversion.custom(err))?, +/// Parse an environment variable or return a default value. +fn parse_env(env_var: &str) -> Result> +where + T: std::str::FromStr, + T::Err: std::error::Error + Send + Sync + 'static, +{ + match std::env::var(env_var) { + Ok(val) => { + let val = val + .parse::() + .map_err(|err| ErrorKind::DataConversion.custom(err))?; - // Default is 1GB which should suit most contract sizes. - Err(_err) => 1024 * 1024 * 1024, - }; - - Ok(max_files) + Ok(Some(val)) + } + Err(_err) => Ok(None), + } } /// Set extra configs for the sandbox defined by workspaces. @@ -61,9 +63,14 @@ pub(crate) fn set_sandbox_configs(home_dir: impl AsRef) -> Result<()> { serde_json::json!({ "rpc": { "limits_config": { - "json_payload_max_size": max_sandbox_json_payload_size()?, + // default to 1GB payload size so that large state patches can work. + "json_payload_max_size": parse_env("NEAR_SANDBOX_MAX_PAYLOAD_SIZE")?.unwrap_or(1024 * 1024 * 1024), }, }, + "store": { + // default to 3,000 files open at a time so that windows WSL can work without configuring. + "max_open_files": parse_env("NEAR_SANDBOX_MAX_FILES")?.unwrap_or(3000), + } }), ) }