Skip to content

Commit e50cbda

Browse files
authored
* node: changed DEFAULT_MAX_ATTEMPTS to env var (#5998)
1 parent b259b41 commit e50cbda

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

docs/environment-variables.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,11 @@ those.
8686
may use (in bytes, defaults to 256MB).
8787
- `GRAPH_MAX_IPFS_CACHE_SIZE`: maximum number of files cached (defaults to 50).
8888
- `GRAPH_MAX_IPFS_CACHE_FILE_SIZE`: maximum size of each cached file (in bytes, defaults to 1MiB).
89-
- `GRAPH_IPFS_REQUEST_LIMIT`: Limits the number of requests per second to IPFS for file data sources.
90-
Defaults to 100.
89+
- `GRAPH_IPFS_REQUEST_LIMIT`: Limits the number of requests per second to IPFS for file data sources. Defaults to 100.
90+
- `GRAPH_IPFS_MAX_ATTEMPTS`: This limits the IPFS retry requests in case of a
91+
file not found or logical issue working as a safety mechanism to
92+
prevent infinite spamming of IPFS servers and network congestion
93+
(default: 100 000).
9194

9295
## GraphQL
9396

graph/src/env/mappings.rs

+7
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ pub struct EnvVarsMapping {
5353
///
5454
/// Set by the environment variable `GRAPH_IPFS_REQUEST_LIMIT`. Defaults to 100.
5555
pub ipfs_request_limit: u16,
56+
/// Limit of max IPFS attempts to retrieve a file.
57+
///
58+
/// Set by the environment variable `GRAPH_IPFS_MAX_ATTEMPTS`. Defaults to 100000.
59+
pub ipfs_max_attempts: usize,
5660

5761
/// Set by the flag `GRAPH_ALLOW_NON_DETERMINISTIC_IPFS`. Off by
5862
/// default.
@@ -94,6 +98,7 @@ impl From<InnerMappingHandlers> for EnvVarsMapping {
9498
max_ipfs_map_file_size: x.max_ipfs_map_file_size.0,
9599
max_ipfs_file_bytes: x.max_ipfs_file_bytes.0,
96100
ipfs_request_limit: x.ipfs_request_limit,
101+
ipfs_max_attempts: x.ipfs_max_attempts,
97102
allow_non_deterministic_ipfs: x.allow_non_deterministic_ipfs.0,
98103
disable_declared_calls: x.disable_declared_calls.0,
99104
store_errors_are_nondeterministic: x.store_errors_are_nondeterministic.0,
@@ -127,6 +132,8 @@ pub struct InnerMappingHandlers {
127132
max_ipfs_file_bytes: WithDefaultUsize<usize, { 25 * 1024 * 1024 }>,
128133
#[envconfig(from = "GRAPH_IPFS_REQUEST_LIMIT", default = "100")]
129134
ipfs_request_limit: u16,
135+
#[envconfig(from = "GRAPH_IPFS_MAX_ATTEMPTS", default = "100000")]
136+
ipfs_max_attempts: usize,
130137
#[envconfig(from = "GRAPH_ALLOW_NON_DETERMINISTIC_IPFS", default = "false")]
131138
allow_non_deterministic_ipfs: EnvVarBoolean,
132139
#[envconfig(from = "GRAPH_DISABLE_DECLARED_CALLS", default = "false")]

graph/src/ipfs/retry_policy.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@ use std::time::Duration;
33
use slog::Logger;
44

55
use crate::ipfs::error::IpfsError;
6+
use crate::prelude::*;
67
use crate::util::futures::retry;
78
use crate::util::futures::RetryConfig;
89

9-
/// This is a safety mechanism to prevent infinite spamming of IPFS servers
10-
/// in the event of logical or unhandled deterministic errors.
11-
const DEFAULT_MAX_ATTEMPTS: usize = 10_0000;
12-
1310
/// The default maximum delay between retries.
1411
const DEFAULT_MAX_DELAY: Duration = Duration::from_secs(60);
1512

@@ -35,7 +32,7 @@ impl RetryPolicy {
3532
logger: &Logger,
3633
) -> RetryConfig<O, IpfsError> {
3734
retry(operation_name, logger)
38-
.limit(DEFAULT_MAX_ATTEMPTS)
35+
.limit(ENV_VARS.mappings.ipfs_max_attempts)
3936
.max_delay(DEFAULT_MAX_DELAY)
4037
.when(move |result: &Result<O, IpfsError>| match result {
4138
Ok(_) => false,

0 commit comments

Comments
 (0)