Skip to content

Commit

Permalink
Flat state transition across forks (#4120)
Browse files Browse the repository at this point in the history
* Update src

* Update tests

* Update spec tests

* Fix Lodestar src

* Fix type issues

* Fix perf test types

* Review PR

* Remove un-used import

* Don't check state root in computeNewStateRoot

* Rename slashValidator
  • Loading branch information
dapplion authored Jun 7, 2022
1 parent f74f9ef commit fe5c98e
Show file tree
Hide file tree
Showing 154 changed files with 775 additions and 1,300 deletions.
15 changes: 6 additions & 9 deletions packages/beacon-state-transition/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@
".": {
"import": "./lib/index.js"
},
"./allForks": {
"import": "./lib/allForks/index.js"
"./block": {
"import": "./lib/block/index.js"
},
"./phase0": {
"import": "./lib/phase0/index.js"
"./epoch": {
"import": "./lib/epoch/index.js"
},
"./altair": {
"import": "./lib/altair/index.js"
},
"./bellatrix": {
"import": "./lib/bellatrix/index.js"
"./slot": {
"import": "./lib/slot/index.js"
}
},
"typesVersions": {
Expand Down
9 changes: 0 additions & 9 deletions packages/beacon-state-transition/src/allForks/block/index.ts

This file was deleted.

7 changes: 0 additions & 7 deletions packages/beacon-state-transition/src/allForks/epoch/index.ts

This file was deleted.

14 changes: 0 additions & 14 deletions packages/beacon-state-transition/src/allForks/index.ts

This file was deleted.

30 changes: 0 additions & 30 deletions packages/beacon-state-transition/src/altair/block/index.ts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

41 changes: 0 additions & 41 deletions packages/beacon-state-transition/src/altair/epoch/index.ts

This file was deleted.

This file was deleted.

This file was deleted.

13 changes: 0 additions & 13 deletions packages/beacon-state-transition/src/altair/index.ts

This file was deleted.

32 changes: 0 additions & 32 deletions packages/beacon-state-transition/src/bellatrix/block/index.ts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

14 changes: 0 additions & 14 deletions packages/beacon-state-transition/src/bellatrix/index.ts

This file was deleted.

47 changes: 47 additions & 0 deletions packages/beacon-state-transition/src/block/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {ForkSeq} from "@chainsafe/lodestar-params";
import {allForks, altair, bellatrix} from "@chainsafe/lodestar-types";
import {ExecutionEngine} from "../util/executionEngine.js";
import {isExecutionEnabled} from "../util/bellatrix.js";
import {CachedBeaconStateAllForks, CachedBeaconStateBellatrix} from "../types.js";
import {processExecutionPayload} from "./processExecutionPayload.js";
import {processSyncAggregate} from "./processSyncCommittee.js";
import {processBlockHeader} from "./processBlockHeader.js";
import {processEth1Data} from "./processEth1Data.js";
import {processOperations} from "./processOperations.js";
import {processRandao} from "./processRandao.js";

// Spec tests
export {processBlockHeader, processExecutionPayload, processRandao, processEth1Data, processSyncAggregate};
export * from "./processOperations.js";

export * from "./initiateValidatorExit.js";
export * from "./isValidIndexedAttestation.js";

export function processBlock(
fork: ForkSeq,
state: CachedBeaconStateAllForks,
block: allForks.BeaconBlock,
verifySignatures = true,
executionEngine: ExecutionEngine | null
): void {
processBlockHeader(state, block);

// The call to the process_execution_payload must happen before the call to the process_randao as the former depends
// on the randao_mix computed with the reveal of the previous block.
if (fork >= ForkSeq.bellatrix) {
if (isExecutionEnabled(state as CachedBeaconStateBellatrix, (block as bellatrix.BeaconBlock).body)) {
processExecutionPayload(
state as CachedBeaconStateBellatrix,
(block as bellatrix.BeaconBlock).body.executionPayload,
executionEngine
);
}
}

processRandao(state, block, verifySignatures);
processEth1Data(state, block.body.eth1Data);
processOperations(fork, state, block.body, verifySignatures);
if (fork >= ForkSeq.altair) {
processSyncAggregate(state, block as altair.BeaconBlock, verifySignatures);
}
}
Loading

0 comments on commit fe5c98e

Please sign in to comment.