Skip to content

Commit

Permalink
fix: ulimit error (#241)
Browse files Browse the repository at this point in the history
* Add general sandbox configurations

* README

* Set max size (tmp)

* Set default open files to 5000

* rebase with conf sandbox PR

* Reduce boilerplate

* Fix nit
  • Loading branch information
ChaoticTempest authored Jan 10, 2023
1 parent 7e6f995 commit 43a21c6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
35 changes: 21 additions & 14 deletions workspaces/src/network/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,22 @@ fn overwrite(home_dir: impl AsRef<Path>, 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<u64> {
let max_files = match std::env::var("NEAR_SANDBOX_MAX_PAYLOAD_SIZE") {
Ok(val) => val
.parse::<u64>()
.map_err(|err| ErrorKind::DataConversion.custom(err))?,
/// Parse an environment variable or return a default value.
fn parse_env<T>(env_var: &str) -> Result<Option<T>>
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::<T>()
.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.
Expand All @@ -61,9 +63,14 @@ pub(crate) fn set_sandbox_configs(home_dir: impl AsRef<Path>) -> 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),
}
}),
)
}

0 comments on commit 43a21c6

Please sign in to comment.