Skip to content

Commit

Permalink
Merge pull request #1185 from cosmos/validator-slashing-update-0.28
Browse files Browse the repository at this point in the history
Fix decoding validator update
  • Loading branch information
webmaster128 committed Jun 21, 2022
2 parents 071c4bf + 317bd0b commit 487abfb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to

## [Unreleased]

- @cosmjs/tendermint-rpc: Fix decoding validator updates due to slashing ([#1177]).

[#1177]: https://github.com/cosmos/cosmjs/issues/1177

## [0.28.7] - 2022-06-14

### Fixed
Expand Down
21 changes: 21 additions & 0 deletions packages/tendermint-rpc/src/tendermint34/adaptor/responses.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,27 @@ describe("Adaptor Responses", () => {
votingPower: 11418237,
});
});

it("works for block results format without voting power", () => {
// from https://rpc.cosmos.network/block_results?height=10883046
const update = decodeValidatorUpdate({
pub_key: {
Sum: {
type: "tendermint.crypto.PublicKey_Ed25519",
value: {
ed25519: "HjSC7VkhKih6xMhudlqfaFE8ZZnP8RKJPv4iqR7RhcE=",
},
},
},
});
expect(update).toEqual({
pubkey: {
algorithm: "ed25519",
data: fromBase64("HjSC7VkhKih6xMhudlqfaFE8ZZnP8RKJPv4iqR7RhcE="),
},
votingPower: 0,
});
});
});

describe("decodeValidatorInfo", () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,14 @@ function decodeConsensusParams(data: RpcConsensusParams): responses.ConsensusPar
// for block results
interface RpcValidatorUpdate {
readonly pub_key: RpcPubkey;
readonly power: string;
// When omitted, this means zero (see https://github.com/cosmos/cosmjs/issues/1177#issuecomment-1160115080)
readonly power?: string;
}

export function decodeValidatorUpdate(data: RpcValidatorUpdate): responses.ValidatorUpdate {
return {
pubkey: decodePubkey(assertObject(data.pub_key)),
votingPower: Integer.parse(assertNotEmpty(data.power)),
votingPower: Integer.parse(data.power ?? 0),
};
}

Expand Down

0 comments on commit 487abfb

Please sign in to comment.