2023-01-12 00:55:30 -08:00
|
|
|
use std::{sync::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-01-16 23:05:24 -08:00
|
|
|
tpu_manager::TpuManager,
|
2022-12-16 18:35:49 -08:00
|
|
|
workers::{BlockListener, TxSender},
|
2023-02-07 13:36:47 -08:00
|
|
|
DEFAULT_RPC_ADDR, DEFAULT_TX_BATCH_INTERVAL_MS, DEFAULT_TX_BATCH_SIZE, 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()));
|
2022-12-27 02:11:06 -08:00
|
|
|
|
2022-12-16 18:35:49 -08:00
|
|
|
let tpu_client = Arc::new(
|
2023-01-16 23:05:24 -08:00
|
|
|
TpuManager::new(
|
|
|
|
rpc_client.clone(),
|
|
|
|
DEFAULT_WS_ADDR.into(),
|
|
|
|
Default::default(),
|
2023-02-08 13:18:09 -08:00
|
|
|
Keypair::new(),
|
2023-01-16 23:05:24 -08:00
|
|
|
)
|
|
|
|
.await
|
|
|
|
.unwrap(),
|
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-01-28 10:54:26 -08:00
|
|
|
let (tx_send, tx_recv) = mpsc::unbounded_channel();
|
|
|
|
|
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-01-09 23:06:24 -08:00
|
|
|
tx_sender.clone().execute(
|
2023-01-28 10:54:26 -08:00
|
|
|
tx_recv,
|
2023-01-09 23:06:24 -08:00
|
|
|
DEFAULT_TX_BATCH_SIZE,
|
|
|
|
Duration::from_millis(DEFAULT_TX_BATCH_INTERVAL_MS),
|
2023-01-28 11:10:49 -08:00
|
|
|
None,
|
2023-01-09 23:06:24 -08:00
|
|
|
),
|
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-01-28 10:54:26 -08:00
|
|
|
tx_send
|
|
|
|
.send((sig.clone(), tx.as_bytes().to_vec(), 0))
|
|
|
|
.unwrap();
|
2023-01-09 23:06:24 -08:00
|
|
|
|
2022-12-16 18:35:49 -08:00
|
|
|
for _ in 0..2 {
|
2023-01-09 23:06:24 -08:00
|
|
|
let tx_status = tx_sender.txs_sent.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 => {}
|
|
|
|
}
|
|
|
|
}
|