From 303543c3fbe47185a0268ec5c4f981f2f7c556fe Mon Sep 17 00:00:00 2001 From: aniketfuryrocks Date: Tue, 31 Jan 2023 23:54:50 +0530 Subject: [PATCH] tx_sender batching fix --- src/workers/tx_sender.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/workers/tx_sender.rs b/src/workers/tx_sender.rs index cc5dd372..3ddd851d 100644 --- a/src/workers/tx_sender.rs +++ b/src/workers/tx_sender.rs @@ -118,12 +118,10 @@ impl TxSender { ); loop { - let prev_inst = tokio::time::Instant::now(); - let mut sigs_and_slots = Vec::with_capacity(tx_batch_size); let mut txs = Vec::with_capacity(tx_batch_size); - while (prev_inst.elapsed() < tx_send_interval) || txs.len() == tx_batch_size { + while txs.len() <= tx_batch_size { match recv.try_recv() { Ok((sig, tx, slot)) => { sigs_and_slots.push((sig, slot)); @@ -132,12 +130,16 @@ impl TxSender { Err(TryRecvError::Disconnected) => { bail!("Channel Disconnected"); } - _ => {} + _ => { + break; + } } } self.forward_txs(sigs_and_slots, txs, postgres_send.clone()) .await; + + tokio::time::sleep(tx_send_interval).await; } }) }