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

Proto decoding of ValidatorSet in tendermint-rs does not match tendermint encoding #1255

Open
toml01 opened this issue Dec 25, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@toml01
Copy link

toml01 commented Dec 25, 2022

HI 👋🏼

What went wrong?

When trying to decode (in tendermint-rs) a proto encoded ValidatorSet (encoded in tendermint) you get the following error:

StringTracer: error converting message type into domain type: StringTracer: mismatch between raw voting (Power(0)) and computed one (Power(10))

I believe that the problem is strictly encoding in tendermint -> decoding in tendermint-rs. The opposite path should work if I understand correctly.

This issue originates from a difference in behavior in encoding/decoding between tendermint and tendermint-rs.
Specifically here you can notice that ValidatorSet.ToProto() will always result in ValidatorSet.TotalVotingPower = 0 (changed in this PR).
However, in tendermint-rs, you require (here) for the raw voting power to match the computed one.

You can also see that in tendermint this is not getting checked in decoding here. vals.TotalVotingPower() recalculates the voting power based on the validator set, and ignores the received raw one.

Steps to reproduce

In tendermint:

nextValSetProto, err := state.NextValidators.ToProto()
if err != nil {
	return state, 0, fmt.Errorf("%v", err)
}
nextValSetBytes, err := nextValSetProto.Marshal()
if err != nil {
	return state, 0, fmt.Errorf("%v", err)
}

<--- ffi magic (or copy-paste raw bytes 🙃) --->

Then in tendermint-rs:

match Set::decode(val_set_slice) {
    Ok(vs) => println!("{:?}", vs),
    Err(e) => println!("{:?}", e),
};

Definition of "done"

The encoding/decoding in tendermint and tendermint-rs should match.
I guess the easy way would be to remove the said assertion in ValidatorSet's try_from() (Set::new() recalculates total_voting_power anyway), But I'm not sure if this is the desired behavior.

@toml01 toml01 added the bug Something isn't working label Dec 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant