From 2de4ab8c9d913cfcbcca43bfe9ca1a17e6f2b593 Mon Sep 17 00:00:00 2001
From: Luke Parker <lukeparker5132@gmail.com>
Date: Sat, 12 Nov 2022 11:46:32 -0500
Subject: [PATCH] Clear the Queue instead of draining and filtering

There shouldn't ever be a message which passes the filter under the
current design.
---
 substrate/tendermint/machine/src/lib.rs | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/substrate/tendermint/machine/src/lib.rs b/substrate/tendermint/machine/src/lib.rs
index 132de804..02433318 100644
--- a/substrate/tendermint/machine/src/lib.rs
+++ b/substrate/tendermint/machine/src/lib.rs
@@ -214,8 +214,8 @@ impl<N: Network + 'static> TendermintMachine<N> {
     let round_end = self.block.end_time[&end_round];
     sleep(round_end.instant().saturating_duration_since(Instant::now())).await;
 
-    // Only keep queued messages for this block
-    self.queue = self.queue.drain(..).filter(|msg| msg.number == self.block.number).collect();
+    // Clear our outbound message queue
+    self.queue = VecDeque::new();
 
     // Create the new block
     self.block = BlockData {
@@ -339,6 +339,7 @@ impl<N: Network + 'static> TendermintMachine<N> {
 
       if let Some((broadcast, msg)) = futures::select_biased! {
         // Handle a new height occuring externally (an external sync loop)
+        // Has the highest priority as it makes all other futures here irrelevant
         msg = self.step_recv.next() => {
           if let Some((commit, proposal)) = msg {
             self.reset_by_commit(commit, proposal).await;