-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
blockchain: Make zero val threshold tuple invalid.
This makes the zero value for a threshold state tuple act as the invalid state and choice instead of using magic sentinel values. In practice, callers should be checking the error of any methods before using any other returned values, however, the code typically tries to adopt a defense in depth model where it makes sure unusable/invalid values are also returned in error cases to help make it obvious when a caller incorrectly uses the returned value without checking the error. It accomplishes this by reording the threshold states so that the invalid state is 0 and converting the choice field to a pointer to the relevant choice as opposed to a choice index. That way the zero value for the overall type is the invalid state and nil the choice, exactly as expected. In addition to being more ergonomic and inline with typical Go code, it has a few additional benefits: * Makes the type harder to misuse * Simplifies identification of a specific resulting choice for votes that have multiple affirmative choices since the choice can be checked by its ID instead of a tightly coupled array index * Provides an easy method to distinguish between a vote that failed due to a majority vote and one that failed due to expiring before a majority result was achieved
- Loading branch information
Showing
6 changed files
with
337 additions
and
336 deletions.
There are no files selected for viewing
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
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
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
Oops, something went wrong.