-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Beacon node slasher improvement #13549
Conversation
1f23ec6
to
39b37e6
Compare
If a first batch of blocks is sent with: - validator 1 - slot 4 - signing root 1 - validator 1 - slot 5 - signing root 1 Then, if a second batch of blocks is sent with: - validator 1 - slot 4 - signing root 2 Because we have two blocks proposed by the same validator (1) and for the same slot (4), but with two different signing roots (1 and 2), the validator 1 should be slashed. This is not the case before this commit. A new test case has been added as well to check this. Fixes #13549
44bbbe1
to
c33ec19
Compare
beacon-chain/db/slasherkv/slasher.go
Outdated
bkt := tx.Bucket(attestedEpochsByValidator) | ||
|
||
min := i + batchSize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'min' collides with the 'builtin' function, could we consider renaming this variable?
beacon-chain/slasher/receive.go
Outdated
@@ -12,10 +12,18 @@ import ( | |||
"github.com/sirupsen/logrus" | |||
) | |||
|
|||
const ( | |||
couldNotSaveAttRecord = "Could not save attestation records to DB" | |||
couldNotSaveSlashableAtt = "Could not check slashable attestations" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couldNotSaveSlashableAtt = "Could not check slashable attestations" | |
couldNotSaveSlashableAtt = "Could not save slashable attestations" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually the message is the OK but the name of the variable is bad. Will fix it.
Fixes #13550. In tests, `exitChan` are now useless since waitgroup are used to wait for all goroutines to be stopped.
- Rename some variables. - Add comments. - Use second element of `range` when possible.
Avoid mixes between `indice(s)`and `index(es)`.
- Same target with different signing roots - Same target with same signing roots
Before this commit, `checkDoubleVotes` did two tasks: - Checking if there are any slashable double votes in the input list of attestations with respect to each other. - Checking if there are any slashable double votes in the input list of attestations with respect to our database. However, `checkDoubleVotes` is called only in `checkSlashableAttestations`. And `checkSlashableAttestations` is called only in: - `processQueuedAttestations`, and in - `IsSlashableAttestation` Study of case `processQueuedAttestations`: --------------------------------------------- In `processQueuedAttestations`, `checkSlashableAttestations` is ALWAYS called after `Database.SaveAttestationRecordsForValidators`. It means that, when calling `checkSlashableAttestations`, `validAtts` are ALREADY stored in the DB. Each attestation of `validAtts` will be checked twice: - Against the other attestations of `validAtts` (the portion of deleted code) - Against the content of the database. One of those two checks is redundent. ==> We can remove the check against other attestations in `validAtts`. Study of case `Database.SaveAttestationRecordsForValidators`: ---------------------------------------------------------------- In `Database.SaveAttestationRecordsForValidators`, `checkSlashableAttestations` is ALWAYS called with a list of attestations containing only ONE attestation. This only attestaion will be checked twice: - Against itself, and an attestation cannot conflict with itself. - Against the content of the database. ==> We can remove the check against other attestations in `validAtts`. ========================= In both cases, we showed that we can remove the check of attestation against the content of `validAtts`, and the corresponding test `Test_checkDoubleVotes_SlashableInputAttestations`.
So we can add new proposals later.
If a first batch of blocks is sent with: - validator 1 - slot 4 - signing root 1 - validator 1 - slot 5 - signing root 1 Then, if a second batch of blocks is sent with: - validator 1 - slot 4 - signing root 2 Because we have two blocks proposed by the same validator (1) and for the same slot (4), but with two different signing roots (1 and 2), the validator 1 should be slashed. This is not the case before this commit. A new test case has been added as well to check this. Fixes #13551
Co-authored-by: Sammy Rosso <15244892+saolyn@users.noreply.github.com>
Co-authored-by: Sammy Rosso <15244892+saolyn@users.noreply.github.com>
a23ed6f
to
8d740aa
Compare
Well, even if, in our case, "happy path" mean slashing.
In case of multiple votes, arbitrarily save the first attestation. Saving the first one in particular has no functional impact, since in any case all attestations will be tested against the content of the database. So all but the first one will be detected as slashable. However, saving the first one and not an other one let us not to modify the end to end tests, since they expect the first one to be saved in the database.
Not to conflict with the new `min` built-in function.
8d740aa
to
e9afe03
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice improvements, thanks @nalepae !
Please read this PR commit by commit. Some commit messages contain a lot of information.
What type of PR is this?
Bug fix
What does this PR do? Why is it needed?
Commits with commit message ending by
NFC
(no functional changes) do not contain any functional change.Which issues(s) does this PR fix?
Fixes:
--slasher
panics at shutdown. #13550 in commit 2756590