-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix malicious identities getting rewards in ATXv2 #6732
Open
fasmat
wants to merge
12
commits into
develop
Choose a base branch
from
fix-malicious-identities-getting-rewards
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
❌ 1 Tests Failed:
View the top 1 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
2d7b249
to
157536f
Compare
ffeb40d
to
bb9eb4f
Compare
bb9eb4f
to
9a77e2d
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
In tests malicious identities were still given rewards by other nodes. This PR fixes the malfeasance checks for ballots and in the process optimises various queries to be more efficient.
Description
ballots.Get
queried not only the ballot from theballots
table, but also joined theidentities
table to set the ballot as malicious if the smesher that created it is a known malfeasant. Not only is this inefficient to do, especially on a database with millions of entries. It is also easy to overlook when identities is refactored (like for malfeasance 2 which stores malfeasance information in a new table). To address this I updated the queries for ballots to avoid joins:ballots.Get
: instead of joining withidentities
the function now first fetches the ballot from the DB and then queries bothidentities
andmalfeasance
for an entry and sets the ballot to malicious if it finds one in at least one of the two tables. This now requires a transaction to be passed toballots.Get
instead of asql.Executor
. I added a TODO there to clean that up in the future: ideally we separate domain ballot types from DTO types and have a service that queries all tables necessary when fetching a ballot and malfeasance information is needed.ballots.Layer
andballots.LayerNoMalicious
: I combined both into a single function that does not fetch information about malfeasance when getting all ballots for a layer. The reason is thatballots.LayerNoMalicious
didn't do this anyway before and all users ofballots.Layer
(only GRPC v1 API) didn't even care about the malfeasance information.ballots.FirstInEpoch
andballots.LastInEpoch
: again I removed fetching malfeasance information for the ballot that is returned by these functions since all callers (only the proposal builder) don't care about the malfeasance information from the ballot.atxs.GetIDWithMaxHeight
: I updated the query to select the maximum epoch only once instead of once per row (since we do not have an index on the epoch column in the ATXs table). Additionally I replaced theJOIN
with aWHERE NOT EXISTS
clause that should be faster than checking fornull
after joining and applied this to bothidentities
andmalfeasance
.atxs.IterateForGrading
: TODOatxs.IterateAtxsWithMalfeasance
: TODOatxs.IterateAtxIdsWithMalfeasance
: TODOTest Plan
all existing tests pass, new tests were added to check that malfeasance information from malfeasance2 is now returned as well when fetching data from the DB.
TODO