Skip to content

Commit 1faa61e

Browse files
authored
fix: remove escrow adapter check (#483)
1 parent 05ee6cf commit 1faa61e

File tree

8 files changed

+37
-233
lines changed

8 files changed

+37
-233
lines changed

crates/tap-agent/src/agent/sender_account.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use crate::adaptative_concurrency::AdaptiveLimiter;
3333
use crate::agent::sender_allocation::{AllocationConfig, SenderAllocationMessage};
3434
use crate::agent::unaggregated_receipts::UnaggregatedReceipts;
3535
use crate::backoff::BackoffInfo;
36-
use crate::tap::escrow_adapter::EscrowAdapter;
3736
use crate::tracker::{SenderFeeTracker, SimpleFeeTracker};
3837
use lazy_static::lazy_static;
3938

@@ -166,7 +165,6 @@ pub struct State {
166165
escrow_subgraph: &'static SubgraphClient,
167166
network_subgraph: &'static SubgraphClient,
168167

169-
escrow_adapter: EscrowAdapter,
170168
domain_separator: Eip712Domain,
171169
pgpool: PgPool,
172170
sender_aggregator: jsonrpsee::http_client::HttpClient,
@@ -221,7 +219,6 @@ impl State {
221219
sender: self.sender,
222220
escrow_accounts: self.escrow_accounts.clone(),
223221
escrow_subgraph: self.escrow_subgraph,
224-
escrow_adapter: self.escrow_adapter.clone(),
225222
domain_separator: self.domain_separator.clone(),
226223
sender_account_ref: sender_account_ref.clone(),
227224
sender_aggregator: self.sender_aggregator.clone(),
@@ -584,8 +581,6 @@ impl Actor for SenderAccount {
584581
}
585582
});
586583

587-
let escrow_adapter = EscrowAdapter::new(escrow_accounts.clone(), sender_id);
588-
589584
// Get deny status from the scalar_tap_denylist table
590585
let denied = sqlx::query!(
591586
r#"
@@ -640,7 +635,6 @@ impl Actor for SenderAccount {
640635
escrow_accounts,
641636
escrow_subgraph,
642637
network_subgraph,
643-
escrow_adapter,
644638
domain_separator,
645639
pgpool,
646640
sender_aggregator,

crates/tap-agent/src/agent/sender_allocation.rs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ use crate::agent::sender_account::SenderAccountMessage;
3535
use crate::agent::sender_accounts_manager::NewReceiptNotification;
3636
use crate::agent::unaggregated_receipts::UnaggregatedReceipts;
3737
use crate::{
38+
tap::context::checks::AllocationId,
3839
tap::context::{checks::Signature, TapAgentContext},
3940
tap::signers_trimmed,
40-
tap::{context::checks::AllocationId, escrow_adapter::EscrowAdapter},
4141
};
4242
use thiserror::Error;
4343

@@ -137,7 +137,6 @@ pub struct SenderAllocationArgs {
137137
pub sender: Address,
138138
pub escrow_accounts: Receiver<EscrowAccounts>,
139139
pub escrow_subgraph: &'static SubgraphClient,
140-
pub escrow_adapter: EscrowAdapter,
141140
pub domain_separator: Eip712Domain,
142141
pub sender_account_ref: ActorRef<SenderAccountMessage>,
143142
pub sender_aggregator: jsonrpsee::http_client::HttpClient,
@@ -340,7 +339,6 @@ impl SenderAllocationState {
340339
sender,
341340
escrow_accounts,
342341
escrow_subgraph,
343-
escrow_adapter,
344342
domain_separator,
345343
sender_account_ref,
346344
sender_aggregator,
@@ -368,7 +366,6 @@ impl SenderAllocationState {
368366
allocation_id,
369367
sender,
370368
escrow_accounts.clone(),
371-
escrow_adapter,
372369
);
373370
let latest_rav = context.last_rav().await.unwrap_or_default();
374371
let tap_manager = TapManager::new(
@@ -869,13 +866,9 @@ pub mod tests {
869866
sender_accounts_manager::NewReceiptNotification,
870867
unaggregated_receipts::UnaggregatedReceipts,
871868
},
872-
tap::{
873-
escrow_adapter::EscrowAdapter,
874-
test_utils::{
875-
create_rav, create_received_receipt, store_invalid_receipt, store_rav,
876-
store_receipt, ALLOCATION_ID_0, INDEXER, SENDER, SIGNER,
877-
TAP_EIP712_DOMAIN_SEPARATOR,
878-
},
869+
tap::test_utils::{
870+
create_rav, create_received_receipt, store_invalid_receipt, store_rav, store_receipt,
871+
ALLOCATION_ID_0, INDEXER, SENDER, SIGNER, TAP_EIP712_DOMAIN_SEPARATOR,
879872
},
880873
};
881874
use futures::future::join_all;
@@ -995,8 +988,6 @@ pub mod tests {
995988
))
996989
.1;
997990

998-
let escrow_adapter = EscrowAdapter::new(escrow_accounts_rx.clone(), SENDER.1);
999-
1000991
let sender_account_ref = match sender_account {
1001992
Some(sender) => sender,
1002993
None => create_mock_sender_account().await.1,
@@ -1011,7 +1002,6 @@ pub mod tests {
10111002
sender: SENDER.1,
10121003
escrow_accounts: escrow_accounts_rx,
10131004
escrow_subgraph,
1014-
escrow_adapter,
10151005
domain_separator: TAP_EIP712_DOMAIN_SEPARATOR.clone(),
10161006
sender_account_ref,
10171007
sender_aggregator,
@@ -1712,18 +1702,20 @@ pub mod tests {
17121702
.register(
17131703
Mock::given(method("POST"))
17141704
.and(body_string_contains("transactions"))
1715-
.respond_with(
1716-
ResponseTemplate::new(200)
1717-
.set_body_json(json!({ "data": { "transactions": []}})),
1718-
),
1705+
.respond_with(ResponseTemplate::new(200).set_body_json(
1706+
json!({ "data": { "transactions": [
1707+
{
1708+
"id": "redeemed"
1709+
}
1710+
]}}),
1711+
)),
17191712
)
17201713
.await;
1721-
// Add invalid receipts to the database. ( receipts are older than rav )
1714+
// Add invalid receipts to the database. ( already redeemed )
17221715
let timestamp = SystemTime::now()
17231716
.duration_since(UNIX_EPOCH)
17241717
.expect("Time went backwards")
1725-
.as_nanos() as u64
1726-
- 10000;
1718+
.as_nanos() as u64;
17271719
const RECEIPT_VALUE: u128 = 1622018441284756158;
17281720
const TOTAL_RECEIPTS: u64 = 10;
17291721
const TOTAL_SUM: u128 = RECEIPT_VALUE * TOTAL_RECEIPTS as u128;

crates/tap-agent/src/tap/context.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ use indexer_common::escrow_accounts::EscrowAccounts;
66
use sqlx::PgPool;
77
use tokio::sync::watch::Receiver;
88

9-
use super::escrow_adapter::EscrowAdapter;
10-
119
pub mod checks;
1210
mod error;
1311
mod escrow;
@@ -22,7 +20,6 @@ pub struct TapAgentContext {
2220
allocation_id: Address,
2321
sender: Address,
2422
escrow_accounts: Receiver<EscrowAccounts>,
25-
escrow_adapter: EscrowAdapter,
2623
}
2724

2825
impl TapAgentContext {
@@ -31,14 +28,12 @@ impl TapAgentContext {
3128
allocation_id: Address,
3229
sender: Address,
3330
escrow_accounts: Receiver<EscrowAccounts>,
34-
escrow_adapter: EscrowAdapter,
3531
) -> Self {
3632
Self {
3733
pgpool,
3834
allocation_id,
3935
sender,
4036
escrow_accounts,
41-
escrow_adapter,
4237
}
4338
}
4439
}

crates/tap-agent/src/tap/context/escrow.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,30 @@ impl From<eventuals::error::Closed> for AdapterError {
1616
}
1717
}
1818

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

23-
async fn get_available_escrow(&self, signer: Address) -> Result<u128, AdapterError> {
24-
self.escrow_adapter.get_available_escrow(signer).await
28+
async fn get_available_escrow(&self, _signer: Address) -> Result<u128, AdapterError> {
29+
Ok(0)
2530
}
2631

27-
async fn subtract_escrow(&self, signer: Address, value: u128) -> Result<(), AdapterError> {
28-
self.escrow_adapter.subtract_escrow(signer, value).await
32+
async fn subtract_escrow(&self, _signer: Address, _value: u128) -> Result<(), AdapterError> {
33+
Ok(())
2934
}
3035

3136
async fn verify_signer(&self, signer: Address) -> Result<bool, Self::AdapterError> {
32-
self.escrow_adapter.verify_signer(signer).await
37+
let escrow_accounts = self.escrow_accounts.borrow();
38+
let sender = escrow_accounts
39+
.get_sender_for_signer(&signer)
40+
.map_err(|_| AdapterError::ValidationError {
41+
error: format!("Could not find the sender for the signer {}", signer),
42+
})?;
43+
Ok(sender == self.sender)
3344
}
3445
}

crates/tap-agent/src/tap/context/rav.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,7 @@ mod test {
133133
use tokio::sync::watch;
134134

135135
use super::*;
136-
use crate::tap::{
137-
escrow_adapter::EscrowAdapter,
138-
test_utils::{create_rav, ALLOCATION_ID_0, SENDER, SIGNER},
139-
};
136+
use crate::tap::test_utils::{create_rav, ALLOCATION_ID_0, SENDER, SIGNER};
140137

141138
#[derive(Debug)]
142139
struct TestableRav(SignedRAV);
@@ -159,7 +156,6 @@ mod test {
159156
*ALLOCATION_ID_0,
160157
SENDER.1,
161158
watch::channel(EscrowAccounts::default()).1,
162-
EscrowAdapter::mock(),
163159
);
164160

165161
// Insert a rav

crates/tap-agent/src/tap/context/receipt.rs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,9 @@ impl ReceiptDelete for TapAgentContext {
193193
#[cfg(test)]
194194
mod test {
195195
use super::*;
196-
use crate::tap::{
197-
escrow_adapter::EscrowAdapter,
198-
test_utils::{
199-
create_received_receipt, store_receipt, wallet, ALLOCATION_ID_0, SENDER, SIGNER,
200-
TAP_EIP712_DOMAIN_SEPARATOR,
201-
},
196+
use crate::tap::test_utils::{
197+
create_received_receipt, store_receipt, wallet, ALLOCATION_ID_0, SENDER, SIGNER,
198+
TAP_EIP712_DOMAIN_SEPARATOR,
202199
};
203200
use alloy::{primitives::U256, signers::local::PrivateKeySigner};
204201
use anyhow::Result;
@@ -224,13 +221,8 @@ mod test {
224221
))
225222
.1;
226223

227-
let storage_adapter = TapAgentContext::new(
228-
pgpool,
229-
*ALLOCATION_ID_0,
230-
SENDER.1,
231-
escrow_accounts.clone(),
232-
EscrowAdapter::mock(),
233-
);
224+
let storage_adapter =
225+
TapAgentContext::new(pgpool, *ALLOCATION_ID_0, SENDER.1, escrow_accounts.clone());
234226

235227
let received_receipt =
236228
create_received_receipt(&ALLOCATION_ID_0, &SIGNER.0, u64::MAX, u64::MAX, u128::MAX);
@@ -445,7 +437,6 @@ mod test {
445437
*ALLOCATION_ID_0,
446438
SENDER.1,
447439
escrow_accounts.clone(),
448-
EscrowAdapter::mock(),
449440
);
450441

451442
// Creating 100 receipts with timestamps 42 to 141
@@ -514,7 +505,6 @@ mod test {
514505
*ALLOCATION_ID_0,
515506
SENDER.1,
516507
escrow_accounts.clone(),
517-
EscrowAdapter::mock(),
518508
);
519509

520510
// Creating 10 receipts with timestamps 42 to 51
@@ -638,13 +628,8 @@ mod test {
638628
))
639629
.1;
640630

641-
let storage_adapter = TapAgentContext::new(
642-
pgpool,
643-
*ALLOCATION_ID_0,
644-
SENDER.1,
645-
escrow_accounts.clone(),
646-
EscrowAdapter::mock(),
647-
);
631+
let storage_adapter =
632+
TapAgentContext::new(pgpool, *ALLOCATION_ID_0, SENDER.1, escrow_accounts.clone());
648633

649634
// Creating 10 receipts with timestamps 42 to 51
650635
let mut received_receipt_vec = Vec::new();

0 commit comments

Comments
 (0)