Skip to content

Commit

Permalink
fix: add receipts timeout config (#537)
Browse files Browse the repository at this point in the history
* fix: add receipts timeout config
  • Loading branch information
rotarur authored Dec 11, 2024
1 parent c627756 commit 2438895
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions crates/config/default_values.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 4 additions & 0 deletions crates/config/maximal-config-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -148,3 +151,4 @@ max_receipts_per_request = 10000

[dips]
allowed_payers = ["0x3333333333333333333333333333333333333333"]

8 changes: 6 additions & 2 deletions crates/config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,17 @@ pub struct ServiceTapConfig {
pub max_receipt_value_grt: NonZeroGRT,
}

#[serde_as]
#[derive(Debug, Deserialize)]
#[cfg_attr(test, derive(PartialEq))]
pub struct TapConfig {
/// what is the maximum amount the indexer is willing to lose in grt
pub max_amount_willing_to_lose_grt: NonZeroGRT,
pub rav_request: RavRequestConfig,

#[serde_as(as = "DurationSecondsWithFrac<f64>")]
pub sender_timeout_secs: Duration,

pub sender_aggregator_endpoints: HashMap<Address, Url>,
}

Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions crates/tap-agent/src/agent/sender_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
}
}
}
Expand Down Expand Up @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions crates/tap-agent/src/agent/sender_accounts_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
};
Expand Down Expand Up @@ -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(());
}
Expand Down Expand Up @@ -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),
}))
}

Expand Down

0 comments on commit 2438895

Please sign in to comment.