Skip to content
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

Sort validators by voting power #556

Closed
wants to merge 12 commits into from
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
- The `tendermint`, `tendermint-rpc`, and `tendermint-light-client` crates now compile to WASM on the `wasm32-unknown-unknown` and `wasm32-wasi` targets ([#463])
- Implement protobuf encoding/decoding of Tendermint Proto types ([#504])
- Separate protobuf types from Rust domain types using the DomainType trait ([#535])
- Changed validator sorting order to sort by voting power. ([#506])

[#526]: https://github.com/informalsystems/tendermint-rs/issues/526
[#498]: https://github.com/informalsystems/tendermint-rs/issues/498
[#463]: https://github.com/informalsystems/tendermint-rs/issues/463
[#504]: https://github.com/informalsystems/tendermint-rs/issues/504
[#535]: https://github.com/informalsystems/tendermint-rs/issues/535
[#506]: https://github.com/informalsystems/tendermint-rs/issues/506

## v0.16.0

Expand Down
12 changes: 5 additions & 7 deletions tendermint/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ impl Set {
}

/// Sort the validators according to the current Tendermint requirements
/// (v. 0.33 -> by validator address, ascending)
/// (v. 0.34 -> by validator power, descending)
fn sort_validators(vals: &mut Vec<Info>) {
vals.sort_by_key(|v| v.address);
vals.sort_by_key(|v| std::cmp::Reverse(v.voting_power));
}

/// Returns the validator with the given Id if its in the Set.
Expand Down Expand Up @@ -321,16 +321,14 @@ mod tests {
],
770_561_664_770_006_272,
);
let _hash_expect = vec![
let hash_expect = vec![
11, 64, 107, 4, 234, 81, 232, 75, 204, 199, 160, 114, 229, 97, 243, 95, 118, 213, 17,
22, 57, 84, 71, 122, 200, 169, 192, 252, 41, 148, 223, 180,
];

let val_set = Set::new(vec![v1, v2, v3]);
let _hash = val_set.hash();
// Todo: Greg Issue #506. The expected hash is correct, but Rust doesn't implement yet the
// correct ordering of the validators. Hence this assertion fails.
//assert_eq!(hash_expect, hash.as_bytes().to_vec());
let hash = val_set.hash();
assert_eq!(hash_expect, hash.as_bytes().to_vec());

let not_in_set = make_validator(
vec![
Expand Down