From 309f41f879b51a1f2840ef0ed2552d7faa338b86 Mon Sep 17 00:00:00 2001 From: Alexis Asseman Date: Tue, 14 Nov 2023 17:04:25 -0800 Subject: [PATCH] refactor!: rename "gateway" to "sender" everywhere Fixes #188 Signed-off-by: Alexis Asseman --- tap_aggregator/README.md | 2 +- tap_aggregator/src/main.rs | 4 +- tap_core/src/adapters/escrow_adapter.rs | 16 +- .../src/adapters/receipt_checks_adapter.rs | 12 +- .../src/adapters/test/escrow_adapter_mock.rs | 42 ++--- .../src/adapters/test/escrow_adapter_test.rs | 36 ++-- .../test/receipt_checks_adapter_mock.rs | 12 +- .../test/receipt_checks_adapter_test.rs | 10 +- tap_core/src/error.rs | 2 +- tap_core/src/tap_manager/test/manager_test.rs | 12 +- tap_core/src/tap_receipt/receipt_auditor.rs | 6 +- .../tests/received_receipt_tests.rs | 18 +- tap_integration_tests/tests/showcase.rs | 162 +++++++++--------- 13 files changed, 164 insertions(+), 170 deletions(-) diff --git a/tap_aggregator/README.md b/tap_aggregator/README.md index 2f7ce8fd..1f6cb09f 100644 --- a/tap_aggregator/README.md +++ b/tap_aggregator/README.md @@ -14,7 +14,7 @@ Options: --port Port to listen on for JSON-RPC requests [env: TAP_PORT=] [default: 8080] --mnemonic - Gateway mnemonic to be used to sign Receipt Aggregate Vouchers [env: TAP_MNEMONIC=] + Sender mnemonic to be used to sign Receipt Aggregate Vouchers [env: TAP_MNEMONIC=] --max-request-body-size Maximum request body size in bytes. Defaults to 10MB [env: TAP_MAX_REQUEST_BODY_SIZE=] [default: 10485760] --max-response-body-size diff --git a/tap_aggregator/src/main.rs b/tap_aggregator/src/main.rs index f781982e..0c2e5079 100644 --- a/tap_aggregator/src/main.rs +++ b/tap_aggregator/src/main.rs @@ -24,11 +24,11 @@ struct Args { #[arg(long, default_value_t = 8080, env = "TAP_PORT")] port: u16, - /// Gateway mnemonic to be used to generate key for signing Receipt Aggregate Vouchers. + /// Sender mnemonic to be used to generate key for signing Receipt Aggregate Vouchers. #[arg(long, env = "TAP_MNEMONIC")] mnemonic: String, - /// Gateway key derive path to be used to generate key for signing Receipt Aggregate Vouchers. + /// Sender key derive path to be used to generate key for signing Receipt Aggregate Vouchers. #[arg(long, default_value = "m/44'/60'/0'/0/0", env = "TAP_KEY_DERIVE_PATH")] key_derive_path: String, diff --git a/tap_core/src/adapters/escrow_adapter.rs b/tap_core/src/adapters/escrow_adapter.rs index 92f5a476..764beddd 100644 --- a/tap_core/src/adapters/escrow_adapter.rs +++ b/tap_core/src/adapters/escrow_adapter.rs @@ -14,11 +14,11 @@ use async_trait::async_trait; /// # Usage /// /// The `get_available_escrow` method should be used to retrieve the local accounting -/// amount of available escrow for a specified gateway. Any errors during this operation +/// amount of available escrow for a specified sender. Any errors during this operation /// should be captured and returned in the `AdapterError` format. /// /// The `subtract_escrow` method is used to deduct a specified value from the local accounting -/// of available escrow of a specified gateway. Any errors during this operation should be captured +/// of available escrow of a specified sender. Any errors during this operation should be captured /// and returned as an `AdapterError`. /// /// This trait is utilized by [crate::tap_manager], which relies on these @@ -36,21 +36,21 @@ pub trait EscrowAdapter { /// Errors of this type are returned to the user when an operation fails. type AdapterError: std::error::Error + std::fmt::Debug + Send + Sync + 'static; - /// Retrieves the local accounting amount of available escrow for a specified gateway. + /// Retrieves the local accounting amount of available escrow for a specified sender. /// /// This method should be implemented to fetch the local accounting amount of available escrow for a - /// specified gateway from your system. Any errors that occur during this process should + /// specified sender from your system. Any errors that occur during this process should /// be captured and returned as an `AdapterError`. - async fn get_available_escrow(&self, gateway_id: Address) -> Result; + async fn get_available_escrow(&self, sender_id: Address) -> Result; - /// Deducts a specified value from the local accounting of available escrow for a specified gateway. + /// Deducts a specified value from the local accounting of available escrow for a specified sender. /// /// This method should be implemented to deduct a specified value from the local accounting of - /// available escrow of a specified gateway in your system. Any errors that occur during this + /// available escrow of a specified sender in your system. Any errors that occur during this /// process should be captured and returned as an `AdapterError`. async fn subtract_escrow( &self, - gateway_id: Address, + sender_id: Address, value: u128, ) -> Result<(), Self::AdapterError>; } diff --git a/tap_core/src/adapters/receipt_checks_adapter.rs b/tap_core/src/adapters/receipt_checks_adapter.rs index d40944f0..ed4dbd7f 100644 --- a/tap_core/src/adapters/receipt_checks_adapter.rs +++ b/tap_core/src/adapters/receipt_checks_adapter.rs @@ -9,7 +9,7 @@ use async_trait::async_trait; /// /// This trait is designed to be implemented by users of this library who want to /// customize the checks done on TAP receipts. This includes ensuring the receipt is unique, -/// verifying the allocation ID, the value and the gateway ID. +/// verifying the allocation ID, the value and the sender ID. /// /// # Usage /// @@ -19,7 +19,7 @@ use async_trait::async_trait; /// /// The `is_valid_value` method should confirm the value of the receipt is valid for the given query ID. /// -/// The `is_valid_gateway_id` method should confirm the gateway ID is valid. +/// The `is_valid_sender_id` method should confirm the sender ID is valid. /// /// This trait is utilized by [crate::tap_manager], which relies on these /// operations for managing TAP receipts. @@ -61,9 +61,9 @@ pub trait ReceiptChecksAdapter { /// This method should be implemented to confirm the validity of the given value for a specific query ID. async fn is_valid_value(&self, value: u128, query_id: u64) -> Result; - /// Confirms the gateway ID is valid. + /// Confirms the sender ID is valid. /// - /// This method should be implemented to validate the given gateway ID is one associated with a gateway the indexer considers valid. - /// The provided gateway ID is the address of the gateway that is recovered from the signature of the receipt. - async fn is_valid_gateway_id(&self, gateway_id: Address) -> Result; + /// This method should be implemented to validate the given sender ID is one associated with a sender the indexer considers valid. + /// The provided sender ID is the address of the sender that is recovered from the signature of the receipt. + async fn is_valid_sender_id(&self, sender_id: Address) -> Result; } diff --git a/tap_core/src/adapters/test/escrow_adapter_mock.rs b/tap_core/src/adapters/test/escrow_adapter_mock.rs index 08f8d67a..b52517eb 100644 --- a/tap_core/src/adapters/test/escrow_adapter_mock.rs +++ b/tap_core/src/adapters/test/escrow_adapter_mock.rs @@ -10,7 +10,7 @@ use tokio::sync::RwLock; use crate::adapters::escrow_adapter::EscrowAdapter; pub struct EscrowAdapterMock { - gateway_escrow_storage: Arc>>, + sender_escrow_storage: Arc>>, } use thiserror::Error; @@ -21,43 +21,43 @@ pub enum AdpaterErrorMock { } impl EscrowAdapterMock { - pub fn new(gateway_escrow_storage: Arc>>) -> Self { + pub fn new(sender_escrow_storage: Arc>>) -> Self { EscrowAdapterMock { - gateway_escrow_storage, + sender_escrow_storage, } } - pub async fn escrow(&self, gateway_id: Address) -> Result { - let gateway_escrow_storage = self.gateway_escrow_storage.read().await; - if let Some(escrow) = gateway_escrow_storage.get(&gateway_id) { + pub async fn escrow(&self, sender_id: Address) -> Result { + let sender_escrow_storage = self.sender_escrow_storage.read().await; + if let Some(escrow) = sender_escrow_storage.get(&sender_id) { return Ok(*escrow); } Err(AdpaterErrorMock::AdapterError { - error: "No escrow exists for provided gateway ID.".to_owned(), + error: "No escrow exists for provided sender ID.".to_owned(), }) } - pub async fn increase_escrow(&mut self, gateway_id: Address, value: u128) { - let mut gateway_escrow_storage = self.gateway_escrow_storage.write().await; + pub async fn increase_escrow(&mut self, sender_id: Address, value: u128) { + let mut sender_escrow_storage = self.sender_escrow_storage.write().await; - if let Some(current_value) = gateway_escrow_storage.get(&gateway_id) { - let mut gateway_escrow_storage = self.gateway_escrow_storage.write().await; - gateway_escrow_storage.insert(gateway_id, current_value + value); + if let Some(current_value) = sender_escrow_storage.get(&sender_id) { + let mut sender_escrow_storage = self.sender_escrow_storage.write().await; + sender_escrow_storage.insert(sender_id, current_value + value); } else { - gateway_escrow_storage.insert(gateway_id, value); + sender_escrow_storage.insert(sender_id, value); } } pub async fn reduce_escrow( &self, - gateway_id: Address, + sender_id: Address, value: u128, ) -> Result<(), AdpaterErrorMock> { - let mut gateway_escrow_storage = self.gateway_escrow_storage.write().await; + let mut sender_escrow_storage = self.sender_escrow_storage.write().await; - if let Some(current_value) = gateway_escrow_storage.get(&gateway_id) { + if let Some(current_value) = sender_escrow_storage.get(&sender_id) { let checked_new_value = current_value.checked_sub(value); if let Some(new_value) = checked_new_value { - gateway_escrow_storage.insert(gateway_id, new_value); + sender_escrow_storage.insert(sender_id, new_value); return Ok(()); } } @@ -70,14 +70,14 @@ impl EscrowAdapterMock { #[async_trait] impl EscrowAdapter for EscrowAdapterMock { type AdapterError = AdpaterErrorMock; - async fn get_available_escrow(&self, gateway_id: Address) -> Result { - self.escrow(gateway_id).await + async fn get_available_escrow(&self, sender_id: Address) -> Result { + self.escrow(sender_id).await } async fn subtract_escrow( &self, - gateway_id: Address, + sender_id: Address, value: u128, ) -> Result<(), Self::AdapterError> { - self.reduce_escrow(gateway_id, value).await + self.reduce_escrow(sender_id, value).await } } diff --git a/tap_core/src/adapters/test/escrow_adapter_test.rs b/tap_core/src/adapters/test/escrow_adapter_test.rs index a1224926..1b35b9be 100644 --- a/tap_core/src/adapters/test/escrow_adapter_test.rs +++ b/tap_core/src/adapters/test/escrow_adapter_test.rs @@ -21,8 +21,8 @@ mod escrow_adapter_unit_test { .phrase("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about") .build() .unwrap(); - let gateway_id: [u8; 20] = wallet.address().into(); - let gateway_id = gateway_id.into(); + let sender_id: [u8; 20] = wallet.address().into(); + let sender_id = sender_id.into(); let invalid_wallet: LocalWallet = MnemonicBuilder::::default() .phrase( @@ -30,40 +30,34 @@ mod escrow_adapter_unit_test { ) .build() .unwrap(); - let invalid_gateway_id: [u8; 20] = invalid_wallet.address().into(); - let invalid_gateway_id = invalid_gateway_id.into(); + let invalid_sender_id: [u8; 20] = invalid_wallet.address().into(); + let invalid_sender_id = invalid_sender_id.into(); let initial_value = 500u128; escrow_adapter - .increase_escrow(gateway_id, initial_value) + .increase_escrow(sender_id, initial_value) .await; - // Check that gateway exists and has valid value through adapter - assert!(escrow_adapter - .get_available_escrow(gateway_id) - .await - .is_ok()); + // Check that sender exists and has valid value through adapter + assert!(escrow_adapter.get_available_escrow(sender_id).await.is_ok()); assert_eq!( escrow_adapter - .get_available_escrow(gateway_id) + .get_available_escrow(sender_id) .await .unwrap(), initial_value ); - // Check that subtracting is valid for valid gateway, and results in expected value - assert!(escrow_adapter - .subtract_escrow(gateway_id, initial_value) - .await - .is_ok()); + // Check that subtracting is valid for valid sender, and results in expected value assert!(escrow_adapter - .get_available_escrow(gateway_id) + .subtract_escrow(sender_id, initial_value) .await .is_ok()); + assert!(escrow_adapter.get_available_escrow(sender_id).await.is_ok()); assert_eq!( escrow_adapter - .get_available_escrow(gateway_id) + .get_available_escrow(sender_id) .await .unwrap(), 0 @@ -71,13 +65,13 @@ mod escrow_adapter_unit_test { // Check that subtracting to negative escrow results in err assert!(escrow_adapter - .subtract_escrow(gateway_id, initial_value) + .subtract_escrow(sender_id, initial_value) .await .is_err()); - // Check that accessing non initialized gateway results in err + // Check that accessing non initialized sender results in err assert!(escrow_adapter - .get_available_escrow(invalid_gateway_id) + .get_available_escrow(invalid_sender_id) .await .is_err()); } diff --git a/tap_core/src/adapters/test/receipt_checks_adapter_mock.rs b/tap_core/src/adapters/test/receipt_checks_adapter_mock.rs index 5eeb858c..eaccbfa7 100644 --- a/tap_core/src/adapters/test/receipt_checks_adapter_mock.rs +++ b/tap_core/src/adapters/test/receipt_checks_adapter_mock.rs @@ -21,7 +21,7 @@ pub struct ReceiptChecksAdapterMock { receipt_storage: Arc>>, query_appraisals: Arc>>, allocation_ids: Arc>>, - gateway_ids: Arc>>, + sender_ids: Arc>>, } #[derive(Debug, Error)] @@ -43,13 +43,13 @@ impl ReceiptChecksAdapterMock { receipt_storage: Arc>>, query_appraisals: Arc>>, allocation_ids: Arc>>, - gateway_ids: Arc>>, + sender_ids: Arc>>, ) -> Self { Self { receipt_storage, query_appraisals, allocation_ids, - gateway_ids, + sender_ids, } } } @@ -90,8 +90,8 @@ impl ReceiptChecksAdapter for ReceiptChecksAdapterMock { Ok(true) } - async fn is_valid_gateway_id(&self, gateway_id: Address) -> Result { - let gateway_ids = self.gateway_ids.read().await; - Ok(gateway_ids.contains(&gateway_id)) + async fn is_valid_sender_id(&self, sender_id: Address) -> Result { + let sender_ids = self.sender_ids.read().await; + Ok(sender_ids.contains(&sender_id)) } } diff --git a/tap_core/src/adapters/test/receipt_checks_adapter_test.rs b/tap_core/src/adapters/test/receipt_checks_adapter_test.rs index e22946ac..6fc8b26a 100644 --- a/tap_core/src/adapters/test/receipt_checks_adapter_test.rs +++ b/tap_core/src/adapters/test/receipt_checks_adapter_test.rs @@ -38,12 +38,12 @@ mod receipt_checks_adapter_unit_test { #[rstest] #[tokio::test] async fn receipt_checks_adapter_test(domain_separator: Eip712Domain) { - let gateway_ids = [ + let sender_ids = [ Address::from_str("0xfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfb").unwrap(), Address::from_str("0xfafafafafafafafafafafafafafafafafafafafa").unwrap(), Address::from_str("0xadadadadadadadadadadadadadadadadadadadad").unwrap(), ]; - let gateway_ids_set = Arc::new(RwLock::new(HashSet::from(gateway_ids))); + let sender_ids_set = Arc::new(RwLock::new(HashSet::from(sender_ids))); let allocation_ids = [ Address::from_str("0xabababababababababababababababababababab").unwrap(), @@ -91,7 +91,7 @@ mod receipt_checks_adapter_unit_test { Arc::clone(&receipt_storage), query_appraisals_storage, allocation_ids_set, - gateway_ids_set, + sender_ids_set, ); let new_receipt = ( @@ -123,8 +123,8 @@ mod receipt_checks_adapter_unit_test { .is_valid_allocation_id(new_receipt.1.signed_receipt.message.allocation_id) .await .unwrap()); - // TODO: Add check when gateway_id is available from received receipt (issue: #56) - // assert!(receipt_checks_adapter.is_valid_gateway_id(gateway_id)); + // TODO: Add check when sender_id is available from received receipt (issue: #56) + // assert!(receipt_checks_adapter.is_valid_sender_id(sender_id)); assert!(receipt_checks_adapter .is_valid_value( new_receipt.1.signed_receipt.message.value, diff --git a/tap_core/src/error.rs b/tap_core/src/error.rs index 216c7d41..5637dfef 100644 --- a/tap_core/src/error.rs +++ b/tap_core/src/error.rs @@ -29,7 +29,7 @@ pub enum Error { WalletError(#[from] WalletError), #[error(transparent)] SignatureError(#[from] SignatureError), - #[error("Recovered gateway address invalid{address}")] + #[error("Recovered sender address invalid{address}")] InvalidRecoveredSigner { address: Address }, #[error("Received RAV does not match expexted RAV")] InvalidReceivedRAV { diff --git a/tap_core/src/tap_manager/test/manager_test.rs b/tap_core/src/tap_manager/test/manager_test.rs index 857a891a..5e4bec4f 100644 --- a/tap_core/src/tap_manager/test/manager_test.rs +++ b/tap_core/src/tap_manager/test/manager_test.rs @@ -53,7 +53,7 @@ mod manager_unit_test { } #[fixture] - fn gateway_ids() -> Vec
{ + fn sender_ids() -> Vec
{ vec![ Address::from_str("0xfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfb").unwrap(), Address::from_str("0xfafafafafafafafafafafafafafafafafafafafa").unwrap(), @@ -81,9 +81,9 @@ mod manager_unit_test { #[fixture] fn escrow_adapters() -> (EscrowAdapterMock, Arc>>) { - let gateway_escrow_storage = Arc::new(RwLock::new(HashMap::new())); - let escrow_adapter = EscrowAdapterMock::new(Arc::clone(&gateway_escrow_storage)); - (escrow_adapter, gateway_escrow_storage) + let sender_escrow_storage = Arc::new(RwLock::new(HashMap::new())); + let escrow_adapter = EscrowAdapterMock::new(Arc::clone(&sender_escrow_storage)); + (escrow_adapter, sender_escrow_storage) } #[fixture] @@ -96,14 +96,14 @@ mod manager_unit_test { let receipt_storage_adapter = ReceiptStorageAdapterMock::new(Arc::clone(&receipt_storage)); let allocation_ids_set = Arc::new(RwLock::new(HashSet::from_iter(allocation_ids()))); - let gateway_ids_set = Arc::new(RwLock::new(HashSet::from_iter(gateway_ids()))); + let sender_ids_set = Arc::new(RwLock::new(HashSet::from_iter(sender_ids()))); let query_appraisal_storage = Arc::new(RwLock::new(HashMap::new())); let receipt_checks_adapter = ReceiptChecksAdapterMock::new( Arc::clone(&receipt_storage), Arc::clone(&query_appraisal_storage), Arc::clone(&allocation_ids_set), - Arc::clone(&gateway_ids_set), + Arc::clone(&sender_ids_set), ); ( diff --git a/tap_core/src/tap_receipt/receipt_auditor.rs b/tap_core/src/tap_receipt/receipt_auditor.rs index e0242829..ea1ffd18 100644 --- a/tap_core/src/tap_receipt/receipt_auditor.rs +++ b/tap_core/src/tap_receipt/receipt_auditor.rs @@ -251,7 +251,7 @@ impl ReceiptAuditor { })?; if !self .receipt_checks_adapter - .is_valid_gateway_id(receipt_signer_address) + .is_valid_sender_id(receipt_signer_address) .await .map_err(|e| ReceiptError::CheckFailedToComplete { source_error_message: e.to_string(), @@ -259,7 +259,7 @@ impl ReceiptAuditor { { return Err(ReceiptError::InvalidSignature { source_error_message: format!( - "Recovered gateway id is not valid: {}", + "Recovered sender id is not valid: {}", receipt_signer_address ), }); @@ -330,7 +330,7 @@ impl ReceiptAuditor { let rav_signer_address = signed_rav.recover_signer(&self.domain_separator)?; if !self .receipt_checks_adapter - .is_valid_gateway_id(rav_signer_address) + .is_valid_sender_id(rav_signer_address) .await .map_err(|err| Error::AdapterError { source_error: anyhow::Error::new(err), diff --git a/tap_core/src/tap_receipt/tests/received_receipt_tests.rs b/tap_core/src/tap_receipt/tests/received_receipt_tests.rs index 5e01a43d..456dd0f0 100644 --- a/tap_core/src/tap_receipt/tests/received_receipt_tests.rs +++ b/tap_core/src/tap_receipt/tests/received_receipt_tests.rs @@ -54,7 +54,7 @@ mod received_receipt_unit_test { } #[fixture] - fn gateway_ids() -> Vec
{ + fn sender_ids() -> Vec
{ vec![ Address::from_str("0xfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfb").unwrap(), Address::from_str("0xfafafafafafafafafafafafafafafafafafafafa").unwrap(), @@ -73,14 +73,14 @@ mod received_receipt_unit_test { let receipt_storage_adapter = ReceiptStorageAdapterMock::new(Arc::clone(&receipt_storage)); let allocation_ids_set = Arc::new(RwLock::new(HashSet::from_iter(allocation_ids()))); - let gateway_ids_set = Arc::new(RwLock::new(HashSet::from_iter(gateway_ids()))); + let sender_ids_set = Arc::new(RwLock::new(HashSet::from_iter(sender_ids()))); let query_appraisal_storage = Arc::new(RwLock::new(HashMap::new())); let receipt_checks_adapter = ReceiptChecksAdapterMock::new( Arc::clone(&receipt_storage), Arc::clone(&query_appraisal_storage), Arc::clone(&allocation_ids_set), - Arc::clone(&gateway_ids_set), + Arc::clone(&sender_ids_set), ); ( @@ -92,9 +92,9 @@ mod received_receipt_unit_test { #[fixture] fn escrow_adapters() -> (EscrowAdapterMock, Arc>>) { - let gateway_escrow_storage = Arc::new(RwLock::new(HashMap::new())); - let escrow_adapter = EscrowAdapterMock::new(Arc::clone(&gateway_escrow_storage)); - (escrow_adapter, gateway_escrow_storage) + let sender_escrow_storage = Arc::new(RwLock::new(HashMap::new())); + let escrow_adapter = EscrowAdapterMock::new(Arc::clone(&sender_escrow_storage)); + (escrow_adapter, sender_escrow_storage) } #[fixture] @@ -169,7 +169,7 @@ mod received_receipt_unit_test { // prepare adapters and storage to correctly validate receipt - // add escrow for gateway + // add escrow for sender escrow_storage .write() .await @@ -240,7 +240,7 @@ mod received_receipt_unit_test { // prepare adapters and storage to correctly validate receipt - // add escrow for gateway + // add escrow for sender escrow_storage .write() .await @@ -321,7 +321,7 @@ mod received_receipt_unit_test { // prepare adapters and storage to correctly validate receipt - // add escrow for gateway + // add escrow for sender escrow_storage .write() .await diff --git a/tap_integration_tests/tests/showcase.rs b/tap_integration_tests/tests/showcase.rs index 2976661c..6a08d279 100644 --- a/tap_integration_tests/tests/showcase.rs +++ b/tap_integration_tests/tests/showcase.rs @@ -1,7 +1,7 @@ // Copyright 2023-, Semiotic AI, Inc. // SPDX-License-Identifier: Apache-2.0 -// These tests simulate a Gateway sending query requests and receipts to one or two Indexers. +// These tests simulate a Sender sending query requests and receipts to one or two Indexers. // The tests use a mock Indexer server running a tap_manager instance and a tap_aggregator to handle RAV requests. // An Indexer checks and stores receipts. After receiving a specific number of receipts, the Indexer sends a RAV request to the aggregator. use std::{ @@ -38,7 +38,7 @@ use tap_core::{ use crate::indexer_mock; -// Fixtures for gateway aggregator server +// Fixtures for sender aggregator server #[fixture] fn http_request_size_limit() -> u32 { 100 * 1024 @@ -84,9 +84,9 @@ fn receipt_threshold_2(num_queries: u64, num_batches: u64) -> u64 { num_queries * num_batches / 2 } -// The private key (LocalWallet) and public key (Address) of a Gateway +// The private key (LocalWallet) and public key (Address) of a Sender #[fixture] -fn keys_gateway() -> (LocalWallet, Address) { +fn keys_sender() -> (LocalWallet, Address) { let wallet: LocalWallet = MnemonicBuilder::::default() .phrase("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about") .build() @@ -98,9 +98,9 @@ fn keys_gateway() -> (LocalWallet, Address) { (wallet, address.into()) } -// The private key (LocalWallet) and public key (Address) of a Gateway. This key is used to test when the Gateway's key differs from the Indexer's expectation. +// The private key (LocalWallet) and public key (Address) of a Sender. This key is used to test when the Sender's key differs from the Indexer's expectation. #[fixture] -fn wrong_keys_gateway() -> (LocalWallet, Address) { +fn wrong_keys_sender() -> (LocalWallet, Address) { let wallet: LocalWallet = MnemonicBuilder::::default() .phrase("devote force reopen galaxy humor virtual hobby chief grit nothing bag pulse") .build() @@ -145,13 +145,13 @@ fn query_price() -> Vec { v } -// Available escrow is set by a Gateway. It's assumed the Indexer has way of knowing this value. +// Available escrow is set by a Sender. It's assumed the Indexer has way of knowing this value. #[fixture] fn available_escrow(query_price: Vec, num_batches: u64) -> u128 { (num_batches as u128) * query_price.into_iter().sum::() } -// The escrow adapter, a storage struct that the Indexer uses to track the available escrow for each Gateway +// The escrow adapter, a storage struct that the Indexer uses to track the available escrow for each Sender #[fixture] fn escrow_adapter() -> EscrowAdapterMock { EscrowAdapterMock::new(Arc::new(RwLock::new(HashMap::new()))) @@ -172,24 +172,24 @@ fn receipt_storage_adapter( // This adapter is used by the Indexer to check the validity of the receipt. #[fixture] fn receipt_checks_adapter( - keys_gateway: (LocalWallet, Address), + keys_sender: (LocalWallet, Address), query_price: Vec, allocation_ids: Vec
, receipt_storage: Arc>>, ) -> ReceiptChecksAdapterMock { - let (_, gateway_address) = keys_gateway; + let (_, sender_address) = keys_sender; let query_appraisals: HashMap<_, _> = (0u64..).zip(query_price).collect(); let query_appraisals_storage = Arc::new(RwLock::new(query_appraisals)); let allocation_ids: Arc>> = Arc::new(RwLock::new(HashSet::from_iter(allocation_ids))); - let gateway_ids: Arc>> = - Arc::new(RwLock::new(HashSet::from([gateway_address]))); + let sender_ids: Arc>> = + Arc::new(RwLock::new(HashSet::from([sender_address]))); ReceiptChecksAdapterMock::new( receipt_storage, query_appraisals_storage, allocation_ids, - gateway_ids, + sender_ids, ) } @@ -271,18 +271,18 @@ fn indexer_2_adapters( // Messages are formatted according to TAP spec and signed according to EIP-712. #[fixture] async fn requests_1( - keys_gateway: (LocalWallet, Address), + keys_sender: (LocalWallet, Address), query_price: Vec, num_batches: u64, allocation_ids: Vec
, domain_separator: Eip712Domain, ) -> Result, u64)>> { - let (gateway_key, _) = keys_gateway; + let (sender_key, _) = keys_sender; // Create your Receipt here let requests = generate_requests( query_price, num_batches, - &gateway_key, + &sender_key, allocation_ids[0], &domain_separator, ) @@ -292,18 +292,18 @@ async fn requests_1( #[fixture] async fn requests_2( - keys_gateway: (LocalWallet, Address), + keys_sender: (LocalWallet, Address), query_price: Vec, num_batches: u64, allocation_ids: Vec
, domain_separator: Eip712Domain, ) -> Result, u64)>> { - let (gateway_key, _) = keys_gateway; + let (sender_key, _) = keys_sender; // Create your Receipt here let requests = generate_requests( query_price, num_batches, - &gateway_key, + &sender_key, allocation_ids[1], &domain_separator, ) @@ -313,20 +313,20 @@ async fn requests_2( #[fixture] async fn repeated_timestamp_request( - keys_gateway: (LocalWallet, Address), + keys_sender: (LocalWallet, Address), query_price: Vec, allocation_ids: Vec
, domain_separator: Eip712Domain, num_batches: u64, receipt_threshold_1: u64, ) -> Result, u64)>> { - let (gateway_key, _) = keys_gateway; + let (sender_key, _) = keys_sender; // Create signed receipts let mut requests = generate_requests( query_price, num_batches, - &gateway_key, + &sender_key, allocation_ids[0], &domain_separator, ) @@ -347,25 +347,25 @@ async fn repeated_timestamp_request( // Sign the new receipt and insert it in the second batch requests[receipt_threshold_1 as usize].0 = - EIP712SignedMessage::new(&domain_separator, repeat_receipt, &gateway_key).await?; + EIP712SignedMessage::new(&domain_separator, repeat_receipt, &sender_key).await?; Ok(requests) } #[fixture] async fn repeated_timestamp_incremented_by_one_request( - keys_gateway: (LocalWallet, Address), + keys_sender: (LocalWallet, Address), query_price: Vec, allocation_ids: Vec
, domain_separator: Eip712Domain, num_batches: u64, receipt_threshold_1: u64, ) -> Result, u64)>> { - let (gateway_key, _) = keys_gateway; + let (sender_key, _) = keys_sender; // Create your Receipt here let mut requests = generate_requests( query_price, num_batches, - &gateway_key, + &sender_key, allocation_ids[0], &domain_separator, ) @@ -387,25 +387,25 @@ async fn repeated_timestamp_incremented_by_one_request( // Sign the new receipt and insert it in the second batch requests[receipt_threshold_1 as usize].0 = - EIP712SignedMessage::new(&domain_separator, repeat_receipt, &gateway_key).await?; + EIP712SignedMessage::new(&domain_separator, repeat_receipt, &sender_key).await?; Ok(requests) } #[fixture] async fn wrong_requests( - wrong_keys_gateway: (LocalWallet, Address), + wrong_keys_sender: (LocalWallet, Address), query_price: Vec, num_batches: u64, allocation_ids: Vec
, domain_separator: Eip712Domain, ) -> Result, u64)>> { - let (gateway_key, _) = wrong_keys_gateway; + let (sender_key, _) = wrong_keys_sender; // Create your Receipt here // Create your Receipt here let requests = generate_requests( query_price, num_batches, - &gateway_key, + &sender_key, allocation_ids[0], &domain_separator, ) @@ -416,7 +416,7 @@ async fn wrong_requests( // Helper fixtures to start servers for tests #[fixture] async fn single_indexer_test_server( - keys_gateway: (LocalWallet, Address), + keys_sender: (LocalWallet, Address), domain_separator: Eip712Domain, http_request_size_limit: u32, http_response_size_limit: u32, @@ -432,9 +432,9 @@ async fn single_indexer_test_server( required_checks: Vec, receipt_threshold_1: u64, ) -> Result<(ServerHandle, SocketAddr, ServerHandle, SocketAddr)> { - let gateway_id = keys_gateway.1; - let (gateway_aggregator_handle, gateway_aggregator_addr) = start_gateway_aggregator( - keys_gateway, + let sender_id = keys_sender.1; + let (sender_aggregator_handle, sender_aggregator_addr) = start_sender_aggregator( + keys_sender, domain_separator.clone(), http_request_size_limit, http_response_size_limit, @@ -449,25 +449,25 @@ async fn single_indexer_test_server( receipt_storage_adapter, receipt_checks_adapter, rav_storage_adapter, - gateway_id, + sender_id, available_escrow, initial_checks, required_checks, receipt_threshold_1, - gateway_aggregator_addr, + sender_aggregator_addr, ) .await?; Ok(( indexer_handle, indexer_addr, - gateway_aggregator_handle, - gateway_aggregator_addr, + sender_aggregator_handle, + sender_aggregator_addr, )) } #[fixture] async fn two_indexers_test_servers( - keys_gateway: (LocalWallet, Address), + keys_sender: (LocalWallet, Address), domain_separator: Eip712Domain, http_request_size_limit: u32, http_response_size_limit: u32, @@ -496,9 +496,9 @@ async fn two_indexers_test_servers( ServerHandle, SocketAddr, )> { - let gateway_id = keys_gateway.1; - let (gateway_aggregator_handle, gateway_aggregator_addr) = start_gateway_aggregator( - keys_gateway, + let sender_id = keys_sender.1; + let (sender_aggregator_handle, sender_aggregator_addr) = start_sender_aggregator( + keys_sender, domain_separator.clone(), http_request_size_limit, http_response_size_limit, @@ -524,12 +524,12 @@ async fn two_indexers_test_servers( receipt_storage_adapter_1, receipt_checks_adapter_1, rav_storage_adapter_1, - gateway_id, + sender_id, available_escrow, initial_checks.clone(), required_checks.clone(), receipt_threshold_1, - gateway_aggregator_addr, + sender_aggregator_addr, ) .await?; @@ -539,12 +539,12 @@ async fn two_indexers_test_servers( receipt_storage_adapter_2, receipt_checks_adapter_2, rav_storage_adapter_2, - gateway_id, + sender_id, available_escrow, initial_checks, required_checks, receipt_threshold_1, - gateway_aggregator_addr, + sender_aggregator_addr, ) .await?; @@ -553,14 +553,14 @@ async fn two_indexers_test_servers( indexer_addr, indexer_handle_2, indexer_addr_2, - gateway_aggregator_handle, - gateway_aggregator_addr, + sender_aggregator_handle, + sender_aggregator_addr, )) } #[fixture] -async fn single_indexer_wrong_gateway_test_server( - wrong_keys_gateway: (LocalWallet, Address), +async fn single_indexer_wrong_sender_test_server( + wrong_keys_sender: (LocalWallet, Address), domain_separator: Eip712Domain, http_request_size_limit: u32, http_response_size_limit: u32, @@ -576,9 +576,9 @@ async fn single_indexer_wrong_gateway_test_server( required_checks: Vec, receipt_threshold_1: u64, ) -> Result<(ServerHandle, SocketAddr, ServerHandle, SocketAddr)> { - let gateway_id = wrong_keys_gateway.1; - let (gateway_aggregator_handle, gateway_aggregator_addr) = start_gateway_aggregator( - wrong_keys_gateway, + let sender_id = wrong_keys_sender.1; + let (sender_aggregator_handle, sender_aggregator_addr) = start_sender_aggregator( + wrong_keys_sender, domain_separator.clone(), http_request_size_limit, http_response_size_limit, @@ -594,20 +594,20 @@ async fn single_indexer_wrong_gateway_test_server( receipt_storage_adapter, receipt_checks_adapter, rav_storage_adapter, - gateway_id, + sender_id, available_escrow, initial_checks, required_checks, receipt_threshold_1, - gateway_aggregator_addr, + sender_aggregator_addr, ) .await?; Ok(( indexer_handle, indexer_addr, - gateway_aggregator_handle, - gateway_aggregator_addr, + sender_aggregator_handle, + sender_aggregator_addr, )) } @@ -620,7 +620,7 @@ async fn test_manager_one_indexer( >, #[future] requests_1: Result, u64)>>, ) -> Result<(), Box> { - let (_server_handle, socket_addr, _gateway_handle, _gateway_addr) = + let (_server_handle, socket_addr, _sender_handle, _sender_addr) = single_indexer_test_server.await?; let indexer_1_address = "http://".to_string() + &socket_addr.to_string(); let client_1 = HttpClientBuilder::default().build(indexer_1_address)?; @@ -660,8 +660,8 @@ async fn test_manager_two_indexers( socket_addr_1, _server_handle_2, socket_addr_2, - _gateway_handle, - _gateway_addr, + _sender_handle, + _sender_addr, ) = two_indexers_test_servers.await?; let indexer_1_address = "http://".to_string() + &socket_addr_1.to_string(); @@ -685,15 +685,15 @@ async fn test_manager_two_indexers( #[rstest] #[tokio::test] async fn test_manager_wrong_aggregator_keys( - #[future] single_indexer_wrong_gateway_test_server: Result< + #[future] single_indexer_wrong_sender_test_server: Result< (ServerHandle, SocketAddr, ServerHandle, SocketAddr), Error, >, #[future] requests_1: Result, u64)>>, receipt_threshold_1: u64, ) -> Result<()> { - let (_server_handle, socket_addr, _gateway_handle, _gateway_addr) = - single_indexer_wrong_gateway_test_server.await?; + let (_server_handle, socket_addr, _sender_handle, _sender_addr) = + single_indexer_wrong_sender_test_server.await?; let indexer_1_address = "http://".to_string() + &socket_addr.to_string(); let client_1 = HttpClientBuilder::default().build(indexer_1_address)?; let requests = requests_1.await?; @@ -702,15 +702,15 @@ async fn test_manager_wrong_aggregator_keys( for (receipt_1, id) in requests { let result: Result<(), jsonrpsee::core::Error> = client_1.request("request", (id, receipt_1)).await; - // The rav request is being made with messages that have been signed with a key that differs from the gateway aggregator's. - // So the Gateway Aggregator should send an error to the requesting Indexer. + // The rav request is being made with messages that have been signed with a key that differs from the sender aggregator's. + // So the Sender Aggregator should send an error to the requesting Indexer. // And so the Indexer should then return an error to the clinet when a rav request is made. // A rav request is made when the number of receipts sent = receipt_threshold_1. // result should be an error when counter = multiple of receipt_threshold_1 and Ok otherwise. if (counter % receipt_threshold_1) == 0 { assert!( result.is_err(), - "Gateway Aggregator should have sent an error to the Indexer." + "Sender Aggregator should have sent an error to the Indexer." ); } else { assert!( @@ -735,7 +735,7 @@ async fn test_manager_wrong_requestor_keys( #[future] wrong_requests: Result, u64)>>, receipt_threshold_1: u64, ) -> Result<()> { - let (_server_handle, socket_addr, _gateway_handle, _gateway_addr) = + let (_server_handle, socket_addr, _sender_handle, _sender_addr) = single_indexer_test_server.await?; let indexer_1_address = "http://".to_string() + &socket_addr.to_string(); let client_1 = HttpClientBuilder::default().build(indexer_1_address)?; @@ -790,8 +790,8 @@ async fn test_tap_manager_rav_timestamp_cuttoff( socket_addr_1, _server_handle_2, socket_addr_2, - _gateway_handle, - _gateway_addr, + _sender_handle, + _sender_addr, ) = two_indexers_test_servers.await?; let indexer_1_address = "http://".to_string() + &socket_addr_1.to_string(); @@ -839,7 +839,7 @@ async fn test_tap_manager_rav_timestamp_cuttoff( #[rstest] #[tokio::test] async fn test_tap_aggregator_rav_timestamp_cuttoff( - keys_gateway: (LocalWallet, Address), + keys_sender: (LocalWallet, Address), domain_separator: Eip712Domain, http_request_size_limit: u32, http_response_size_limit: u32, @@ -851,15 +851,15 @@ async fn test_tap_aggregator_rav_timestamp_cuttoff( receipt_threshold_1: u64, ) -> Result<(), Box> { // This test checks that tap_aggregator is correctly rejecting receipts with invalid timestamps - let (gateway_handle, gateway_addr) = start_gateway_aggregator( - keys_gateway, + let (sender_handle, sender_addr) = start_sender_aggregator( + keys_sender, domain_separator, http_request_size_limit, http_response_size_limit, http_max_concurrent_connections, ) .await?; - let client = HttpClientBuilder::default().build(format!("http://{}", gateway_addr))?; + let client = HttpClientBuilder::default().build(format!("http://{}", sender_addr))?; // This is the first part of the test, two batches of receipts are sent to the aggregator. // The second batch has one receipt with the same timestamp as the latest receipt in the first batch. @@ -929,14 +929,14 @@ async fn test_tap_aggregator_rav_timestamp_cuttoff( } assert!(expected_value == second_rav_response.data.message.value_aggregate); - gateway_handle.stop()?; + sender_handle.stop()?; Ok(()) } async fn generate_requests( query_price: Vec, num_batches: u64, - gateway_key: &LocalWallet, + sender_key: &LocalWallet, allocation_id: Address, domain_separator: &Eip712Domain, ) -> Result, u64)>> { @@ -949,7 +949,7 @@ async fn generate_requests( EIP712SignedMessage::new( domain_separator, Receipt::new(allocation_id, *value)?, - gateway_key, + sender_key, ) .await?, counter, @@ -962,14 +962,14 @@ async fn generate_requests( Ok(requests) } -// Start-up a mock Indexer. Requires a Gateway Aggregator to be running. +// Start-up a mock Indexer. Requires a Sender Aggregator to be running. async fn start_indexer_server( domain_separator: Eip712Domain, mut escrow_adapter: EscrowAdapterMock, receipt_storage_adapter: ReceiptStorageAdapterMock, receipt_checks_adapter: ReceiptChecksAdapterMock, rav_storage_adapter: RAVStorageAdapterMock, - gateway_id: Address, + sender_id: Address, available_escrow: u128, initial_checks: Vec, required_checks: Vec, @@ -982,7 +982,7 @@ async fn start_indexer_server( }; escrow_adapter - .increase_escrow(gateway_id, available_escrow) + .increase_escrow(sender_id, available_escrow) .await; let aggregate_server_address = "http://".to_string() + &agg_server_addr.to_string(); @@ -1004,8 +1004,8 @@ async fn start_indexer_server( Ok((server_handle, socket_addr)) } -// Start-up a Gateway Aggregator. -async fn start_gateway_aggregator( +// Start-up a Sender Aggregator. +async fn start_sender_aggregator( keys: (LocalWallet, Address), domain_separator: Eip712Domain, http_request_size_limit: u32,