-
-
Notifications
You must be signed in to change notification settings - Fork 348
/
Copy pathprocessOperations.ts
82 lines (70 loc) · 3.07 KB
/
processOperations.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import {ForkSeq} from "@lodestar/params";
import {BeaconBlockBody, capella, electra} from "@lodestar/types";
import {CachedBeaconStateAllForks, CachedBeaconStateCapella, CachedBeaconStateElectra} from "../types.js";
import {getEth1DepositCount} from "../util/deposit.js";
import {processAttestations} from "./processAttestations.js";
import {processAttesterSlashing} from "./processAttesterSlashing.js";
import {processBlsToExecutionChange} from "./processBlsToExecutionChange.js";
import {processConsolidationRequest} from "./processConsolidationRequest.js";
import {processDeposit} from "./processDeposit.js";
import {processDepositRequest} from "./processDepositRequest.js";
import {processProposerSlashing} from "./processProposerSlashing.js";
import {processVoluntaryExit} from "./processVoluntaryExit.js";
import {processWithdrawalRequest} from "./processWithdrawalRequest.js";
import {ProcessBlockOpts} from "./types.js";
export {
processProposerSlashing,
processAttesterSlashing,
processAttestations,
processDeposit,
processVoluntaryExit,
processWithdrawalRequest,
processBlsToExecutionChange,
processDepositRequest,
processConsolidationRequest,
};
export function processOperations(
fork: ForkSeq,
state: CachedBeaconStateAllForks,
body: BeaconBlockBody,
opts: ProcessBlockOpts = {verifySignatures: true}
): void {
// verify that outstanding deposits are processed up to the maximum number of deposits
const maxDeposits = getEth1DepositCount(state);
if (body.deposits.length !== maxDeposits) {
throw new Error(
`Block contains incorrect number of deposits: depositCount=${body.deposits.length} expected=${maxDeposits}`
);
}
for (const proposerSlashing of body.proposerSlashings) {
processProposerSlashing(fork, state, proposerSlashing, opts.verifySignatures);
}
for (const attesterSlashing of body.attesterSlashings) {
processAttesterSlashing(fork, state, attesterSlashing, opts.verifySignatures);
}
processAttestations(fork, state, body.attestations, opts.verifySignatures);
for (const deposit of body.deposits) {
processDeposit(fork, state, deposit);
}
for (const voluntaryExit of body.voluntaryExits) {
processVoluntaryExit(fork, state, voluntaryExit, opts.verifySignatures);
}
if (fork >= ForkSeq.capella) {
for (const blsToExecutionChange of (body as capella.BeaconBlockBody).blsToExecutionChanges) {
processBlsToExecutionChange(state as CachedBeaconStateCapella, blsToExecutionChange);
}
}
if (fork >= ForkSeq.electra) {
const stateElectra = state as CachedBeaconStateElectra;
const bodyElectra = body as electra.BeaconBlockBody;
for (const depositRequest of bodyElectra.executionRequests.deposits) {
processDepositRequest(stateElectra, depositRequest);
}
for (const elWithdrawalRequest of bodyElectra.executionRequests.withdrawals) {
processWithdrawalRequest(fork, stateElectra, elWithdrawalRequest);
}
for (const elConsolidationRequest of bodyElectra.executionRequests.consolidations) {
processConsolidationRequest(stateElectra, elConsolidationRequest);
}
}
}