Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions crates/tap-agent/src/agent/sender_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use crate::adaptative_concurrency::AdaptiveLimiter;
use crate::agent::sender_allocation::{AllocationConfig, SenderAllocationMessage};
use crate::agent::unaggregated_receipts::UnaggregatedReceipts;
use crate::backoff::BackoffInfo;
use crate::tap::escrow_adapter::EscrowAdapter;
use crate::tracker::{SenderFeeTracker, SimpleFeeTracker};
use lazy_static::lazy_static;

Expand Down Expand Up @@ -166,7 +165,6 @@ pub struct State {
escrow_subgraph: &'static SubgraphClient,
network_subgraph: &'static SubgraphClient,

escrow_adapter: EscrowAdapter,
domain_separator: Eip712Domain,
pgpool: PgPool,
sender_aggregator: jsonrpsee::http_client::HttpClient,
Expand Down Expand Up @@ -221,7 +219,6 @@ impl State {
sender: self.sender,
escrow_accounts: self.escrow_accounts.clone(),
escrow_subgraph: self.escrow_subgraph,
escrow_adapter: self.escrow_adapter.clone(),
domain_separator: self.domain_separator.clone(),
sender_account_ref: sender_account_ref.clone(),
sender_aggregator: self.sender_aggregator.clone(),
Expand Down Expand Up @@ -584,8 +581,6 @@ impl Actor for SenderAccount {
}
});

let escrow_adapter = EscrowAdapter::new(escrow_accounts.clone(), sender_id);

