-
Notifications
You must be signed in to change notification settings - Fork 129
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(lib/grandpa): Duplicate votes is GRANDPA are counted as equivocatory votes (GSR-11) #2624
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -284,22 +284,22 @@ func (h *MessageHandler) verifyCatchUpResponseCompletability(prevote, precommit | |
return nil | ||
} | ||
|
||
func getEquivocatoryVoters(votes []AuthData) (map[ed25519.PublicKeyBytes]struct{}, error) { | ||
func getEquivocatoryVoters(votes []AuthData) map[ed25519.PublicKeyBytes]struct{} { | ||
eqvVoters := make(map[ed25519.PublicKeyBytes]struct{}) | ||
voters := make(map[ed25519.PublicKeyBytes]int, len(votes)) | ||
voters := make(map[ed25519.PublicKeyBytes][64]byte, len(votes)) | ||
|
||
for _, v := range votes { | ||
voters[v.AuthorityID]++ | ||
switch voters[v.AuthorityID] { | ||
case 1: | ||
case 2: | ||
eqvVoters[v.AuthorityID] = struct{}{} | ||
default: | ||
return nil, fmt.Errorf("%w: authority id %x has %d votes", | ||
errInvalidMultiplicity, v.AuthorityID, voters[v.AuthorityID]) | ||
signature, present := voters[v.AuthorityID] | ||
if present { | ||
if !bytes.Equal(signature[:], v.Signature[:]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, it looks like we don't do anything if voter already has an entry in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there is a vote present for the authority, and the signature of that vote doesn't equal the votes signature then we add that voter to the equivocatory voters map. The voter is equivocatory since there are votes for that voter that do not match.
edwardmack marked this conversation as resolved.
Show resolved
Hide resolved
|
||
eqvVoters[v.AuthorityID] = struct{}{} | ||
} | ||
} else { | ||
voters[v.AuthorityID] = v.Signature | ||
} | ||
} | ||
return eqvVoters, nil | ||
|
||
return eqvVoters | ||
} | ||
|
||
func isDescendantOfHighestFinalisedBlock(blockState BlockState, hash common.Hash) (bool, error) { | ||
|
@@ -329,10 +329,7 @@ func (h *MessageHandler) verifyCommitMessageJustification(fm *CommitMessage) err | |
return errVoteBlockMismatch | ||
} | ||
|
||
eqvVoters, err := getEquivocatoryVoters(fm.AuthData) | ||
if err != nil { | ||
return fmt.Errorf("could not get valid equivocatory voters: %w", err) | ||
} | ||
eqvVoters := getEquivocatoryVoters(fm.AuthData) | ||
|
||
var count int | ||
for i, pc := range fm.Precommits { | ||
|
@@ -465,10 +462,7 @@ func (h *MessageHandler) verifyPreCommitJustification(msg *CatchUpResponse) erro | |
return errVoteBlockMismatch | ||
} | ||
|
||
eqvVoters, err := getEquivocatoryVoters(auths) | ||
if err != nil { | ||
return fmt.Errorf("could not get valid equivocatory voters: %w", err) | ||
} | ||
eqvVoters := getEquivocatoryVoters(auths) | ||
|
||
// verify pre-commit justification | ||
var count uint64 | ||
|
@@ -603,10 +597,7 @@ func (s *Service) VerifyBlockJustification(hash common.Hash, justification []byt | |
authPubKeys[i] = AuthData{AuthorityID: pcj.AuthorityID} | ||
} | ||
|
||
equivocatoryVoters, err := getEquivocatoryVoters(authPubKeys) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not get valid equivocatory voters: %w", err) | ||
} | ||
equivocatoryVoters := getEquivocatoryVoters(authPubKeys) | ||
|
||
var count int | ||
|
||
|
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.
Does not this already take cared of the case when a vote appears twice in the AuthData list?
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.
The audit issue and spec say that duplicate votes are not equivocatory, just when votes don't match they are then equivocatory.