Improve program-test process_transaction() speed by reducing sleep duration in banks-server (#20508)
* banks_server: Reduce sleep duration for local server This speeds up process_transaction_with_commitment_and_context() and thus most program tests by a lot. * Plumb tick duration through poh config and signature polling Co-authored-by: Jon Cinque <jon.cinque@gmail.com>
This commit is contained in:
@ -32,6 +32,7 @@ use {
|
||||
instruction::InstructionError,
|
||||
message::Message,
|
||||
native_token::sol_to_lamports,
|
||||
poh_config::PohConfig,
|
||||
process_instruction::{stable_log, InvokeContext, ProcessInstructionWithContext},
|
||||
program_error::{ProgramError, ACCOUNT_BORROW_FAILED, UNSUPPORTED_SYSVAR},
|
||||
pubkey::Pubkey,
|
||||
@ -756,7 +757,7 @@ impl ProgramTest {
|
||||
let mint_keypair = Keypair::new();
|
||||
let voting_keypair = Keypair::new();
|
||||
|
||||
let genesis_config = create_genesis_config_with_leader_ex(
|
||||
let mut genesis_config = create_genesis_config_with_leader_ex(
|
||||
sol_to_lamports(1_000_000.0),
|
||||
&mint_keypair.pubkey(),
|
||||
&bootstrap_validator_pubkey,
|
||||
@ -769,6 +770,8 @@ impl ProgramTest {
|
||||
ClusterType::Development,
|
||||
vec![],
|
||||
);
|
||||
let target_tick_duration = Duration::from_micros(100);
|
||||
genesis_config.poh_config = PohConfig::new_sleep(target_tick_duration);
|
||||
debug!("Payer address: {}", mint_keypair.pubkey());
|
||||
debug!("Genesis config: {}", genesis_config);
|
||||
|
||||
@ -838,8 +841,13 @@ impl ProgramTest {
|
||||
|
||||
pub async fn start(self) -> (BanksClient, Keypair, Hash) {
|
||||
let (bank_forks, block_commitment_cache, last_blockhash, gci) = self.setup_bank();
|
||||
let transport =
|
||||
start_local_server(bank_forks.clone(), block_commitment_cache.clone()).await;
|
||||
let target_tick_duration = gci.genesis_config.poh_config.target_tick_duration;
|
||||
let transport = start_local_server(
|
||||
bank_forks.clone(),
|
||||
block_commitment_cache.clone(),
|
||||
target_tick_duration,
|
||||
)
|
||||
.await;
|
||||
let banks_client = start_client(transport)
|
||||
.await
|
||||
.unwrap_or_else(|err| panic!("Failed to start banks client: {}", err));
|
||||
@ -847,7 +855,6 @@ impl ProgramTest {
|
||||
// Run a simulated PohService to provide the client with new blockhashes. New blockhashes
|
||||
// are required when sending multiple otherwise identical transactions in series from a
|
||||
// test
|
||||
let target_tick_duration = gci.genesis_config.poh_config.target_tick_duration;
|
||||
tokio::spawn(async move {
|
||||
loop {
|
||||
bank_forks
|
||||
@ -868,8 +875,13 @@ impl ProgramTest {
|
||||
/// with SOL for sending transactions
|
||||
pub async fn start_with_context(self) -> ProgramTestContext {
|
||||
let (bank_forks, block_commitment_cache, last_blockhash, gci) = self.setup_bank();
|
||||
let transport =
|
||||
start_local_server(bank_forks.clone(), block_commitment_cache.clone()).await;
|
||||
let target_tick_duration = gci.genesis_config.poh_config.target_tick_duration;
|
||||
let transport = start_local_server(
|
||||
bank_forks.clone(),
|
||||
block_commitment_cache.clone(),
|
||||
target_tick_duration,
|
||||
)
|
||||
.await;
|
||||
let banks_client = start_client(transport)
|
||||
.await
|
||||
.unwrap_or_else(|err| panic!("Failed to start banks client: {}", err));
|
||||
|
Reference in New Issue
Block a user