// Get deny status from the scalar_tap_denylist table
let denied = sqlx::query!(
r#"
Expand Down Expand Up @@ -640,7 +635,6 @@ impl Actor for SenderAccount {
escrow_accounts,
escrow_subgraph,
network_subgraph,
escrow_adapter,
domain_separator,
pgpool,
sender_aggregator,
Expand Down
34 changes: 13 additions & 21 deletions crates/tap-agent/src/agent/sender_allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ use crate::agent::sender_account::SenderAccountMessage;
use crate::agent::sender_accounts_manager::NewReceiptNotification;
use crate::agent::unaggregated_receipts::UnaggregatedReceipts;
use crate::{
tap::context::checks::AllocationId,
tap::context::{checks::Signature, TapAgentContext},
tap::signers_trimmed,
tap::{context::checks::AllocationId, escrow_adapter::EscrowAdapter},
};
use thiserror::Error;

Expand Down Expand Up @@ -137,7 +137,6 @@ pub struct SenderAllocationArgs {
pub sender: Address,
pub escrow_accounts: Receiver<EscrowAccounts>,
pub escrow_subgraph: &'static SubgraphClient,
pub escrow_adapter: EscrowAdapter,
pub domain_separator: Eip712Domain,
pub sender_account_ref: ActorRef<SenderAccountMessage>,
pub sender_aggregator: jsonrpsee::http_client::HttpClient,
Expand Down Expand Up @@ -340,7 +339,6 @@ impl SenderAllocationState {
sender,
escrow_accounts,
escrow_subgraph,
escrow_adapter,
domain_separator,
sender_account_ref,
sender_aggregator,
Expand Down Expand Up @@ -368,7 +366,6 @@ impl SenderAllocationState {
allocation_id,
sender,
escrow_accounts.clone(),
escrow_adapter,
);
let latest_rav = context.last_rav().await.unwrap_or_default();
let tap_manager = TapManager::new(
Expand Down Expand Up @@ -869,13 +866,9 @@ pub mod tests {
sender_accounts_manager::NewReceiptNotification,
unaggregated_receipts::UnaggregatedReceipts,
},
tap::{
escrow_adapter::EscrowAdapter,
test_utils::{
create_rav, create_received_receipt, store_invalid_receipt, store_rav,
store_receipt, ALLOCATION_ID_0, INDEXER, SENDER, SIGNER,
TAP_EIP712_DOMAIN_SEPARATOR,
},
tap::test_utils::{
create_rav, create_received_receipt, store_invalid_receipt, store_rav, store_receipt,
ALLOCATION_ID_0, INDEXER, SENDER, SIGNER, TAP_EIP712_DOMAIN_SEPARATOR,
},
};
use futures::future::join_all;
Expand Down Expand Up @@ -995,8 +988,6 @@ pub mod tests {
))
.1;

let escrow_adapter = EscrowAdapter::new(escrow_accounts_rx.clone(), SENDER.1);

let sender_account_ref = match sender_account {
Some(sender) => sender,
None => create_mock_sender_account().await.1,
Expand All @@ -1011,7 +1002,6 @@ pub mod tests {
sender: SENDER.1,
escrow_accounts: escrow_accounts_rx,
escrow_subgraph,
escrow_adapter,
domain_separator: TAP_EIP712_DOMAIN_SEPARATOR.clone(),
sender_account_ref,
sender_aggregator,
Expand Down Expand Up @@ -1712,18 +1702,20 @@ pub mod tests {
.register(
Mock::given(method("POST"))
.and(body_string_contains("transactions"))
.respond_with(
ResponseTemplate::new(200)
.set_body_json(json!({ "data": { "transactions": []}})),
),
.respond_with(ResponseTemplate::new(200).set_body_json(
json!({ "data": { "transactions": [
{
"id": "redeemed"
}
]}}),
)),
)
.await;
// Add invalid receipts to the database. ( receipts are older than rav )
// Add invalid receipts to the database. ( already redeemed )
let timestamp = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Time went backwards")
.as_nanos() as u64
- 10000;
.as_nanos() as u64;
const RECEIPT_VALUE: u128 = 1622018441284756158;
const TOTAL_RECEIPTS: u64 = 10;
const TOTAL_SUM: u128 = RECEIPT_VALUE * TOTAL_RECEIPTS as u128;
Expand Down
5 changes: 0 additions & 5 deletions crates/tap-agent/src/tap/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use indexer_common::escrow_accounts::EscrowAccounts;
use sqlx::PgPool;
use tokio::sync::watch::Receiver;

use super::escrow_adapter::EscrowAdapter;

pub mod checks;
mod error;
mod escrow;
Expand All @@ -22,7 +20,6 @@ pub struct TapAgentContext {
allocation_id: Address,
sender: Address,
escrow_accounts: Receiver<EscrowAccounts>,
escrow_adapter: EscrowAdapter,
}

impl TapAgentContext {
Expand All @@ -31,14 +28,12 @@ impl TapAgentContext {
allocation_id: Address,
sender: Address,
escrow_accounts: Receiver<EscrowAccounts>,
escrow_adapter: EscrowAdapter,
) -> Self {
Self {
pgpool,
allocation_id,
sender,
escrow_accounts,
escrow_adapter,
}
}
}
21 changes: 16 additions & 5 deletions crates/tap-agent/src/tap/context/escrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,30 @@ impl From<eventuals::error::Closed> for AdapterError {
}
}

// we don't need these checks anymore because there are being done before triggering
// a rav request.
//
// In any case, we don't want to fail a receipt because of this.
// The receipt is fine, just the escrow account that is not.
#[async_trait]
impl EscrowAdapterTrait for TapAgentContext {
type AdapterError = AdapterError;

async fn get_available_escrow(&self, signer: Address) -> Result<u128, AdapterError> {
self.escrow_adapter.get_available_escrow(signer).await
async fn get_available_escrow(&self, _signer: Address) -> Result<u128, AdapterError> {
Ok(0)
}

async fn subtract_escrow(&self, signer: Address, value: u128) -> Result<(), AdapterError> {
self.escrow_adapter.subtract_escrow(signer, value).await
async fn subtract_escrow(&self, _signer: Address, _value: u128) -> Result<(), AdapterError> {
Ok(())
}

async fn verify_signer(&self, signer: Address) -> Result<bool, Self::AdapterError> {
self.escrow_adapter.verify_signer(signer).await
let escrow_accounts = self.escrow_accounts.borrow();
let sender = escrow_accounts
.get_sender_for_signer(&signer)
.map_err(|_| AdapterError::ValidationError {
error: format!("Could not find the sender for the signer {}", signer),
})?;
Ok(sender == self.sender)
}
}
6 changes: 1 addition & 5 deletions crates/tap-agent/src/tap/context/rav.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,7 @@ mod test {
use tokio::sync::watch;

use super::*;
use crate::tap::{
escrow_adapter::EscrowAdapter,
test_utils::{create_rav, ALLOCATION_ID_0, SENDER, SIGNER},
};
use crate::tap::test_utils::{create_rav, ALLOCATION_ID_0, SENDER, SIGNER};

#[derive(Debug)]
struct TestableRav(SignedRAV);
Expand All @@ -159,7 +156,6 @@ mod test {
*ALLOCATION_ID_0,
SENDER.1,
watch::channel(EscrowAccounts::default()).1,
EscrowAdapter::mock(),
);

// Insert a rav
Expand Down
29 changes: 7 additions & 22 deletions crates/tap-agent/src/tap/context/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,9 @@ impl ReceiptDelete for TapAgentContext {
#[cfg(test)]
mod test {
use super::*;
use crate::tap::{
escrow_adapter::EscrowAdapter,
test_utils::{
create_received_receipt, store_receipt, wallet, ALLOCATION_ID_0, SENDER, SIGNER,
TAP_EIP712_DOMAIN_SEPARATOR,
},
use crate::tap::test_utils::{
create_received_receipt, store_receipt, wallet, ALLOCATION_ID_0, SENDER, SIGNER,
TAP_EIP712_DOMAIN_SEPARATOR,
};
use alloy::{primitives::U256, signers::local::PrivateKeySigner};
use anyhow::Result;
Expand All @@ -224,13 +221,8 @@ mod test {
))
.1;

let storage_adapter = TapAgentContext::new(
pgpool,
*ALLOCATION_ID_0,
SENDER.1,
escrow_accounts.clone(),
EscrowAdapter::mock(),
);
let storage_adapter =
TapAgentContext::new(pgpool, *ALLOCATION_ID_0, SENDER.1, escrow_accounts.clone());

let received_receipt =
create_received_receipt(&ALLOCATION_ID_0, &SIGNER.0, u64::MAX, u64::MAX, u128::MAX);
Expand Down Expand Up @@ -445,7 +437,6 @@ mod test {
*ALLOCATION_ID_0,
SENDER.1,
escrow_accounts.clone(),
EscrowAdapter::mock(),
);

// Creating 100 receipts with timestamps 42 to 141
Expand Down Expand Up @@ -514,7 +505,6 @@ mod test {
*ALLOCATION_ID_0,
SENDER.1,
escrow_accounts.clone(),
EscrowAdapter::mock(),
);

// Creating 10 receipts with timestamps 42 to 51
Expand Down Expand Up @@ -638,13 +628,8 @@ mod test {
))
.1;

let storage_adapter = TapAgentContext::new(
pgpool,
*ALLOCATION_ID_0,
SENDER.1,
escrow_accounts.clone(),
EscrowAdapter::mock(),
);
let storage_adapter =
TapAgentContext::new(pgpool, *ALLOCATION_ID_0, SENDER.1, escrow_accounts.clone());

// Creating 10 receipts with timestamps 42 to 51
let mut received_receipt_vec = Vec::new();
Expand Down
Loading
Loading