Skip to content

Commit

Permalink
Make RAV value threshold per sender
Browse files Browse the repository at this point in the history
Fixes #93

Signed-off-by: Alexis Asseman <[email protected]>
  • Loading branch information
aasseman committed Jan 31, 2024
1 parent 6a0eed3 commit 4dd0687
Show file tree
Hide file tree
Showing 10 changed files with 1,696 additions and 1,211 deletions.
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 @@ -10,8 +10,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 @@ -96,18 +96,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 @@ -126,7 +126,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 @@ -199,7 +199,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 @@ -386,7 +386,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 @@ -397,7 +397,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 @@ -421,7 +421,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 @@ -530,7 +530,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 @@ -541,7 +541,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 @@ -565,7 +565,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 4dd0687

Please sign in to comment.