-
-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove dead code from chain/produceBlock (#4844)
- v1.27.1
- v1.27.1-rc.1
- v1.27.1-rc.0
- v1.27.0
- v1.27.0-rc.2
- v1.27.0-rc.1
- v1.27.0-rc.0
- v1.26.0
- v1.26.0-rc.1
- v1.26.0-rc.0
- v1.25.0
- v1.25.0-rc.0
- v1.24.0
- v1.24.0-rc.3
- v1.24.0-rc.2
- v1.24.0-rc.1
- v1.24.0-rc.0
- v1.23.1
- v1.23.1-rc.0
- v1.23.0
- v1.23.0-rc.6
- v1.23.0-rc.5
- v1.23.0-rc.4
- v1.23.0-rc.3
- v1.23.0-rc.2
- v1.23.0-rc.1
- v1.23.0-rc.0
- v1.22.0
- v1.22.0-rc.0
- v1.21.0
- v1.21.0-rc.5
- v1.21.0-rc.4
- v1.21.0-rc.3
- v1.21.0-rc.2
- v1.21.0-rc.1
- v1.21.0-rc.0
- v1.20.2
- v1.20.2-rc.1
- v1.20.2-rc.0
- v1.20.1
- v1.20.1-rc.1
- v1.20.1-rc.0
- v1.20.0
- v1.20.0-rc.0
- v1.19.0
- v1.19.0-rc.2
- v1.19.0-rc.1
- v1.19.0-rc.0
- v1.18.1
- v1.18.1-rc.0
- v1.18.0
- v1.18.0-rc.2
- v1.18.0-rc.1
- v1.18.0-rc.0
- v1.17.0
- v1.17.0-rc.2
- v1.17.0-rc.1
- v1.17.0-rc.0
- v1.16.0
- v1.16.0-rc.1
- v1.16.0-rc.0
- v1.15.1
- v1.15.1-rc.0
- v1.15.0
- v1.15.0-rc.0
- v1.14.0
- v1.14.0-rc.2
- v1.14.0-rc.1
- v1.14.0-rc.0
- v1.13.0
- v1.13.0-rc.1
- v1.13.0-rc.0
- v1.12.1
- v1.12.1-rc.4
- v1.12.1-rc.3
- v1.12.1-rc.2
- v1.12.1-rc.1
- v1.12.1-rc.0
- v1.12.0
- v1.12.0-rc.3
- v1.12.0-rc.2
- v1.12.0-rc.1
- v1.12.0-rc.0
- v1.11.3
- v1.11.1
- v1.11.0
- v1.11.0-rc.0
- v1.10.0
- v1.10.0-rc.1
- v1.10.0-rc.0
- v1.9.2
- v1.9.2-rc.0
- v1.9.1
- v1.9.1-rc.1
- v1.9.1-rc.0
- v1.9.0
- v1.9.0-rc.3
- v1.9.0-rc.2
- v1.9.0-rc.1
- v1.9.0-rc.0
- v1.8.0
- v1.8.0-rc.1
- v1.8.0-rc.0
- v1.7.2
- v1.7.2-rc.0
- v1.7.1
- v1.7.1-rc.0
- v1.7.0
- v1.7.0-rc.1
- v1.7.0-rc.0
- v1.6.0
- v1.6.0-rc.3
- v1.6.0-rc.2
- v1.6.0-rc.1
- v1.6.0-rc.0
- v1.5.1
- v1.5.1-rc.1
- v1.5.1-rc.0
- v1.5.0
- v1.5.0-rc.1
- v1.5.0-rc.0
- v1.4.3
- v1.4.2
- v1.4.2-rc.0
- v1.4.1
- v1.4.0
- v1.4.0-rc.1
- v1.4.0-rc.0
- v1.3.0
- v1.3.0-rc.2
- v1.3.0-rc.1
- v1.3.0-rc.0
- 1.17.11
Showing
1 changed file
with
2 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,2 @@ | ||
import {CachedBeaconStateAllForks, stateTransition} from "@lodestar/state-transition"; | ||
import {allForks, Root} from "@lodestar/types"; | ||
import {fromHexString} from "@chainsafe/ssz"; | ||
|
||
import {ZERO_HASH} from "../../constants/index.js"; | ||
import {IMetrics} from "../../metrics/index.js"; | ||
import {RegenCaller} from "../regen/index.js"; | ||
import type {BeaconChain} from "../chain.js"; | ||
import {produceBlockBody, BlockType, AssembledBlockType, BlockAttributes} from "./produceBlockBody.js"; | ||
|
||
export {BlockType, AssembledBlockType}; | ||
|
||
export async function produceBlock<T extends BlockType>( | ||
this: BeaconChain, | ||
blockType: T, | ||
{randaoReveal, graffiti, slot}: BlockAttributes | ||
): Promise<AssembledBlockType<T>> { | ||
const head = this.forkChoice.getHead(); | ||
const state = await this.regen.getBlockSlotState(head.blockRoot, slot, RegenCaller.produceBlock); | ||
const parentBlockRoot = fromHexString(head.blockRoot); | ||
const proposerIndex = state.epochCtx.getBeaconProposer(slot); | ||
const proposerPubKey = state.epochCtx.index2pubkey[proposerIndex]?.toBytes(); | ||
// if (!proposerPubKey) throw Error("proposerPubKey not found"); | ||
|
||
const block = { | ||
slot, | ||
proposerIndex, | ||
parentRoot: parentBlockRoot, | ||
stateRoot: ZERO_HASH, | ||
body: await produceBlockBody.call(this, blockType, state, { | ||
randaoReveal, | ||
graffiti, | ||
slot, | ||
parentSlot: slot - 1, | ||
parentBlockRoot, | ||
proposerIndex, | ||
proposerPubKey, | ||
}), | ||
} as AssembledBlockType<T>; | ||
|
||
block.stateRoot = computeNewStateRoot(this.metrics, state, block); | ||
|
||
return block; | ||
} | ||
|
||
/** | ||
* 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) | ||
*/ | ||
function computeNewStateRoot( | ||
metrics: IMetrics | null, | ||
state: CachedBeaconStateAllForks, | ||
block: allForks.FullOrBlindedBeaconBlock | ||
): Root { | ||
// Set signature to zero to re-use stateTransition() function which requires the SignedBeaconBlock type | ||
const blockEmptySig = {message: block, signature: ZERO_HASH} as allForks.FullOrBlindedSignedBeaconBlock; | ||
|
||
const postState = stateTransition( | ||
state, | ||
blockEmptySig, | ||
// verifyStateRoot: false | the root in the block is zero-ed, it's being computed here | ||
// verifyProposer: false | as the block signature is zero-ed | ||
// verifySignatures: false | since the data to assemble the block is trusted | ||
{verifyStateRoot: false, verifyProposer: false, verifySignatures: false}, | ||
metrics | ||
); | ||
|
||
return postState.hashTreeRoot(); | ||
} | ||
export * from "./computeNewStateRoot.js"; | ||
export * from "./produceBlockBody.js"; |