@lodestar/state-transition 1.39.0-dev.ad129ced66 → 1.39.0-dev.ad81ef1e30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cache/epochCache.d.ts +2 -16
- package/lib/cache/epochCache.d.ts.map +1 -1
- package/lib/cache/epochCache.js +7 -75
- package/lib/cache/epochCache.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/util/index.d.ts +1 -2
- package/lib/util/index.d.ts.map +1 -1
- package/lib/util/index.js +1 -2
- package/lib/util/index.js.map +1 -1
- package/lib/util/shuffling.d.ts +58 -0
- package/lib/util/shuffling.d.ts.map +1 -0
- package/lib/util/shuffling.js +175 -0
- package/lib/util/shuffling.js.map +1 -0
- package/package.json +7 -7
- package/src/cache/epochCache.ts +12 -96
- package/src/index.ts +0 -2
- package/src/util/index.ts +1 -2
- package/src/util/shuffling.ts +234 -0
- package/lib/util/calculateCommitteeAssignments.d.ts +0 -12
- package/lib/util/calculateCommitteeAssignments.d.ts.map +0 -1
- package/lib/util/calculateCommitteeAssignments.js +0 -26
- package/lib/util/calculateCommitteeAssignments.js.map +0 -1
- package/lib/util/shufflingDecisionRoot.d.ts +0 -20
- package/lib/util/shufflingDecisionRoot.d.ts.map +0 -1
- package/lib/util/shufflingDecisionRoot.js +0 -76
- package/lib/util/shufflingDecisionRoot.js.map +0 -1
- package/src/util/calculateCommitteeAssignments.ts +0 -43
- package/src/util/shufflingDecisionRoot.ts +0 -81
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { SLOTS_PER_EPOCH } from "@lodestar/params";
|
|
2
|
-
export function calculateCommitteeAssignments(epochShuffling, requestedValidatorIndices) {
|
|
3
|
-
const requestedValidatorIndicesSet = new Set(requestedValidatorIndices);
|
|
4
|
-
const duties = new Map();
|
|
5
|
-
const epochCommittees = epochShuffling.committees;
|
|
6
|
-
for (let epochSlot = 0; epochSlot < SLOTS_PER_EPOCH; epochSlot++) {
|
|
7
|
-
const slotCommittees = epochCommittees[epochSlot];
|
|
8
|
-
for (let i = 0, committeesAtSlot = slotCommittees.length; i < committeesAtSlot; i++) {
|
|
9
|
-
for (let j = 0, committeeLength = slotCommittees[i].length; j < committeeLength; j++) {
|
|
10
|
-
const validatorIndex = slotCommittees[i][j];
|
|
11
|
-
if (requestedValidatorIndicesSet.has(validatorIndex)) {
|
|
12
|
-
duties.set(validatorIndex, {
|
|
13
|
-
validatorIndex,
|
|
14
|
-
committeeLength,
|
|
15
|
-
committeesAtSlot,
|
|
16
|
-
validatorCommitteeIndex: j,
|
|
17
|
-
committeeIndex: i,
|
|
18
|
-
slot: epochShuffling.epoch * SLOTS_PER_EPOCH + epochSlot,
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return duties;
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=calculateCommitteeAssignments.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"calculateCommitteeAssignments.js","sourceRoot":"","sources":["../../src/util/calculateCommitteeAssignments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,kBAAkB,CAAC;AAcjD,MAAM,UAAU,6BAA6B,CAC3C,cAA8B,EAC9B,yBAA2C;IAE3C,MAAM,4BAA4B,GAAG,IAAI,GAAG,CAAC,yBAAyB,CAAC,CAAC;IACxE,MAAM,MAAM,GAAG,IAAI,GAAG,EAAgC,CAAC;IAEvD,MAAM,eAAe,GAAG,cAAc,CAAC,UAAU,CAAC;IAClD,KAAK,IAAI,SAAS,GAAG,CAAC,EAAE,SAAS,GAAG,eAAe,EAAE,SAAS,EAAE,EAAE,CAAC;QACjE,MAAM,cAAc,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;QAClD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,gBAAgB,GAAG,cAAc,CAAC,MAAM,EAAE,CAAC,GAAG,gBAAgB,EAAE,CAAC,EAAE,EAAE,CAAC;YACpF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,eAAe,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,eAAe,EAAE,CAAC,EAAE,EAAE,CAAC;gBACrF,MAAM,cAAc,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC5C,IAAI,4BAA4B,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,CAAC;oBACrD,MAAM,CAAC,GAAG,CAAC,cAAc,EAAE;wBACzB,cAAc;wBACd,eAAe;wBACf,gBAAgB;wBAChB,uBAAuB,EAAE,CAAC;wBAC1B,cAAc,EAAE,CAAC;wBACjB,IAAI,EAAE,cAAc,CAAC,KAAK,GAAG,eAAe,GAAG,SAAS;qBACzD,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ForkName } from "@lodestar/params";
|
|
2
|
-
import { Epoch, Root } from "@lodestar/types";
|
|
3
|
-
import { CachedBeaconStateAllForks } from "../types.js";
|
|
4
|
-
/**
|
|
5
|
-
* Returns the block root which decided the proposer shuffling for the current epoch. This root
|
|
6
|
-
* can be used to key this proposer shuffling.
|
|
7
|
-
*
|
|
8
|
-
* Returns `null` on the one-off scenario where the genesis block decides its own shuffling.
|
|
9
|
-
* It should be set to the latest block applied to this `state` or the genesis block root.
|
|
10
|
-
*/
|
|
11
|
-
export declare function proposerShufflingDecisionRoot(fork: ForkName, state: CachedBeaconStateAllForks): Root | null;
|
|
12
|
-
/**
|
|
13
|
-
* Returns the block root which decided the attester shuffling for the given `requestedEpoch`.
|
|
14
|
-
* This root can be used to key that attester shuffling.
|
|
15
|
-
*
|
|
16
|
-
* Returns `null` on the one-off scenario where the genesis block decides its own shuffling.
|
|
17
|
-
* It should be set to the latest block applied to this `state` or the genesis block root.
|
|
18
|
-
*/
|
|
19
|
-
export declare function attesterShufflingDecisionRoot(state: CachedBeaconStateAllForks, requestedEpoch: Epoch): Root | null;
|
|
20
|
-
//# sourceMappingURL=shufflingDecisionRoot.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shufflingDecisionRoot.d.ts","sourceRoot":"","sources":["../../src/util/shufflingDecisionRoot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAiB,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAC,KAAK,EAAE,IAAI,EAAO,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAC,yBAAyB,EAAC,MAAM,aAAa,CAAC;AAItD;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,yBAAyB,GAAG,IAAI,GAAG,IAAI,CAM3G;AAaD;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,yBAAyB,EAAE,cAAc,EAAE,KAAK,GAAG,IAAI,GAAG,IAAI,CAMlH"}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { isForkPostFulu } from "@lodestar/params";
|
|
2
|
-
import { getBlockRootAtSlot } from "./blockRoot.js";
|
|
3
|
-
import { computeStartSlotAtEpoch } from "./epoch.js";
|
|
4
|
-
/**
|
|
5
|
-
* Returns the block root which decided the proposer shuffling for the current epoch. This root
|
|
6
|
-
* can be used to key this proposer shuffling.
|
|
7
|
-
*
|
|
8
|
-
* Returns `null` on the one-off scenario where the genesis block decides its own shuffling.
|
|
9
|
-
* It should be set to the latest block applied to this `state` or the genesis block root.
|
|
10
|
-
*/
|
|
11
|
-
export function proposerShufflingDecisionRoot(fork, state) {
|
|
12
|
-
const decisionSlot = proposerShufflingDecisionSlot(fork, state);
|
|
13
|
-
if (state.slot === decisionSlot) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
return getBlockRootAtSlot(state, decisionSlot);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Returns the slot at which the proposer shuffling was decided. The block root at this slot
|
|
20
|
-
* can be used to key the proposer shuffling for the current epoch.
|
|
21
|
-
*/
|
|
22
|
-
function proposerShufflingDecisionSlot(fork, state) {
|
|
23
|
-
// After fulu, the decision slot is in previous epoch due to deterministic proposer lookahead
|
|
24
|
-
const epoch = isForkPostFulu(fork) ? state.epochCtx.epoch - 1 : state.epochCtx.epoch;
|
|
25
|
-
const startSlot = computeStartSlotAtEpoch(epoch);
|
|
26
|
-
return Math.max(startSlot - 1, 0);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Returns the block root which decided the attester shuffling for the given `requestedEpoch`.
|
|
30
|
-
* This root can be used to key that attester shuffling.
|
|
31
|
-
*
|
|
32
|
-
* Returns `null` on the one-off scenario where the genesis block decides its own shuffling.
|
|
33
|
-
* It should be set to the latest block applied to this `state` or the genesis block root.
|
|
34
|
-
*/
|
|
35
|
-
export function attesterShufflingDecisionRoot(state, requestedEpoch) {
|
|
36
|
-
const decisionSlot = attesterShufflingDecisionSlot(state, requestedEpoch);
|
|
37
|
-
if (state.slot === decisionSlot) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
return getBlockRootAtSlot(state, decisionSlot);
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Returns the slot at which the proposer shuffling was decided. The block root at this slot
|
|
44
|
-
* can be used to key the proposer shuffling for the current epoch.
|
|
45
|
-
*/
|
|
46
|
-
function attesterShufflingDecisionSlot(state, requestedEpoch) {
|
|
47
|
-
const epoch = attesterShufflingDecisionEpoch(state, requestedEpoch);
|
|
48
|
-
const slot = computeStartSlotAtEpoch(epoch);
|
|
49
|
-
return Math.max(slot - 1, 0);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Returns the epoch at which the attester shuffling was decided.
|
|
53
|
-
*
|
|
54
|
-
* Spec ref: https://github.com/ethereum/beacon-APIs/blob/v2.1.0/apis/validator/duties/attester.yaml#L15
|
|
55
|
-
*
|
|
56
|
-
* Throws an error when:
|
|
57
|
-
* - `EpochTooLow` when `requestedEpoch` is more than 1 prior to `currentEpoch`.
|
|
58
|
-
* - `EpochTooHigh` when `requestedEpoch` is more than 1 after `currentEpoch`.
|
|
59
|
-
*/
|
|
60
|
-
function attesterShufflingDecisionEpoch(state, requestedEpoch) {
|
|
61
|
-
const currentEpoch = state.epochCtx.epoch;
|
|
62
|
-
// Next
|
|
63
|
-
if (requestedEpoch === currentEpoch + 1)
|
|
64
|
-
return currentEpoch;
|
|
65
|
-
// Current
|
|
66
|
-
if (requestedEpoch === currentEpoch)
|
|
67
|
-
return Math.max(currentEpoch - 1, 0);
|
|
68
|
-
// Previous
|
|
69
|
-
if (requestedEpoch === currentEpoch - 1)
|
|
70
|
-
return Math.max(currentEpoch - 2, 0);
|
|
71
|
-
if (requestedEpoch < currentEpoch) {
|
|
72
|
-
throw Error(`EpochTooLow: current ${currentEpoch} requested ${requestedEpoch}`);
|
|
73
|
-
}
|
|
74
|
-
throw Error(`EpochTooHigh: current ${currentEpoch} requested ${requestedEpoch}`);
|
|
75
|
-
}
|
|
76
|
-
//# sourceMappingURL=shufflingDecisionRoot.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shufflingDecisionRoot.js","sourceRoot":"","sources":["../../src/util/shufflingDecisionRoot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAG1D,OAAO,EAAC,kBAAkB,EAAC,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAC,uBAAuB,EAAC,MAAM,YAAY,CAAC;AAEnD;;;;;;GAMG;AACH,MAAM,UAAU,6BAA6B,CAAC,IAAc,EAAE,KAAgC;IAC5F,MAAM,YAAY,GAAG,6BAA6B,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAChE,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,kBAAkB,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;AACjD,CAAC;AAED;;;GAGG;AACH,SAAS,6BAA6B,CAAC,IAAc,EAAE,KAAgC;IACrF,6FAA6F;IAC7F,MAAM,KAAK,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;IACrF,MAAM,SAAS,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAC;IACjD,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;AACpC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,6BAA6B,CAAC,KAAgC,EAAE,cAAqB;IACnG,MAAM,YAAY,GAAG,6BAA6B,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;IAC1E,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,kBAAkB,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;AACjD,CAAC;AAED;;;GAGG;AACH,SAAS,6BAA6B,CAAC,KAAgC,EAAE,cAAqB;IAC5F,MAAM,KAAK,GAAG,8BAA8B,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;IACpE,MAAM,IAAI,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAC;IAC5C,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;AAC/B,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,8BAA8B,CAAC,KAAgC,EAAE,cAAqB;IAC7F,MAAM,YAAY,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;IAE1C,OAAO;IACP,IAAI,cAAc,KAAK,YAAY,GAAG,CAAC;QAAE,OAAO,YAAY,CAAC;IAC7D,UAAU;IACV,IAAI,cAAc,KAAK,YAAY;QAAE,OAAO,IAAI,CAAC,GAAG,CAAC,YAAY,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1E,WAAW;IACX,IAAI,cAAc,KAAK,YAAY,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC,GAAG,CAAC,YAAY,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IAE9E,IAAI,cAAc,GAAG,YAAY,EAAE,CAAC;QAClC,MAAM,KAAK,CAAC,wBAAwB,YAAY,cAAc,cAAc,EAAE,CAAC,CAAC;IAClF,CAAC;IACD,MAAM,KAAK,CAAC,yBAAyB,YAAY,cAAc,cAAc,EAAE,CAAC,CAAC;AACnF,CAAC"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import {SLOTS_PER_EPOCH} from "@lodestar/params";
|
|
2
|
-
import {CommitteeIndex, Slot, ValidatorIndex} from "@lodestar/types";
|
|
3
|
-
import {EpochShuffling} from "./epochShuffling.js";
|
|
4
|
-
|
|
5
|
-
// Copied from lodestar-api package to avoid depending on the package
|
|
6
|
-
export interface AttesterDuty {
|
|
7
|
-
validatorIndex: ValidatorIndex;
|
|
8
|
-
committeeIndex: CommitteeIndex;
|
|
9
|
-
committeeLength: number;
|
|
10
|
-
committeesAtSlot: number;
|
|
11
|
-
validatorCommitteeIndex: number;
|
|
12
|
-
slot: Slot;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function calculateCommitteeAssignments(
|
|
16
|
-
epochShuffling: EpochShuffling,
|
|
17
|
-
requestedValidatorIndices: ValidatorIndex[]
|
|
18
|
-
): Map<ValidatorIndex, AttesterDuty> {
|
|
19
|
-
const requestedValidatorIndicesSet = new Set(requestedValidatorIndices);
|
|
20
|
-
const duties = new Map<ValidatorIndex, AttesterDuty>();
|
|
21
|
-
|
|
22
|
-
const epochCommittees = epochShuffling.committees;
|
|
23
|
-
for (let epochSlot = 0; epochSlot < SLOTS_PER_EPOCH; epochSlot++) {
|
|
24
|
-
const slotCommittees = epochCommittees[epochSlot];
|
|
25
|
-
for (let i = 0, committeesAtSlot = slotCommittees.length; i < committeesAtSlot; i++) {
|
|
26
|
-
for (let j = 0, committeeLength = slotCommittees[i].length; j < committeeLength; j++) {
|
|
27
|
-
const validatorIndex = slotCommittees[i][j];
|
|
28
|
-
if (requestedValidatorIndicesSet.has(validatorIndex)) {
|
|
29
|
-
duties.set(validatorIndex, {
|
|
30
|
-
validatorIndex,
|
|
31
|
-
committeeLength,
|
|
32
|
-
committeesAtSlot,
|
|
33
|
-
validatorCommitteeIndex: j,
|
|
34
|
-
committeeIndex: i,
|
|
35
|
-
slot: epochShuffling.epoch * SLOTS_PER_EPOCH + epochSlot,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return duties;
|
|
43
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import {ForkName, isForkPostFulu} from "@lodestar/params";
|
|
2
|
-
import {Epoch, Root, Slot} from "@lodestar/types";
|
|
3
|
-
import {CachedBeaconStateAllForks} from "../types.js";
|
|
4
|
-
import {getBlockRootAtSlot} from "./blockRoot.js";
|
|
5
|
-
import {computeStartSlotAtEpoch} from "./epoch.js";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Returns the block root which decided the proposer shuffling for the current epoch. This root
|
|
9
|
-
* can be used to key this proposer shuffling.
|
|
10
|
-
*
|
|
11
|
-
* Returns `null` on the one-off scenario where the genesis block decides its own shuffling.
|
|
12
|
-
* It should be set to the latest block applied to this `state` or the genesis block root.
|
|
13
|
-
*/
|
|
14
|
-
export function proposerShufflingDecisionRoot(fork: ForkName, state: CachedBeaconStateAllForks): Root | null {
|
|
15
|
-
const decisionSlot = proposerShufflingDecisionSlot(fork, state);
|
|
16
|
-
if (state.slot === decisionSlot) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
return getBlockRootAtSlot(state, decisionSlot);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Returns the slot at which the proposer shuffling was decided. The block root at this slot
|
|
24
|
-
* can be used to key the proposer shuffling for the current epoch.
|
|
25
|
-
*/
|
|
26
|
-
function proposerShufflingDecisionSlot(fork: ForkName, state: CachedBeaconStateAllForks): Slot {
|
|
27
|
-
// After fulu, the decision slot is in previous epoch due to deterministic proposer lookahead
|
|
28
|
-
const epoch = isForkPostFulu(fork) ? state.epochCtx.epoch - 1 : state.epochCtx.epoch;
|
|
29
|
-
const startSlot = computeStartSlotAtEpoch(epoch);
|
|
30
|
-
return Math.max(startSlot - 1, 0);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Returns the block root which decided the attester shuffling for the given `requestedEpoch`.
|
|
35
|
-
* This root can be used to key that attester shuffling.
|
|
36
|
-
*
|
|
37
|
-
* Returns `null` on the one-off scenario where the genesis block decides its own shuffling.
|
|
38
|
-
* It should be set to the latest block applied to this `state` or the genesis block root.
|
|
39
|
-
*/
|
|
40
|
-
export function attesterShufflingDecisionRoot(state: CachedBeaconStateAllForks, requestedEpoch: Epoch): Root | null {
|
|
41
|
-
const decisionSlot = attesterShufflingDecisionSlot(state, requestedEpoch);
|
|
42
|
-
if (state.slot === decisionSlot) {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
return getBlockRootAtSlot(state, decisionSlot);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Returns the slot at which the proposer shuffling was decided. The block root at this slot
|
|
50
|
-
* can be used to key the proposer shuffling for the current epoch.
|
|
51
|
-
*/
|
|
52
|
-
function attesterShufflingDecisionSlot(state: CachedBeaconStateAllForks, requestedEpoch: Epoch): Slot {
|
|
53
|
-
const epoch = attesterShufflingDecisionEpoch(state, requestedEpoch);
|
|
54
|
-
const slot = computeStartSlotAtEpoch(epoch);
|
|
55
|
-
return Math.max(slot - 1, 0);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Returns the epoch at which the attester shuffling was decided.
|
|
60
|
-
*
|
|
61
|
-
* Spec ref: https://github.com/ethereum/beacon-APIs/blob/v2.1.0/apis/validator/duties/attester.yaml#L15
|
|
62
|
-
*
|
|
63
|
-
* Throws an error when:
|
|
64
|
-
* - `EpochTooLow` when `requestedEpoch` is more than 1 prior to `currentEpoch`.
|
|
65
|
-
* - `EpochTooHigh` when `requestedEpoch` is more than 1 after `currentEpoch`.
|
|
66
|
-
*/
|
|
67
|
-
function attesterShufflingDecisionEpoch(state: CachedBeaconStateAllForks, requestedEpoch: Epoch): Epoch {
|
|
68
|
-
const currentEpoch = state.epochCtx.epoch;
|
|
69
|
-
|
|
70
|
-
// Next
|
|
71
|
-
if (requestedEpoch === currentEpoch + 1) return currentEpoch;
|
|
72
|
-
// Current
|
|
73
|
-
if (requestedEpoch === currentEpoch) return Math.max(currentEpoch - 1, 0);
|
|
74
|
-
// Previous
|
|
75
|
-
if (requestedEpoch === currentEpoch - 1) return Math.max(currentEpoch - 2, 0);
|
|
76
|
-
|
|
77
|
-
if (requestedEpoch < currentEpoch) {
|
|
78
|
-
throw Error(`EpochTooLow: current ${currentEpoch} requested ${requestedEpoch}`);
|
|
79
|
-
}
|
|
80
|
-
throw Error(`EpochTooHigh: current ${currentEpoch} requested ${requestedEpoch}`);
|
|
81
|
-
}
|