Tags: cometbft/cometbft
Tags
chore: add voting power validation (v0.38.x) (#5520) validates voting power and returns an error instead of panicking --- #### PR checklist - [ ] Tests written/updated - [ ] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Switch total voting power computation to return errors instead of panicking, add a safe accessor, and update callers/tests accordingly. > > - **Types (`types/validator_set.go`)**: > - Change `updateTotalVotingPower()` to return `error` instead of panicking on overflow and set `totalVotingPower`. > - Add `TotalVotingPowerSafe()` to get TVP with error handling. > - Update `TotalVotingPower()` to panic only if `updateTotalVotingPower()` returns an error. > - Use error-based TVP validation in `updateWithChangeSet()`, `ValidatorSetFromProto()` (now returns error on bad input), and `ValidatorSetFromExistingValidators()`. > - **Tests (`types/validator_set_test.go`)**: > - Add `TestValidatorSetFromProtoReturnsErrorOnOverflow` to assert error on TVP overflow from proto input. > - Update `verifyValidatorSet()` to handle `updateTotalVotingPower()` error. > - Minor import addition for crypto key encoding. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit a66f19f. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
chore: remove panic (#5525) removes a panic from code #### PR checklist - [ ] Tests written/updated - [ ] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Replaces panics on total voting power overflow with error returns, adds a safe accessor, and updates callers and tests accordingly. > > - **types/validator_set.go**: > - `updateTotalVotingPower` now returns `error` instead of panicking on overflow; propagates error where applicable. > - Added `TotalVotingPowerSafe()` to compute/return total voting power or an error. > - `TotalVotingPower()` now panics only if `updateTotalVotingPower()` returns an error. > - Updated callers: `updateWithChangeSet`, `ValidatorSetFromProto`, and `ValidatorSetFromExistingValidators` to handle/propagate errors. > - **tests** (`types/validator_set_test.go`): > - Added `TestValidatorSetFromProtoReturnsErrorOnOverflow`. > - Adjusted tests to handle new error-returning behavior (e.g., checking `require.NoError` from `updateTotalVotingPower`). > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit d7d7ae4. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
PreviousNext