Improve program-test process_transaction() speed by reducing sleep duration in banks-server (backport #20508) (#20733)
* 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>
(cherry picked from commit bea181eba9
)
# Conflicts:
# banks-server/src/banks_server.rs
# program-test/src/lib.rs
* Fix merge issues
Co-authored-by: Christian Kamm <ckamm@delightful-solutions.de>
Co-authored-by: Jon Cinque <jon.cinque@gmail.com>
This commit is contained in:
@@ -27,6 +27,7 @@ use {
|
||||
instruction::InstructionError,
|
||||
message::Message,
|
||||
native_token::sol_to_lamports,
|
||||
poh_config::PohConfig,
|
||||
process_instruction::{
|
||||
stable_log, BpfComputeBudget, InvokeContext, ProcessInstructionWithContext,
|
||||
},
|
||||
@@ -754,7 +755,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,
|
||||
@@ -767,6 +768,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);
|
||||
|
||||
@@ -836,8 +839,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));
|
||||
@@ -845,7 +853,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
|
||||
@@ -866,8 +873,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