@lodestar/state-transition 1.39.1 → 1.40.0-dev.193b2e2047
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/block/index.d.ts +1 -0
- package/lib/block/index.d.ts.map +1 -1
- package/lib/block/index.js +1 -0
- package/lib/block/index.js.map +1 -1
- package/lib/block/isValidIndexedAttestation.d.ts +4 -5
- package/lib/block/isValidIndexedAttestation.d.ts.map +1 -1
- package/lib/block/isValidIndexedAttestation.js +9 -10
- package/lib/block/isValidIndexedAttestation.js.map +1 -1
- package/lib/block/isValidIndexedPayloadAttestation.d.ts.map +1 -1
- package/lib/block/isValidIndexedPayloadAttestation.js +1 -1
- package/lib/block/isValidIndexedPayloadAttestation.js.map +1 -1
- package/lib/block/processAttestationPhase0.d.ts.map +1 -1
- package/lib/block/processAttestationPhase0.js +1 -1
- package/lib/block/processAttestationPhase0.js.map +1 -1
- package/lib/block/processAttestationsAltair.d.ts.map +1 -1
- package/lib/block/processAttestationsAltair.js +2 -2
- package/lib/block/processAttestationsAltair.js.map +1 -1
- package/lib/block/processAttesterSlashing.d.ts +3 -2
- package/lib/block/processAttesterSlashing.d.ts.map +1 -1
- package/lib/block/processAttesterSlashing.js +3 -3
- package/lib/block/processAttesterSlashing.js.map +1 -1
- package/lib/block/processBlsToExecutionChange.d.ts +3 -1
- package/lib/block/processBlsToExecutionChange.d.ts.map +1 -1
- package/lib/block/processBlsToExecutionChange.js +7 -11
- package/lib/block/processBlsToExecutionChange.js.map +1 -1
- package/lib/block/processConsolidationRequest.d.ts +1 -2
- package/lib/block/processConsolidationRequest.d.ts.map +1 -1
- package/lib/block/processConsolidationRequest.js +2 -2
- package/lib/block/processConsolidationRequest.js.map +1 -1
- package/lib/block/processDepositRequest.d.ts +8 -2
- package/lib/block/processDepositRequest.d.ts.map +1 -1
- package/lib/block/processDepositRequest.js +81 -8
- package/lib/block/processDepositRequest.js.map +1 -1
- package/lib/block/processExecutionPayloadBid.d.ts.map +1 -1
- package/lib/block/processExecutionPayloadBid.js +16 -29
- package/lib/block/processExecutionPayloadBid.js.map +1 -1
- package/lib/block/processExecutionPayloadEnvelope.d.ts.map +1 -1
- package/lib/block/processExecutionPayloadEnvelope.js +26 -25
- package/lib/block/processExecutionPayloadEnvelope.js.map +1 -1
- package/lib/block/processOperations.js +2 -2
- package/lib/block/processOperations.js.map +1 -1
- package/lib/block/processProposerSlashing.d.ts +5 -2
- package/lib/block/processProposerSlashing.d.ts.map +1 -1
- package/lib/block/processProposerSlashing.js +8 -6
- package/lib/block/processProposerSlashing.js.map +1 -1
- package/lib/block/processSyncCommittee.d.ts +1 -2
- package/lib/block/processSyncCommittee.d.ts.map +1 -1
- package/lib/block/processSyncCommittee.js +5 -5
- package/lib/block/processSyncCommittee.js.map +1 -1
- package/lib/block/processVoluntaryExit.d.ts +1 -1
- package/lib/block/processVoluntaryExit.d.ts.map +1 -1
- package/lib/block/processVoluntaryExit.js +45 -3
- package/lib/block/processVoluntaryExit.js.map +1 -1
- package/lib/block/processWithdrawalRequest.js +1 -1
- package/lib/block/processWithdrawalRequest.js.map +1 -1
- package/lib/block/processWithdrawals.d.ts +1 -0
- package/lib/block/processWithdrawals.d.ts.map +1 -1
- package/lib/block/processWithdrawals.js +121 -66
- package/lib/block/processWithdrawals.js.map +1 -1
- package/lib/cache/epochCache.d.ts +8 -28
- package/lib/cache/epochCache.d.ts.map +1 -1
- package/lib/cache/epochCache.js +40 -180
- package/lib/cache/epochCache.js.map +1 -1
- package/lib/cache/epochTransitionCache.d.ts +5 -12
- package/lib/cache/epochTransitionCache.d.ts.map +1 -1
- package/lib/cache/epochTransitionCache.js +4 -14
- package/lib/cache/epochTransitionCache.js.map +1 -1
- package/lib/cache/stateCache.d.ts.map +1 -1
- package/lib/cache/stateCache.js +1 -2
- package/lib/cache/stateCache.js.map +1 -1
- package/lib/epoch/processBuilderPendingPayments.d.ts.map +1 -1
- package/lib/epoch/processBuilderPendingPayments.js +1 -4
- package/lib/epoch/processBuilderPendingPayments.js.map +1 -1
- package/lib/epoch/processProposerLookahead.d.ts.map +1 -1
- package/lib/epoch/processProposerLookahead.js +3 -6
- package/lib/epoch/processProposerLookahead.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/rewards/blockRewards.d.ts +2 -1
- package/lib/rewards/blockRewards.d.ts.map +1 -1
- package/lib/rewards/blockRewards.js +3 -2
- package/lib/rewards/blockRewards.js.map +1 -1
- package/lib/rewards/syncCommitteeRewards.d.ts.map +1 -1
- package/lib/rewards/syncCommitteeRewards.js +10 -11
- package/lib/rewards/syncCommitteeRewards.js.map +1 -1
- package/lib/signatureSets/attesterSlashings.d.ts +3 -4
- package/lib/signatureSets/attesterSlashings.d.ts.map +1 -1
- package/lib/signatureSets/attesterSlashings.js +6 -6
- package/lib/signatureSets/attesterSlashings.js.map +1 -1
- package/lib/signatureSets/blsToExecutionChange.d.ts +4 -5
- package/lib/signatureSets/blsToExecutionChange.d.ts.map +1 -1
- package/lib/signatureSets/blsToExecutionChange.js +2 -2
- package/lib/signatureSets/blsToExecutionChange.js.map +1 -1
- package/lib/signatureSets/executionPayloadBid.d.ts +4 -0
- package/lib/signatureSets/executionPayloadBid.d.ts.map +1 -0
- package/lib/signatureSets/executionPayloadBid.js +8 -0
- package/lib/signatureSets/executionPayloadBid.js.map +1 -0
- package/lib/signatureSets/executionPayloadEnvelope.d.ts +4 -0
- package/lib/signatureSets/executionPayloadEnvelope.d.ts.map +1 -0
- package/lib/signatureSets/executionPayloadEnvelope.js +8 -0
- package/lib/signatureSets/executionPayloadEnvelope.js.map +1 -0
- package/lib/signatureSets/index.d.ts +3 -2
- package/lib/signatureSets/index.d.ts.map +1 -1
- package/lib/signatureSets/index.js +10 -8
- package/lib/signatureSets/index.js.map +1 -1
- package/lib/signatureSets/indexedAttestation.d.ts +3 -4
- package/lib/signatureSets/indexedAttestation.d.ts.map +1 -1
- package/lib/signatureSets/indexedAttestation.js +6 -6
- package/lib/signatureSets/indexedAttestation.js.map +1 -1
- package/lib/signatureSets/indexedPayloadAttestation.d.ts +5 -4
- package/lib/signatureSets/indexedPayloadAttestation.d.ts.map +1 -1
- package/lib/signatureSets/indexedPayloadAttestation.js +3 -3
- package/lib/signatureSets/indexedPayloadAttestation.js.map +1 -1
- package/lib/signatureSets/proposer.d.ts +3 -3
- package/lib/signatureSets/proposer.d.ts.map +1 -1
- package/lib/signatureSets/proposer.js +12 -12
- package/lib/signatureSets/proposer.js.map +1 -1
- package/lib/signatureSets/proposerSlashings.d.ts +2 -3
- package/lib/signatureSets/proposerSlashings.d.ts.map +1 -1
- package/lib/signatureSets/proposerSlashings.js +6 -6
- package/lib/signatureSets/proposerSlashings.js.map +1 -1
- package/lib/signatureSets/randao.d.ts +1 -1
- package/lib/signatureSets/randao.d.ts.map +1 -1
- package/lib/signatureSets/randao.js +4 -4
- package/lib/signatureSets/randao.js.map +1 -1
- package/lib/signatureSets/voluntaryExits.d.ts +2 -2
- package/lib/signatureSets/voluntaryExits.d.ts.map +1 -1
- package/lib/signatureSets/voluntaryExits.js +6 -6
- package/lib/signatureSets/voluntaryExits.js.map +1 -1
- package/lib/types.d.ts +1 -1
- package/lib/types.d.ts.map +1 -1
- package/lib/util/electra.d.ts.map +1 -1
- package/lib/util/electra.js +1 -2
- package/lib/util/electra.js.map +1 -1
- package/lib/util/epochShuffling.d.ts +1 -34
- package/lib/util/epochShuffling.d.ts.map +1 -1
- package/lib/util/epochShuffling.js +1 -1
- package/lib/util/epochShuffling.js.map +1 -1
- package/lib/util/gloas.d.ts +46 -5
- package/lib/util/gloas.d.ts.map +1 -1
- package/lib/util/gloas.js +91 -5
- package/lib/util/gloas.js.map +1 -1
- package/lib/util/index.d.ts +2 -2
- package/lib/util/index.d.ts.map +1 -1
- package/lib/util/index.js +2 -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/lib/util/signatureSets.d.ts +38 -5
- package/lib/util/signatureSets.d.ts.map +1 -1
- package/lib/util/signatureSets.js +48 -6
- package/lib/util/signatureSets.js.map +1 -1
- package/lib/util/validator.d.ts +6 -1
- package/lib/util/validator.d.ts.map +1 -1
- package/lib/util/validator.js +26 -16
- package/lib/util/validator.js.map +1 -1
- package/package.json +7 -7
- package/src/block/index.ts +1 -0
- package/src/block/isValidIndexedAttestation.ts +18 -12
- package/src/block/isValidIndexedPayloadAttestation.ts +4 -1
- package/src/block/processAttestationPhase0.ts +2 -1
- package/src/block/processAttestationsAltair.ts +2 -8
- package/src/block/processAttesterSlashing.ts +16 -4
- package/src/block/processBlsToExecutionChange.ts +13 -14
- package/src/block/processConsolidationRequest.ts +2 -3
- package/src/block/processDepositRequest.ts +101 -8
- package/src/block/processExecutionPayloadBid.ts +20 -42
- package/src/block/processExecutionPayloadEnvelope.ts +34 -30
- package/src/block/processOperations.ts +2 -2
- package/src/block/processProposerSlashing.ts +22 -12
- package/src/block/processSyncCommittee.ts +3 -6
- package/src/block/processVoluntaryExit.ts +60 -5
- package/src/block/processWithdrawalRequest.ts +1 -1
- package/src/block/processWithdrawals.ts +168 -70
- package/src/cache/epochCache.ts +52 -214
- package/src/cache/epochTransitionCache.ts +9 -34
- package/src/cache/stateCache.ts +1 -2
- package/src/epoch/processBuilderPendingPayments.ts +1 -5
- package/src/epoch/processProposerLookahead.ts +3 -7
- package/src/index.ts +0 -2
- package/src/rewards/blockRewards.ts +6 -3
- package/src/rewards/syncCommitteeRewards.ts +10 -13
- package/src/signatureSets/attesterSlashings.ts +3 -7
- package/src/signatureSets/blsToExecutionChange.ts +5 -6
- package/src/signatureSets/executionPayloadBid.ts +14 -0
- package/src/signatureSets/executionPayloadEnvelope.ts +13 -0
- package/src/signatureSets/index.ts +8 -9
- package/src/signatureSets/indexedAttestation.ts +2 -7
- package/src/signatureSets/indexedPayloadAttestation.ts +9 -7
- package/src/signatureSets/proposer.ts +8 -12
- package/src/signatureSets/proposerSlashings.ts +4 -7
- package/src/signatureSets/randao.ts +4 -8
- package/src/signatureSets/voluntaryExits.ts +5 -10
- package/src/types.ts +1 -0
- package/src/util/electra.ts +1 -4
- package/src/util/epochShuffling.ts +2 -43
- package/src/util/gloas.ts +116 -10
- package/src/util/index.ts +2 -2
- package/src/util/shuffling.ts +234 -0
- package/src/util/signatureSets.ts +84 -8
- package/src/util/validator.ts +31 -16
- 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
package/src/util/gloas.ts
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import {byteArrayEquals} from "@chainsafe/ssz";
|
|
2
2
|
import {
|
|
3
|
+
BUILDER_INDEX_FLAG,
|
|
3
4
|
BUILDER_PAYMENT_THRESHOLD_DENOMINATOR,
|
|
4
5
|
BUILDER_PAYMENT_THRESHOLD_NUMERATOR,
|
|
5
6
|
BUILDER_WITHDRAWAL_PREFIX,
|
|
6
7
|
EFFECTIVE_BALANCE_INCREMENT,
|
|
8
|
+
FAR_FUTURE_EPOCH,
|
|
9
|
+
MIN_DEPOSIT_AMOUNT,
|
|
7
10
|
SLOTS_PER_EPOCH,
|
|
8
11
|
} from "@lodestar/params";
|
|
9
|
-
import {gloas} from "@lodestar/types";
|
|
12
|
+
import {BuilderIndex, Epoch, ValidatorIndex, gloas} from "@lodestar/types";
|
|
10
13
|
import {AttestationData} from "@lodestar/types/phase0";
|
|
11
|
-
import {CachedBeaconStateGloas} from "../types.
|
|
12
|
-
import {getBlockRootAtSlot} from "./blockRoot.
|
|
13
|
-
import {computeEpochAtSlot} from "./epoch.
|
|
14
|
-
import {RootCache} from "./rootCache.
|
|
14
|
+
import {CachedBeaconStateGloas} from "../types.js";
|
|
15
|
+
import {getBlockRootAtSlot} from "./blockRoot.js";
|
|
16
|
+
import {computeEpochAtSlot} from "./epoch.js";
|
|
17
|
+
import {RootCache} from "./rootCache.js";
|
|
15
18
|
|
|
16
|
-
export function
|
|
19
|
+
export function isBuilderWithdrawalCredential(withdrawalCredentials: Uint8Array): boolean {
|
|
17
20
|
return withdrawalCredentials[0] === BUILDER_WITHDRAWAL_PREFIX;
|
|
18
21
|
}
|
|
19
22
|
|
|
@@ -25,14 +28,117 @@ export function getBuilderPaymentQuorumThreshold(state: CachedBeaconStateGloas):
|
|
|
25
28
|
return Math.floor(quorum / BUILDER_PAYMENT_THRESHOLD_DENOMINATOR);
|
|
26
29
|
}
|
|
27
30
|
|
|
28
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Check if a validator index represents a builder (has the builder flag set).
|
|
33
|
+
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/gloas/beacon-chain.md#new-is_builder_index
|
|
34
|
+
*/
|
|
35
|
+
export function isBuilderIndex(validatorIndex: number): boolean {
|
|
36
|
+
return (validatorIndex & BUILDER_INDEX_FLAG) !== 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Convert a builder index to a flagged validator index for use in Withdrawal containers.
|
|
41
|
+
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/gloas/beacon-chain.md#new-convert_builder_index_to_validator_index
|
|
42
|
+
*/
|
|
43
|
+
export function convertBuilderIndexToValidatorIndex(builderIndex: BuilderIndex): ValidatorIndex {
|
|
44
|
+
return builderIndex | BUILDER_INDEX_FLAG;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Convert a flagged validator index back to a builder index.
|
|
49
|
+
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/gloas/beacon-chain.md#new-convert_validator_index_to_builder_index
|
|
50
|
+
*/
|
|
51
|
+
export function convertValidatorIndexToBuilderIndex(validatorIndex: ValidatorIndex): BuilderIndex {
|
|
52
|
+
return validatorIndex & ~BUILDER_INDEX_FLAG;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Check if a builder is active (deposited and not yet withdrawable).
|
|
57
|
+
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/gloas/beacon-chain.md#isactivebuilder
|
|
58
|
+
*/
|
|
59
|
+
export function isActiveBuilder(builder: gloas.Builder, finalizedEpoch: Epoch): boolean {
|
|
60
|
+
return builder.depositEpoch < finalizedEpoch && builder.withdrawableEpoch === FAR_FUTURE_EPOCH;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Get the total pending balance to withdraw for a builder (from withdrawals + payments).
|
|
65
|
+
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/gloas/beacon-chain.md#new-get_pending_balance_to_withdraw_for_builder
|
|
66
|
+
*/
|
|
67
|
+
export function getPendingBalanceToWithdrawForBuilder(
|
|
29
68
|
state: CachedBeaconStateGloas,
|
|
30
|
-
|
|
69
|
+
builderIndex: BuilderIndex
|
|
70
|
+
): number {
|
|
71
|
+
let pendingBalance = 0;
|
|
72
|
+
|
|
73
|
+
// Sum pending withdrawals
|
|
74
|
+
for (let i = 0; i < state.builderPendingWithdrawals.length; i++) {
|
|
75
|
+
const withdrawal = state.builderPendingWithdrawals.getReadonly(i);
|
|
76
|
+
if (withdrawal.builderIndex === builderIndex) {
|
|
77
|
+
pendingBalance += withdrawal.amount;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Sum pending payments
|
|
82
|
+
for (let i = 0; i < state.builderPendingPayments.length; i++) {
|
|
83
|
+
const payment = state.builderPendingPayments.getReadonly(i);
|
|
84
|
+
if (payment.withdrawal.builderIndex === builderIndex) {
|
|
85
|
+
pendingBalance += payment.withdrawal.amount;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return pendingBalance;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Check if a builder has sufficient balance to cover a bid amount.
|
|
94
|
+
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/gloas/beacon-chain.md#new-can_builder_cover_bid
|
|
95
|
+
*/
|
|
96
|
+
export function canBuilderCoverBid(
|
|
97
|
+
state: CachedBeaconStateGloas,
|
|
98
|
+
builderIndex: BuilderIndex,
|
|
99
|
+
bidAmount: number
|
|
31
100
|
): boolean {
|
|
32
|
-
const builder = state.
|
|
101
|
+
const builder = state.builders.getReadonly(builderIndex);
|
|
102
|
+
const pendingBalance = getPendingBalanceToWithdrawForBuilder(state, builderIndex);
|
|
103
|
+
const minBalance = MIN_DEPOSIT_AMOUNT + pendingBalance;
|
|
104
|
+
|
|
105
|
+
if (builder.balance < minBalance) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return builder.balance - minBalance >= bidAmount;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Initiate a builder exit by setting their withdrawable epoch.
|
|
114
|
+
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/gloas/beacon-chain.md#new-initiate_builder_exit
|
|
115
|
+
*/
|
|
116
|
+
export function initiateBuilderExit(state: CachedBeaconStateGloas, builderIndex: BuilderIndex): void {
|
|
117
|
+
const builder = state.builders.get(builderIndex);
|
|
118
|
+
|
|
119
|
+
// Return if builder already initiated exit
|
|
120
|
+
if (builder.withdrawableEpoch !== FAR_FUTURE_EPOCH) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Set builder exit epoch
|
|
33
125
|
const currentEpoch = computeEpochAtSlot(state.slot);
|
|
126
|
+
builder.withdrawableEpoch = currentEpoch + state.config.MIN_BUILDER_WITHDRAWABILITY_DELAY;
|
|
127
|
+
}
|
|
34
128
|
|
|
35
|
-
|
|
129
|
+
/**
|
|
130
|
+
* Find the index of a builder by their public key.
|
|
131
|
+
* Returns null if not found.
|
|
132
|
+
*
|
|
133
|
+
* May consider builder pubkey cache if performance becomes an issue.
|
|
134
|
+
*/
|
|
135
|
+
export function findBuilderIndexByPubkey(state: CachedBeaconStateGloas, pubkey: Uint8Array): BuilderIndex | null {
|
|
136
|
+
for (let i = 0; i < state.builders.length; i++) {
|
|
137
|
+
if (byteArrayEquals(state.builders.getReadonly(i).pubkey, pubkey)) {
|
|
138
|
+
return i;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return null;
|
|
36
142
|
}
|
|
37
143
|
|
|
38
144
|
export function isAttestationSameSlot(state: CachedBeaconStateGloas, data: AttestationData): boolean {
|
package/src/util/index.ts
CHANGED
|
@@ -5,7 +5,6 @@ export * from "./attesterStatus.js";
|
|
|
5
5
|
export * from "./balance.js";
|
|
6
6
|
export * from "./blindedBlock.js";
|
|
7
7
|
export * from "./blockRoot.js";
|
|
8
|
-
export * from "./calculateCommitteeAssignments.js";
|
|
9
8
|
export * from "./capella.js";
|
|
10
9
|
export * from "./computeAnchorCheckpoint.js";
|
|
11
10
|
export * from "./deposit.js";
|
|
@@ -16,11 +15,12 @@ export * from "./epochShuffling.js";
|
|
|
16
15
|
export * from "./execution.js";
|
|
17
16
|
export * from "./finality.js";
|
|
18
17
|
export * from "./genesis.js";
|
|
18
|
+
export * from "./gloas.js";
|
|
19
19
|
export * from "./interop.js";
|
|
20
20
|
export * from "./loadState/index.js";
|
|
21
21
|
export * from "./rootCache.js";
|
|
22
22
|
export * from "./seed.js";
|
|
23
|
-
export * from "./
|
|
23
|
+
export * from "./shuffling.js";
|
|
24
24
|
export * from "./signatureSets.js";
|
|
25
25
|
export * from "./signingRoot.js";
|
|
26
26
|
export * from "./slot.js";
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import {ForkName, ForkSeq, SLOTS_PER_EPOCH, isForkPostFulu} from "@lodestar/params";
|
|
2
|
+
import {
|
|
3
|
+
Attestation,
|
|
4
|
+
CommitteeIndex,
|
|
5
|
+
Epoch,
|
|
6
|
+
IndexedAttestation,
|
|
7
|
+
Root,
|
|
8
|
+
Slot,
|
|
9
|
+
ValidatorIndex,
|
|
10
|
+
electra,
|
|
11
|
+
} from "@lodestar/types";
|
|
12
|
+
import {LodestarError} from "@lodestar/utils";
|
|
13
|
+
import {CachedBeaconStateAllForks} from "../cache/stateCache.js";
|
|
14
|
+
import {getBlockRootAtSlot} from "./blockRoot.js";
|
|
15
|
+
import {computeStartSlotAtEpoch} from "./epoch.js";
|
|
16
|
+
import {EpochShuffling} from "./epochShuffling.js";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Returns the block root which decided the proposer shuffling for the current epoch. This root
|
|
20
|
+
* can be used to key this proposer shuffling.
|
|
21
|
+
*
|
|
22
|
+
* Returns `null` on the one-off scenario where the genesis block decides its own shuffling.
|
|
23
|
+
* It should be set to the latest block applied to this `state` or the genesis block root.
|
|
24
|
+
*/
|
|
25
|
+
export function proposerShufflingDecisionRoot(fork: ForkName, state: CachedBeaconStateAllForks): Root | null {
|
|
26
|
+
const decisionSlot = proposerShufflingDecisionSlot(fork, state);
|
|
27
|
+
if (state.slot === decisionSlot) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return getBlockRootAtSlot(state, decisionSlot);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Returns the slot at which the proposer shuffling was decided. The block root at this slot
|
|
35
|
+
* can be used to key the proposer shuffling for the current epoch.
|
|
36
|
+
*/
|
|
37
|
+
function proposerShufflingDecisionSlot(fork: ForkName, state: CachedBeaconStateAllForks): Slot {
|
|
38
|
+
// After fulu, the decision slot is in previous epoch due to deterministic proposer lookahead
|
|
39
|
+
const epoch = isForkPostFulu(fork) ? state.epochCtx.epoch - 1 : state.epochCtx.epoch;
|
|
40
|
+
const startSlot = computeStartSlotAtEpoch(epoch);
|
|
41
|
+
return Math.max(startSlot - 1, 0);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Returns the block root which decided the attester shuffling for the given `requestedEpoch`.
|
|
46
|
+
* This root can be used to key that attester shuffling.
|
|
47
|
+
*
|
|
48
|
+
* Returns `null` on the one-off scenario where the genesis block decides its own shuffling.
|
|
49
|
+
* It should be set to the latest block applied to this `state` or the genesis block root.
|
|
50
|
+
*/
|
|
51
|
+
export function attesterShufflingDecisionRoot(state: CachedBeaconStateAllForks, requestedEpoch: Epoch): Root | null {
|
|
52
|
+
const decisionSlot = attesterShufflingDecisionSlot(state, requestedEpoch);
|
|
53
|
+
if (state.slot === decisionSlot) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
return getBlockRootAtSlot(state, decisionSlot);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Returns the slot at which the proposer shuffling was decided. The block root at this slot
|
|
61
|
+
* can be used to key the proposer shuffling for the current epoch.
|
|
62
|
+
*/
|
|
63
|
+
function attesterShufflingDecisionSlot(state: CachedBeaconStateAllForks, requestedEpoch: Epoch): Slot {
|
|
64
|
+
const epoch = attesterShufflingDecisionEpoch(state, requestedEpoch);
|
|
65
|
+
const slot = computeStartSlotAtEpoch(epoch);
|
|
66
|
+
return Math.max(slot - 1, 0);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Returns the epoch at which the attester shuffling was decided.
|
|
71
|
+
*
|
|
72
|
+
* Spec ref: https://github.com/ethereum/beacon-APIs/blob/v2.1.0/apis/validator/duties/attester.yaml#L15
|
|
73
|
+
*
|
|
74
|
+
* Throws an error when:
|
|
75
|
+
* - `EpochTooLow` when `requestedEpoch` is more than 1 prior to `currentEpoch`.
|
|
76
|
+
* - `EpochTooHigh` when `requestedEpoch` is more than 1 after `currentEpoch`.
|
|
77
|
+
*/
|
|
78
|
+
function attesterShufflingDecisionEpoch(state: CachedBeaconStateAllForks, requestedEpoch: Epoch): Epoch {
|
|
79
|
+
const currentEpoch = state.epochCtx.epoch;
|
|
80
|
+
|
|
81
|
+
// Next
|
|
82
|
+
if (requestedEpoch === currentEpoch + 1) return currentEpoch;
|
|
83
|
+
// Current
|
|
84
|
+
if (requestedEpoch === currentEpoch) return Math.max(currentEpoch - 1, 0);
|
|
85
|
+
// Previous
|
|
86
|
+
if (requestedEpoch === currentEpoch - 1) return Math.max(currentEpoch - 2, 0);
|
|
87
|
+
|
|
88
|
+
if (requestedEpoch < currentEpoch) {
|
|
89
|
+
throw Error(`EpochTooLow: current ${currentEpoch} requested ${requestedEpoch}`);
|
|
90
|
+
}
|
|
91
|
+
throw Error(`EpochTooHigh: current ${currentEpoch} requested ${requestedEpoch}`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Copied from lodestar-api package to avoid depending on the package
|
|
95
|
+
export interface AttesterDuty {
|
|
96
|
+
validatorIndex: ValidatorIndex;
|
|
97
|
+
committeeIndex: CommitteeIndex;
|
|
98
|
+
committeeLength: number;
|
|
99
|
+
committeesAtSlot: number;
|
|
100
|
+
validatorCommitteeIndex: number;
|
|
101
|
+
slot: Slot;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function calculateCommitteeAssignments(
|
|
105
|
+
epochShuffling: EpochShuffling,
|
|
106
|
+
requestedValidatorIndices: ValidatorIndex[]
|
|
107
|
+
): Map<ValidatorIndex, AttesterDuty> {
|
|
108
|
+
const requestedValidatorIndicesSet = new Set(requestedValidatorIndices);
|
|
109
|
+
const duties = new Map<ValidatorIndex, AttesterDuty>();
|
|
110
|
+
|
|
111
|
+
const epochCommittees = epochShuffling.committees;
|
|
112
|
+
for (let epochSlot = 0; epochSlot < SLOTS_PER_EPOCH; epochSlot++) {
|
|
113
|
+
const slotCommittees = epochCommittees[epochSlot];
|
|
114
|
+
for (let i = 0, committeesAtSlot = slotCommittees.length; i < committeesAtSlot; i++) {
|
|
115
|
+
for (let j = 0, committeeLength = slotCommittees[i].length; j < committeeLength; j++) {
|
|
116
|
+
const validatorIndex = slotCommittees[i][j];
|
|
117
|
+
if (requestedValidatorIndicesSet.has(validatorIndex)) {
|
|
118
|
+
duties.set(validatorIndex, {
|
|
119
|
+
validatorIndex,
|
|
120
|
+
committeeLength,
|
|
121
|
+
committeesAtSlot,
|
|
122
|
+
validatorCommitteeIndex: j,
|
|
123
|
+
committeeIndex: i,
|
|
124
|
+
slot: epochShuffling.epoch * SLOTS_PER_EPOCH + epochSlot,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return duties;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Return the indexed attestation corresponding to ``attestation``.
|
|
136
|
+
*/
|
|
137
|
+
export function getIndexedAttestation(
|
|
138
|
+
epochShuffling: EpochShuffling,
|
|
139
|
+
fork: ForkSeq,
|
|
140
|
+
attestation: Attestation
|
|
141
|
+
): IndexedAttestation {
|
|
142
|
+
const {data} = attestation;
|
|
143
|
+
const attestingIndices = getAttestingIndices(epochShuffling, fork, attestation);
|
|
144
|
+
|
|
145
|
+
// sort in-place
|
|
146
|
+
attestingIndices.sort((a, b) => a - b);
|
|
147
|
+
return {
|
|
148
|
+
attestingIndices: attestingIndices,
|
|
149
|
+
data: data,
|
|
150
|
+
signature: attestation.signature,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Return indices of validators who attestested in `attestation`
|
|
156
|
+
*/
|
|
157
|
+
export function getAttestingIndices(epochShuffling: EpochShuffling, fork: ForkSeq, attestation: Attestation): number[] {
|
|
158
|
+
if (fork < ForkSeq.electra) {
|
|
159
|
+
const {aggregationBits, data} = attestation;
|
|
160
|
+
const validatorIndices = getBeaconCommittee(epochShuffling, data.slot, data.index);
|
|
161
|
+
|
|
162
|
+
return aggregationBits.intersectValues(validatorIndices);
|
|
163
|
+
}
|
|
164
|
+
const {aggregationBits, committeeBits, data} = attestation as electra.Attestation;
|
|
165
|
+
|
|
166
|
+
// There is a naming conflict on the term `committeeIndices`
|
|
167
|
+
// In Lodestar it usually means a list of validator indices of participants in a committee
|
|
168
|
+
// In the spec it means a list of committee indices according to committeeBits
|
|
169
|
+
// This `committeeIndices` refers to the latter
|
|
170
|
+
// TODO Electra: resolve the naming conflicts
|
|
171
|
+
const committeeIndices = committeeBits.getTrueBitIndexes();
|
|
172
|
+
|
|
173
|
+
const validatorsByCommittee = getBeaconCommittees(epochShuffling, data.slot, committeeIndices);
|
|
174
|
+
|
|
175
|
+
// Create a new Uint32Array to flatten `validatorsByCommittee`
|
|
176
|
+
const totalLength = validatorsByCommittee.reduce((acc, curr) => acc + curr.length, 0);
|
|
177
|
+
const committeeValidators = new Uint32Array(totalLength);
|
|
178
|
+
|
|
179
|
+
let offset = 0;
|
|
180
|
+
for (const committee of validatorsByCommittee) {
|
|
181
|
+
committeeValidators.set(committee, offset);
|
|
182
|
+
offset += committee.length;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return aggregationBits.intersectValues(committeeValidators);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Return the beacon committee at slot for index.
|
|
190
|
+
*/
|
|
191
|
+
export function getBeaconCommittee(epochShuffling: EpochShuffling, slot: Slot, index: CommitteeIndex): Uint32Array {
|
|
192
|
+
return getBeaconCommittees(epochShuffling, slot, [index])[0];
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Return a Uint32Array[] representing committees validator indices
|
|
197
|
+
*/
|
|
198
|
+
export function getBeaconCommittees(
|
|
199
|
+
epochShuffling: EpochShuffling,
|
|
200
|
+
slot: Slot,
|
|
201
|
+
indices: CommitteeIndex[]
|
|
202
|
+
): Uint32Array[] {
|
|
203
|
+
if (indices.length === 0) {
|
|
204
|
+
throw new Error("Attempt to get committees without providing CommitteeIndex");
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const slotCommittees = epochShuffling.committees[slot % SLOTS_PER_EPOCH];
|
|
208
|
+
const committees = [];
|
|
209
|
+
|
|
210
|
+
for (const index of indices) {
|
|
211
|
+
if (index >= slotCommittees.length) {
|
|
212
|
+
throw new ShufflingError({
|
|
213
|
+
code: ShufflingErrorCode.COMMITTEE_INDEX_OUT_OF_RANGE,
|
|
214
|
+
index,
|
|
215
|
+
maxIndex: slotCommittees.length,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
committees.push(slotCommittees[index]);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return committees;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export enum ShufflingErrorCode {
|
|
225
|
+
COMMITTEE_INDEX_OUT_OF_RANGE = "SHUFFLING_ERROR_COMMITTEE_INDEX_OUT_OF_RANGE",
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
type ShufflingErrorType = {
|
|
229
|
+
code: ShufflingErrorCode.COMMITTEE_INDEX_OUT_OF_RANGE;
|
|
230
|
+
index: number;
|
|
231
|
+
maxIndex: number;
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
export class ShufflingError extends LodestarError<ShufflingErrorType> {}
|
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
import {PublicKey, Signature, fastAggregateVerify, verify} from "@chainsafe/blst";
|
|
1
|
+
import {PublicKey, Signature, aggregatePublicKeys, fastAggregateVerify, verify} from "@chainsafe/blst";
|
|
2
2
|
import {Root} from "@lodestar/types";
|
|
3
|
+
import {Index2PubkeyCache} from "../cache/pubkeyCache.js";
|
|
3
4
|
|
|
4
5
|
export enum SignatureSetType {
|
|
5
6
|
single = "single",
|
|
6
7
|
aggregate = "aggregate",
|
|
8
|
+
/**
|
|
9
|
+
* Single signature with validator index instead of pubkey.
|
|
10
|
+
* Pubkey lookup is deferred to verification time.
|
|
11
|
+
*/
|
|
12
|
+
indexed = "indexed",
|
|
7
13
|
}
|
|
8
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Single signature with pubkey directly.
|
|
17
|
+
* Used when pubkey comes from the message itself (e.g. BLS to execution change).
|
|
18
|
+
*/
|
|
9
19
|
export type SingleSignatureSet = {
|
|
10
20
|
type: SignatureSetType.single;
|
|
11
21
|
pubkey: PublicKey;
|
|
@@ -13,16 +23,57 @@ export type SingleSignatureSet = {
|
|
|
13
23
|
signature: Uint8Array;
|
|
14
24
|
};
|
|
15
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Single signature with validator index.
|
|
28
|
+
* Pubkey is looked up at verification time.
|
|
29
|
+
*/
|
|
30
|
+
export type IndexedSignatureSet = {
|
|
31
|
+
type: SignatureSetType.indexed;
|
|
32
|
+
index: number;
|
|
33
|
+
signingRoot: Root;
|
|
34
|
+
signature: Uint8Array;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Aggregate signature with validator indices.
|
|
39
|
+
* Pubkeys are looked up and aggregated at verification time.
|
|
40
|
+
*/
|
|
16
41
|
export type AggregatedSignatureSet = {
|
|
17
42
|
type: SignatureSetType.aggregate;
|
|
18
|
-
|
|
43
|
+
indices: number[];
|
|
19
44
|
signingRoot: Root;
|
|
20
45
|
signature: Uint8Array;
|
|
21
46
|
};
|
|
22
47
|
|
|
23
|
-
export type ISignatureSet = SingleSignatureSet | AggregatedSignatureSet;
|
|
48
|
+
export type ISignatureSet = SingleSignatureSet | IndexedSignatureSet | AggregatedSignatureSet;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Get the pubkey for a signature set, performing aggregation if necessary.
|
|
52
|
+
* Requires index2pubkey cache for indexed and aggregate sets.
|
|
53
|
+
*/
|
|
54
|
+
export function getSignatureSetPubkey(signatureSet: ISignatureSet, index2pubkey: Index2PubkeyCache): PublicKey {
|
|
55
|
+
switch (signatureSet.type) {
|
|
56
|
+
case SignatureSetType.single:
|
|
57
|
+
return signatureSet.pubkey;
|
|
58
|
+
|
|
59
|
+
case SignatureSetType.indexed:
|
|
60
|
+
return index2pubkey[signatureSet.index];
|
|
61
|
+
|
|
62
|
+
case SignatureSetType.aggregate: {
|
|
63
|
+
const pubkeys = signatureSet.indices.map((i) => index2pubkey[i]);
|
|
64
|
+
return aggregatePublicKeys(pubkeys);
|
|
65
|
+
}
|
|
24
66
|
|
|
25
|
-
|
|
67
|
+
default:
|
|
68
|
+
throw Error("Unknown signature set type");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function verifySignatureSet(signatureSet: SingleSignatureSet, index2pubkey?: Index2PubkeyCache): boolean;
|
|
73
|
+
export function verifySignatureSet(signatureSet: IndexedSignatureSet, index2pubkey: Index2PubkeyCache): boolean;
|
|
74
|
+
export function verifySignatureSet(signatureSet: AggregatedSignatureSet, index2pubkey: Index2PubkeyCache): boolean;
|
|
75
|
+
export function verifySignatureSet(signatureSet: ISignatureSet, index2pubkey: Index2PubkeyCache): boolean;
|
|
76
|
+
export function verifySignatureSet(signatureSet: ISignatureSet, index2pubkey?: Index2PubkeyCache): boolean {
|
|
26
77
|
// All signatures are not trusted and must be group checked (p2.subgroup_check)
|
|
27
78
|
const signature = Signature.fromBytes(signatureSet.signature, true);
|
|
28
79
|
|
|
@@ -30,8 +81,20 @@ export function verifySignatureSet(signatureSet: ISignatureSet): boolean {
|
|
|
30
81
|
case SignatureSetType.single:
|
|
31
82
|
return verify(signatureSet.signingRoot, signatureSet.pubkey, signature);
|
|
32
83
|
|
|
33
|
-
case SignatureSetType.
|
|
34
|
-
|
|
84
|
+
case SignatureSetType.indexed: {
|
|
85
|
+
if (!index2pubkey) {
|
|
86
|
+
throw Error("index2pubkey required for indexed signature set");
|
|
87
|
+
}
|
|
88
|
+
return verify(signatureSet.signingRoot, index2pubkey[signatureSet.index], signature);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
case SignatureSetType.aggregate: {
|
|
92
|
+
if (!index2pubkey) {
|
|
93
|
+
throw Error("index2pubkey required for aggregate signature set");
|
|
94
|
+
}
|
|
95
|
+
const pubkeys = signatureSet.indices.map((i) => index2pubkey[i]);
|
|
96
|
+
return fastAggregateVerify(signatureSet.signingRoot, pubkeys, signature);
|
|
97
|
+
}
|
|
35
98
|
|
|
36
99
|
default:
|
|
37
100
|
throw Error("Unknown signature set type");
|
|
@@ -51,14 +114,27 @@ export function createSingleSignatureSetFromComponents(
|
|
|
51
114
|
};
|
|
52
115
|
}
|
|
53
116
|
|
|
117
|
+
export function createIndexedSignatureSetFromComponents(
|
|
118
|
+
index: number,
|
|
119
|
+
signingRoot: Root,
|
|
120
|
+
signature: Uint8Array
|
|
121
|
+
): IndexedSignatureSet {
|
|
122
|
+
return {
|
|
123
|
+
type: SignatureSetType.indexed,
|
|
124
|
+
index,
|
|
125
|
+
signingRoot,
|
|
126
|
+
signature,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
54
130
|
export function createAggregateSignatureSetFromComponents(
|
|
55
|
-
|
|
131
|
+
indices: number[],
|
|
56
132
|
signingRoot: Root,
|
|
57
133
|
signature: Uint8Array
|
|
58
134
|
): AggregatedSignatureSet {
|
|
59
135
|
return {
|
|
60
136
|
type: SignatureSetType.aggregate,
|
|
61
|
-
|
|
137
|
+
indices,
|
|
62
138
|
signingRoot,
|
|
63
139
|
signature,
|
|
64
140
|
};
|
package/src/util/validator.ts
CHANGED
|
@@ -2,13 +2,15 @@ import {ChainForkConfig} from "@lodestar/config";
|
|
|
2
2
|
import {
|
|
3
3
|
EFFECTIVE_BALANCE_INCREMENT,
|
|
4
4
|
ForkSeq,
|
|
5
|
+
MAX_EFFECTIVE_BALANCE,
|
|
5
6
|
MAX_EFFECTIVE_BALANCE_ELECTRA,
|
|
6
7
|
MIN_ACTIVATION_BALANCE,
|
|
7
8
|
} from "@lodestar/params";
|
|
8
9
|
import {Epoch, ValidatorIndex, phase0} from "@lodestar/types";
|
|
9
10
|
import {intDiv} from "@lodestar/utils";
|
|
10
11
|
import {BeaconStateAllForks, CachedBeaconStateElectra, CachedBeaconStateGloas, EpochCache} from "../types.js";
|
|
11
|
-
import {
|
|
12
|
+
import {hasEth1WithdrawalCredential} from "./capella.js";
|
|
13
|
+
import {hasCompoundingWithdrawalCredential, hasExecutionWithdrawalCredential} from "./electra.js";
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* Check if [[validator]] is active
|
|
@@ -94,8 +96,35 @@ export function getMaxEffectiveBalance(withdrawalCredentials: Uint8Array): numbe
|
|
|
94
96
|
return MIN_ACTIVATION_BALANCE;
|
|
95
97
|
}
|
|
96
98
|
|
|
99
|
+
/**
|
|
100
|
+
* Check if validator is partially withdrawable.
|
|
101
|
+
* https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/electra/beacon-chain.md#modified-is_partially_withdrawable_validator
|
|
102
|
+
*/
|
|
103
|
+
export function isPartiallyWithdrawableValidator(fork: ForkSeq, validator: phase0.Validator, balance: number): boolean {
|
|
104
|
+
const isPostElectra = fork >= ForkSeq.electra;
|
|
105
|
+
|
|
106
|
+
// Check withdrawal credentials
|
|
107
|
+
const hasWithdrawableCredentials = isPostElectra
|
|
108
|
+
? hasExecutionWithdrawalCredential(validator.withdrawalCredentials)
|
|
109
|
+
: hasEth1WithdrawalCredential(validator.withdrawalCredentials);
|
|
110
|
+
|
|
111
|
+
if (!hasWithdrawableCredentials) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Get max effective balance based on fork
|
|
116
|
+
const maxEffectiveBalance = isPostElectra
|
|
117
|
+
? getMaxEffectiveBalance(validator.withdrawalCredentials)
|
|
118
|
+
: MAX_EFFECTIVE_BALANCE;
|
|
119
|
+
|
|
120
|
+
// Check if at max effective balance and has excess balance
|
|
121
|
+
const hasMaxEffectiveBalance = validator.effectiveBalance === maxEffectiveBalance;
|
|
122
|
+
const hasExcessBalance = balance > maxEffectiveBalance;
|
|
123
|
+
|
|
124
|
+
return hasMaxEffectiveBalance && hasExcessBalance;
|
|
125
|
+
}
|
|
126
|
+
|
|
97
127
|
export function getPendingBalanceToWithdraw(
|
|
98
|
-
fork: ForkSeq,
|
|
99
128
|
state: CachedBeaconStateElectra | CachedBeaconStateGloas,
|
|
100
129
|
validatorIndex: ValidatorIndex
|
|
101
130
|
): number {
|
|
@@ -106,19 +135,5 @@ export function getPendingBalanceToWithdraw(
|
|
|
106
135
|
}
|
|
107
136
|
}
|
|
108
137
|
|
|
109
|
-
if (fork >= ForkSeq.gloas) {
|
|
110
|
-
const stateGloas = state as CachedBeaconStateGloas;
|
|
111
|
-
for (const item of stateGloas.builderPendingWithdrawals.getAllReadonly()) {
|
|
112
|
-
if (item.builderIndex === validatorIndex) {
|
|
113
|
-
total += item.amount;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
for (const item of stateGloas.builderPendingPayments.getAllReadonly()) {
|
|
117
|
-
if (item.withdrawal.builderIndex === validatorIndex) {
|
|
118
|
-
total += item.withdrawal.amount;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
138
|
return total;
|
|
124
139
|
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { CommitteeIndex, Slot, ValidatorIndex } from "@lodestar/types";
|
|
2
|
-
import { EpochShuffling } from "./epochShuffling.js";
|
|
3
|
-
export interface AttesterDuty {
|
|
4
|
-
validatorIndex: ValidatorIndex;
|
|
5
|
-
committeeIndex: CommitteeIndex;
|
|
6
|
-
committeeLength: number;
|
|
7
|
-
committeesAtSlot: number;
|
|
8
|
-
validatorCommitteeIndex: number;
|
|
9
|
-
slot: Slot;
|
|
10
|
-
}
|
|
11
|
-
export declare function calculateCommitteeAssignments(epochShuffling: EpochShuffling, requestedValidatorIndices: ValidatorIndex[]): Map<ValidatorIndex, AttesterDuty>;
|
|
12
|
-
//# sourceMappingURL=calculateCommitteeAssignments.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"calculateCommitteeAssignments.d.ts","sourceRoot":"","sources":["../../src/util/calculateCommitteeAssignments.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,cAAc,EAAE,IAAI,EAAE,cAAc,EAAC,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AAGnD,MAAM,WAAW,YAAY;IAC3B,cAAc,EAAE,cAAc,CAAC;IAC/B,cAAc,EAAE,cAAc,CAAC;IAC/B,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,uBAAuB,EAAE,MAAM,CAAC;IAChC,IAAI,EAAE,IAAI,CAAC;CACZ;AAED,wBAAgB,6BAA6B,CAC3C,cAAc,EAAE,cAAc,EAC9B,yBAAyB,EAAE,cAAc,EAAE,GAC1C,GAAG,CAAC,cAAc,EAAE,YAAY,CAAC,CAyBnC"}
|
|
@@ -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
|