Skip to content

Commit

Permalink
Make RAV value threshold per sender (#113)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
aasseman and gusinacio authored Feb 16, 2024
1 parent d3b58eb commit 308562e
Show file tree
Hide file tree
Showing 15 changed files with 1,893 additions and 1,243 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tap-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ tracing-subscriber = { version = "0.3", features = [
"std",
"json",
] }
enum-as-inner = "0.6.0"

[dev-dependencies]
ethers-signers = "2.0.8"
Expand Down
7 changes: 3 additions & 4 deletions tap-agent/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ use indexer_common::prelude::{
};

use crate::{
aggregator_endpoints, config, database,
tap::sender_allocation_relationships_manager::SenderAllocationRelationshipsManager,
aggregator_endpoints, config, database, tap::sender_accounts_manager::SenderAccountsManager,
};

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

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

SenderAllocationRelationshipsManager::new(
SenderAccountsManager::new(
config,
pgpool,
indexer_allocations,
Expand Down
6 changes: 4 additions & 2 deletions tap-agent/src/tap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ mod escrow_adapter;
mod rav_storage_adapter;
mod receipt_checks_adapter;
mod receipt_storage_adapter;
mod sender_allocation_relationship;
pub mod sender_allocation_relationships_manager;
mod sender_account;
pub mod sender_accounts_manager;
mod sender_allocation;
mod unaggregated_receipts;

#[cfg(test)]
pub mod test_utils;
Expand Down
8 changes: 4 additions & 4 deletions tap-agent/src/tap/rav_storage_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,18 @@ impl RAVStorageAdapter {
#[cfg(test)]
mod test {
use super::*;
use crate::tap::test_utils::{create_rav, ALLOCATION_ID, SENDER, SIGNER};
use crate::tap::test_utils::{create_rav, ALLOCATION_ID_0, SENDER, SIGNER};
use tap_core::adapters::rav_storage_adapter::RAVStorageAdapter as RAVStorageAdapterTrait;

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

// Insert a rav
let mut new_rav = create_rav(
*ALLOCATION_ID,
*ALLOCATION_ID_0,
SIGNER.0.clone(),
timestamp_ns,
value_aggregate,
Expand All @@ -121,7 +121,7 @@ mod test {
// Update the RAV 3 times in quick succession
for i in 0..3 {
new_rav = create_rav(
*ALLOCATION_ID,
*ALLOCATION_ID_0,
SIGNER.0.clone(),
timestamp_ns + i,
value_aggregate - (i as u128),
Expand Down
14 changes: 7 additions & 7 deletions tap-agent/src/tap/receipt_storage_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ mod test {

use super::*;
use crate::tap::test_utils::{
create_received_receipt, store_receipt, ALLOCATION_ID, ALLOCATION_ID_IRRELEVANT, SENDER,
create_received_receipt, store_receipt, ALLOCATION_ID_0, ALLOCATION_ID_IRRELEVANT, SENDER,
SENDER_IRRELEVANT, SIGNER, TAP_EIP712_DOMAIN_SEPARATOR,
};
use anyhow::Result;
Expand Down Expand Up @@ -381,7 +381,7 @@ mod test {

let storage_adapter = ReceiptStorageAdapter::new(
pgpool.clone(),
*ALLOCATION_ID,
*ALLOCATION_ID_0,
SENDER.1,
get_full_list_of_checks(),
escrow_accounts.clone(),
Expand All @@ -392,7 +392,7 @@ mod test {
for i in 0..10 {
received_receipt_vec.push(
create_received_receipt(
&ALLOCATION_ID,
&ALLOCATION_ID_0,
&SIGNER.0,
i + 684,
i + 42,
Expand All @@ -416,7 +416,7 @@ mod test {
);
received_receipt_vec.push(
create_received_receipt(
&ALLOCATION_ID,
&ALLOCATION_ID_0,
&SENDER_IRRELEVANT.0,
i + 684,
i + 42,
Expand Down Expand Up @@ -525,7 +525,7 @@ mod test {

let storage_adapter = ReceiptStorageAdapter::new(
pgpool,
*ALLOCATION_ID,
*ALLOCATION_ID_0,
SENDER.1,
get_full_list_of_checks(),
escrow_accounts.clone(),
Expand All @@ -536,7 +536,7 @@ mod test {
for i in 0..10 {
received_receipt_vec.push(
create_received_receipt(
&ALLOCATION_ID,
&ALLOCATION_ID_0,
&SIGNER.0,
i + 684,
i + 42,
Expand All @@ -560,7 +560,7 @@ mod test {
);
received_receipt_vec.push(
create_received_receipt(
&ALLOCATION_ID,
&ALLOCATION_ID_0,
&SENDER_IRRELEVANT.0,
i + 684,
i + 42,
Expand Down
Loading

0 comments on commit 308562e

Please sign in to comment.