From 41b0b23971d722f6932efa24cbb2075b73530716 Mon Sep 17 00:00:00 2001 From: Alexis Asseman Date: Thu, 26 Oct 2023 13:35:55 -0700 Subject: [PATCH] Share EscrowAdapter Signed-off-by: Alexis Asseman --- tap_agent/src/tap/account.rs | 6 +++++- tap_agent/src/tap/accounts_manager.rs | 7 +++++++ tap_agent/src/tap/escrow_adapter.rs | 9 ++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/tap_agent/src/tap/account.rs b/tap_agent/src/tap/account.rs index 70b2de2fe..feb06e7a5 100644 --- a/tap_agent/src/tap/account.rs +++ b/tap_agent/src/tap/account.rs @@ -85,6 +85,7 @@ impl Account { sender: Address, escrow_accounts: Eventual>, escrow_subgraph: &'static SubgraphClient, + escrow_adapter: EscrowAdapter, tap_eip712_domain_separator: Eip712Domain, sender_aggregator_endpoint: String, ) -> Self { @@ -96,7 +97,7 @@ impl Account { ReceiptCheck::CheckSignature, ReceiptCheck::CheckAndReserveEscrow, ]; - let escrow_adapter = EscrowAdapter::new(escrow_accounts.clone()); + let receipt_checks_adapter = ReceiptChecksAdapter::new( config, pgpool.clone(), @@ -475,6 +476,8 @@ mod tests { Eventual::>::new(); escrow_accounts_writer.write(HashMap::from([(SENDER.1, 1000.into())])); + let escrow_adapter = EscrowAdapter::new(escrow_accounts_eventual.clone()); + Account::new( config, pgpool.clone(), @@ -482,6 +485,7 @@ mod tests { SENDER.1, escrow_accounts_eventual, escrow_subgraph, + escrow_adapter, TAP_EIP712_DOMAIN_SEPARATOR.clone(), sender_aggregator_endpoint, ) diff --git a/tap_agent/src/tap/accounts_manager.rs b/tap_agent/src/tap/accounts_manager.rs index 3abe00ff1..7676a5012 100644 --- a/tap_agent/src/tap/accounts_manager.rs +++ b/tap_agent/src/tap/accounts_manager.rs @@ -16,6 +16,7 @@ use tokio::sync::RwLock; use tracing::{error, warn}; use super::account::Account; +use super::escrow_adapter::EscrowAdapter; use crate::config; #[derive(Deserialize, Debug)] @@ -42,6 +43,7 @@ struct Inner { indexer_allocations: Eventual>, escrow_accounts: Eventual>, escrow_subgraph: &'static SubgraphClient, + escrow_adapter: EscrowAdapter, tap_eip712_domain_separator: Eip712Domain, sender_aggregator_endpoints: HashMap, } @@ -56,6 +58,8 @@ impl AccountsManager { tap_eip712_domain_separator: Eip712Domain, sender_aggregator_endpoints: HashMap, ) -> Self { + let escrow_adapter = EscrowAdapter::new(escrow_accounts.clone()); + let inner = Arc::new(Inner { config, pgpool, @@ -63,6 +67,7 @@ impl AccountsManager { indexer_allocations, escrow_accounts, escrow_subgraph, + escrow_adapter, tap_eip712_domain_separator, sender_aggregator_endpoints, }); @@ -129,6 +134,7 @@ impl AccountsManager { sender, inner.escrow_accounts.clone(), inner.escrow_subgraph, + inner.escrow_adapter.clone(), inner.tap_eip712_domain_separator.clone(), inner .sender_aggregator_endpoints @@ -239,6 +245,7 @@ impl AccountsManager { *sender, inner.escrow_accounts.clone(), inner.escrow_subgraph, + inner.escrow_adapter.clone(), inner.tap_eip712_domain_separator.clone(), inner .sender_aggregator_endpoints diff --git a/tap_agent/src/tap/escrow_adapter.rs b/tap_agent/src/tap/escrow_adapter.rs index b88701564..5a0a62ab8 100644 --- a/tap_agent/src/tap/escrow_adapter.rs +++ b/tap_agent/src/tap/escrow_adapter.rs @@ -11,7 +11,14 @@ use tap_core::adapters::escrow_adapter::EscrowAdapter as EscrowAdapterTrait; use thiserror::Error; use tokio::sync::RwLock; -/// This is Arc internally, so it can be cloned and shared between threads. +/// The EscrowAdapter is used to track the available escrow for all senders. It is updated when +/// receipt checks are finalized (right before a RAV request). +/// +/// It is to be shared between all Account instances. Note that it is Arc internally, so it can be +/// shared through clones. +/// +/// It is not used to track unaggregated fees (yet?), because we are currently batch finalizing +/// receipt checks only when we need to send a RAV request. #[derive(Clone)] pub struct EscrowAdapter { escrow_accounts: Eventual>,