actually spawn tasks

This commit is contained in:
Maximilian Schneider 2023-02-04 02:14:14 +09:00
parent 17ba55eac6
commit 6287f1c344
4 changed files with 13 additions and 7 deletions

View File

@ -38,7 +38,7 @@ pub async fn init(client: Arc<RpcClient>) -> Arc<RwLock<Hash>> {
let join_hdl = {
// create a thread-local reference to blockhash
let blockhash_c = blockhash.clone();
spawn(async move { poll_loop(blockhash_c, client) })
spawn(async move { poll_loop(blockhash_c, client).await })
};
return blockhash;

View File

@ -112,6 +112,8 @@ async fn main() -> anyhow::Result<()> {
)
.expect("init transaction builder");
// TODO: throttle cranking, currently runs very fast
// TODO: use real keypair from config / env
transaction_sender::init(instruction_receiver, blockhash, rpc_client, Keypair::new());
info!(

View File

@ -97,7 +97,7 @@ pub fn init(
Ok(account_info) => {
// only process if the account state changed
let evq_version = (account_info.slot, account_info.write_version);
trace!("evq={evq_b58} write_version={:?}", evq_version);
trace!("mango perp evq={evq_b58} write_version={:?}", evq_version);
if evq_version == *last_evq_version {
continue;
}
@ -110,7 +110,6 @@ pub fn init(
account.data().borrow_mut(),
)
.unwrap();
trace!("evq={evq_b58} seq_num={}", event_queue.header.seq_num);
if !event_queue.empty() {
let mango_accounts: HashSet<_> = event_queue
@ -157,6 +156,7 @@ pub fn init(
),
};
info!("mango perp evq={evq_b58} count={} limit=10", event_queue.iter().count());
instruction_sender.send(vec![ix]).await;
}
}
@ -172,11 +172,11 @@ pub fn init(
Ok(account_info) => {
// only process if the account state changed
let evq_version = (account_info.slot, account_info.write_version);
trace!("evq={evq_b58} write_version={:?}", evq_version);
trace!("serum evq={evq_b58} write_version={:?}", evq_version);
if evq_version == *last_evq_version {
continue;
}
last_evq_versions.insert(evq_b58, evq_version);
last_evq_versions.insert(evq_b58.clone(), evq_version);
let account = &account_info.account;
@ -234,6 +234,7 @@ pub fn init(
data: MarketInstruction::ConsumeEvents(count as u16).pack(),
};
info!("serum evq={evq_b58} count={count}");
instruction_sender.send(vec![ix]).await;
}
}

View File

@ -1,3 +1,4 @@
use log::*;
use solana_client::{nonblocking::rpc_client::RpcClient, rpc_config::RpcSendTransactionConfig};
use solana_sdk::{
hash::Hash, instruction::Instruction, signature::Keypair, signature::Signer,
@ -12,12 +13,14 @@ pub async fn send_loop(
client: Arc<RpcClient>,
keypair: Keypair,
) {
info!("signing with keypair pk={:?}", keypair.pubkey());
let cfg = RpcSendTransactionConfig {
skip_preflight: true,
..RpcSendTransactionConfig::default()
};
loop {
if let Ok(ixs) = ixs_rx.recv().await {
// TODO add priority fee
let tx = Transaction::new_signed_with_payer(
&ixs,
Some(&keypair.pubkey()),
@ -25,6 +28,7 @@ pub async fn send_loop(
*blockhash.read().unwrap(),
);
// TODO: collect metrics
info!("send tx={:?}", tx.signatures[0]);
client.send_transaction_with_config(&tx, cfg).await;
}
}
@ -36,6 +40,5 @@ pub fn init(
client: Arc<RpcClient>,
keypair: Keypair,
) {
// launch task
spawn(async move { send_loop(ixs_rx, blockhash, client, keypair) });
spawn(async move { send_loop(ixs_rx, blockhash, client, keypair).await });
}