From d1f8b3299a58b971fc712ef4577ad3087fb35cde Mon Sep 17 00:00:00 2001 From: teor Date: Mon, 5 Sep 2022 13:54:14 +1000 Subject: [PATCH] Add transactions to the list, rather than replacing the list with each new block --- .../lightwalletd/send_transaction_test.rs | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/zebrad/tests/common/lightwalletd/send_transaction_test.rs b/zebrad/tests/common/lightwalletd/send_transaction_test.rs index 57738b189f6..78b32e66b1e 100644 --- a/zebrad/tests/common/lightwalletd/send_transaction_test.rs +++ b/zebrad/tests/common/lightwalletd/send_transaction_test.rs @@ -296,21 +296,38 @@ async fn load_transactions_from_block_after( assert!( tip_height > height, - "Chain not synchronized to a block after the specified height" + "Chain not synchronized to a block after the specified height", ); let mut target_height = height.0; let mut transactions = Vec::new(); while transactions.len() < max_sent_transactions() { - transactions = + let mut new_transactions = load_transactions_from_block(block::Height(target_height), &mut state).await?; - transactions.retain(|transaction| !transaction.is_coinbase()); + if let Some(new_transactions) = new_transactions { + new_transactions.retain(|transaction| !transaction.is_coinbase()); + transactions.append(new_transactions); + } else { + tracing::info!( + "Reached the end of the finalized chain\n\ + collected {} transactions from {} blocks before {target_height:?}", + transactions.len(), + target_height.0 - height.0 - 1, + ); + break; + } target_height += 1; } + tracing::info!( + "Collected {} transactions from {} blocks before {target_height:?}", + transactions.len(), + target_height.0 - height.0 - 1, + ); + Ok(transactions) } @@ -320,7 +337,7 @@ async fn load_transactions_from_block_after( async fn load_transactions_from_block( height: block::Height, state: &mut ReadStateService, -) -> Result>> +) -> Result>>> where ReadStateService: Service< zebra_state::ReadRequest, @@ -339,12 +356,15 @@ where let block = match response { zebra_state::ReadResponse::Block(Some(block)) => block, zebra_state::ReadResponse::Block(None) => { - panic!("Missing block at {height:?} from state") + tracing::info!( + "Reached the end of the finalized chain, state is missing block at {height:?}", + ); + return Ok(None); } _ => unreachable!("Incorrect response from state service: {response:?}"), }; - Ok(block.transactions.to_vec()) + Ok(Some(block.transactions.to_vec())) } /// Prepare a request to send to lightwalletd that contains a transaction to be sent.