Skip to content

Commit 308562e

Browse files
aassemangusinacio
andauthored
Make RAV value threshold per sender (#113)
* Make RAV value threshold per sender Fixes #93 Signed-off-by: Alexis Asseman <[email protected]> * fix: simplify rav_requester_finalize error handling Signed-off-by: Alexis Asseman <[email protected]> * fix: proper signer/sender handling at startup DB SenderAccount loading Signed-off-by: Alexis Asseman <[email protected]> * test: cleanup Signed-off-by: Alexis Asseman <[email protected]> * fix: nested SQL query in sender_accounts_manager Signed-off-by: Alexis Asseman <[email protected]> * refactor: move static methods into Inner impl Signed-off-by: Alexis Asseman <[email protected]> * refactor: simplify SenderAcccount's fees_add Signed-off-by: Alexis Asseman <[email protected]> * refactor: replace active and ineligible allocations with AllocationStateEnum and single HashMap Signed-off-by: Alexis Asseman <[email protected]> * fix: locking issue and recompute unaggregated fees * fix: unaggregated fees update race condition with tokio mutex guards Signed-off-by: Alexis Asseman <[email protected]> * chore: fix comments Signed-off-by: Alexis Asseman <[email protected]> * fix: use std mutex for sender_accounts Signed-off-by: Alexis Asseman <[email protected]> --------- Signed-off-by: Alexis Asseman <[email protected]> Co-authored-by: Gustavo Inacio <[email protected]>
1 parent d3b58eb commit 308562e

15 files changed

+1893
-1243
lines changed

.sqlx/query-08726aaece34702a956885e927166df6b1f8ad0a0589464b9cbd9f09ca3f38db.json

+26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-778a427621acd2003b94340e46df1b73bfc863f0fa48004a4d5bd39cd97b07bb.json

-26
This file was deleted.

.sqlx/query-9fb8ca8ec1553951f20f81acdcfe52ad56d1bbac73fbcf5a93808bd4eaafdd4a.json

+26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.lock

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tap-agent/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ tracing-subscriber = { version = "0.3", features = [
4646
"std",
4747
"json",
4848
] }
49+
enum-as-inner = "0.6.0"
4950

5051
[dev-dependencies]
5152
ethers-signers = "2.0.8"

tap-agent/src/agent.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ use indexer_common::prelude::{
99
};
1010

1111
use crate::{
12-
aggregator_endpoints, config, database,
13-
tap::sender_allocation_relationships_manager::SenderAllocationRelationshipsManager,
12+
aggregator_endpoints, config, database, tap::sender_accounts_manager::SenderAccountsManager,
1413
};
1514

16-
pub async fn start_agent(config: &'static config::Cli) -> SenderAllocationRelationshipsManager {
15+
pub async fn start_agent(config: &'static config::Cli) -> SenderAccountsManager {
1716
let pgpool = database::connect(&config.postgres).await;
1817

1918
let http_client = reqwest::Client::new();
@@ -80,7 +79,7 @@ pub async fn start_agent(config: &'static config::Cli) -> SenderAllocationRelati
8079
verifying_contract: config.receipts.receipts_verifier_address,
8180
};
8281

83-
SenderAllocationRelationshipsManager::new(
82+
SenderAccountsManager::new(
8483
config,
8584
pgpool,
8685
indexer_allocations,

tap-agent/src/tap/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ mod escrow_adapter;
1111
mod rav_storage_adapter;
1212
mod receipt_checks_adapter;
1313
mod receipt_storage_adapter;
14-
mod sender_allocation_relationship;
15-
pub mod sender_allocation_relationships_manager;
14+
mod sender_account;
15+
pub mod sender_accounts_manager;
16+
mod sender_allocation;
17+
mod unaggregated_receipts;
1618

1719
#[cfg(test)]
1820
pub mod test_utils;

tap-agent/src/tap/rav_storage_adapter.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,18 @@ impl RAVStorageAdapter {
9191
#[cfg(test)]
9292
mod test {
9393
use super::*;
94-
use crate::tap::test_utils::{create_rav, ALLOCATION_ID, SENDER, SIGNER};
94+
use crate::tap::test_utils::{create_rav, ALLOCATION_ID_0, SENDER, SIGNER};
9595
use tap_core::adapters::rav_storage_adapter::RAVStorageAdapter as RAVStorageAdapterTrait;
9696

9797
#[sqlx::test(migrations = "../migrations")]
9898
async fn update_and_retrieve_rav(pool: PgPool) {
9999
let timestamp_ns = u64::MAX - 10;
100100
let value_aggregate = u128::MAX;
101-
let rav_storage_adapter = RAVStorageAdapter::new(pool.clone(), *ALLOCATION_ID, SENDER.1);
101+
let rav_storage_adapter = RAVStorageAdapter::new(pool.clone(), *ALLOCATION_ID_0, SENDER.1);
102102

103103
// Insert a rav
104104
let mut new_rav = create_rav(
105-
*ALLOCATION_ID,
105+
*ALLOCATION_ID_0,
106106
SIGNER.0.clone(),
107107
timestamp_ns,
108108
value_aggregate,
@@ -121,7 +121,7 @@ mod test {
121121
// Update the RAV 3 times in quick succession
122122
for i in 0..3 {
123123
new_rav = create_rav(
124-
*ALLOCATION_ID,
124+
*ALLOCATION_ID_0,
125125
SIGNER.0.clone(),
126126
timestamp_ns + i,
127127
value_aggregate - (i as u128),

tap-agent/src/tap/receipt_storage_adapter.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ mod test {
194194

195195
use super::*;
196196
use crate::tap::test_utils::{
197-
create_received_receipt, store_receipt, ALLOCATION_ID, ALLOCATION_ID_IRRELEVANT, SENDER,
197+
create_received_receipt, store_receipt, ALLOCATION_ID_0, ALLOCATION_ID_IRRELEVANT, SENDER,
198198
SENDER_IRRELEVANT, SIGNER, TAP_EIP712_DOMAIN_SEPARATOR,
199199
};
200200
use anyhow::Result;
@@ -381,7 +381,7 @@ mod test {
381381

382382
let storage_adapter = ReceiptStorageAdapter::new(
383383
pgpool.clone(),
384-
*ALLOCATION_ID,
384+
*ALLOCATION_ID_0,
385385
SENDER.1,
386386
get_full_list_of_checks(),
387387
escrow_accounts.clone(),
@@ -392,7 +392,7 @@ mod test {
392392
for i in 0..10 {
393393
received_receipt_vec.push(
394394
create_received_receipt(
395-
&ALLOCATION_ID,
395+
&ALLOCATION_ID_0,
396396
&SIGNER.0,
397397
i + 684,
398398
i + 42,
@@ -416,7 +416,7 @@ mod test {
416416
);
417417
received_receipt_vec.push(
418418
create_received_receipt(
419-
&ALLOCATION_ID,
419+
&ALLOCATION_ID_0,
420420
&SENDER_IRRELEVANT.0,
421421
i + 684,
422422
i + 42,
@@ -525,7 +525,7 @@ mod test {
525525

526526
let storage_adapter = ReceiptStorageAdapter::new(
527527
pgpool,
528-
*ALLOCATION_ID,
528+
*ALLOCATION_ID_0,
529529
SENDER.1,
530530
get_full_list_of_checks(),
531531
escrow_accounts.clone(),
@@ -536,7 +536,7 @@ mod test {
536536
for i in 0..10 {
537537
received_receipt_vec.push(
538538
create_received_receipt(
539-
&ALLOCATION_ID,
539+
&ALLOCATION_ID_0,
540540
&SIGNER.0,
541541
i + 684,
542542
i + 42,
@@ -560,7 +560,7 @@ mod test {
560560
);
561561
received_receipt_vec.push(
562562
create_received_receipt(
563-
&ALLOCATION_ID,
563+
&ALLOCATION_ID_0,
564564
&SENDER_IRRELEVANT.0,
565565
i + 684,
566566
i + 42,

0 commit comments

Comments
 (0)