From d70b1ca11cb2354eefc2af21b3d6d0f51fde8a89 Mon Sep 17 00:00:00 2001 From: scx1332 Date: Wed, 25 Oct 2023 14:34:45 +0200 Subject: [PATCH] Working on intervals --- config-payments.toml | 2 ++ crates/erc20_payment_lib/src/config.rs | 1 + crates/erc20_payment_lib/src/runtime.rs | 1 + crates/erc20_payment_lib/src/sender/service.rs | 5 ++++- crates/erc20_payment_lib/src/setup.rs | 3 +++ crates/erc20_payment_lib_extra/src/account_balance.rs | 3 ++- crates/erc20_payment_lib_test/src/config_setup.rs | 1 + src/main.rs | 2 +- 8 files changed, 15 insertions(+), 3 deletions(-) diff --git a/config-payments.toml b/config-payments.toml index e9ad210e..98f8dbdf 100644 --- a/config-payments.toml +++ b/config-payments.toml @@ -1,6 +1,8 @@ [engine] # proces interval (in seconds) is to set how often we want to check for transaction process-interval = 5 +# proces interval after error (in seconds) is to set how long to wait after encountering error before trying again +process-interval-after-error = 15 # gather interval (in seconds) is to set how often payments are gathered gather-interval = 600 # gather payments on payment driver start (otherwise wait for first gather-sleep) diff --git a/crates/erc20_payment_lib/src/config.rs b/crates/erc20_payment_lib/src/config.rs index 234b214f..c0b2a992 100644 --- a/crates/erc20_payment_lib/src/config.rs +++ b/crates/erc20_payment_lib/src/config.rs @@ -47,6 +47,7 @@ impl AdditionalOptions { #[serde(rename_all = "kebab-case")] pub struct Engine { pub process_interval: u64, + pub process_interval_after_error: u64, pub gather_interval: u64, pub gather_at_start: bool, pub automatic_recover: bool, diff --git a/crates/erc20_payment_lib/src/runtime.rs b/crates/erc20_payment_lib/src/runtime.rs index a7365ca5..47afbb59 100644 --- a/crates/erc20_payment_lib/src/runtime.rs +++ b/crates/erc20_payment_lib/src/runtime.rs @@ -363,6 +363,7 @@ impl PaymentRuntime { options.generate_tx_only, options.skip_multi_contract_check, config.engine.process_interval, + config.engine.process_interval_after_error, config.engine.gather_interval, config.engine.gather_at_start, config.engine.automatic_recover, diff --git a/crates/erc20_payment_lib/src/sender/service.rs b/crates/erc20_payment_lib/src/sender/service.rs index 42fbc02e..aaea502d 100644 --- a/crates/erc20_payment_lib/src/sender/service.rs +++ b/crates/erc20_payment_lib/src/sender/service.rs @@ -382,7 +382,10 @@ pub async fn service_loop( .await { log::error!("Error in process transactions: {}", e); - tokio::time::sleep(std::time::Duration::from_secs(10)).await; + tokio::time::sleep(std::time::Duration::from_secs( + payment_setup.process_interval, + )) + .await; continue; } diff --git a/crates/erc20_payment_lib/src/setup.rs b/crates/erc20_payment_lib/src/setup.rs index 07353ce1..f133c78e 100644 --- a/crates/erc20_payment_lib/src/setup.rs +++ b/crates/erc20_payment_lib/src/setup.rs @@ -61,6 +61,7 @@ pub struct PaymentSetup { pub generate_tx_only: bool, pub skip_multi_contract_check: bool, pub process_interval: u64, + pub process_interval_after_error: u64, pub gather_interval: u64, pub gather_at_start: bool, pub automatic_recover: bool, @@ -79,6 +80,7 @@ impl PaymentSetup { generate_txs_only: bool, skip_multi_contract_check: bool, process_interval: u64, + process_interval_after_error: u64, gather_interval: u64, gather_at_start: bool, automatic_recover: bool, @@ -91,6 +93,7 @@ impl PaymentSetup { generate_tx_only: generate_txs_only, skip_multi_contract_check, process_interval, + process_interval_after_error, gather_interval, gather_at_start, automatic_recover, diff --git a/crates/erc20_payment_lib_extra/src/account_balance.rs b/crates/erc20_payment_lib_extra/src/account_balance.rs index 41c6cb5a..0fbd4e81 100644 --- a/crates/erc20_payment_lib_extra/src/account_balance.rs +++ b/crates/erc20_payment_lib_extra/src/account_balance.rs @@ -62,7 +62,8 @@ pub async fn account_balance( account_balance_options.chain_name ))?; - let payment_setup = PaymentSetup::new(config, vec![], true, false, false, 1, 1, false, false)?; + let payment_setup = + PaymentSetup::new(config, vec![], true, false, false, 1, 1, 1, false, false)?; let web3 = payment_setup.get_provider(chain_cfg.chain_id)?; diff --git a/crates/erc20_payment_lib_test/src/config_setup.rs b/crates/erc20_payment_lib_test/src/config_setup.rs index 197bffad..ef695f09 100644 --- a/crates/erc20_payment_lib_test/src/config_setup.rs +++ b/crates/erc20_payment_lib_test/src/config_setup.rs @@ -40,6 +40,7 @@ pub async fn create_default_config_setup(proxy_url_base: &str, proxy_key: &str) chain: chain_map, engine: Engine { process_interval: 1, + process_interval_after_error: 1, gather_interval: 1, automatic_recover: false, gather_at_start: false, diff --git a/src/main.rs b/src/main.rs index e8cdcb06..6f0bb653 100644 --- a/src/main.rs +++ b/src/main.rs @@ -292,7 +292,7 @@ async fn main_internal() -> Result<(), PaymentError> { log::info!("Scanning blockchain {}", scan_blockchain_options.chain_name); let payment_setup = - PaymentSetup::new(&config, vec![], true, false, false, 1, 1, false, false)?; + PaymentSetup::new(&config, vec![], true, false, false, 1, 1, 1, false, false)?; let chain_cfg = config .chain .get(&scan_blockchain_options.chain_name)