Skip to content

Commit

Permalink
avoids panic when a future block has only a coinbase transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
arya2 committed Nov 26, 2024
1 parent 4467929 commit 55bcd27
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions zebrad/tests/common/lightwalletd/send_transaction_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,19 @@ pub async fn run() -> Result<()> {
let mut counter = 0;

for block in blocks {
let (zebrad_child, has_shielded_elements, count) =
send_transactions_from_block(zebrad, &mut rpc_client, &zebrad_rpc_client, block)
.await?;
let (zebrad_child, has_shielded_elements, count) = send_transactions_from_block(
zebrad,
&mut rpc_client,
&zebrad_rpc_client,
block.clone(),
)
.await?;

zebrad = zebrad_child;
has_tx_with_shielded_elements |= has_shielded_elements;
counter += count;

zebrad_rpc_client.submit_block(block).await?;
}

// GetMempoolTx: make sure at least one of the transactions were inserted into the mempool.
Expand Down Expand Up @@ -231,6 +237,10 @@ async fn send_transactions_from_block(
.filter(|tx| !tx.is_coinbase())
.collect();

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

let transaction_hashes: Vec<transaction::Hash> =
transactions.iter().map(|tx| tx.hash()).collect();

Expand All @@ -241,7 +251,7 @@ async fn send_transactions_from_block(
);

let mut has_tx_with_shielded_elements = false;
for transaction in transactions {
for &transaction in &transactions {
let transaction_hash = transaction.hash();

// See <https://github.com/zcash/lightwalletd/blob/master/parser/transaction.go#L367>
Expand Down Expand Up @@ -329,8 +339,6 @@ async fn send_transactions_from_block(
_counter += 1;
}

zebrad_rpc_client.submit_block(block).await?;

Ok((zebrad, has_tx_with_shielded_elements, counter))
}

Expand Down

0 comments on commit 55bcd27

Please sign in to comment.