From 7784ca40411658a7d0935543bb311401fd676038 Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Wed, 30 Aug 2023 16:20:29 +0100 Subject: [PATCH 1/3] Only add validators to the duped set if they're already present --- ethereum_bridge/src/protocol/transactions/votes/update.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ethereum_bridge/src/protocol/transactions/votes/update.rs b/ethereum_bridge/src/protocol/transactions/votes/update.rs index 56987a8d3d..824eae8cfa 100644 --- a/ethereum_bridge/src/protocol/transactions/votes/update.rs +++ b/ethereum_bridge/src/protocol/transactions/votes/update.rs @@ -61,8 +61,9 @@ impl NewVotes { let mut inner = self.inner; let mut removed = HashSet::default(); for voter in voters { - inner.remove(voter); - removed.insert(voter); + if inner.remove(voter).is_some() { + removed.insert(voter); + } } (Self { inner }, removed) } From 28b83e2a267b3fc0d9d64b904b1a24667cdef164 Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Wed, 30 Aug 2023 16:20:45 +0100 Subject: [PATCH 2/3] Add test_vote_info_remove_non_dupe() unit test --- .../src/protocol/transactions/votes/update.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/ethereum_bridge/src/protocol/transactions/votes/update.rs b/ethereum_bridge/src/protocol/transactions/votes/update.rs index 824eae8cfa..369290ef6b 100644 --- a/ethereum_bridge/src/protocol/transactions/votes/update.rs +++ b/ethereum_bridge/src/protocol/transactions/votes/update.rs @@ -314,6 +314,25 @@ mod tests { Ok(()) } + #[test] + fn test_vote_info_remove_non_dupe() -> Result<()> { + let validator = address::testing::established_address_1(); + let new_validator = address::testing::established_address_2(); + let vote_height = BlockHeight(100); + let voting_power = FractionalVotingPower::ONE_THIRD; + let vote = (validator.clone(), vote_height); + let votes = Votes::from([vote.clone()]); + let voting_powers = HashMap::from([(vote, voting_power)]); + let vote_info = NewVotes::new(votes, &voting_powers)?; + + let (vote_info, removed) = + vote_info.without_voters(vec![&new_validator]); + + assert!(removed.is_empty()); + assert_eq!(vote_info.voters(), BTreeSet::from([validator])); + Ok(()) + } + #[test] fn test_apply_duplicate_votes() -> Result<()> { let mut wl_storage = TestWlStorage::default(); From 827cfbe969f22001dd8ee7e9ddd051f1cdd19f74 Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Wed, 30 Aug 2023 19:13:26 +0100 Subject: [PATCH 3/3] Changelog for #1860 --- .changelog/unreleased/bug-fixes/1860-duped-eth-tally-votes.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/unreleased/bug-fixes/1860-duped-eth-tally-votes.md diff --git a/.changelog/unreleased/bug-fixes/1860-duped-eth-tally-votes.md b/.changelog/unreleased/bug-fixes/1860-duped-eth-tally-votes.md new file mode 100644 index 0000000000..5ac6c4c3ca --- /dev/null +++ b/.changelog/unreleased/bug-fixes/1860-duped-eth-tally-votes.md @@ -0,0 +1,2 @@ +- Log proper duped validator votes on Ethereum tallies + ([\#1860](https://github.com/anoma/namada/pull/1860)) \ No newline at end of file