@lodestar/beacon-node
Version:
A Typescript implementation of the beacon chain
21 lines • 852 B
JavaScript
import { toRootHex } from "@lodestar/utils";
/**
* String to uniquely identify block segments. Used for peer scoring and to compare if batches are equivalent.
*/
export function hashBlocks(blocks, config) {
switch (blocks.length) {
case 0:
return "0x";
case 1: {
const block0 = blocks[0].block;
return toRootHex(config.getForkTypes(block0.message.slot).SignedBeaconBlock.hashTreeRoot(block0));
}
default: {
const block0 = blocks[0].block;
const blockN = blocks.at(-1)?.block;
return (toRootHex(config.getForkTypes(block0.message.slot).SignedBeaconBlock.hashTreeRoot(block0)) +
toRootHex(config.getForkTypes(blockN.message.slot).SignedBeaconBlock.hashTreeRoot(blockN)));
}
}
}
//# sourceMappingURL=hashBlocks.js.map