Skip to content

Commit

Permalink
Max behind fixed to allow unlimited head behind
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 committed Feb 9, 2024
1 parent 48fb3ac commit d0b485d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion crates/erc20_payment_lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub struct RpcSettings {
pub verify_interval_secs: Option<u64>,
pub min_interval_ms: Option<u64>,
pub max_timeout_ms: Option<u64>,
pub allowed_head_behind_secs: Option<u64>,
pub allowed_head_behind_secs: Option<i64>,
pub max_consecutive_errors: Option<u64>,
}

Expand Down
18 changes: 9 additions & 9 deletions crates/erc20_payment_lib/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ impl PaymentSetup {
let mut dns_sources = Vec::new();
for rpc_settings in &chain_config.1.rpc_endpoints {
let endpoint_names = split_string_by_coma(&rpc_settings.names).unwrap_or_default();
let max_head_behind_secs = rpc_settings.allowed_head_behind_secs.unwrap_or(120);
let max_head_behind_secs = if max_head_behind_secs < 0 {
None
} else {
Some(max_head_behind_secs as u64)
};
if let Some(endpoints) = split_string_by_coma(&rpc_settings.endpoints) {
for (idx, endpoint) in endpoints.iter().enumerate() {
let endpoint = Web3RpcSingleParams {
Expand All @@ -165,9 +171,7 @@ impl PaymentSetup {
.verify_interval_secs
.unwrap_or(120),
max_response_time_ms: rpc_settings.max_timeout_ms.unwrap_or(10000),
max_head_behind_secs: Some(
rpc_settings.allowed_head_behind_secs.unwrap_or(120),
),
max_head_behind_secs,
max_number_of_consecutive_errors: rpc_settings
.max_consecutive_errors
.unwrap_or(5),
Expand All @@ -187,9 +191,7 @@ impl PaymentSetup {
skip_validation: rpc_settings.skip_validation.unwrap_or(false),
verify_interval_secs: rpc_settings.verify_interval_secs.unwrap_or(120),
max_response_time_ms: rpc_settings.max_timeout_ms.unwrap_or(10000),
max_head_behind_secs: Some(
rpc_settings.allowed_head_behind_secs.unwrap_or(120),
),
max_head_behind_secs,
max_number_of_consecutive_errors: rpc_settings
.max_consecutive_errors
.unwrap_or(5),
Expand All @@ -206,9 +208,7 @@ impl PaymentSetup {
skip_validation: rpc_settings.skip_validation.unwrap_or(false),
verify_interval_secs: rpc_settings.verify_interval_secs.unwrap_or(120),
max_response_time_ms: rpc_settings.max_timeout_ms.unwrap_or(10000),
max_head_behind_secs: Some(
rpc_settings.allowed_head_behind_secs.unwrap_or(120),
),
max_head_behind_secs,
max_number_of_consecutive_errors: rpc_settings
.max_consecutive_errors
.unwrap_or(5),
Expand Down
24 changes: 15 additions & 9 deletions src/actions/check_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ pub async fn check_rpc_local(
))?;
let mut single_endpoints = Vec::with_capacity(100);
for rpc_settings in &chain_cfg.rpc_endpoints {
let max_head_behind_secs = rpc_settings.allowed_head_behind_secs.unwrap_or(120);
let max_head_behind_secs = if max_head_behind_secs < 0 {
None
} else {
Some(max_head_behind_secs as u64)
};
let endpoint_names = split_string_by_coma(&rpc_settings.names).unwrap_or_default();
if let Some(endpoints) = split_string_by_coma(&rpc_settings.endpoints) {
for (idx, endpoint) in endpoints.iter().enumerate() {
Expand All @@ -44,9 +50,7 @@ pub async fn check_rpc_local(
skip_validation: rpc_settings.skip_validation.unwrap_or(false),
verify_interval_secs: rpc_settings.verify_interval_secs.unwrap_or(120),
max_response_time_ms: rpc_settings.max_timeout_ms.unwrap_or(10000),
max_head_behind_secs: Some(
rpc_settings.allowed_head_behind_secs.unwrap_or(120),
),
max_head_behind_secs,
max_number_of_consecutive_errors: rpc_settings
.max_consecutive_errors
.unwrap_or(5),
Expand Down Expand Up @@ -74,6 +78,12 @@ pub async fn check_rpc_local(
Duration::from_secs(300),
);
for rpc_settings in &chain_cfg.rpc_endpoints {
let max_head_behind_secs = rpc_settings.allowed_head_behind_secs.unwrap_or(120);
let max_head_behind_secs = if max_head_behind_secs < 0 {
None
} else {
Some(max_head_behind_secs as u64)
};
if split_string_by_coma(&rpc_settings.endpoints).is_some() {
//already processed above
} else if let Some(dns_source) = &rpc_settings.dns_source {
Expand All @@ -96,9 +106,7 @@ pub async fn check_rpc_local(
skip_validation: rpc_settings.skip_validation.unwrap_or(false),
verify_interval_secs: rpc_settings.verify_interval_secs.unwrap_or(120),
max_response_time_ms: rpc_settings.max_timeout_ms.unwrap_or(10000),
max_head_behind_secs: Some(
rpc_settings.allowed_head_behind_secs.unwrap_or(120),
),
max_head_behind_secs,
max_number_of_consecutive_errors: rpc_settings
.max_consecutive_errors
.unwrap_or(5),
Expand Down Expand Up @@ -149,9 +157,7 @@ pub async fn check_rpc_local(
skip_validation: rpc_settings.skip_validation.unwrap_or(false),
verify_interval_secs: rpc_settings.verify_interval_secs.unwrap_or(120),
max_response_time_ms: rpc_settings.max_timeout_ms.unwrap_or(10000),
max_head_behind_secs: Some(
rpc_settings.allowed_head_behind_secs.unwrap_or(120),
),
max_head_behind_secs,
max_number_of_consecutive_errors: rpc_settings
.max_consecutive_errors
.unwrap_or(5),
Expand Down

0 comments on commit d0b485d

Please sign in to comment.