-
Notifications
You must be signed in to change notification settings - Fork 182
Remove vote when checkVote() fails in HandleGovernanceVote #1367
Conversation
@ian0371 Can you add a scenario test case in I see that unit test for HandleGovernanceVote checks crucial conditions. But having an intuitive scenario as a test would be more comprehensible. |
Let me ask a simple question. Is it invalid removing duplicated vote immediately from Vote()? Why did you delegate it to |
Each independent test case seems separated by comment. It looks better to make an arbitrary scope case by case or split them into functions. You may consider this later. |
Good question. Validator set can be fetched from istanbul.snapshot, which is inaccessible from governance package (istanbul/backend package imports governance, so the reverse cannot be done.
I agree that the current readability is not so great. I'll take this into account later :) |
@ian0371, Okay. then, does not have a side-effect of this post-processing? |
No, it does not have a side effect. The removing vote is rarely executed in the real world (i.e., when adding an existing validator). |
Okay.. thank you. |
nodeKeys = append(nodeKeys, allNodeKeys[i]) | ||
addrs = append(addrs, allAddrs[i]) | ||
includeNode(allAddrs[i], allNodeKeys[i]) |
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.
Why are these lines changed?
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.
@ehnuje Without them, the same node ends up twice in nodeKeys
/addrs
, resulting in "invalid committed seals".
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.
@ian0371 What I meant to say was that changing the test code because of the core code change looks strange. Do we need to sync the test code logic and the core code logic manually for this test?
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.
@ehnuje Changing these lines is inevitable because the existing code cannot handle the new test cases. You can consider it "fixing a bug".
I could add a new test function to verify them, but instead, I decided to reuse the existing function because most parts (i.e., except for these lines) will be reused. You might not want to go down that road.
Rebased to the latest dev |
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.
LGTM, thanks!
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.
Thanks @ian0371 👍
Proposed changes
governance.vote("governance.addvalidator", existing_val_addr)
has a bug. Refer to the log below.checkVote()
checks if the address to be added already exists in the validator set, in which case it returns WITHOUT REMOVING THE VOTE.checkVote()
fails. (remove in this context means setting Casted to true)Bug log
For an initial council, we remove one validator so that we can add it back.
We can see that the second vote is not cast and it keeps appearing in every block the voter becomes the proposer.
Types of changes
Please put an x in the boxes related to your change.
Checklist
Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.
$ make test
)Related issues
Further comments
If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...