From bb7ae764707430c5c31768327e8be9f2b3a2a438 Mon Sep 17 00:00:00 2001 From: Warm Beer Date: Mon, 6 Jan 2025 10:28:00 +0100 Subject: [PATCH 1/5] feat: add arbitrum-sepolia-test EVM network --- evmlib/src/lib.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/evmlib/src/lib.rs b/evmlib/src/lib.rs index e2715c0ed6..bb8fff8047 100644 --- a/evmlib/src/lib.rs +++ b/evmlib/src/lib.rs @@ -27,6 +27,9 @@ pub mod testnet; pub mod utils; pub mod wallet; +/// Timeout for transactions +const TX_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(60); + static PUBLIC_ARBITRUM_ONE_HTTP_RPC_URL: LazyLock = LazyLock::new(|| { "https://arb1.arbitrum.io/rpc" .parse() @@ -45,6 +48,9 @@ const ARBITRUM_ONE_PAYMENT_TOKEN_ADDRESS: Address = const ARBITRUM_SEPOLIA_PAYMENT_TOKEN_ADDRESS: Address = address!("BE1802c27C324a28aeBcd7eeC7D734246C807194"); +const ARBITRUM_SEPOLIA_TEST_PAYMENT_TOKEN_ADDRESS: Address = + address!("4bc1aCE0E66170375462cB4E6Af42Ad4D5EC689C"); + // Should be updated when the smart contract changes! const ARBITRUM_ONE_DATA_PAYMENTS_ADDRESS: Address = address!("607483B50C5F06c25cDC316b6d1E071084EeC9f5"); @@ -52,8 +58,8 @@ const ARBITRUM_ONE_DATA_PAYMENTS_ADDRESS: Address = const ARBITRUM_SEPOLIA_DATA_PAYMENTS_ADDRESS: Address = address!("993C7739f50899A997fEF20860554b8a28113634"); -/// Timeout for transactions -const TX_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(60); +const ARBITRUM_SEPOLIA_TEST_DATA_PAYMENTS_ADDRESS: Address = + address!("7f0842a78f7d4085d975ba91d630d680f91b1295"); #[serde_as] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] @@ -81,6 +87,7 @@ pub enum Network { #[default] ArbitrumOne, ArbitrumSepolia, + ArbitrumSepoliaTest, Custom(CustomNetwork), } @@ -89,6 +96,7 @@ impl std::fmt::Display for Network { match self { Network::ArbitrumOne => write!(f, "evm-arbitrum-one"), Network::ArbitrumSepolia => write!(f, "evm-arbitrum-sepolia"), + Network::ArbitrumSepoliaTest => write!(f, "evm-arbitrum-sepolia-test"), Network::Custom(_) => write!(f, "evm-custom"), } } @@ -107,6 +115,7 @@ impl Network { match self { Network::ArbitrumOne => "arbitrum-one", Network::ArbitrumSepolia => "arbitrum-sepolia", + Network::ArbitrumSepoliaTest => "arbitrum-sepolia-test", Network::Custom(_) => "custom", } } @@ -115,6 +124,7 @@ impl Network { match self { Network::ArbitrumOne => &PUBLIC_ARBITRUM_ONE_HTTP_RPC_URL, Network::ArbitrumSepolia => &PUBLIC_ARBITRUM_SEPOLIA_HTTP_RPC_URL, + Network::ArbitrumSepoliaTest => &PUBLIC_ARBITRUM_SEPOLIA_HTTP_RPC_URL, Network::Custom(custom) => &custom.rpc_url_http, } } @@ -123,6 +133,7 @@ impl Network { match self { Network::ArbitrumOne => &ARBITRUM_ONE_PAYMENT_TOKEN_ADDRESS, Network::ArbitrumSepolia => &ARBITRUM_SEPOLIA_PAYMENT_TOKEN_ADDRESS, + Network::ArbitrumSepoliaTest => &ARBITRUM_SEPOLIA_TEST_PAYMENT_TOKEN_ADDRESS, Network::Custom(custom) => &custom.payment_token_address, } } @@ -131,6 +142,7 @@ impl Network { match self { Network::ArbitrumOne => &ARBITRUM_ONE_DATA_PAYMENTS_ADDRESS, Network::ArbitrumSepolia => &ARBITRUM_SEPOLIA_DATA_PAYMENTS_ADDRESS, + Network::ArbitrumSepoliaTest => &ARBITRUM_SEPOLIA_TEST_DATA_PAYMENTS_ADDRESS, Network::Custom(custom) => &custom.data_payments_address, } } From 3c97c91e9c6466480745c5713a088bd2f47e1e39 Mon Sep 17 00:00:00 2001 From: Warm Beer Date: Mon, 6 Jan 2025 12:19:32 +0100 Subject: [PATCH 2/5] test: add quoting test and rename existing tests --- evmlib/tests/payment_vault.rs | 78 +++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 26 deletions(-) diff --git a/evmlib/tests/payment_vault.rs b/evmlib/tests/payment_vault.rs index 41c5881cbb..b9437c6f6d 100644 --- a/evmlib/tests/payment_vault.rs +++ b/evmlib/tests/payment_vault.rs @@ -116,8 +116,8 @@ async fn test_deploy() { } #[tokio::test] -async fn test_proxy_reachable() { - let network = Network::ArbitrumOne; +async fn test_proxy_reachable_on_arb_sepolia() { + let network = Network::ArbitrumSepolia; let provider = http_provider(network.rpc_url().clone()); let payment_vault = PaymentVaultHandler::new(*network.data_payments_address(), provider); @@ -130,12 +130,38 @@ async fn test_proxy_reachable() { } #[tokio::test] -async fn test_verify_payment() { +async fn test_get_quote_on_arb_sepolia_test() { + let network = Network::ArbitrumSepoliaTest; + let provider = http_provider(network.rpc_url().clone()); + let payment_vault = PaymentVaultHandler::new(*network.data_payments_address(), provider); + + let quoting_metrics = QuotingMetrics { + close_records_stored: 10, + max_records: 16 * 1024, + received_payment_count: 0, + live_time: 1400, + network_density: Some([ + 4, 4, 224, 228, 247, 252, 14, 44, 67, 21, 153, 47, 244, 18, 232, 1, 152, 195, 44, 43, + 29, 135, 19, 217, 240, 129, 64, 245, 240, 227, 129, 162, + ]), + network_size: Some(240), + }; + + let amount = payment_vault + .get_quote(vec![quoting_metrics]) + .await + .unwrap(); + + assert_eq!(amount, vec![Amount::from(610678225049958_u64)]); +} + +#[tokio::test] +async fn test_pay_for_quotes_on_local() { let (_anvil, network_token, mut payment_vault) = setup().await; let mut quote_payments = vec![]; - for _ in 0..5 { + for _ in 0..MAX_TRANSFERS_PER_TRANSACTION { let quote_payment = random_quote_payment(); quote_payments.push(quote_payment); } @@ -149,36 +175,18 @@ async fn test_verify_payment() { // so we set it to the same as the network token contract payment_vault.set_provider(network_token.contract.provider().clone()); - let result = payment_vault.pay_for_quotes(quote_payments.clone()).await; + let result = payment_vault.pay_for_quotes(quote_payments).await; assert!(result.is_ok(), "Failed with error: {:?}", result.err()); - - let payment_verifications: Vec<_> = quote_payments - .into_iter() - .map(|v| interface::IPaymentVault::PaymentVerification { - metrics: QuotingMetrics::default().into(), - rewardsAddress: v.1, - quoteHash: v.0, - }) - .collect(); - - let results = payment_vault - .verify_payment(payment_verifications) - .await - .expect("Verify payment failed"); - - for result in results { - assert!(result.isValid); - } } #[tokio::test] -async fn test_pay_for_quotes() { +async fn test_verify_payment_on_local() { let (_anvil, network_token, mut payment_vault) = setup().await; let mut quote_payments = vec![]; - for _ in 0..MAX_TRANSFERS_PER_TRANSACTION { + for _ in 0..5 { let quote_payment = random_quote_payment(); quote_payments.push(quote_payment); } @@ -192,7 +200,25 @@ async fn test_pay_for_quotes() { // so we set it to the same as the network token contract payment_vault.set_provider(network_token.contract.provider().clone()); - let result = payment_vault.pay_for_quotes(quote_payments).await; + let result = payment_vault.pay_for_quotes(quote_payments.clone()).await; assert!(result.is_ok(), "Failed with error: {:?}", result.err()); + + let payment_verifications: Vec<_> = quote_payments + .into_iter() + .map(|v| interface::IPaymentVault::PaymentVerification { + metrics: QuotingMetrics::default().into(), + rewardsAddress: v.1, + quoteHash: v.0, + }) + .collect(); + + let results = payment_vault + .verify_payment(payment_verifications) + .await + .expect("Verify payment failed"); + + for result in results { + assert!(result.isValid); + } } From 0a7422e2bd2d701a91729999bdefdfe68b0d39b6 Mon Sep 17 00:00:00 2001 From: Warm Beer Date: Mon, 6 Jan 2025 13:06:44 +0100 Subject: [PATCH 3/5] feat: add arb sepolia test network subcommand to node and manager --- ant-node-manager/src/bin/cli/subcommands/evm_network.rs | 4 ++++ ant-node/src/bin/antnode/subcommands.rs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/ant-node-manager/src/bin/cli/subcommands/evm_network.rs b/ant-node-manager/src/bin/cli/subcommands/evm_network.rs index 2d795846cf..868c33aea2 100644 --- a/ant-node-manager/src/bin/cli/subcommands/evm_network.rs +++ b/ant-node-manager/src/bin/cli/subcommands/evm_network.rs @@ -19,6 +19,9 @@ pub enum EvmNetworkCommand { /// Use the Arbitrum Sepolia network EvmArbitrumSepolia, + /// Use the Arbitrum Sepolia network with test contracts + EvmArbitrumSepoliaTest, + /// Use a custom network EvmCustom { /// The RPC URL for the custom network @@ -45,6 +48,7 @@ impl TryInto for EvmNetworkCommand { match self { Self::EvmArbitrumOne => Ok(EvmNetwork::ArbitrumOne), Self::EvmArbitrumSepolia => Ok(EvmNetwork::ArbitrumSepolia), + Self::EvmArbitrumSepoliaTest => Ok(EvmNetwork::ArbitrumSepoliaTest), Self::EvmLocal => { if !cfg!(feature = "local") { return Err(color_eyre::eyre::eyre!( diff --git a/ant-node/src/bin/antnode/subcommands.rs b/ant-node/src/bin/antnode/subcommands.rs index a9e02d2be4..52c48f1ea7 100644 --- a/ant-node/src/bin/antnode/subcommands.rs +++ b/ant-node/src/bin/antnode/subcommands.rs @@ -10,6 +10,9 @@ pub(crate) enum EvmNetworkCommand { /// Use the Arbitrum Sepolia network EvmArbitrumSepolia, + /// Use the Arbitrum Sepolia network with test contracts + EvmArbitrumSepoliaTest, + /// Use a custom network EvmCustom { /// The RPC URL for the custom network @@ -32,6 +35,7 @@ impl Into for EvmNetworkCommand { match self { Self::EvmArbitrumOne => EvmNetwork::ArbitrumOne, Self::EvmArbitrumSepolia => EvmNetwork::ArbitrumSepolia, + Self::EvmArbitrumSepoliaTest => EvmNetwork::ArbitrumSepoliaTest, Self::EvmCustom { rpc_url, payment_token_address, From 8da56e549848feb6e35196f02e46f5c71eb537f5 Mon Sep 17 00:00:00 2001 From: Warm Beer Date: Mon, 6 Jan 2025 13:41:27 +0100 Subject: [PATCH 4/5] feat: add arb sepolia test network to evmlib util --- evmlib/src/utils.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/evmlib/src/utils.rs b/evmlib/src/utils.rs index 4e3133713f..8e679d95d7 100644 --- a/evmlib/src/utils.rs +++ b/evmlib/src/utils.rs @@ -112,12 +112,19 @@ pub fn get_evm_network_from_env() -> Result { .map(|v| v == "arbitrum-sepolia") .unwrap_or(false); + let use_arbitrum_sepolia_test = std::env::var("EVM_NETWORK") + .map(|v| v == "arbitrum-sepolia-test") + .unwrap_or(false); + if use_arbitrum_one { info!("Using Arbitrum One EVM network as EVM_NETWORK is set to 'arbitrum-one'"); Ok(Network::ArbitrumOne) } else if use_arbitrum_sepolia { info!("Using Arbitrum Sepolia EVM network as EVM_NETWORK is set to 'arbitrum-sepolia'"); Ok(Network::ArbitrumSepolia) + } else if use_arbitrum_sepolia_test { + info!("Using Arbitrum Sepolia Test EVM network as EVM_NETWORK is set to 'arbitrum-sepolia-test'"); + Ok(Network::ArbitrumSepoliaTest) } else if let Ok(evm_vars) = evm_vars { info!("Using custom EVM network from environment variables"); Ok(Network::Custom(CustomNetwork::new( From ef35c1b21a9bb72f39f2acc280f2b24842bdd65c Mon Sep 17 00:00:00 2001 From: Warm Beer Date: Mon, 6 Jan 2025 14:09:05 +0100 Subject: [PATCH 5/5] chore: add more logging to the fetch store quotes fn --- autonomi/src/client/quote.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/autonomi/src/client/quote.rs b/autonomi/src/client/quote.rs index ca8c515ad4..b89e1bbf34 100644 --- a/autonomi/src/client/quote.rs +++ b/autonomi/src/client/quote.rs @@ -62,6 +62,7 @@ impl Client { .into_iter() .map(|content_addr| fetch_store_quote_with_retries(&self.network, content_addr)) .collect(); + let raw_quotes_per_addr = futures::future::try_join_all(futures).await?; // choose the quotes to pay for each address @@ -70,9 +71,15 @@ impl Client { let mut rate_limiter = RateLimiter::new(); for (content_addr, raw_quotes) in raw_quotes_per_addr { + debug!( + "fetching market price for content_addr: {content_addr}, with {} quotes.", + raw_quotes.len() + ); + // FIXME: find better way to deal with paid content addrs and feedback to the user // assume that content addr is already paid for and uploaded if raw_quotes.is_empty() { + debug!("content_addr: {content_addr} is already paid for. No need to fetch market price."); continue; } @@ -90,6 +97,8 @@ impl Client { ) .await?; + debug!("market prices: {all_prices:?}"); + let mut prices: Vec<(PeerId, PaymentQuote, Amount)> = all_prices .into_iter() .zip(raw_quotes.into_iter())