Skip to content

Commit d735660

Browse files
committed
feat: add escape hatch to trusted gateways
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent 32f30db commit d735660

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

crates/config/maximal-config-example.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ max_receipt_value_grt = "0.001" # 0.001 GRT. We use strings to prevent rounding
124124
# max_amount_willing_to_lose_grt = "0.1"
125125
max_amount_willing_to_lose_grt = 20
126126

127+
# List of Gateways that are allowed to spend up to `max_amount_willing_to_lose_grt`
128+
# over the escrow balance
129+
trusted_gateways = ["0xdeadbeefcafebabedeadbeefcafebabedeadbeef"]
130+
131+
127132
# Receipts query timeout
128133
sender_timeout_secs = 30
129134

crates/config/src/config.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use std::{
5-
collections::HashMap,
5+
collections::{HashMap, HashSet},
66
env,
77
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
88
path::PathBuf,
@@ -382,6 +382,10 @@ pub struct TapConfig {
382382
pub sender_timeout_secs: Duration,
383383

384384
pub sender_aggregator_endpoints: HashMap<Address, Url>,
385+
386+
/// gateways that are allowed to spend up to
387+
/// `max_amount_willing_to_lose_grt` over the escrow balance
388+
pub trusted_gateways: HashSet<Address>,
385389
}
386390

387391
#[derive(Debug, Deserialize)]

crates/tap-agent/src/agent/sender_account.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,10 @@ pub struct State {
317317
// reset in case of a successful response
318318
backoff_info: BackoffInfo,
319319

320+
/// Allows the gateway to go over escrow balance
321+
/// limited to `max_amount_willing_to_lose_grt`
322+
trusted_gateway: bool,
323+
320324
// Config forwarded to [SenderAllocation]
321325
config: &'static SenderAccountConfig,
322326
}
@@ -343,6 +347,9 @@ pub struct SenderAccountConfig {
343347
///
344348
/// This is reached if the database is too slow
345349
pub tap_sender_timeout: Duration,
350+
/// Gateways that are allowed to spend up to
351+
/// `max_amount_willing_to_lose_grt` over the escrow balance
352+
pub trusted_gateways: HashSet<Address>,
346353
}
347354

348355
impl SenderAccountConfig {
@@ -357,6 +364,7 @@ impl SenderAccountConfig {
357364
trigger_value: config.tap.get_trigger_value(),
358365
rav_request_timeout: config.tap.rav_request.request_timeout_secs,
359366
tap_sender_timeout: config.tap.sender_timeout_secs,
367+
trusted_gateways: config.tap.trusted_gateways.clone(),
360368
}
361369
}
362370
}
@@ -531,9 +539,16 @@ impl State {
531539
fn deny_condition_reached(&self) -> bool {
532540
let pending_ravs = self.rav_tracker.get_total_fee();
533541
let unaggregated_fees = self.sender_fee_tracker.get_total_fee();
534-
let pending_fees_over_balance =
535-
U256::from(pending_ravs + unaggregated_fees) >= self.sender_balance;
536542
let max_amount_willing_to_lose = self.config.max_amount_willing_to_lose_grt;
543+
544+
// if it's a trusted gateway, allow to spend up to max_amount_willing_to_lose
545+
let balance = if self.trusted_gateway {
546+
self.sender_balance + U256::from(max_amount_willing_to_lose)
547+
} else {
548+
self.sender_balance
549+
};
550+
551+
let pending_fees_over_balance = U256::from(pending_ravs + unaggregated_fees) >= balance;
537552
let invalid_receipt_fees = self.invalid_receipts_tracker.get_total_fee();
538553
let total_fee_over_max_value =
539554
unaggregated_fees + invalid_receipt_fees >= max_amount_willing_to_lose;
@@ -841,6 +856,7 @@ impl Actor for SenderAccount {
841856
aggregator_v1,
842857
aggregator_v2,
843858
backoff_info: BackoffInfo::default(),
859+
trusted_gateway: config.trusted_gateways.contains(&sender_id),
844860
config,
845861
};
846862

crates/tap-agent/src/test.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ pub fn get_sender_account_config() -> &'static SenderAccountConfig {
9393
indexer_address: INDEXER.1,
9494
escrow_polling_interval: ESCROW_POLLING_INTERVAL,
9595
tap_sender_timeout: Duration::from_secs(63),
96+
trusted_gateways: HashSet::new(),
9697
}))
9798
}
9899

@@ -122,6 +123,7 @@ pub async fn create_sender_account(
122123
indexer_address: INDEXER.1,
123124
escrow_polling_interval: Duration::default(),
124125
tap_sender_timeout: TAP_SENDER_TIMEOUT,
126+
trusted_gateways: HashSet::new(),
125127
}));
126128

127129
let network_subgraph = Box::leak(Box::new(

0 commit comments

Comments
 (0)