Skip to content

Commit

Permalink
add configurable timeout to rpc client (#4253)
Browse files Browse the repository at this point in the history
  • Loading branch information
LesnyRumcajs authored Apr 23, 2024
1 parent 95ecdb8 commit aee172e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
- [#4183](https://github.com/ChainSafe/forest/issues/4183) Add support for the
`Filecoin.EthGetBlockByNumber` RPC method.

- [#4253](https://github.com/ChainSafe/forest/pull/4253) RPC client default
timeout is now configurable via the `FOREST_RPC_DEFAULT_TIMEOUT` environment
variable.

- [#4240](https://github.com/ChainSafe/forest/pull/4240) Added `--fixed-unit`
and `--exact-balance` flags to `forest-wallet balance` similarly to
`forest-wallet list` subcommand.
Expand Down
1 change: 1 addition & 0 deletions documentation/src/environment_variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ process.
| FOREST_PROOFS_ONLY_IPFS_GATEWAY | 1 or true | false | Use only IPFS gateway for proofs parameters download |
| FOREST_FORCE_TRUST_PARAMS | 1 or true | false | Trust the parameters downloaded from the Cloudflare/IPFS |
| IPFS_GATEWAY | URL | https://proofs.filecoin.io/ipfs/ | The IPFS gateway to use for downloading proofs parameters |
| FOREST_RPC_DEFAULT_TIMEOUT | Duration (in seconds) | 60 | The default timeout for RPC calls |

### FOREST_DB_DEV_MODE

Expand Down
2 changes: 2 additions & 0 deletions scripts/tests/api_compare/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ services:
- api-tests
environment:
- RUST_LOG=info,forest_filecoin::tool::subcommands=debug
- FOREST_RPC_DEFAULT_TIMEOUT=120
entrypoint: [ "/bin/bash", "-c" ]
command:
- |
Expand All @@ -168,6 +169,7 @@ services:
- api-tests
environment:
- RUST_LOG=info,forest_filecoin::tool::subcommands=debug
- FOREST_RPC_DEFAULT_TIMEOUT=120
entrypoint: [ "/bin/bash", "-c" ]
command:
- |
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/reflect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub trait RpcMethodExt<const ARITY: usize>: RpcMethod<ARITY> {
params,
result_type: std::marker::PhantomData,
api_version: Self::API_VERSION,
timeout: crate::rpc_client::DEFAULT_TIMEOUT,
timeout: *crate::rpc_client::DEFAULT_TIMEOUT,
})
}
fn call_raw(
Expand Down
15 changes: 12 additions & 3 deletions src/rpc_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,21 @@ use crate::lotus_json::HasLotusJson;
use crate::rpc::{self, ApiVersion, ServerError};
use anyhow::Context as _;
use jsonrpsee::core::traits::ToRpcParams;
use once_cell::sync::Lazy;
use std::{env, fmt, marker::PhantomData, str::FromStr, time::Duration};
use url::Url;

pub const API_INFO_KEY: &str = "FULLNODE_API_INFO";
pub const DEFAULT_PORT: u16 = 2345;
pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(60);

/// Default timeout for RPC requests. Doesn't apply to all requests, e.g., snapshot export which
/// has no timeout.
pub static DEFAULT_TIMEOUT: Lazy<Duration> = Lazy::new(|| {
std::env::var("FOREST_RPC_DEFAULT_TIMEOUT")
.ok()
.and_then(|it| Duration::from_secs(it.parse().ok()?).into())
.unwrap_or(Duration::from_secs(60))
});

/// Token and URL for an [`rpc::Client`].
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -136,7 +145,7 @@ impl<T> RpcRequest<T> {
),
result_type: PhantomData,
api_version: ApiVersion::V0,
timeout: DEFAULT_TIMEOUT,
timeout: *DEFAULT_TIMEOUT,
}
}

Expand All @@ -150,7 +159,7 @@ impl<T> RpcRequest<T> {
),
result_type: PhantomData,
api_version: ApiVersion::V1,
timeout: DEFAULT_TIMEOUT,
timeout: *DEFAULT_TIMEOUT,
}
}

Expand Down

0 comments on commit aee172e

Please sign in to comment.