Skip to content

Commit

Permalink
fix(test): truncate the number of transactions in send transaction te…
Browse files Browse the repository at this point in the history
…st (#4848)

* truncate the number of transactions in send transaction test

* Limit send transaction test to RPC queue length

Co-authored-by: teor <[email protected]>
  • Loading branch information
oxarbitrage and teor2345 authored Aug 1, 2022
1 parent e9c9ea9 commit a6f15e8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion zebra-rpc/src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion zebrad/src/components/mempool/downloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
8 changes: 7 additions & 1 deletion zebrad/tests/common/lightwalletd/send_transaction_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
//! already been seen in a block.
use std::{
cmp::min,
path::{Path, PathBuf},
sync::Arc,
};
Expand All @@ -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},
Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -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...",
Expand Down

0 comments on commit a6f15e8

Please sign in to comment.