Skip to content

Commit

Permalink
Add transactions to the list, rather than replacing the list with eac…
Browse files Browse the repository at this point in the history
…h new block
  • Loading branch information
teor2345 committed Sep 5, 2022
1 parent 46d9fc0 commit d1f8b32
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions zebrad/tests/common/lightwalletd/send_transaction_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -320,7 +337,7 @@ async fn load_transactions_from_block_after(
async fn load_transactions_from_block<ReadStateService>(
height: block::Height,
state: &mut ReadStateService,
) -> Result<Vec<Arc<Transaction>>>
) -> Result<Option<Vec<Arc<Transaction>>>>
where
ReadStateService: Service<
zebra_state::ReadRequest,
Expand All @@ -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.
Expand Down

0 comments on commit d1f8b32

Please sign in to comment.