Skip to content

Commit 27faf27

Browse files
committed
Make the order of votes consistent
When there are multiple proposals, we want to use the first proposal consistently. To do that the order or votes should be consistent.
1 parent 0c68995 commit 27faf27

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

core/src/consensus/tendermint/vote_collector.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// You should have received a copy of the GNU Affero General Public License
1515
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

17-
use std::collections::{BTreeMap, HashMap, HashSet};
17+
use std::collections::{BTreeMap, HashMap};
1818
use std::iter::Iterator;
1919

2020
use ckey::SchnorrSignature;
@@ -35,7 +35,7 @@ pub struct VoteCollector {
3535
struct StepCollector {
3636
voted: HashMap<usize, ConsensusMessage>,
3737
block_votes: HashMap<Option<H256>, BTreeMap<usize, SchnorrSignature>>,
38-
messages: HashSet<ConsensusMessage>,
38+
messages: Vec<ConsensusMessage>,
3939
}
4040

4141
#[derive(Debug)]
@@ -64,7 +64,8 @@ impl StepCollector {
6464
/// Returns Some(&Address) when validator is double voting.
6565
fn insert(&mut self, message: ConsensusMessage) -> Option<DoubleVote> {
6666
// Do nothing when message was seen.
67-
if self.messages.insert(message.clone()) {
67+
if self.messages.contains(&message) {
68+
self.messages.push(message.clone());
6869
if let Some(previous) = self.voted.insert(message.signer_index(), message.clone()) {
6970
// Bad validator sent a different message.
7071
return Some(DoubleVote {
@@ -217,11 +218,11 @@ impl VoteCollector {
217218
}
218219

219220
pub fn get_all(&self) -> Vec<ConsensusMessage> {
220-
self.votes.iter().flat_map(|(_round, collector)| collector.messages.iter()).cloned().collect()
221+
self.votes.iter().flat_map(|(_round, collector)| collector.messages.clone()).collect()
221222
}
222223

223224
pub fn get_all_votes_in_round(&self, round: &VoteStep) -> Vec<ConsensusMessage> {
224-
self.votes.get(round).map(|c| c.messages.iter().cloned().collect()).unwrap_or_default()
225+
self.votes.get(round).map(|c| c.messages.clone()).unwrap_or_default()
225226
}
226227

227228
pub fn get_all_votes_and_indices_in_round(&self, round: &VoteStep) -> Vec<(usize, ConsensusMessage)> {

0 commit comments

Comments
 (0)