diff --git a/zebra-rpc/src/queue.rs b/zebra-rpc/src/queue.rs index 880b13cac..dd8b607f4 100644 --- a/zebra-rpc/src/queue.rs +++ b/zebra-rpc/src/queue.rs @@ -39,7 +39,7 @@ mod tests; const NUMBER_OF_BLOCKS_TO_EXPIRE: i64 = 5; /// Size of the queue and channel. -const CHANNEL_AND_QUEUE_CAPACITY: usize = 20; +pub const CHANNEL_AND_QUEUE_CAPACITY: usize = 20; /// The height to use in spacing calculation if we don't have a chain tip. const NO_CHAIN_TIP_HEIGHT: Height = Height(1); diff --git a/zebrad/src/components/mempool/downloads.rs b/zebrad/src/components/mempool/downloads.rs index 38f47f9e8..472d9b477 100644 --- a/zebrad/src/components/mempool/downloads.rs +++ b/zebrad/src/components/mempool/downloads.rs @@ -94,7 +94,7 @@ pub(crate) const TRANSACTION_VERIFY_TIMEOUT: Duration = BLOCK_VERIFY_TIMEOUT; /// Since Zebra keeps an `inv` index, inbound downloads for malicious transactions /// will be directed to the malicious node that originally gossiped the hash. /// Therefore, this attack can be carried out by a single malicious node. -pub(crate) const MAX_INBOUND_CONCURRENCY: usize = 10; +pub const MAX_INBOUND_CONCURRENCY: usize = 10; /// Errors that can occur while downloading and verifying a transaction. #[derive(Error, Debug)] diff --git a/zebrad/tests/common/lightwalletd/send_transaction_test.rs b/zebrad/tests/common/lightwalletd/send_transaction_test.rs index 2963d66e5..7578f9f29 100644 --- a/zebrad/tests/common/lightwalletd/send_transaction_test.rs +++ b/zebrad/tests/common/lightwalletd/send_transaction_test.rs @@ -14,6 +14,7 @@ //! already been seen in a block. use std::{ + cmp::min, path::{Path, PathBuf}, sync::Arc, }; @@ -26,7 +27,9 @@ use zebra_chain::{ block, chain_tip::ChainTip, parameters::Network, serialization::ZcashSerialize, transaction::Transaction, }; +use zebra_rpc::queue::CHANNEL_AND_QUEUE_CAPACITY; use zebra_state::HashOrHeight; +use zebrad::components::mempool::downloads::MAX_INBOUND_CONCURRENCY; use crate::common::{ cached_state::{load_tip_height_from_state_directory, start_state_service_with_cache_dir}, @@ -74,7 +77,7 @@ pub async fn run() -> Result<()> { "running gRPC send transaction test using lightwalletd & zebrad", ); - let transactions = + let mut transactions = load_transactions_from_a_future_block(network, zebrad_state_path.clone()).await?; tracing::info!( @@ -105,6 +108,9 @@ pub async fn run() -> Result<()> { let mut rpc_client = connect_to_lightwalletd(lightwalletd_rpc_port).await?; + // To avoid filling the mempool queue, limit the transactions to be sent to the RPC and mempool queue limits + transactions.truncate(min(CHANNEL_AND_QUEUE_CAPACITY, MAX_INBOUND_CONCURRENCY) - 1); + tracing::info!( transaction_count = ?transactions.len(), "connected gRPC client to lightwalletd, sending transactions...",