Skip to content

Commit

Permalink
feat: add option to avoid denying senders (#607)
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodus authored Feb 10, 2025
1 parent ff8c1f3 commit d0731e3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ pub struct TapConfig {
pub sender_timeout_secs: Duration,

pub sender_aggregator_endpoints: HashMap<Address, Url>,
/// Set of sender addresses that will not be added to the denylist
#[serde(default)]
pub trusted_senders: Vec<Address>,
}

#[derive(Debug, Deserialize)]
Expand Down
14 changes: 14 additions & 0 deletions crates/tap-agent/src/agent/sender_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ pub struct SenderAccountConfig {
pub max_amount_willing_to_lose_grt: u128,
/// What value triggers a new Rav request
pub trigger_value: u128,
/// Set of sender addresses that will not be added to the denylist
pub trusted_senders: HashSet<Address>,

// allocation config
/// Timeout config for rav requests
Expand All @@ -355,6 +357,7 @@ impl SenderAccountConfig {
escrow_polling_interval: config.subgraphs.escrow.config.syncing_interval_secs,
max_amount_willing_to_lose_grt: config.tap.max_amount_willing_to_lose_grt.get_value(),
trigger_value: config.tap.get_trigger_value(),
trusted_senders: config.tap.trusted_senders.iter().copied().collect(),
rav_request_timeout: config.tap.rav_request.request_timeout_secs,
tap_sender_timeout: config.tap.sender_timeout_secs,
}
Expand Down Expand Up @@ -549,6 +552,17 @@ impl State {

/// Will update [`State::denied`], as well as the denylist table in the database.
async fn add_to_denylist(&mut self) {
if self.config.trusted_senders.contains(&self.sender) {
tracing::warn!(
fee_tracker = self.sender_fee_tracker.get_total_fee(),
rav_tracker = self.rav_tracker.get_total_fee(),
max_amount_willing_to_lose = self.config.max_amount_willing_to_lose_grt,
sender_balance = self.sender_balance.to_u128(),
"Trusted sender would be denied."
);
return;
}

tracing::warn!(
fee_tracker = self.sender_fee_tracker.get_total_fee(),
rav_tracker = self.rav_tracker.get_total_fee(),
Expand Down
2 changes: 2 additions & 0 deletions crates/tap-agent/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub fn get_sender_account_config() -> &'static SenderAccountConfig {
rav_request_buffer: RAV_REQUEST_BUFFER,
max_amount_willing_to_lose_grt: TRIGGER_VALUE + 100,
trigger_value: TRIGGER_VALUE,
trusted_senders: Default::default(),
rav_request_timeout: Duration::from_secs(30),
rav_request_receipt_limit: 1000,
indexer_address: INDEXER.1,
Expand Down Expand Up @@ -105,6 +106,7 @@ pub async fn create_sender_account(
rav_request_buffer: BUFFER_DURATION,
max_amount_willing_to_lose_grt,
trigger_value: rav_request_trigger_value,
trusted_senders: Default::default(),
rav_request_timeout: RAV_REQUEST_TIMEOUT,
rav_request_receipt_limit,
indexer_address: INDEXER.1,
Expand Down
1 change: 1 addition & 0 deletions crates/tap-agent/tests/tap_agent_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub async fn start_agent(
rav_request_buffer: Duration::from_millis(500),
max_amount_willing_to_lose_grt: 50,
trigger_value: 150,
trusted_senders: Default::default(),
rav_request_timeout: Duration::from_secs(60),
rav_request_receipt_limit: 10,
indexer_address: INDEXER_ADDRESS,
Expand Down

0 comments on commit d0731e3

Please sign in to comment.