Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ulimit error #241

Merged
merged 7 commits into from
Jan 10, 2023
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 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 @@ -37,20 +37,22 @@ fn overwrite(home_dir: &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 @@ -60,9 +62,14 @@ pub(crate) fn set_sandbox_configs(home_dir: &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),
}
}),
)
}