Skip to content

Commit

Permalink
chore: rename gateway to sender
Browse files Browse the repository at this point in the history
Signed-off-by: Gustavo Inacio <[email protected]>
  • Loading branch information
gusinacio committed Feb 11, 2025
1 parent da7ac0f commit 5c6a9f0
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
4 changes: 2 additions & 2 deletions crates/config/maximal-config-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +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

# List of Gateways that are allowed to spend up to `max_amount_willing_to_lose_grt`
# List of Senders that are allowed to spend up to `max_amount_willing_to_lose_grt`
# over the escrow balance
trusted_gateways = ["0xdeadbeefcafebabedeadbeefcafebabedeadbeef"]
trusted_senders = ["0xdeadbeefcafebabedeadbeefcafebabedeadbeef"]


# Receipts query timeout
Expand Down
6 changes: 3 additions & 3 deletions crates/config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,9 @@ pub struct TapConfig {

pub sender_aggregator_endpoints: HashMap<Address, Url>,

/// gateways that are allowed to spend up to
/// `max_amount_willing_to_lose_grt` over the escrow balance
pub trusted_gateways: HashSet<Address>,
/// Senders that are allowed to spend up to `max_amount_willing_to_lose_grt`
/// over the escrow balance
pub trusted_senders: HashSet<Address>,
}

#[derive(Debug, Deserialize)]
Expand Down
22 changes: 11 additions & 11 deletions crates/tap-agent/src/agent/sender_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,9 @@ pub struct State {
// reset in case of a successful response
backoff_info: BackoffInfo,

/// Allows the gateway to go over escrow balance
/// Allows the sender to go over escrow balance
/// limited to `max_amount_willing_to_lose_grt`
trusted_gateway: bool,
trusted_sender: bool,

// Config forwarded to [SenderAllocation]
config: &'static SenderAccountConfig,
Expand Down Expand Up @@ -347,9 +347,9 @@ pub struct SenderAccountConfig {
///
/// This is reached if the database is too slow
pub tap_sender_timeout: Duration,
/// Gateways that are allowed to spend up to
/// `max_amount_willing_to_lose_grt` over the escrow balance
pub trusted_gateways: HashSet<Address>,
/// Senders that are allowed to spend up to `max_amount_willing_to_lose_grt`
/// over the escrow balance
pub trusted_senders: HashSet<Address>,
}

impl SenderAccountConfig {
Expand All @@ -364,7 +364,7 @@ impl SenderAccountConfig {
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,
trusted_gateways: config.tap.trusted_gateways.clone(),
trusted_senders: config.tap.trusted_senders.clone(),
}
}
}
Expand Down Expand Up @@ -541,8 +541,8 @@ impl State {
let unaggregated_fees = self.sender_fee_tracker.get_total_fee();
let max_amount_willing_to_lose = self.config.max_amount_willing_to_lose_grt;

// if it's a trusted gateway, allow to spend up to max_amount_willing_to_lose
let balance = if self.trusted_gateway {
// if it's a trusted sender, allow to spend up to max_amount_willing_to_lose
let balance = if self.trusted_sender {
self.sender_balance + U256::from(max_amount_willing_to_lose)
} else {
self.sender_balance
Expand Down Expand Up @@ -856,7 +856,7 @@ impl Actor for SenderAccount {
aggregator_v1,
aggregator_v2,
backoff_info: BackoffInfo::default(),
trusted_gateway: config.trusted_gateways.contains(&sender_id),
trusted_sender: config.trusted_senders.contains(&sender_id),
config,
};

Expand Down Expand Up @@ -2002,12 +2002,12 @@ pub mod tests {
}

#[sqlx::test(migrations = "../../migrations")]
async fn test_trusted_gateway(pgpool: PgPool) {
async fn test_trusted_sender(pgpool: PgPool) {
let max_amount_willing_to_lose_grt = ESCROW_VALUE / 10;
// initialize with no trigger value and no max receipt deny
let (sender_account, notify, prefix, _) = create_sender_account()
.pgpool(pgpool)
.trusted_gateway(true)
.trusted_sender(true)
.rav_request_trigger_value(u128::MAX)
.max_amount_willing_to_lose_grt(max_amount_willing_to_lose_grt)
.call()
Expand Down
8 changes: 4 additions & 4 deletions crates/tap-agent/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub fn get_sender_account_config() -> &'static SenderAccountConfig {
indexer_address: INDEXER.1,
escrow_polling_interval: ESCROW_POLLING_INTERVAL,
tap_sender_timeout: Duration::from_secs(63),
trusted_gateways: HashSet::new(),
trusted_senders: HashSet::new(),
}))
}

Expand All @@ -108,14 +108,14 @@ pub async fn create_sender_account(
network_subgraph_endpoint: Option<&str>,
#[builder(default = RECEIPT_LIMIT)] rav_request_receipt_limit: u64,
aggregator_endpoint: Option<Url>,
#[builder(default = false)] trusted_gateway: bool,
#[builder(default = false)] trusted_sender: bool,
) -> (
ActorRef<SenderAccountMessage>,
Arc<Notify>,
String,
Sender<EscrowAccounts>,
) {
let trusted_gateways = if trusted_gateway {
let trusted_senders = if trusted_sender {
HashSet::from([SENDER.1])
} else {
HashSet::new()
Expand All @@ -129,7 +129,7 @@ pub async fn create_sender_account(
indexer_address: INDEXER.1,
escrow_polling_interval: Duration::default(),
tap_sender_timeout: TAP_SENDER_TIMEOUT,
trusted_gateways,
trusted_senders,
}));

let network_subgraph = Box::leak(Box::new(
Expand Down
8 changes: 7 additions & 1 deletion crates/tap-agent/tests/tap_agent_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
// SPDX-License-Identifier: Apache-2.0

use std::{collections::HashMap, str::FromStr, sync::Arc, time::Duration};
use std::{
collections::{HashMap, HashSet},
str::FromStr,
sync::Arc,
time::Duration,
};

use indexer_monitor::{DeploymentDetails, EscrowAccounts, SubgraphClient};
use indexer_tap_agent::{
Expand Down Expand Up @@ -87,6 +92,7 @@ pub async fn start_agent(
indexer_address: INDEXER_ADDRESS,
escrow_polling_interval: Duration::from_secs(10),
tap_sender_timeout: Duration::from_secs(30),
trusted_senders: HashSet::new(),
}));

let args = SenderAccountsManagerArgs {
Expand Down

0 comments on commit 5c6a9f0

Please sign in to comment.