@lodestar/beacon-node
Version:
A Typescript implementation of the beacon chain
34 lines • 2.02 kB
JavaScript
import { DataAvailabilityStatus, ExecutionPayloadStatus, StateHashTreeRootSource, stateTransition, } from "@lodestar/state-transition";
import { ZERO_HASH } from "../../constants/index.js";
/**
* Instead of running fastStateTransition(), only need to process block since
* state is processed until block.slot already (this is to avoid double
* epoch transition which happen at slot % 32 === 0)
*/
export function computeNewStateRoot(metrics, state, block) {
// Set signature to zero to re-use stateTransition() function which requires the SignedBeaconBlock type
const blockEmptySig = { message: block, signature: ZERO_HASH };
const postState = stateTransition(state, blockEmptySig, {
// ExecutionPayloadStatus.valid: Assume payload valid, it has been produced by a trusted EL
executionPayloadStatus: ExecutionPayloadStatus.valid,
// DataAvailabilityStatus.available: Assume the blobs to be available, have just been produced by trusted EL
dataAvailabilityStatus: DataAvailabilityStatus.Available,
// verifyStateRoot: false | the root in the block is zero-ed, it's being computed here
verifyStateRoot: false,
// verifyProposer: false | as the block signature is zero-ed
verifyProposer: false,
// verifySignatures: false | since the data to assemble the block is trusted
verifySignatures: false,
// Preserve cache in source state, since the resulting state is not added to the state cache
dontTransferCache: true,
}, { metrics });
const { attestations, syncAggregate, slashing } = postState.proposerRewards;
const proposerReward = BigInt(attestations + syncAggregate + slashing);
const hashTreeRootTimer = metrics?.stateHashTreeRootTime.startTimer({
source: StateHashTreeRootSource.computeNewStateRoot,
});
const newStateRoot = postState.hashTreeRoot();
hashTreeRootTimer?.();
return { newStateRoot, proposerReward };
}
//# sourceMappingURL=computeNewStateRoot.js.map