The Block structure has a hash: OnceCell<BlockHash> field used to cache block hash computation. This is pretty useful as it allows us to avoid computing a block's hash multiple times without having to keep track of a second hash variable.
This is not the case for BlockHeader, as we still need to compute the hash of a header once and then pass it along with the header itself which is not ideal.
We only need the BlockHeader in order to compute the block's hash, so we can move the cached computation to BlockHeader and still be able to access the cached hash from both Block and BlockHeader
The
Blockstructure has ahash: OnceCell<BlockHash>field used to cache block hash computation. This is pretty useful as it allows us to avoid computing a block's hash multiple times without having to keep track of a secondhashvariable.This is not the case for
BlockHeader, as we still need to compute the hash of a header once and then pass it along with the header itself which is not ideal.We only need the
BlockHeaderin order to compute the block's hash, so we can move the cached computation toBlockHeaderand still be able to access the cached hash from bothBlockandBlockHeader