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:
@ -385,7 +385,9 @@ mod tests {
|
|||||||
let message = Message::new(&[instruction], Some(&mint_pubkey));
|
let message = Message::new(&[instruction], Some(&mint_pubkey));
|
||||||
|
|
||||||
Runtime::new()?.block_on(async {
|
Runtime::new()?.block_on(async {
|
||||||
let client_transport = start_local_server(bank_forks, block_commitment_cache).await;
|
let client_transport =
|
||||||
|
start_local_server(bank_forks, block_commitment_cache, Duration::from_millis(1))
|
||||||
|
.await;
|
||||||
let mut banks_client = start_client(client_transport).await?;
|
let mut banks_client = start_client(client_transport).await?;
|
||||||
|
|
||||||
let recent_blockhash = banks_client.get_recent_blockhash().await?;
|
let recent_blockhash = banks_client.get_recent_blockhash().await?;
|
||||||
@ -416,7 +418,9 @@ mod tests {
|
|||||||
let message = Message::new(&[instruction], Some(mint_pubkey));
|
let message = Message::new(&[instruction], Some(mint_pubkey));
|
||||||
|
|
||||||
Runtime::new()?.block_on(async {
|
Runtime::new()?.block_on(async {
|
||||||
let client_transport = start_local_server(bank_forks, block_commitment_cache).await;
|
let client_transport =
|
||||||
|
start_local_server(bank_forks, block_commitment_cache, Duration::from_millis(1))
|
||||||
|
.await;
|
||||||
let mut banks_client = start_client(client_transport).await?;
|
let mut banks_client = start_client(client_transport).await?;
|
||||||
let (_, recent_blockhash, last_valid_block_height) = banks_client.get_fees().await?;
|
let (_, recent_blockhash, last_valid_block_height) = banks_client.get_fees().await?;
|
||||||
let transaction = Transaction::new(&[&genesis.mint_keypair], message, recent_blockhash);
|
let transaction = Transaction::new(&[&genesis.mint_keypair], message, recent_blockhash);
|
||||||
|
@ -43,6 +43,7 @@ struct BanksServer {
|
|||||||
bank_forks: Arc<RwLock<BankForks>>,
|
bank_forks: Arc<RwLock<BankForks>>,
|
||||||
block_commitment_cache: Arc<RwLock<BlockCommitmentCache>>,
|
block_commitment_cache: Arc<RwLock<BlockCommitmentCache>>,
|
||||||
transaction_sender: Sender<TransactionInfo>,
|
transaction_sender: Sender<TransactionInfo>,
|
||||||
|
poll_signature_status_sleep_duration: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BanksServer {
|
impl BanksServer {
|
||||||
@ -54,11 +55,13 @@ impl BanksServer {
|
|||||||
bank_forks: Arc<RwLock<BankForks>>,
|
bank_forks: Arc<RwLock<BankForks>>,
|
||||||
block_commitment_cache: Arc<RwLock<BlockCommitmentCache>>,
|
block_commitment_cache: Arc<RwLock<BlockCommitmentCache>>,
|
||||||
transaction_sender: Sender<TransactionInfo>,
|
transaction_sender: Sender<TransactionInfo>,
|
||||||
|
poll_signature_status_sleep_duration: Duration,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
bank_forks,
|
bank_forks,
|
||||||
block_commitment_cache,
|
block_commitment_cache,
|
||||||
transaction_sender,
|
transaction_sender,
|
||||||
|
poll_signature_status_sleep_duration,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,6 +84,7 @@ impl BanksServer {
|
|||||||
fn new_loopback(
|
fn new_loopback(
|
||||||
bank_forks: Arc<RwLock<BankForks>>,
|
bank_forks: Arc<RwLock<BankForks>>,
|
||||||
block_commitment_cache: Arc<RwLock<BlockCommitmentCache>>,
|
block_commitment_cache: Arc<RwLock<BlockCommitmentCache>>,
|
||||||
|
poll_signature_status_sleep_duration: Duration,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let (transaction_sender, transaction_receiver) = channel();
|
let (transaction_sender, transaction_receiver) = channel();
|
||||||
let bank = bank_forks.read().unwrap().working_bank();
|
let bank = bank_forks.read().unwrap().working_bank();
|
||||||
@ -95,7 +99,12 @@ impl BanksServer {
|
|||||||
.name("solana-bank-forks-client".to_string())
|
.name("solana-bank-forks-client".to_string())
|
||||||
.spawn(move || Self::run(server_bank_forks, transaction_receiver))
|
.spawn(move || Self::run(server_bank_forks, transaction_receiver))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Self::new(bank_forks, block_commitment_cache, transaction_sender)
|
Self::new(
|
||||||
|
bank_forks,
|
||||||
|
block_commitment_cache,
|
||||||
|
transaction_sender,
|
||||||
|
poll_signature_status_sleep_duration,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn slot(&self, commitment: CommitmentLevel) -> Slot {
|
fn slot(&self, commitment: CommitmentLevel) -> Slot {
|
||||||
@ -120,7 +129,7 @@ impl BanksServer {
|
|||||||
.bank(commitment)
|
.bank(commitment)
|
||||||
.get_signature_status_with_blockhash(signature, blockhash);
|
.get_signature_status_with_blockhash(signature, blockhash);
|
||||||
while status.is_none() {
|
while status.is_none() {
|
||||||
sleep(Duration::from_millis(200)).await;
|
sleep(self.poll_signature_status_sleep_duration).await;
|
||||||
let bank = self.bank(commitment);
|
let bank = self.bank(commitment);
|
||||||
if bank.block_height() > last_valid_block_height {
|
if bank.block_height() > last_valid_block_height {
|
||||||
break;
|
break;
|
||||||
@ -264,8 +273,13 @@ impl Banks for BanksServer {
|
|||||||
pub async fn start_local_server(
|
pub async fn start_local_server(
|
||||||
bank_forks: Arc<RwLock<BankForks>>,
|
bank_forks: Arc<RwLock<BankForks>>,
|
||||||
block_commitment_cache: Arc<RwLock<BlockCommitmentCache>>,
|
block_commitment_cache: Arc<RwLock<BlockCommitmentCache>>,
|
||||||
|
poll_signature_status_sleep_duration: Duration,
|
||||||
) -> UnboundedChannel<Response<BanksResponse>, ClientMessage<BanksRequest>> {
|
) -> UnboundedChannel<Response<BanksResponse>, ClientMessage<BanksRequest>> {
|
||||||
let banks_server = BanksServer::new_loopback(bank_forks, block_commitment_cache);
|
let banks_server = BanksServer::new_loopback(
|
||||||
|
bank_forks,
|
||||||
|
block_commitment_cache,
|
||||||
|
poll_signature_status_sleep_duration,
|
||||||
|
);
|
||||||
let (client_transport, server_transport) = transport::channel::unbounded();
|
let (client_transport, server_transport) = transport::channel::unbounded();
|
||||||
let server = server::new(server::Config::default())
|
let server = server::new(server::Config::default())
|
||||||
.incoming(stream::once(future::ready(server_transport)))
|
.incoming(stream::once(future::ready(server_transport)))
|
||||||
@ -300,8 +314,12 @@ pub async fn start_tcp_server(
|
|||||||
|
|
||||||
SendTransactionService::new(tpu_addr, &bank_forks, receiver);
|
SendTransactionService::new(tpu_addr, &bank_forks, receiver);
|
||||||
|
|
||||||
let server =
|
let server = BanksServer::new(
|
||||||
BanksServer::new(bank_forks.clone(), block_commitment_cache.clone(), sender);
|
bank_forks.clone(),
|
||||||
|
block_commitment_cache.clone(),
|
||||||
|
sender,
|
||||||
|
Duration::from_millis(200),
|
||||||
|
);
|
||||||
chan.respond_with(server.serve()).execute()
|
chan.respond_with(server.serve()).execute()
|
||||||
})
|
})
|
||||||
// Max 10 channels.
|
// Max 10 channels.
|
||||||
|
@ -27,6 +27,7 @@ use {
|
|||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
message::Message,
|
message::Message,
|
||||||
native_token::sol_to_lamports,
|
native_token::sol_to_lamports,
|
||||||
|
poh_config::PohConfig,
|
||||||
process_instruction::{
|
process_instruction::{
|
||||||
stable_log, BpfComputeBudget, InvokeContext, ProcessInstructionWithContext,
|
stable_log, BpfComputeBudget, InvokeContext, ProcessInstructionWithContext,
|
||||||
},
|
},
|
||||||
@ -754,7 +755,7 @@ impl ProgramTest {
|
|||||||
let mint_keypair = Keypair::new();
|
let mint_keypair = Keypair::new();
|
||||||
let voting_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),
|
sol_to_lamports(1_000_000.0),
|
||||||
&mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
&bootstrap_validator_pubkey,
|
&bootstrap_validator_pubkey,
|
||||||
@ -767,6 +768,8 @@ impl ProgramTest {
|
|||||||
ClusterType::Development,
|
ClusterType::Development,
|
||||||
vec![],
|
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!("Payer address: {}", mint_keypair.pubkey());
|
||||||
debug!("Genesis config: {}", genesis_config);
|
debug!("Genesis config: {}", genesis_config);
|
||||||
|
|
||||||
@ -836,8 +839,13 @@ impl ProgramTest {
|
|||||||
|
|
||||||
pub async fn start(self) -> (BanksClient, Keypair, Hash) {
|
pub async fn start(self) -> (BanksClient, Keypair, Hash) {
|
||||||
let (bank_forks, block_commitment_cache, last_blockhash, gci) = self.setup_bank();
|
let (bank_forks, block_commitment_cache, last_blockhash, gci) = self.setup_bank();
|
||||||
let transport =
|
let target_tick_duration = gci.genesis_config.poh_config.target_tick_duration;
|
||||||
start_local_server(bank_forks.clone(), block_commitment_cache.clone()).await;
|
let transport = start_local_server(
|
||||||
|
bank_forks.clone(),
|
||||||
|
block_commitment_cache.clone(),
|
||||||
|
target_tick_duration,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
let banks_client = start_client(transport)
|
let banks_client = start_client(transport)
|
||||||
.await
|
.await
|
||||||
.unwrap_or_else(|err| panic!("Failed to start banks client: {}", err));
|
.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
|
// 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
|
// are required when sending multiple otherwise identical transactions in series from a
|
||||||
// test
|
// test
|
||||||
let target_tick_duration = gci.genesis_config.poh_config.target_tick_duration;
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
loop {
|
loop {
|
||||||
bank_forks
|
bank_forks
|
||||||
@ -866,8 +873,13 @@ impl ProgramTest {
|
|||||||
/// with SOL for sending transactions
|
/// with SOL for sending transactions
|
||||||
pub async fn start_with_context(self) -> ProgramTestContext {
|
pub async fn start_with_context(self) -> ProgramTestContext {
|
||||||
let (bank_forks, block_commitment_cache, last_blockhash, gci) = self.setup_bank();
|
let (bank_forks, block_commitment_cache, last_blockhash, gci) = self.setup_bank();
|
||||||
let transport =
|
let target_tick_duration = gci.genesis_config.poh_config.target_tick_duration;
|
||||||
start_local_server(bank_forks.clone(), block_commitment_cache.clone()).await;
|
let transport = start_local_server(
|
||||||
|
bank_forks.clone(),
|
||||||
|
block_commitment_cache.clone(),
|
||||||
|
target_tick_duration,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
let banks_client = start_client(transport)
|
let banks_client = start_client(transport)
|
||||||
.await
|
.await
|
||||||
.unwrap_or_else(|err| panic!("Failed to start banks client: {}", err));
|
.unwrap_or_else(|err| panic!("Failed to start banks client: {}", err));
|
||||||
|
Reference in New Issue
Block a user