Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sort RewardDelegators when marshaling a validator (pokt-network#1591)
## Description This is a fix for a regression introduced by pokt-network#1581. When a node stores a validator with the new `RewardDelegators` field, its marshaled product is not deterministic because the order of map iteration is not deterministic. As a result, the merkle tree of application.db can differ between nodes, leading to consensus failure. The proposed fix is to sort the keys of `RewardDelegators` by using the stable marshaler. <!-- reviewpad:summarize:start --> ### Summary generated by Reviewpad on 15 Jan 24 18:21 UTC This pull request includes changes to the `nodes.proto` file and a file diff. The changes in the `nodes.proto` file include: - Added an option `stable_marshaler` with a value of `true`. This option is used to make the order of `RewardDelegators` deterministic. - Updated the `Address` field to include additional options `(gogoproto.casttype)`, `(gogoproto.moretags)`, and `(gogoproto.jsontag)`. - Updated the `PublicKey` field to include additional options `(gogoproto.moretags)` and `(gogoproto.jsontag)`. - Updated the `jailed` field to include an additional option `(gogoproto.jsontag)`. The file diff includes the following changes: - Imported the "encoding/hex", "math/rand", "reflect", "strconv", and "time" packages. - Added a test case for marshalling RewardDelegators. - Added the "Test_Marshal_RewardDelegators" function. - Created variables and constants within the test function. - Generated random numbers to be used as reward delegator addresses. - Created and initialized a map, "delegatorMap", with random numbers as keys and their corresponding modulo 10 values as values. - Created a "Validator" struct with various fields and assigned values to them. - Marshaled the validator struct and ensured that the resulting hash is the same for every iteration of the test. Please let me know if there is anything specific you would like me to focus on. <!-- reviewpad:summarize:end -->
- Loading branch information