-
-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
spec runner merge sanity and operations fixes
- Loading branch information
Showing
9 changed files
with
108 additions
and
16 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
17 changes: 17 additions & 0 deletions
17
packages/beacon-state-transition/src/merge/block/processAttesterSlashing.ts
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {allForks, merge, phase0} from "@chainsafe/lodestar-types"; | ||
import {ForkName} from "@chainsafe/lodestar-params"; | ||
import {CachedBeaconState} from "../../allForks/util"; | ||
import {processAttesterSlashing as processAttesterSlashingAllForks} from "../../allForks/block"; | ||
|
||
export function processAttesterSlashing( | ||
state: CachedBeaconState<merge.BeaconState>, | ||
attesterSlashing: phase0.AttesterSlashing, | ||
verifySignatures = true | ||
): void { | ||
processAttesterSlashingAllForks( | ||
ForkName.merge, | ||
state as CachedBeaconState<allForks.BeaconState>, | ||
attesterSlashing, | ||
verifySignatures | ||
); | ||
} |
44 changes: 44 additions & 0 deletions
44
packages/beacon-state-transition/src/merge/block/processOperations.ts
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import {readonlyValues} from "@chainsafe/ssz"; | ||
import {altair, merge} from "@chainsafe/lodestar-types"; | ||
|
||
import {CachedBeaconState} from "../../allForks/util"; | ||
import {processProposerSlashing} from "./processProposerSlashing"; | ||
import {processAttesterSlashing} from "./processAttesterSlashing"; | ||
import {processAttestations} from "../../altair/block/processAttestation"; | ||
import {processDeposit} from "../../altair/block/processDeposit"; | ||
import {processVoluntaryExit} from "../../altair/block/processVoluntaryExit"; | ||
import {MAX_DEPOSITS} from "@chainsafe/lodestar-params"; | ||
|
||
export function processOperations( | ||
state: CachedBeaconState<merge.BeaconState>, | ||
body: merge.BeaconBlockBody, | ||
verifySignatures = true | ||
): void { | ||
// verify that outstanding deposits are processed up to the maximum number of deposits | ||
const maxDeposits = Math.min(MAX_DEPOSITS, state.eth1Data.depositCount - state.eth1DepositIndex); | ||
if (body.deposits.length !== maxDeposits) { | ||
throw new Error( | ||
`Block contains incorrect number of deposits: depositCount=${body.deposits.length} expected=${maxDeposits}` | ||
); | ||
} | ||
|
||
for (const proposerSlashing of readonlyValues(body.proposerSlashings)) { | ||
processProposerSlashing(state, proposerSlashing, verifySignatures); | ||
} | ||
for (const attesterSlashing of readonlyValues(body.attesterSlashings)) { | ||
processAttesterSlashing(state, attesterSlashing, verifySignatures); | ||
} | ||
|
||
processAttestations( | ||
(state as unknown) as CachedBeaconState<altair.BeaconState>, | ||
Array.from(readonlyValues(body.attestations)), | ||
verifySignatures | ||
); | ||
|
||
for (const deposit of readonlyValues(body.deposits)) { | ||
processDeposit((state as unknown) as CachedBeaconState<altair.BeaconState>, deposit); | ||
} | ||
for (const voluntaryExit of readonlyValues(body.voluntaryExits)) { | ||
processVoluntaryExit((state as unknown) as CachedBeaconState<altair.BeaconState>, voluntaryExit, verifySignatures); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/beacon-state-transition/src/merge/block/processProposerSlashing.ts
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {allForks, merge, phase0} from "@chainsafe/lodestar-types"; | ||
import {ForkName} from "@chainsafe/lodestar-params"; | ||
import {CachedBeaconState} from "../../allForks/util"; | ||
import {processProposerSlashing as processProposerSlashingAllForks} from "../../allForks/block"; | ||
|
||
export function processProposerSlashing( | ||
state: CachedBeaconState<merge.BeaconState>, | ||
proposerSlashing: phase0.ProposerSlashing, | ||
verifySignatures = true | ||
): void { | ||
processProposerSlashingAllForks( | ||
ForkName.merge, | ||
state as CachedBeaconState<allForks.BeaconState>, | ||
proposerSlashing, | ||
verifySignatures | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export {processSlashings} from "./processSlashings"; |
8 changes: 8 additions & 0 deletions
8
packages/beacon-state-transition/src/merge/epoch/processSlashings.ts
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {allForks, merge} from "@chainsafe/lodestar-types"; | ||
import {ForkName} from "@chainsafe/lodestar-params"; | ||
import {CachedBeaconState, IEpochProcess} from "../../allForks/util"; | ||
import {processSlashingsAllForks} from "../../allForks/epoch/processSlashings"; | ||
|
||
export function processSlashings(state: CachedBeaconState<merge.BeaconState>, epochProcess: IEpochProcess): void { | ||
processSlashingsAllForks(ForkName.merge, state as CachedBeaconState<allForks.BeaconState>, epochProcess); | ||
} |
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
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
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