@lodestar/state-transition 1.41.0-dev.116358ed6c → 1.41.0-dev.165a02f873
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/externalData.d.ts +2 -1
- package/lib/block/externalData.d.ts.map +1 -1
- package/lib/block/externalData.js +2 -0
- package/lib/block/externalData.js.map +1 -1
- package/lib/block/isValidIndexedAttestation.d.ts +3 -3
- package/lib/block/isValidIndexedAttestation.d.ts.map +1 -1
- package/lib/block/isValidIndexedAttestation.js +4 -4
- package/lib/block/isValidIndexedAttestation.js.map +1 -1
- package/lib/block/isValidIndexedPayloadAttestation.js +1 -1
- package/lib/block/isValidIndexedPayloadAttestation.js.map +1 -1
- package/lib/block/processAttestationPhase0.js +1 -1
- package/lib/block/processAttestationPhase0.js.map +1 -1
- package/lib/block/processAttestationsAltair.js +1 -1
- package/lib/block/processAttestationsAltair.js.map +1 -1
- package/lib/block/processAttesterSlashing.d.ts +2 -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/processExecutionPayloadEnvelope.d.ts +4 -1
- package/lib/block/processExecutionPayloadEnvelope.d.ts.map +1 -1
- package/lib/block/processExecutionPayloadEnvelope.js +25 -15
- package/lib/block/processExecutionPayloadEnvelope.js.map +1 -1
- package/lib/block/processProposerSlashing.d.ts +2 -2
- package/lib/block/processProposerSlashing.d.ts.map +1 -1
- package/lib/block/processProposerSlashing.js +3 -3
- package/lib/block/processProposerSlashing.js.map +1 -1
- package/lib/block/processRandao.js +1 -1
- package/lib/block/processRandao.js.map +1 -1
- package/lib/block/processSyncCommittee.js +1 -1
- package/lib/block/processSyncCommittee.js.map +1 -1
- package/lib/block/processVoluntaryExit.js +1 -1
- package/lib/block/processVoluntaryExit.js.map +1 -1
- package/lib/block/processWithdrawalRequest.js +2 -2
- package/lib/block/processWithdrawalRequest.js.map +1 -1
- package/lib/cache/epochCache.d.ts +8 -15
- package/lib/cache/epochCache.d.ts.map +1 -1
- package/lib/cache/epochCache.js +34 -33
- package/lib/cache/epochCache.js.map +1 -1
- package/lib/cache/pubkeyCache.d.ts +21 -6
- package/lib/cache/pubkeyCache.d.ts.map +1 -1
- package/lib/cache/pubkeyCache.js +39 -14
- package/lib/cache/pubkeyCache.js.map +1 -1
- package/lib/cache/stateCache.d.ts +1 -1
- package/lib/cache/stateCache.d.ts.map +1 -1
- package/lib/cache/stateCache.js +3 -7
- package/lib/cache/stateCache.js.map +1 -1
- package/lib/cache/syncCommitteeCache.d.ts +3 -2
- package/lib/cache/syncCommitteeCache.d.ts.map +1 -1
- package/lib/cache/syncCommitteeCache.js +4 -4
- package/lib/cache/syncCommitteeCache.js.map +1 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/lightClient/proofs.d.ts +10 -0
- package/lib/lightClient/proofs.d.ts.map +1 -0
- package/lib/lightClient/proofs.js +63 -0
- package/lib/lightClient/proofs.js.map +1 -0
- package/lib/lightClient/types.d.ts +34 -0
- package/lib/lightClient/types.d.ts.map +1 -0
- package/lib/lightClient/types.js +2 -0
- package/lib/lightClient/types.js.map +1 -0
- package/lib/rewards/attestationsRewards.d.ts +2 -2
- package/lib/rewards/attestationsRewards.d.ts.map +1 -1
- package/lib/rewards/attestationsRewards.js +4 -4
- package/lib/rewards/attestationsRewards.js.map +1 -1
- package/lib/rewards/syncCommitteeRewards.d.ts +2 -2
- package/lib/rewards/syncCommitteeRewards.d.ts.map +1 -1
- package/lib/rewards/syncCommitteeRewards.js +5 -2
- package/lib/rewards/syncCommitteeRewards.js.map +1 -1
- package/lib/signatureSets/proposer.d.ts +2 -2
- package/lib/signatureSets/proposer.d.ts.map +1 -1
- package/lib/signatureSets/proposer.js +2 -2
- package/lib/signatureSets/proposer.js.map +1 -1
- package/lib/signatureSets/randao.d.ts +2 -2
- package/lib/signatureSets/randao.d.ts.map +1 -1
- package/lib/signatureSets/randao.js +2 -2
- 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 +2 -2
- package/lib/signatureSets/voluntaryExits.js.map +1 -1
- package/lib/stateTransition.d.ts +2 -1
- package/lib/stateTransition.d.ts.map +1 -1
- package/lib/stateTransition.js +2 -1
- package/lib/stateTransition.js.map +1 -1
- package/lib/stateView/beaconStateView.d.ts +144 -0
- package/lib/stateView/beaconStateView.d.ts.map +1 -0
- package/lib/stateView/beaconStateView.js +496 -0
- package/lib/stateView/beaconStateView.js.map +1 -0
- package/lib/stateView/index.d.ts +3 -0
- package/lib/stateView/index.d.ts.map +1 -0
- package/lib/stateView/index.js +3 -0
- package/lib/stateView/index.js.map +1 -0
- package/lib/stateView/interface.d.ts +118 -0
- package/lib/stateView/interface.d.ts.map +1 -0
- package/lib/stateView/interface.js +2 -0
- package/lib/stateView/interface.js.map +1 -0
- package/lib/util/signatureSets.d.ts +7 -7
- package/lib/util/signatureSets.d.ts.map +1 -1
- package/lib/util/signatureSets.js +18 -12
- package/lib/util/signatureSets.js.map +1 -1
- package/lib/util/weakSubjectivity.js +1 -1
- package/lib/util/weakSubjectivity.js.map +1 -1
- package/package.json +7 -7
- package/src/block/externalData.ts +2 -0
- package/src/block/isValidIndexedAttestation.ts +5 -5
- package/src/block/isValidIndexedPayloadAttestation.ts +1 -1
- package/src/block/processAttestationPhase0.ts +1 -1
- package/src/block/processAttestationsAltair.ts +1 -1
- package/src/block/processAttesterSlashing.ts +4 -4
- package/src/block/processExecutionPayloadEnvelope.ts +34 -16
- package/src/block/processProposerSlashing.ts +4 -4
- package/src/block/processRandao.ts +1 -1
- package/src/block/processSyncCommittee.ts +1 -1
- package/src/block/processVoluntaryExit.ts +1 -1
- package/src/block/processWithdrawalRequest.ts +2 -2
- package/src/cache/epochCache.ts +44 -36
- package/src/cache/pubkeyCache.ts +62 -21
- package/src/cache/stateCache.ts +4 -8
- package/src/cache/syncCommitteeCache.ts +4 -5
- package/src/index.ts +3 -1
- package/src/lightClient/proofs.ts +83 -0
- package/src/lightClient/types.ts +33 -0
- package/src/rewards/attestationsRewards.ts +5 -5
- package/src/rewards/syncCommitteeRewards.ts +6 -5
- package/src/signatureSets/proposer.ts +3 -3
- package/src/signatureSets/randao.ts +3 -7
- package/src/signatureSets/voluntaryExits.ts +3 -3
- package/src/stateTransition.ts +2 -1
- package/src/stateView/beaconStateView.ts +744 -0
- package/src/stateView/index.ts +2 -0
- package/src/stateView/interface.ts +196 -0
- package/src/util/signatureSets.ts +23 -17
- package/src/util/weakSubjectivity.ts +1 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map";
|
|
2
1
|
import {BeaconConfig} from "@lodestar/config";
|
|
3
2
|
import {
|
|
4
3
|
EFFECTIVE_BALANCE_INCREMENT,
|
|
@@ -16,6 +15,7 @@ import {
|
|
|
16
15
|
import {ValidatorIndex, rewards} from "@lodestar/types";
|
|
17
16
|
import {fromHex} from "@lodestar/utils";
|
|
18
17
|
import {EpochTransitionCache, beforeProcessEpoch} from "../cache/epochTransitionCache.js";
|
|
18
|
+
import {PubkeyCache} from "../cache/pubkeyCache.js";
|
|
19
19
|
import {CachedBeaconStateAllForks, CachedBeaconStateAltair} from "../types.js";
|
|
20
20
|
import {
|
|
21
21
|
FLAG_ELIGIBLE_ATTESTER,
|
|
@@ -34,7 +34,7 @@ const defaultAttestationsPenalty = {target: 0, source: 0};
|
|
|
34
34
|
|
|
35
35
|
export async function computeAttestationsRewards(
|
|
36
36
|
config: BeaconConfig,
|
|
37
|
-
|
|
37
|
+
pubkeyCache: PubkeyCache,
|
|
38
38
|
state: CachedBeaconStateAllForks,
|
|
39
39
|
validatorIds?: (ValidatorIndex | string)[]
|
|
40
40
|
): Promise<rewards.AttestationsRewards> {
|
|
@@ -53,7 +53,7 @@ export async function computeAttestationsRewards(
|
|
|
53
53
|
);
|
|
54
54
|
const totalRewards = computeTotalAttestationsRewardsAltair(
|
|
55
55
|
config,
|
|
56
|
-
|
|
56
|
+
pubkeyCache,
|
|
57
57
|
stateAltair,
|
|
58
58
|
transitionCache,
|
|
59
59
|
idealRewards,
|
|
@@ -142,7 +142,7 @@ function computeIdealAttestationsRewardsAndPenaltiesAltair(
|
|
|
142
142
|
// Same calculation as `getRewardsAndPenaltiesAltair` but returns the breakdown of rewards instead of aggregated
|
|
143
143
|
function computeTotalAttestationsRewardsAltair(
|
|
144
144
|
config: BeaconConfig,
|
|
145
|
-
|
|
145
|
+
pubkeyCache: PubkeyCache,
|
|
146
146
|
state: CachedBeaconStateAltair,
|
|
147
147
|
transitionCache: EpochTransitionCache,
|
|
148
148
|
idealRewards: rewards.IdealAttestationsReward[],
|
|
@@ -153,7 +153,7 @@ function computeTotalAttestationsRewardsAltair(
|
|
|
153
153
|
const {flags} = transitionCache;
|
|
154
154
|
const {epochCtx} = state;
|
|
155
155
|
const validatorIndices = validatorIds
|
|
156
|
-
.map((id) => (typeof id === "number" ? id :
|
|
156
|
+
.map((id) => (typeof id === "number" ? id : pubkeyCache.getIndex(fromHex(id))))
|
|
157
157
|
.filter((index) => index !== undefined); // Validator indices to include in the result
|
|
158
158
|
|
|
159
159
|
const inactivityPenaltyDenominator = config.INACTIVITY_SCORE_BIAS * INACTIVITY_PENALTY_QUOTIENT_ALTAIR;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {BeaconConfig} from "@lodestar/config";
|
|
2
2
|
import {ForkName, SYNC_COMMITTEE_SIZE} from "@lodestar/params";
|
|
3
3
|
import {BeaconBlock, ValidatorIndex, altair, rewards} from "@lodestar/types";
|
|
4
|
-
import {
|
|
4
|
+
import {PubkeyCache} from "../cache/pubkeyCache.js";
|
|
5
5
|
import {CachedBeaconStateAllForks, CachedBeaconStateAltair} from "../cache/stateCache.js";
|
|
6
6
|
|
|
7
7
|
export async function computeSyncCommitteeRewards(
|
|
8
8
|
config: BeaconConfig,
|
|
9
|
-
|
|
9
|
+
pubkeyCache: PubkeyCache,
|
|
10
10
|
block: BeaconBlock,
|
|
11
11
|
preState: CachedBeaconStateAllForks,
|
|
12
12
|
validatorIds: (ValidatorIndex | string)[] = []
|
|
@@ -47,9 +47,10 @@ export async function computeSyncCommitteeRewards(
|
|
|
47
47
|
|
|
48
48
|
if (validatorIds.length) {
|
|
49
49
|
const filtersSet = new Set(validatorIds);
|
|
50
|
-
return rewards.filter(
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
return rewards.filter((reward) => {
|
|
51
|
+
const pubkeyHex = pubkeyCache.get(reward.validatorIndex)?.toHex();
|
|
52
|
+
return filtersSet.has(reward.validatorIndex) || (pubkeyHex !== undefined && filtersSet.has(pubkeyHex));
|
|
53
|
+
});
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
return rewards;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {BeaconConfig} from "@lodestar/config";
|
|
2
2
|
import {DOMAIN_BEACON_PROPOSER} from "@lodestar/params";
|
|
3
3
|
import {SignedBeaconBlock, SignedBlindedBeaconBlock, Slot, isBlindedBeaconBlock, phase0, ssz} from "@lodestar/types";
|
|
4
|
-
import {
|
|
4
|
+
import {PubkeyCache} from "../cache/pubkeyCache.js";
|
|
5
5
|
import {computeSigningRoot} from "../util/index.js";
|
|
6
6
|
import {ISignatureSet, SignatureSetType, verifySignatureSet} from "../util/signatureSets.js";
|
|
7
7
|
|
|
8
8
|
export function verifyProposerSignature(
|
|
9
9
|
config: BeaconConfig,
|
|
10
|
-
|
|
10
|
+
pubkeyCache: PubkeyCache,
|
|
11
11
|
signedBlock: SignedBeaconBlock | SignedBlindedBeaconBlock
|
|
12
12
|
): boolean {
|
|
13
13
|
const signatureSet = getBlockProposerSignatureSet(config, signedBlock);
|
|
14
|
-
return verifySignatureSet(signatureSet,
|
|
14
|
+
return verifySignatureSet(signatureSet, pubkeyCache);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export function getBlockProposerSignatureSet(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {BeaconConfig} from "@lodestar/config";
|
|
2
2
|
import {DOMAIN_RANDAO} from "@lodestar/params";
|
|
3
3
|
import {BeaconBlock, ssz} from "@lodestar/types";
|
|
4
|
-
import {
|
|
4
|
+
import {PubkeyCache} from "../cache/pubkeyCache.js";
|
|
5
5
|
import {
|
|
6
6
|
ISignatureSet,
|
|
7
7
|
SignatureSetType,
|
|
@@ -10,12 +10,8 @@ import {
|
|
|
10
10
|
verifySignatureSet,
|
|
11
11
|
} from "../util/index.js";
|
|
12
12
|
|
|
13
|
-
export function verifyRandaoSignature(
|
|
14
|
-
config
|
|
15
|
-
index2pubkey: Index2PubkeyCache,
|
|
16
|
-
block: BeaconBlock
|
|
17
|
-
): boolean {
|
|
18
|
-
return verifySignatureSet(getRandaoRevealSignatureSet(config, block), index2pubkey);
|
|
13
|
+
export function verifyRandaoSignature(config: BeaconConfig, pubkeyCache: PubkeyCache, block: BeaconBlock): boolean {
|
|
14
|
+
return verifySignatureSet(getRandaoRevealSignatureSet(config, block), pubkeyCache);
|
|
19
15
|
}
|
|
20
16
|
|
|
21
17
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {BeaconConfig} from "@lodestar/config";
|
|
2
2
|
import {SignedBeaconBlock, Slot, phase0, ssz} from "@lodestar/types";
|
|
3
|
-
import {
|
|
3
|
+
import {PubkeyCache} from "../cache/pubkeyCache.js";
|
|
4
4
|
import {
|
|
5
5
|
ISignatureSet,
|
|
6
6
|
SignatureSetType,
|
|
@@ -11,11 +11,11 @@ import {
|
|
|
11
11
|
|
|
12
12
|
export function verifyVoluntaryExitSignature(
|
|
13
13
|
config: BeaconConfig,
|
|
14
|
-
|
|
14
|
+
pubkeyCache: PubkeyCache,
|
|
15
15
|
stateSlot: Slot,
|
|
16
16
|
signedVoluntaryExit: phase0.SignedVoluntaryExit
|
|
17
17
|
): boolean {
|
|
18
|
-
return verifySignatureSet(getVoluntaryExitSignatureSet(config, stateSlot, signedVoluntaryExit),
|
|
18
|
+
return verifySignatureSet(getVoluntaryExitSignatureSet(config, stateSlot, signedVoluntaryExit), pubkeyCache);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
package/src/stateTransition.ts
CHANGED
|
@@ -76,6 +76,7 @@ export enum StateHashTreeRootSource {
|
|
|
76
76
|
prepareNextEpoch = "prepare_next_epoch",
|
|
77
77
|
regenState = "regen_state",
|
|
78
78
|
computeNewStateRoot = "compute_new_state_root",
|
|
79
|
+
computeEnvelopeStateRoot = "compute_envelope_state_root",
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
/**
|
|
@@ -111,7 +112,7 @@ export function stateTransition(
|
|
|
111
112
|
postState = processSlotsWithTransientCache(postState, blockSlot, options, {metrics, validatorMonitor});
|
|
112
113
|
|
|
113
114
|
// Verify proposer signature only
|
|
114
|
-
if (verifyProposer && !verifyProposerSignature(postState.config, postState.epochCtx.
|
|
115
|
+
if (verifyProposer && !verifyProposerSignature(postState.config, postState.epochCtx.pubkeyCache, signedBlock)) {
|
|
115
116
|
throw new Error("Invalid block signature");
|
|
116
117
|
}
|
|
117
118
|
|