Skip to content

Commit

Permalink
Share EscrowAdapter
Browse files Browse the repository at this point in the history
Signed-off-by: Alexis Asseman <[email protected]>
  • Loading branch information
aasseman committed Oct 26, 2023
1 parent 22def75 commit 41b0b23
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
6 changes: 5 additions & 1 deletion tap_agent/src/tap/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ impl Account {
sender: Address,
escrow_accounts: Eventual<HashMap<Address, U256>>,
escrow_subgraph: &'static SubgraphClient,
escrow_adapter: EscrowAdapter,
tap_eip712_domain_separator: Eip712Domain,
sender_aggregator_endpoint: String,
) -> Self {
Expand All @@ -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(),
Expand Down Expand Up @@ -475,13 +476,16 @@ mod tests {
Eventual::<HashMap<Address, U256>>::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(),
*ALLOCATION_ID,
SENDER.1,
escrow_accounts_eventual,
escrow_subgraph,
escrow_adapter,
TAP_EIP712_DOMAIN_SEPARATOR.clone(),
sender_aggregator_endpoint,
)
Expand Down
7 changes: 7 additions & 0 deletions tap_agent/src/tap/accounts_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -42,6 +43,7 @@ struct Inner {
indexer_allocations: Eventual<HashMap<Address, Allocation>>,
escrow_accounts: Eventual<HashMap<Address, U256>>,
escrow_subgraph: &'static SubgraphClient,
escrow_adapter: EscrowAdapter,
tap_eip712_domain_separator: Eip712Domain,
sender_aggregator_endpoints: HashMap<Address, String>,
}
Expand All @@ -56,13 +58,16 @@ impl AccountsManager {
tap_eip712_domain_separator: Eip712Domain,
sender_aggregator_endpoints: HashMap<Address, String>,
) -> Self {
let escrow_adapter = EscrowAdapter::new(escrow_accounts.clone());

let inner = Arc::new(Inner {
config,
pgpool,
accounts: Arc::new(RwLock::new(HashMap::new())),
indexer_allocations,
escrow_accounts,
escrow_subgraph,
escrow_adapter,
tap_eip712_domain_separator,
sender_aggregator_endpoints,
});
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion tap_agent/src/tap/escrow_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HashMap<Address, U256>>,
Expand Down

0 comments on commit 41b0b23

Please sign in to comment.