Skip to content

Commit

Permalink
removes unnecessary wait_for_stdout calls and fixes condition for ear…
Browse files Browse the repository at this point in the history
…ly return
  • Loading branch information
arya2 committed Nov 29, 2024
1 parent 07fa64e commit f624891
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 24 deletions.
2 changes: 1 addition & 1 deletion zebrad/src/components/mempool/downloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub enum TransactionDownloadVerifyError {
#[error("transaction download / verification was cancelled")]
Cancelled,

#[error("transaction did not pass consensus validation, error: {0}")]
#[error("transaction did not pass consensus validation, error: {0:?}")]
Invalid(#[from] zebra_consensus::error::TransactionError),
}

Expand Down
24 changes: 1 addition & 23 deletions zebrad/tests/common/lightwalletd/send_transaction_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ pub async fn run() -> Result<()> {
?lightwalletd_rpc_port,
"connecting gRPC client to lightwalletd...",
);
zebrad.wait_for_stdout_line(None);

let mut rpc_client = connect_to_lightwalletd(lightwalletd_rpc_port).await?;

Expand All @@ -182,14 +181,11 @@ pub async fn run() -> Result<()> {
.get_mempool_tx(Exclude { txid: vec![] })
.await?
.into_inner();
zebrad.wait_for_stdout_line(None);

let mut has_tx_with_shielded_elements = false;
let mut counter = 0;

for block in blocks {
zebrad.wait_for_stdout_line(None);

let (zebrad_child, has_shielded_elements, count) = send_transactions_from_block(
zebrad,
&mut rpc_client,
Expand All @@ -199,7 +195,6 @@ pub async fn run() -> Result<()> {
.await?;

zebrad = zebrad_child;
zebrad.wait_for_stdout_line(None);

has_tx_with_shielded_elements |= has_shielded_elements;
counter += count;
Expand All @@ -208,9 +203,6 @@ pub async fn run() -> Result<()> {
}

// GetMempoolTx: make sure at least one of the transactions were inserted into the mempool.
//
// TODO: Update `load_transactions_from_future_blocks()` to return block height offsets and,
// only check if a transaction from the first block has shielded elements
assert!(
!has_tx_with_shielded_elements || counter >= 1,
"failed to read v4+ transactions with shielded elements \
Expand Down Expand Up @@ -245,7 +237,7 @@ async fn send_transactions_from_block(
.filter(|tx| !tx.is_coinbase())
.collect();

if !transactions.is_empty() {
if transactions.is_empty() {
return Ok((zebrad, false, 0));
}

Expand All @@ -272,8 +264,6 @@ async fn send_transactions_from_block(
};

tracing::info!(?transaction_hash, "sending transaction...");
// TODO: This may consume expected lines, try increasing the tracing buffer size instead if a full stdout pipe is causing panics.
zebrad.wait_for_stdout_line(None);

let request = prepare_send_transaction_request(transaction.clone());

Expand All @@ -294,24 +284,17 @@ async fn send_transactions_from_block(
// Fails if there are only coinbase transactions in the first 50 future blocks
tracing::info!("waiting for mempool to verify some transactions...");
zebrad.expect_stdout_line_matches("sending mempool transaction broadcast")?;
} else {
zebrad.wait_for_stdout_line(None);
}

// Wait for more transactions to verify, `GetMempoolTx` only returns txs where tx.HasShieldedElements()
// <https://github.com/zcash/lightwalletd/blob/master/frontend/service.go#L537>
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
zebrad.wait_for_stdout_line(None);

sleep_until_lwd_last_mempool_refresh.await;
zebrad.wait_for_stdout_line(None);

tracing::info!("calling GetMempoolTx gRPC to fetch transactions...");
let mut transactions_stream = rpc_client
.get_mempool_tx(Exclude { txid: vec![] })
.await?
.into_inner();
zebrad.wait_for_stdout_line(None);

// Sometimes lightwalletd doesn't check the mempool, and waits for the next block instead.
// If that happens, we skip the rest of the test.
Expand All @@ -335,8 +318,6 @@ async fn send_transactions_from_block(
tracing::info!("checking the mempool contains some of the sent transactions...");
let mut counter = 0;
while let Some(tx) = transactions_stream.message().await? {
zebrad.wait_for_stdout_line(None);

let hash: [u8; 32] = tx.hash.clone().try_into().expect("hash is correct length");
let hash = transaction::Hash::from_bytes_in_display_order(&hash);

Expand All @@ -348,18 +329,15 @@ async fn send_transactions_from_block(

counter += 1;
}
zebrad.wait_for_stdout_line(None);

// TODO: GetMempoolStream: make sure at least one of the transactions were inserted into the mempool.
tracing::info!("calling GetMempoolStream gRPC to fetch transactions...");
let mut transaction_stream = rpc_client.get_mempool_stream(Empty {}).await?.into_inner();
zebrad.wait_for_stdout_line(None);

let mut _counter = 0;
while let Some(_tx) = transaction_stream.message().await? {
// TODO: check tx.data or tx.height here?
_counter += 1;
zebrad.wait_for_stdout_line(None);
}

Ok((zebrad, has_tx_with_shielded_elements, counter))
Expand Down

0 comments on commit f624891

Please sign in to comment.