From 243889570d2a2146816a23dab3bfe39e79e5e010 Mon Sep 17 00:00:00 2001 From: Ruslan Rotaru Date: Wed, 11 Dec 2024 15:35:14 +0000 Subject: [PATCH] fix: add receipts timeout config (#537) * fix: add receipts timeout config --- crates/config/default_values.toml | 2 ++ crates/config/maximal-config-example.toml | 4 ++++ crates/config/src/config.rs | 8 ++++++-- crates/tap-agent/src/agent/sender_account.rs | 3 +++ crates/tap-agent/src/agent/sender_accounts_manager.rs | 5 +++-- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/crates/config/default_values.toml b/crates/config/default_values.toml index 802a1452..48a6647a 100644 --- a/crates/config/default_values.toml +++ b/crates/config/default_values.toml @@ -19,9 +19,11 @@ max_receipt_value_grt = "0.001" # We use strings to prevent rounding errors [tap] max_amount_willing_to_lose_grt = 20 +sender_timeout_secs = 30 [tap.rav_request] trigger_value_divisor = 10 timestamp_buffer_secs = 60 request_timeout_secs = 5 max_receipts_per_request = 10000 + diff --git a/crates/config/maximal-config-example.toml b/crates/config/maximal-config-example.toml index 0efa9d57..d5e84783 100644 --- a/crates/config/maximal-config-example.toml +++ b/crates/config/maximal-config-example.toml @@ -124,6 +124,9 @@ max_receipt_value_grt = "0.001" # 0.001 GRT. We use strings to prevent rounding # max_amount_willing_to_lose_grt = "0.1" max_amount_willing_to_lose_grt = 20 +# Receipts query timeout +sender_timeout_secs = 30 + [tap.rav_request] # Trigger value is the amount used to trigger a rav request # The dividor is used to define the trigger value of a RAV request using @@ -148,3 +151,4 @@ max_receipts_per_request = 10000 [dips] allowed_payers = ["0x3333333333333333333333333333333333333333"] + diff --git a/crates/config/src/config.rs b/crates/config/src/config.rs index 1703d4e8..6604ca1e 100644 --- a/crates/config/src/config.rs +++ b/crates/config/src/config.rs @@ -373,6 +373,7 @@ pub struct ServiceTapConfig { pub max_receipt_value_grt: NonZeroGRT, } +#[serde_as] #[derive(Debug, Deserialize)] #[cfg_attr(test, derive(PartialEq))] pub struct TapConfig { @@ -380,6 +381,9 @@ pub struct TapConfig { pub max_amount_willing_to_lose_grt: NonZeroGRT, pub rav_request: RavRequestConfig, + #[serde_as(as = "DurationSecondsWithFrac")] + pub sender_timeout_secs: Duration, + pub sender_aggregator_endpoints: HashMap, } @@ -578,7 +582,7 @@ mod tests { key1 = "${TEST_VAR1}" key2 = "${TEST_VAR-default}" key3 = "{{TEST_VAR3}}" - + [section2] key4 = "prefix_${TEST_VAR1}_${TEST_VAR-default}_suffix" key5 = "a_key_without_substitution" @@ -590,7 +594,7 @@ mod tests { key1 = "changed_value_1" key2 = "${TEST_VAR-default}" key3 = "{{TEST_VAR3}}" - + [section2] key4 = "prefix_changed_value_1_${TEST_VAR-default}_suffix" key5 = "a_key_without_substitution" diff --git a/crates/tap-agent/src/agent/sender_account.rs b/crates/tap-agent/src/agent/sender_account.rs index 5c0e6613..1dcfd325 100644 --- a/crates/tap-agent/src/agent/sender_account.rs +++ b/crates/tap-agent/src/agent/sender_account.rs @@ -190,6 +190,7 @@ pub struct SenderAccountConfig { pub rav_request_receipt_limit: u64, pub indexer_address: Address, pub escrow_polling_interval: Duration, + pub tap_sender_timeout: Duration, } impl SenderAccountConfig { @@ -202,6 +203,7 @@ impl SenderAccountConfig { max_amount_willing_to_lose_grt: config.tap.max_amount_willing_to_lose_grt.get_value(), trigger_value: config.tap.get_trigger_value(), rav_request_timeout: config.tap.rav_request.request_timeout_secs, + tap_sender_timeout: config.tap.sender_timeout_secs, } } } @@ -1147,6 +1149,7 @@ pub mod tests { rav_request_receipt_limit, indexer_address: INDEXER.1, escrow_polling_interval: Duration::default(), + tap_sender_timeout: Duration::from_secs(30), })); let network_subgraph = Box::leak(Box::new( diff --git a/crates/tap-agent/src/agent/sender_accounts_manager.rs b/crates/tap-agent/src/agent/sender_accounts_manager.rs index 6a22e07c..75b5b94c 100644 --- a/crates/tap-agent/src/agent/sender_accounts_manager.rs +++ b/crates/tap-agent/src/agent/sender_accounts_manager.rs @@ -142,7 +142,7 @@ impl Actor for SenderAccountsManager { }; let sender_allocation = select! { sender_allocation = state.get_pending_sender_allocation_id() => sender_allocation, - _ = tokio::time::sleep(std::time::Duration::from_secs(30)) => { + _ = tokio::time::sleep(state.config.tap_sender_timeout) => { panic!("Timeout while getting pending sender allocation ids"); } }; @@ -252,7 +252,7 @@ impl Actor for SenderAccountsManager { let mut sender_allocation = select! { sender_allocation = state.get_pending_sender_allocation_id() => sender_allocation, - _ = tokio::time::sleep(std::time::Duration::from_secs(30)) => { + _ = tokio::time::sleep(state.config.tap_sender_timeout) => { tracing::error!("Timeout while getting pending sender allocation ids"); return Ok(()); } @@ -643,6 +643,7 @@ mod tests { rav_request_receipt_limit: 1000, indexer_address: INDEXER.1, escrow_polling_interval: Duration::default(), + tap_sender_timeout: Duration::from_secs(30), })) }