From c5130912fd122ce7351ef5530f04b61569e12a88 Mon Sep 17 00:00:00 2001 From: "dak-agent[bot]" <284037069+dak-agent[bot]@users.noreply.github.com> Date: Thu, 23 Jul 2026 16:29:14 +0000 Subject: [PATCH] fix(backend): widen TPS window to ~3.33 blocks for 300ms block time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The TPS metric summed 2.5 blocks of transaction counts to approximate one second, on the assumption that average block time is ~400ms (2.5 * 400ms = 1s). With block time now ~300ms, a 2.5-block window covers only ~750ms, causing TPS to be under-reported by ~25%. Track a fourth block and sum ~3.33 blocks (3.33 * 300ms = 1s) so the metric again approximates one second of throughput. Co-authored-by: Vukašin Manojlović <8989109+iamvukasin@users.noreply.github.com> --- backend/src/lib/server.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/backend/src/lib/server.rs b/backend/src/lib/server.rs index 57766bd..a3724bb 100644 --- a/backend/src/lib/server.rs +++ b/backend/src/lib/server.rs @@ -60,6 +60,7 @@ struct TPSTracker { block_1_txs: usize, block_2_txs: usize, block_3_txs: usize, + block_4_txs: usize, current_tx_count: usize, } @@ -72,15 +73,16 @@ impl TPSTracker { self.current_tx_count += 1; } - /// Calculates the TPS over an effective window of 2.5 blocks. - /// The formula sums the transaction counts of the two most recent full blocks and half of the newest (partial) block. - /// This is because average block time is approximately 400ms; summing 2.5 blocks provides a close approximation of one second. + /// Calculates the TPS over an effective window of ~3.33 blocks. + /// The formula sums the transaction counts of the three most recent full blocks and one third of the block before them. + /// This is because average block time is approximately 300ms; summing 3.33 blocks (3.33 * 300ms) provides a close approximation of one second. pub fn get_tps(&mut self) -> usize { self.block_1_txs = self.block_2_txs; self.block_2_txs = self.block_3_txs; - self.block_3_txs = self.current_tx_count; + self.block_3_txs = self.block_4_txs; + self.block_4_txs = self.current_tx_count; self.current_tx_count = 0; - self.block_1_txs + self.block_2_txs + (self.block_3_txs / 2) + self.block_2_txs + self.block_3_txs + self.block_4_txs + (self.block_1_txs / 3) } }