2023-04-03 02:13:01 -07:00
|
|
|
use std::{
|
|
|
|
sync::{atomic::AtomicU64, Arc},
|
|
|
|
time::Duration,
|
|
|
|
};
|
2022-12-16 18:35:49 -08:00
|
|
|
|
2023-01-12 00:55:30 -08:00
|
|
|
use bench::helpers::BenchHelper;
|
2022-12-23 11:58:42 -08:00
|
|
|
use futures::future::try_join_all;
|
2022-12-16 18:35:49 -08:00
|
|
|
use lite_rpc::{
|
2023-02-02 05:30:15 -08:00
|
|
|
block_store::BlockStore,
|
2022-12-16 18:35:49 -08:00
|
|
|
encoding::BinaryEncoding,
|
2023-04-03 02:13:01 -07:00
|
|
|
workers::{tpu_utils::tpu_service::TpuService, BlockListener, TxSender},
|
2023-04-03 04:38:43 -07:00
|
|
|
DEFAULT_RPC_ADDR, DEFAULT_WS_ADDR,
|
2022-12-16 18:35:49 -08:00
|
|
|
};
|
2023-01-31 02:02:48 -08:00
|
|
|
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
|
2022-12-16 18:35:49 -08:00
|
|
|
|
2023-02-08 13:18:09 -08:00
|
|
|
use solana_sdk::{commitment_config::CommitmentConfig, signature::Keypair};
|
2023-01-08 06:13:33 -08:00
|
|
|
use solana_transaction_status::TransactionConfirmationStatus;
|
2023-01-28 10:54:26 -08:00
|
|
|
use tokio::sync::mpsc;
|
2022-12-16 18:35:49 -08:00
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn send_and_confirm_txs() {
|
|
|
|
let rpc_client = Arc::new(RpcClient::new(DEFAULT_RPC_ADDR.to_string()));
|
2023-04-03 02:13:01 -07:00
|
|
|
let current_slot = rpc_client.get_slot().await.unwrap();
|
|
|
|
|
|
|
|
let tpu_service = TpuService::new(
|
|
|
|
Arc::new(AtomicU64::new(current_slot)),
|
|
|
|
32,
|
|
|
|
Arc::new(Keypair::new()),
|
|
|
|
rpc_client.clone(),
|
|
|
|
DEFAULT_WS_ADDR.into(),
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2022-12-27 02:11:06 -08:00
|
|
|
|
2023-04-04 01:49:58 -07:00
|
|
|
let tpu_client = Arc::new(tpu_service);
|
2022-12-16 18:35:49 -08:00
|
|
|
|
2023-01-09 23:06:24 -08:00
|
|
|
let tx_sender = TxSender::new(tpu_client);
|
2023-02-02 05:30:15 -08:00
|
|
|
let block_store = BlockStore::new(&rpc_client).await.unwrap();
|
2023-01-08 06:13:33 -08:00
|
|
|
|
2023-02-07 06:35:02 -08:00
|
|
|
let block_listener = BlockListener::new(rpc_client.clone(), tx_sender.clone(), block_store);
|
2022-12-16 18:35:49 -08:00
|
|
|
|
2023-04-03 10:01:42 -07:00
|
|
|
let (tx_send, tx_recv) = mpsc::channel(1024);
|
2023-01-28 10:54:26 -08:00
|
|
|
|
2022-12-23 11:58:42 -08:00
|
|
|
let services = try_join_all(vec![
|
2023-02-02 05:30:15 -08:00
|
|
|
block_listener
|
|
|
|
.clone()
|
|
|
|
.listen(CommitmentConfig::confirmed(), None),
|
2023-04-03 02:13:01 -07:00
|
|
|
tx_sender.clone().execute(tx_recv, None),
|
2022-12-23 11:58:42 -08:00
|
|
|
]);
|
2022-12-16 18:35:49 -08:00
|
|
|
|
|
|
|
let confirm = tokio::spawn(async move {
|
2023-02-07 13:36:47 -08:00
|
|
|
let funded_payer = BenchHelper::get_payer().await.unwrap();
|
2022-12-16 18:35:49 -08:00
|
|
|
|
|
|
|
let blockhash = rpc_client.get_latest_blockhash().await.unwrap();
|
|
|
|
|
2023-02-07 13:36:47 -08:00
|
|
|
let tx = BenchHelper::create_transaction(&funded_payer, blockhash);
|
2022-12-16 18:35:49 -08:00
|
|
|
let sig = tx.signatures[0];
|
|
|
|
let tx = BinaryEncoding::Base58.encode(bincode::serialize(&tx).unwrap());
|
|
|
|
let sig = sig.to_string();
|
|
|
|
|
2023-04-03 10:07:50 -07:00
|
|
|
let _ = tx_send.send((sig.clone(), tx.as_bytes().to_vec(), 0)).await;
|
2023-01-09 23:06:24 -08:00
|
|
|
|
2022-12-16 18:35:49 -08:00
|
|
|
for _ in 0..2 {
|
2023-03-05 14:40:02 -08:00
|
|
|
let tx_status = tx_sender.txs_sent_store.get(&sig).unwrap();
|
2023-01-08 06:13:33 -08:00
|
|
|
|
2023-01-10 06:56:41 -08:00
|
|
|
if let Some(tx_status) = &tx_status.value().status {
|
2023-01-08 09:36:37 -08:00
|
|
|
if tx_status.confirmation_status() == TransactionConfirmationStatus::Confirmed {
|
2023-01-08 06:13:33 -08:00
|
|
|
return;
|
|
|
|
}
|
2022-12-16 18:35:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
tokio::time::sleep(Duration::from_millis(800)).await;
|
|
|
|
}
|
|
|
|
|
|
|
|
panic!("Tx {sig} not confirmed in 1600ms");
|
|
|
|
});
|
|
|
|
|
|
|
|
tokio::select! {
|
|
|
|
_ = services => {
|
|
|
|
panic!("Services stopped unexpectedly")
|
|
|
|
},
|
|
|
|
_ = confirm => {}
|
|
|
|
}
|
|
|
|
}
|