Skip to content

Commit

Permalink
Use assertSet consistently to check the hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed May 27, 2021
1 parent 2701acf commit 8d3c93a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
20 changes: 18 additions & 2 deletions packages/tendermint-rpc/src/tendermint34/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 8d3c93a

Please sign in to comment.