From 8d3c93a44c443ec22347fef5765a29b42634d453 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Thu, 27 May 2021 17:17:16 +0200 Subject: [PATCH] Use assertSet consistently to check the hashes --- .../tendermint34/adaptors/v0-34/responses.ts | 10 +++++----- .../src/tendermint34/responses.ts | 20 +++++++++++++++++-- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/packages/tendermint-rpc/src/tendermint34/adaptors/v0-34/responses.ts b/packages/tendermint-rpc/src/tendermint34/adaptors/v0-34/responses.ts index 7a9888a8bb..90be82da73 100644 --- a/packages/tendermint-rpc/src/tendermint34/adaptors/v0-34/responses.ts +++ b/packages/tendermint-rpc/src/tendermint34/adaptors/v0-34/responses.ts @@ -345,13 +345,13 @@ function decodeHeader(data: RpcHeader): responses.Header { // { hash: '', parts: { total: 0, hash: '' } } lastBlockId: data.last_block_id.hash ? decodeBlockId(data.last_block_id) : null, - lastCommitHash: fromHex(assertNotEmpty(data.last_commit_hash)), + lastCommitHash: fromHex(assertSet(data.last_commit_hash)), dataHash: fromHex(assertSet(data.data_hash)), - validatorsHash: fromHex(assertNotEmpty(data.validators_hash)), - nextValidatorsHash: fromHex(assertNotEmpty(data.next_validators_hash)), - consensusHash: fromHex(assertNotEmpty(data.consensus_hash)), - appHash: fromHex(data.app_hash), + validatorsHash: fromHex(assertSet(data.validators_hash)), + nextValidatorsHash: fromHex(assertSet(data.next_validators_hash)), + consensusHash: fromHex(assertSet(data.consensus_hash)), + appHash: fromHex(assertSet(data.app_hash)), lastResultsHash: fromHex(assertSet(data.last_results_hash)), evidenceHash: fromHex(assertSet(data.evidence_hash)), diff --git a/packages/tendermint-rpc/src/tendermint34/responses.ts b/packages/tendermint-rpc/src/tendermint34/responses.ts index 7906718969..926178a683 100644 --- a/packages/tendermint-rpc/src/tendermint34/responses.ts +++ b/packages/tendermint-rpc/src/tendermint34/responses.ts @@ -277,18 +277,34 @@ export interface Header { */ readonly lastBlockId: BlockId | null; - // hashes of block data + /** + * Hashes of block data. + * + * This is `sha256("")` for height 1 🤷‍ + */ readonly lastCommitHash: Uint8Array; - readonly dataHash: Uint8Array; // empty when number of transaction is 0 + /** + * This is `sha256("")` as long as there is no data 🤷‍ + */ + readonly dataHash: Uint8Array; // hashes from the app output from the prev block readonly validatorsHash: Uint8Array; readonly nextValidatorsHash: Uint8Array; readonly consensusHash: Uint8Array; + /** + * This can be an empty string for height 1 and turn into "0000000000000000" later on 🤷‍ + */ readonly appHash: Uint8Array; + /** + * This is `sha256("")` as long as there is no data 🤷‍ + */ readonly lastResultsHash: Uint8Array; // consensus info + /** + * This is `sha256("")` as long as there is no data 🤷‍ + */ readonly evidenceHash: Uint8Array; readonly proposerAddress: Uint8Array; }