@lodestar/state-transition 1.50.1 → 1.51.0-dev.0586e6e617
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 -1
- package/lib/block/index.d.ts.map +1 -1
- package/lib/block/index.js +3 -3
- package/lib/block/index.js.map +1 -1
- package/lib/block/processAttestationsAltair.d.ts.map +1 -1
- package/lib/block/processAttestationsAltair.js +3 -1
- package/lib/block/processAttestationsAltair.js.map +1 -1
- package/lib/block/processDeposit.d.ts +2 -2
- package/lib/block/processDeposit.d.ts.map +1 -1
- package/lib/block/processDeposit.js +1 -1
- package/lib/block/processDeposit.js.map +1 -1
- package/lib/block/processEth1Data.d.ts +3 -3
- package/lib/block/processEth1Data.d.ts.map +1 -1
- package/lib/block/processEth1Data.js.map +1 -1
- package/lib/block/processOperations.d.ts +1 -1
- package/lib/block/processOperations.d.ts.map +1 -1
- package/lib/block/processOperations.js +9 -7
- package/lib/block/processOperations.js.map +1 -1
- package/lib/cache/epochCache.d.ts +5 -2
- package/lib/cache/epochCache.d.ts.map +1 -1
- package/lib/cache/epochCache.js +12 -5
- package/lib/cache/epochCache.js.map +1 -1
- package/lib/cache/epochTransitionCache.d.ts.map +1 -1
- package/lib/cache/epochTransitionCache.js +2 -1
- package/lib/cache/epochTransitionCache.js.map +1 -1
- package/lib/cache/stateCache.d.ts +2 -1
- package/lib/cache/stateCache.d.ts.map +1 -1
- package/lib/cache/stateCache.js.map +1 -1
- package/lib/cache/syncCommitteeCache.d.ts +1 -1
- package/lib/cache/syncCommitteeCache.d.ts.map +1 -1
- package/lib/cache/types.d.ts +2 -1
- package/lib/cache/types.d.ts.map +1 -1
- package/lib/epoch/getRewardsAndPenalties.d.ts.map +1 -1
- package/lib/epoch/getRewardsAndPenalties.js +9 -2
- package/lib/epoch/getRewardsAndPenalties.js.map +1 -1
- package/lib/epoch/index.d.ts +2 -2
- package/lib/epoch/index.d.ts.map +1 -1
- package/lib/epoch/index.js +5 -3
- package/lib/epoch/index.js.map +1 -1
- package/lib/epoch/processEth1DataReset.d.ts +2 -2
- package/lib/epoch/processEth1DataReset.d.ts.map +1 -1
- package/lib/epoch/processEth1DataReset.js.map +1 -1
- package/lib/epoch/processSyncCommitteeUpdates.js +1 -1
- package/lib/epoch/processSyncCommitteeUpdates.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/lightClient/spec/store.d.ts +1 -1
- package/lib/lightClient/spec/store.d.ts.map +1 -1
- package/lib/lightClient/spec/utils.d.ts.map +1 -1
- package/lib/lightClient/spec/utils.js +1 -1
- package/lib/lightClient/spec/utils.js.map +1 -1
- package/lib/lightClient/spec/validateLightClientUpdate.d.ts.map +1 -1
- package/lib/lightClient/spec/validateLightClientUpdate.js +1 -1
- package/lib/lightClient/spec/validateLightClientUpdate.js.map +1 -1
- package/lib/metrics.d.ts +1 -1
- package/lib/metrics.d.ts.map +1 -1
- package/lib/metrics.js +4 -4
- package/lib/metrics.js.map +1 -1
- package/lib/rewards/attestationsRewards.d.ts +1 -1
- package/lib/rewards/attestationsRewards.d.ts.map +1 -1
- package/lib/rewards/attestationsRewards.js +10 -3
- package/lib/rewards/attestationsRewards.js.map +1 -1
- package/lib/rewards/syncCommitteeRewards.d.ts +1 -1
- package/lib/rewards/syncCommitteeRewards.d.ts.map +1 -1
- package/lib/signatureSets/inclusionList.d.ts +5 -0
- package/lib/signatureSets/inclusionList.d.ts.map +1 -0
- package/lib/signatureSets/inclusionList.js +14 -0
- package/lib/signatureSets/inclusionList.js.map +1 -0
- package/lib/signatureSets/index.d.ts +1 -0
- package/lib/signatureSets/index.d.ts.map +1 -1
- package/lib/signatureSets/index.js +1 -0
- package/lib/signatureSets/index.js.map +1 -1
- package/lib/slot/upgradeStateToHeze.d.ts.map +1 -1
- package/lib/slot/upgradeStateToHeze.js +4 -4
- package/lib/slot/upgradeStateToHeze.js.map +1 -1
- package/lib/stateTransition.js +2 -2
- package/lib/stateTransition.js.map +1 -1
- package/lib/stateView/beaconStateView.d.ts +2 -0
- package/lib/stateView/beaconStateView.d.ts.map +1 -1
- package/lib/stateView/beaconStateView.js +11 -1
- package/lib/stateView/beaconStateView.js.map +1 -1
- package/lib/stateView/interface.d.ts +5 -4
- package/lib/stateView/interface.d.ts.map +1 -1
- package/lib/stateView/interface.js.map +1 -1
- package/lib/stateView/nativeBeaconStateView.d.ts +16 -6
- package/lib/stateView/nativeBeaconStateView.d.ts.map +1 -1
- package/lib/stateView/nativeBeaconStateView.js +99 -25
- package/lib/stateView/nativeBeaconStateView.js.map +1 -1
- package/lib/stateView/stateViewFactory.d.ts.map +1 -1
- package/lib/stateView/stateViewFactory.js +5 -4
- package/lib/stateView/stateViewFactory.js.map +1 -1
- package/lib/testUtils/interopPubkeyCache.js +1 -1
- package/lib/testUtils/interopPubkeyCache.js.map +1 -1
- package/lib/testUtils/state.d.ts.map +1 -1
- package/lib/testUtils/state.js +1 -1
- package/lib/testUtils/state.js.map +1 -1
- package/lib/testUtils/util.d.ts +1 -1
- package/lib/testUtils/util.d.ts.map +1 -1
- package/lib/testUtils/util.js +2 -2
- package/lib/testUtils/util.js.map +1 -1
- package/lib/types.d.ts +2 -2
- package/lib/types.d.ts.map +1 -1
- package/lib/util/altair.d.ts +3 -1
- package/lib/util/altair.d.ts.map +1 -1
- package/lib/util/altair.js +7 -4
- package/lib/util/altair.js.map +1 -1
- package/lib/util/blindedBlock.d.ts +1 -1
- package/lib/util/blindedBlock.d.ts.map +1 -1
- package/lib/util/blindedBlock.js +9 -14
- package/lib/util/blindedBlock.js.map +1 -1
- package/lib/util/clock.d.ts +5 -0
- package/lib/util/clock.d.ts.map +1 -1
- package/lib/util/clock.js +20 -17
- package/lib/util/clock.js.map +1 -1
- package/lib/util/deposit.d.ts +2 -2
- package/lib/util/deposit.d.ts.map +1 -1
- package/lib/util/deposit.js.map +1 -1
- 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/genesis.d.ts.map +1 -1
- package/lib/util/genesis.js +46 -23
- package/lib/util/genesis.js.map +1 -1
- package/lib/util/inclusionListCommittee.d.ts +9 -0
- package/lib/util/inclusionListCommittee.d.ts.map +1 -0
- package/lib/util/inclusionListCommittee.js +18 -0
- package/lib/util/inclusionListCommittee.js.map +1 -0
- package/lib/util/index.d.ts +1 -0
- package/lib/util/index.d.ts.map +1 -1
- package/lib/util/index.js +1 -0
- package/lib/util/index.js.map +1 -1
- package/lib/util/interop.d.ts +1 -1
- package/lib/util/interop.d.ts.map +1 -1
- package/lib/util/interop.js +1 -1
- package/lib/util/interop.js.map +1 -1
- package/lib/util/seed.js +1 -1
- package/lib/util/seed.js.map +1 -1
- package/lib/util/shuffling.d.ts +3 -0
- package/lib/util/shuffling.d.ts.map +1 -1
- package/lib/util/shuffling.js +41 -1
- package/lib/util/shuffling.js.map +1 -1
- package/lib/util/signatureSets.d.ts +1 -1
- package/lib/util/signatureSets.d.ts.map +1 -1
- package/lib/util/signatureSets.js +1 -1
- package/lib/util/signatureSets.js.map +1 -1
- package/lib/util/slot.d.ts +18 -2
- package/lib/util/slot.d.ts.map +1 -1
- package/lib/util/slot.js +70 -6
- package/lib/util/slot.js.map +1 -1
- package/lib/util/syncCommittee.d.ts +4 -3
- package/lib/util/syncCommittee.d.ts.map +1 -1
- package/lib/util/syncCommittee.js +10 -8
- package/lib/util/syncCommittee.js.map +1 -1
- package/lib/util/validator.d.ts +1 -1
- package/lib/util/validator.d.ts.map +1 -1
- package/lib/util/validator.js +32 -11
- package/lib/util/validator.js.map +1 -1
- package/lib/util/weakSubjectivity.d.ts.map +1 -1
- package/lib/util/weakSubjectivity.js +4 -3
- package/lib/util/weakSubjectivity.js.map +1 -1
- package/package.json +9 -9
- package/src/block/index.ts +15 -15
- package/src/block/processAttestationsAltair.ts +4 -1
- package/src/block/processDeposit.ts +9 -4
- package/src/block/processEth1Data.ts +3 -3
- package/src/block/processOperations.ts +19 -16
- package/src/cache/epochCache.ts +30 -6
- package/src/cache/epochTransitionCache.ts +2 -1
- package/src/cache/stateCache.ts +2 -0
- package/src/cache/syncCommitteeCache.ts +1 -1
- package/src/cache/types.ts +2 -1
- package/src/epoch/getRewardsAndPenalties.ts +11 -1
- package/src/epoch/index.ts +18 -16
- package/src/epoch/processEth1DataReset.ts +2 -2
- package/src/epoch/processSyncCommitteeUpdates.ts +1 -1
- package/src/index.ts +2 -0
- package/src/lightClient/spec/store.ts +1 -1
- package/src/lightClient/spec/utils.ts +1 -1
- package/src/lightClient/spec/validateLightClientUpdate.ts +1 -1
- package/src/metrics.ts +5 -4
- package/src/rewards/attestationsRewards.ts +13 -2
- package/src/rewards/syncCommitteeRewards.ts +1 -1
- package/src/signatureSets/inclusionList.ts +20 -0
- package/src/signatureSets/index.ts +1 -0
- package/src/slot/upgradeStateToHeze.ts +6 -4
- package/src/stateTransition.ts +2 -2
- package/src/stateView/beaconStateView.ts +14 -2
- package/src/stateView/interface.ts +5 -10
- package/src/stateView/nativeBeaconStateView.ts +100 -29
- package/src/stateView/stateViewFactory.ts +5 -4
- package/src/testUtils/interopPubkeyCache.ts +1 -1
- package/src/testUtils/state.ts +1 -1
- package/src/testUtils/util.ts +2 -2
- package/src/types.ts +2 -0
- package/src/util/altair.ts +15 -4
- package/src/util/blindedBlock.ts +12 -15
- package/src/util/clock.ts +26 -17
- package/src/util/deposit.ts +2 -2
- package/src/util/epochShuffling.ts +1 -1
- package/src/util/genesis.ts +56 -30
- package/src/util/inclusionListCommittee.ts +17 -0
- package/src/util/index.ts +1 -0
- package/src/util/interop.ts +1 -1
- package/src/util/seed.ts +1 -1
- package/src/util/shuffling.ts +46 -1
- package/src/util/signatureSets.ts +1 -1
- package/src/util/slot.ts +78 -8
- package/src/util/syncCommittee.ts +22 -10
- package/src/util/validator.ts +47 -20
- package/src/util/weakSubjectivity.ts +3 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {CompactMultiProof} from "@chainsafe/persistent-merkle-tree";
|
|
2
2
|
import {BitArray, ByteViews} from "@chainsafe/ssz";
|
|
3
3
|
import type {BeaconConfig} from "@lodestar/config";
|
|
4
|
-
import {ForkName, ForkSeq} from "@lodestar/params";
|
|
4
|
+
import {ForkName, ForkPostElectra, ForkSeq} from "@lodestar/params";
|
|
5
5
|
import {
|
|
6
6
|
BeaconBlock,
|
|
7
7
|
BeaconState,
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
phase0,
|
|
29
29
|
rewards,
|
|
30
30
|
ssz,
|
|
31
|
+
sszTypesFor,
|
|
31
32
|
} from "@lodestar/types";
|
|
32
33
|
import {Checkpoint, Fork} from "@lodestar/types/phase0";
|
|
33
34
|
import {VoluntaryExitValidity} from "../block/processVoluntaryExit.js";
|
|
@@ -39,6 +40,7 @@ import {SyncCommitteeWitness} from "../lightClient/types.js";
|
|
|
39
40
|
import {StateTransitionModules, StateTransitionOpts} from "../stateTransition.js";
|
|
40
41
|
import {EpochShuffling} from "../util/epochShuffling.js";
|
|
41
42
|
import {PreVerifyBuilderDepositsResult} from "../util/preVerifyBuilderDeposits.js";
|
|
43
|
+
import {getStateSlotFromBytes} from "../util/sszBytes.js";
|
|
42
44
|
import {computeNewStateRootStateTransitionOpts, getComputeNewStateRootResult} from "./computeNewStateRoot.js";
|
|
43
45
|
import {
|
|
44
46
|
BlockSTFInput,
|
|
@@ -47,8 +49,15 @@ import {
|
|
|
47
49
|
IBeaconStateViewGloas,
|
|
48
50
|
IBeaconStateViewLatestFork,
|
|
49
51
|
IBeaconStateViewNative,
|
|
52
|
+
isStatePostGloas,
|
|
50
53
|
} from "./interface.js";
|
|
51
54
|
|
|
55
|
+
export function assertNativeForkSupported(config: BeaconConfig, slot: Slot): void {
|
|
56
|
+
if (config.getForkSeq(slot) > ForkSeq.gloas) {
|
|
57
|
+
throw Error(`Native state transition does not support ${config.getForkName(slot)}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
52
61
|
/**
|
|
53
62
|
* Wraps a native binding (the auto-generated JS interface produced by a `.node`
|
|
54
63
|
* file) and exposes it as a fully-conformant `IBeaconStateViewLatestFork`.
|
|
@@ -97,6 +106,7 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
97
106
|
private cachedPreviousEpochParticipation: Uint8Array | null = null;
|
|
98
107
|
private cachedCurrentEpochParticipation: Uint8Array | null = null;
|
|
99
108
|
private cachedCurrentSyncCommitteeIndexed: SyncCommitteeCache | null = null;
|
|
109
|
+
private cachedCurrentSyncCommitteeValidatorIndices: Uint32Array | null = null;
|
|
100
110
|
private cachedSyncProposerReward: number | null = null;
|
|
101
111
|
// bellatrix
|
|
102
112
|
private cachedLatestExecutionPayloadHeader: ExecutionPayloadHeader | null = null;
|
|
@@ -114,6 +124,14 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
114
124
|
private cachedPendingConsolidationsCount: number | null = null;
|
|
115
125
|
// fulu
|
|
116
126
|
private cachedProposerLookahead: fulu.ProposerLookahead | null = null;
|
|
127
|
+
// gloas
|
|
128
|
+
private cachedLatestBlockHash: Bytes32 | null = null;
|
|
129
|
+
private cachedExecutionPayloadAvailability: BitArray | null = null;
|
|
130
|
+
private cachedLatestExecutionPayloadBid: ExecutionPayloadBid | null = null;
|
|
131
|
+
private cachedPayloadExpectedWithdrawals: capella.Withdrawal[] | null = null;
|
|
132
|
+
private cachedBuilderPendingPayments: gloas.BuilderPendingPayments | null = null;
|
|
133
|
+
private cachedBuilderPendingWithdrawals: gloas.BuilderPendingWithdrawals | null = null;
|
|
134
|
+
private cachedBuildersLength: number | null = null;
|
|
117
135
|
// Per-argument caches for argument-taking methods. The binding is treated as
|
|
118
136
|
// immutable for the view's lifetime, so a given argument always yields the
|
|
119
137
|
// same result. Maps grow only with touched arguments — typical call patterns
|
|
@@ -173,7 +191,11 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
173
191
|
}
|
|
174
192
|
|
|
175
193
|
get executionPayloadAvailability(): BitArray {
|
|
176
|
-
|
|
194
|
+
if (this.cachedExecutionPayloadAvailability === null) {
|
|
195
|
+
const {uint8Array, bitLen} = this.binding.executionPayloadAvailability;
|
|
196
|
+
this.cachedExecutionPayloadAvailability = new BitArray(uint8Array, bitLen);
|
|
197
|
+
}
|
|
198
|
+
return this.cachedExecutionPayloadAvailability;
|
|
177
199
|
}
|
|
178
200
|
|
|
179
201
|
// ─── phase0 ──────────────────────────────────────────────────────────────
|
|
@@ -228,6 +250,9 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
228
250
|
}
|
|
229
251
|
|
|
230
252
|
get eth1Data(): phase0.Eth1Data {
|
|
253
|
+
if (this.forkSeq >= ForkSeq.heze) {
|
|
254
|
+
throw new Error("eth1Data was removed from the beacon state in Heze");
|
|
255
|
+
}
|
|
231
256
|
if (this.cachedEth1Data === null) {
|
|
232
257
|
this.cachedEth1Data = this.binding.eth1Data;
|
|
233
258
|
}
|
|
@@ -594,6 +619,7 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
594
619
|
seedValidatorsBytes?: Uint8Array,
|
|
595
620
|
opts?: {preloadValidatorsAndBalances?: boolean}
|
|
596
621
|
): IBeaconStateView {
|
|
622
|
+
assertNativeForkSupported(this.config, getStateSlotFromBytes(stateBytes));
|
|
597
623
|
return new NativeBeaconStateView(this.config, this.binding.loadOtherState(stateBytes, seedValidatorsBytes, opts));
|
|
598
624
|
}
|
|
599
625
|
|
|
@@ -659,6 +685,7 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
659
685
|
options: StateTransitionOpts,
|
|
660
686
|
_modules: StateTransitionModules
|
|
661
687
|
): IBeaconStateView {
|
|
688
|
+
assertNativeForkSupported(this.config, block.message.slot);
|
|
662
689
|
const isBlinded = isBlindedBeaconBlock(block.message);
|
|
663
690
|
const signedBlockBytes =
|
|
664
691
|
ssz ??
|
|
@@ -671,6 +698,7 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
671
698
|
}
|
|
672
699
|
|
|
673
700
|
processSlots(slot: Slot, opts?: {dontTransferCache?: boolean}, _modules?: StateTransitionModules): IBeaconStateView {
|
|
701
|
+
assertNativeForkSupported(this.config, slot);
|
|
674
702
|
return new NativeBeaconStateView(this.config, this.binding.processSlots(slot, opts));
|
|
675
703
|
}
|
|
676
704
|
|
|
@@ -719,6 +747,16 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
719
747
|
return this.cachedCurrentSyncCommitteeIndexed;
|
|
720
748
|
}
|
|
721
749
|
|
|
750
|
+
get currentSyncCommitteeValidatorIndices(): Uint32Array {
|
|
751
|
+
if (this.cachedCurrentSyncCommitteeValidatorIndices === null) {
|
|
752
|
+
this.cachedCurrentSyncCommitteeValidatorIndices =
|
|
753
|
+
this.cachedCurrentSyncCommitteeIndexed?.validatorIndices ??
|
|
754
|
+
this.binding.currentSyncCommitteeValidatorIndices ??
|
|
755
|
+
this.currentSyncCommitteeIndexed.validatorIndices;
|
|
756
|
+
}
|
|
757
|
+
return this.cachedCurrentSyncCommitteeValidatorIndices;
|
|
758
|
+
}
|
|
759
|
+
|
|
722
760
|
get syncProposerReward(): number {
|
|
723
761
|
if (this.cachedSyncProposerReward === null) {
|
|
724
762
|
this.cachedSyncProposerReward = this.binding.syncProposerReward;
|
|
@@ -818,7 +856,8 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
818
856
|
|
|
819
857
|
get pendingDeposits(): electra.PendingDeposits {
|
|
820
858
|
if (this.cachedPendingDeposits === null) {
|
|
821
|
-
|
|
859
|
+
const type = sszTypesFor(this.forkName as ForkPostElectra).PendingDeposits;
|
|
860
|
+
this.cachedPendingDeposits = type.deserialize(this.binding.pendingDeposits);
|
|
822
861
|
}
|
|
823
862
|
return this.cachedPendingDeposits;
|
|
824
863
|
}
|
|
@@ -832,9 +871,8 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
832
871
|
|
|
833
872
|
get pendingPartialWithdrawals(): electra.PendingPartialWithdrawals {
|
|
834
873
|
if (this.cachedPendingPartialWithdrawals === null) {
|
|
835
|
-
this.
|
|
836
|
-
|
|
837
|
-
);
|
|
874
|
+
const type = sszTypesFor(this.forkName as ForkPostElectra).PendingPartialWithdrawals;
|
|
875
|
+
this.cachedPendingPartialWithdrawals = type.deserialize(this.binding.pendingPartialWithdrawals);
|
|
838
876
|
}
|
|
839
877
|
return this.cachedPendingPartialWithdrawals;
|
|
840
878
|
}
|
|
@@ -848,9 +886,8 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
848
886
|
|
|
849
887
|
get pendingConsolidations(): electra.PendingConsolidations {
|
|
850
888
|
if (this.cachedPendingConsolidations === null) {
|
|
851
|
-
this.
|
|
852
|
-
|
|
853
|
-
);
|
|
889
|
+
const type = sszTypesFor(this.forkName as ForkPostElectra).PendingConsolidations;
|
|
890
|
+
this.cachedPendingConsolidations = type.deserialize(this.binding.pendingConsolidations);
|
|
854
891
|
}
|
|
855
892
|
return this.cachedPendingConsolidations;
|
|
856
893
|
}
|
|
@@ -875,60 +912,94 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
|
|
|
875
912
|
_maxBuilderDeposits: number,
|
|
876
913
|
_maxDurationMs: number
|
|
877
914
|
): PreVerifyBuilderDepositsResult {
|
|
878
|
-
|
|
915
|
+
// The native fork upgrade verifies directly; it does not maintain a warm-up cache.
|
|
916
|
+
return {
|
|
917
|
+
validBuilderSignaturesCount: 0,
|
|
918
|
+
invalidBuilderSignaturesCount: 0,
|
|
919
|
+
validValidatorSignaturesCount: 0,
|
|
920
|
+
invalidValidatorSignaturesCount: 0,
|
|
921
|
+
scannedPendingDeposits: 0,
|
|
922
|
+
totalCachedDeposits: 0,
|
|
923
|
+
totalBuilderPubkeys: 0,
|
|
924
|
+
pendingDepositsCount: this.pendingDepositsCount,
|
|
925
|
+
};
|
|
879
926
|
}
|
|
880
927
|
|
|
881
928
|
clearPreGloasBuilderDepositCache(): void {
|
|
882
|
-
|
|
929
|
+
// The native implementation has no pre-Gloas deposit cache to clear.
|
|
883
930
|
}
|
|
884
931
|
|
|
885
932
|
// ─── gloas ───────────────────────────────────────────────────────────────
|
|
886
933
|
|
|
887
934
|
get latestBlockHash(): Bytes32 {
|
|
888
|
-
|
|
935
|
+
if (this.cachedLatestBlockHash === null) {
|
|
936
|
+
this.cachedLatestBlockHash = this.binding.latestBlockHash;
|
|
937
|
+
}
|
|
938
|
+
return this.cachedLatestBlockHash;
|
|
889
939
|
}
|
|
890
940
|
|
|
891
941
|
get latestExecutionPayloadBid(): ExecutionPayloadBid {
|
|
892
|
-
|
|
942
|
+
if (this.cachedLatestExecutionPayloadBid === null) {
|
|
943
|
+
this.cachedLatestExecutionPayloadBid = this.binding.latestExecutionPayloadBid;
|
|
944
|
+
}
|
|
945
|
+
return this.cachedLatestExecutionPayloadBid;
|
|
893
946
|
}
|
|
894
947
|
|
|
895
948
|
get payloadExpectedWithdrawals(): capella.Withdrawal[] {
|
|
896
|
-
|
|
949
|
+
if (this.cachedPayloadExpectedWithdrawals === null) {
|
|
950
|
+
this.cachedPayloadExpectedWithdrawals = this.binding.payloadExpectedWithdrawals;
|
|
951
|
+
}
|
|
952
|
+
return this.cachedPayloadExpectedWithdrawals;
|
|
897
953
|
}
|
|
898
954
|
|
|
899
955
|
get builderPendingPayments(): gloas.BuilderPendingPayments {
|
|
900
|
-
|
|
956
|
+
if (this.cachedBuilderPendingPayments === null) {
|
|
957
|
+
this.cachedBuilderPendingPayments = this.binding.builderPendingPayments;
|
|
958
|
+
}
|
|
959
|
+
return this.cachedBuilderPendingPayments;
|
|
901
960
|
}
|
|
902
961
|
|
|
903
962
|
get builderPendingWithdrawals(): gloas.BuilderPendingWithdrawals {
|
|
904
|
-
|
|
963
|
+
if (this.cachedBuilderPendingWithdrawals === null) {
|
|
964
|
+
this.cachedBuilderPendingWithdrawals = this.binding.builderPendingWithdrawals;
|
|
965
|
+
}
|
|
966
|
+
return this.cachedBuilderPendingWithdrawals;
|
|
905
967
|
}
|
|
906
968
|
|
|
907
|
-
getBuilder(
|
|
908
|
-
|
|
969
|
+
getBuilder(index: BuilderIndex): gloas.Builder {
|
|
970
|
+
return this.binding.getBuilder(index);
|
|
909
971
|
}
|
|
910
972
|
|
|
911
973
|
getBuildersLength(): number {
|
|
912
|
-
|
|
974
|
+
if (this.cachedBuildersLength === null) {
|
|
975
|
+
this.cachedBuildersLength = this.binding.getBuildersLength();
|
|
976
|
+
}
|
|
977
|
+
return this.cachedBuildersLength;
|
|
913
978
|
}
|
|
914
979
|
|
|
915
|
-
canBuilderCoverBid(
|
|
916
|
-
|
|
980
|
+
canBuilderCoverBid(builderIndex: BuilderIndex, bidAmount: number): boolean {
|
|
981
|
+
return this.binding.canBuilderCoverBid(builderIndex, bidAmount);
|
|
917
982
|
}
|
|
918
983
|
|
|
919
|
-
getEpochPTCs(
|
|
920
|
-
|
|
984
|
+
getEpochPTCs(epoch: Epoch): Uint32Array[] {
|
|
985
|
+
return this.binding.getEpochPTCs(epoch);
|
|
921
986
|
}
|
|
922
987
|
|
|
923
|
-
getPayloadTimelinessCommittee(
|
|
924
|
-
|
|
988
|
+
getPayloadTimelinessCommittee(slot: Slot): Uint32Array {
|
|
989
|
+
return this.binding.getPayloadTimelinessCommittee(slot);
|
|
925
990
|
}
|
|
926
991
|
|
|
927
|
-
getIndicesInPayloadTimelinessCommittee(
|
|
928
|
-
|
|
992
|
+
getIndicesInPayloadTimelinessCommittee(validatorIndex: ValidatorIndex, slot: Slot): number[] {
|
|
993
|
+
return this.binding.getIndicesInPayloadTimelinessCommittee(validatorIndex, slot);
|
|
929
994
|
}
|
|
930
995
|
|
|
931
|
-
withParentPayloadApplied(
|
|
932
|
-
|
|
996
|
+
withParentPayloadApplied(executionRequests: gloas.ExecutionRequests): IBeaconStateViewGloas {
|
|
997
|
+
const bytes = ssz.gloas.ExecutionRequests.serialize(executionRequests);
|
|
998
|
+
const state = new NativeBeaconStateView(this.config, this.binding.withParentPayloadApplied(bytes));
|
|
999
|
+
if (!isStatePostGloas(state)) {
|
|
1000
|
+
state.release();
|
|
1001
|
+
throw Error("Expected Gloas state after applying the parent payload");
|
|
1002
|
+
}
|
|
1003
|
+
return state;
|
|
933
1004
|
}
|
|
934
1005
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import bindings from "@chainsafe/lodestar-z";
|
|
2
|
-
import {pubkeyCache} from "@chainsafe/lodestar-z/pubkeys";
|
|
3
1
|
import {BeaconConfig} from "@lodestar/config";
|
|
2
|
+
import bindings from "@lodestar/native";
|
|
3
|
+
import {pubkeyCache} from "@lodestar/native/pubkeys";
|
|
4
4
|
import {createCachedBeaconState} from "../cache/stateCache.js";
|
|
5
|
-
import {getStateTypeFromBytes} from "../util/sszBytes.js";
|
|
5
|
+
import {getStateSlotFromBytes, getStateTypeFromBytes} from "../util/sszBytes.js";
|
|
6
6
|
import {BeaconStateView} from "./beaconStateView.js";
|
|
7
7
|
import {IBeaconStateView, IBeaconStateViewNative} from "./interface.js";
|
|
8
|
-
import {NativeBeaconStateView} from "./nativeBeaconStateView.js";
|
|
8
|
+
import {NativeBeaconStateView, assertNativeForkSupported} from "./nativeBeaconStateView.js";
|
|
9
9
|
|
|
10
10
|
// ---- createBeaconStateView (startup path) ----
|
|
11
11
|
|
|
@@ -62,6 +62,7 @@ export function createBeaconStateViewForHistoricalRegen(opts: RegenNodeJSOpts |
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
function createNativeBeaconStateView(config: BeaconConfig, stateBytes: Uint8Array): IBeaconStateView {
|
|
65
|
+
assertNativeForkSupported(config, getStateSlotFromBytes(stateBytes));
|
|
65
66
|
const nativeConfig = new bindings.BeaconConfig(config, config.genesisValidatorsRoot);
|
|
66
67
|
return new NativeBeaconStateView(
|
|
67
68
|
config,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import {pubkeyCache} from "@
|
|
3
|
+
import {pubkeyCache} from "@lodestar/native/pubkeys";
|
|
4
4
|
import {interopSecretKey} from "../util/interop.js";
|
|
5
5
|
import {testCachePath} from "./cache.js";
|
|
6
6
|
|
package/src/testUtils/state.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {pubkeyCache} from "@chainsafe/lodestar-z/pubkeys";
|
|
2
1
|
import {ChainForkConfig, createBeaconConfig} from "@lodestar/config";
|
|
3
2
|
import {config, config as minimalConfig} from "@lodestar/config/default";
|
|
3
|
+
import {pubkeyCache} from "@lodestar/native/pubkeys";
|
|
4
4
|
import {
|
|
5
5
|
EPOCHS_PER_HISTORICAL_VECTOR,
|
|
6
6
|
EPOCHS_PER_SLASHINGS_VECTOR,
|
package/src/testUtils/util.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {PublicKey, SecretKey} from "@chainsafe/lodestar-z/blst";
|
|
2
|
-
import {pubkeyCache} from "@chainsafe/lodestar-z/pubkeys";
|
|
3
1
|
import {BitArray, fromHexString} from "@chainsafe/ssz";
|
|
4
2
|
import {BeaconConfig, createBeaconConfig, createChainForkConfig} from "@lodestar/config";
|
|
5
3
|
import {config} from "@lodestar/config/default";
|
|
4
|
+
import {PublicKey, SecretKey} from "@lodestar/native/blst";
|
|
5
|
+
import {pubkeyCache} from "@lodestar/native/pubkeys";
|
|
6
6
|
import {
|
|
7
7
|
BUILDER_WITHDRAWAL_PREFIX,
|
|
8
8
|
DOMAIN_DEPOSIT,
|
package/src/types.ts
CHANGED
|
@@ -12,6 +12,7 @@ export type {
|
|
|
12
12
|
CachedBeaconStateGloas,
|
|
13
13
|
CachedBeaconStateHeze,
|
|
14
14
|
CachedBeaconStatePhase0,
|
|
15
|
+
CachedBeaconStatePreHeze,
|
|
15
16
|
} from "./cache/stateCache.js";
|
|
16
17
|
export type {
|
|
17
18
|
BeaconStateAllForks,
|
|
@@ -25,5 +26,6 @@ export type {
|
|
|
25
26
|
BeaconStateGloas,
|
|
26
27
|
BeaconStateHeze,
|
|
27
28
|
BeaconStatePhase0,
|
|
29
|
+
BeaconStatePreHeze,
|
|
28
30
|
ShufflingGetter,
|
|
29
31
|
} from "./cache/types.js";
|
package/src/util/altair.ts
CHANGED
|
@@ -1,13 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {ChainConfig} from "@lodestar/config";
|
|
2
|
+
import {BASE_REWARD_FACTOR, EFFECTIVE_BALANCE_INCREMENT, GENESIS_EPOCH} from "@lodestar/params";
|
|
3
|
+
import {Epoch} from "@lodestar/types";
|
|
2
4
|
import {bigIntSqrt, bnToNum} from "@lodestar/utils";
|
|
5
|
+
import {getSlotDurationMsAtEpoch} from "./slot.js";
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
8
|
* Before we manage bigIntSqrt(totalActiveStake) as BigInt and return BigInt.
|
|
6
9
|
* bigIntSqrt(totalActiveStake) should fit a number (2 ** 53 -1 max)
|
|
7
10
|
**/
|
|
8
|
-
export function computeBaseRewardPerIncrement(
|
|
11
|
+
export function computeBaseRewardPerIncrement(
|
|
12
|
+
config: ChainConfig,
|
|
13
|
+
epoch: Epoch,
|
|
14
|
+
totalActiveStakeByIncrement: number
|
|
15
|
+
): number {
|
|
16
|
+
// Divide last so the exact slot duration ratio applies
|
|
17
|
+
const numerator = Math.floor(
|
|
18
|
+
(EFFECTIVE_BALANCE_INCREMENT * BASE_REWARD_FACTOR * getSlotDurationMsAtEpoch(config, epoch)) /
|
|
19
|
+
getSlotDurationMsAtEpoch(config, GENESIS_EPOCH)
|
|
20
|
+
);
|
|
9
21
|
return Math.floor(
|
|
10
|
-
(
|
|
11
|
-
bnToNum(bigIntSqrt(BigInt(totalActiveStakeByIncrement) * BigInt(EFFECTIVE_BALANCE_INCREMENT)))
|
|
22
|
+
numerator / bnToNum(bigIntSqrt(BigInt(totalActiveStakeByIncrement) * BigInt(EFFECTIVE_BALANCE_INCREMENT)))
|
|
12
23
|
);
|
|
13
24
|
}
|
package/src/util/blindedBlock.ts
CHANGED
|
@@ -3,10 +3,12 @@ import {
|
|
|
3
3
|
ForkName,
|
|
4
4
|
ForkPostBellatrix,
|
|
5
5
|
ForkPostDeneb,
|
|
6
|
+
ForkPreDeneb,
|
|
6
7
|
ForkPreGloas,
|
|
7
8
|
ForkSeq,
|
|
8
9
|
isForkPostBellatrix,
|
|
9
10
|
isForkPostDeneb,
|
|
11
|
+
isForkPostGloas,
|
|
10
12
|
} from "@lodestar/params";
|
|
11
13
|
import {
|
|
12
14
|
BeaconBlock,
|
|
@@ -31,13 +33,9 @@ export function blindedOrFullBlockHashTreeRoot(
|
|
|
31
33
|
): Root {
|
|
32
34
|
return isBlindedBeaconBlock(blindedOrFull)
|
|
33
35
|
? // Blinded
|
|
34
|
-
config
|
|
35
|
-
.getPostBellatrixForkTypes(blindedOrFull.slot)
|
|
36
|
-
.BlindedBeaconBlock.hashTreeRoot(blindedOrFull)
|
|
36
|
+
config.getPostBellatrixForkTypes(blindedOrFull.slot).BlindedBeaconBlock.hashTreeRoot(blindedOrFull)
|
|
37
37
|
: // Full
|
|
38
|
-
config
|
|
39
|
-
.getForkTypes(blindedOrFull.slot)
|
|
40
|
-
.BeaconBlock.hashTreeRoot(blindedOrFull);
|
|
38
|
+
config.getForkTypes(blindedOrFull.slot).BeaconBlock.hashTreeRoot(blindedOrFull);
|
|
41
39
|
}
|
|
42
40
|
|
|
43
41
|
export function blindedOrFullBlockToHeader(
|
|
@@ -46,13 +44,9 @@ export function blindedOrFullBlockToHeader(
|
|
|
46
44
|
): BeaconBlockHeader {
|
|
47
45
|
const bodyRoot = isBlindedBeaconBlock(blindedOrFull)
|
|
48
46
|
? // Blinded
|
|
49
|
-
config
|
|
50
|
-
.getPostBellatrixForkTypes(blindedOrFull.slot)
|
|
51
|
-
.BlindedBeaconBlockBody.hashTreeRoot(blindedOrFull.body)
|
|
47
|
+
config.getPostBellatrixForkTypes(blindedOrFull.slot).BlindedBeaconBlockBody.hashTreeRoot(blindedOrFull.body)
|
|
52
48
|
: // Full
|
|
53
|
-
config
|
|
54
|
-
.getForkTypes(blindedOrFull.slot)
|
|
55
|
-
.BeaconBlockBody.hashTreeRoot(blindedOrFull.body);
|
|
49
|
+
config.getForkTypes(blindedOrFull.slot).BeaconBlockBody.hashTreeRoot(blindedOrFull.body);
|
|
56
50
|
|
|
57
51
|
return {
|
|
58
52
|
slot: blindedOrFull.slot,
|
|
@@ -128,7 +122,10 @@ export function reconstructSignedBlockContents(
|
|
|
128
122
|
signedBlindedBlock: SignedBlindedBeaconBlock,
|
|
129
123
|
executionPayload: ExecutionPayload | null,
|
|
130
124
|
blobsBundle: BlobsBundle | null
|
|
131
|
-
): SignedBlockContents {
|
|
125
|
+
): SignedBlockContents<ForkPreGloas> {
|
|
126
|
+
if (isForkPostGloas(fork)) {
|
|
127
|
+
throw Error("Blinded block reconstruction is not supported after Gloas");
|
|
128
|
+
}
|
|
132
129
|
const signedBlock = signedBlindedBlockToFull(fork, signedBlindedBlock, executionPayload);
|
|
133
130
|
|
|
134
131
|
if (isForkPostDeneb(fork)) {
|
|
@@ -136,10 +133,10 @@ export function reconstructSignedBlockContents(
|
|
|
136
133
|
throw Error("Missing blobs bundle to reconstruct post-deneb block contents");
|
|
137
134
|
}
|
|
138
135
|
return {
|
|
139
|
-
signedBlock: signedBlock as SignedBeaconBlock<ForkPostDeneb>,
|
|
136
|
+
signedBlock: signedBlock as SignedBeaconBlock<ForkPostDeneb & ForkPreGloas>,
|
|
140
137
|
kzgProofs: blobsBundle.proofs,
|
|
141
138
|
blobs: blobsBundle.blobs,
|
|
142
139
|
};
|
|
143
140
|
}
|
|
144
|
-
return {signedBlock};
|
|
141
|
+
return {signedBlock: signedBlock as SignedBeaconBlock<ForkPreDeneb>};
|
|
145
142
|
}
|
package/src/util/clock.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {ChainForkConfig} from "@lodestar/config";
|
|
2
|
-
import {
|
|
2
|
+
import {SLOTS_PER_EPOCH} from "@lodestar/params";
|
|
3
3
|
import {Epoch, Slot, TimeSeconds} from "@lodestar/types";
|
|
4
4
|
import {ErrorAborted, Logger, isErrorAborted, sleep} from "@lodestar/utils";
|
|
5
5
|
import {computeEpochAtSlot} from "./epoch.js";
|
|
6
|
-
import {computeTimeAtSlot, getCurrentSlot} from "./slot.js";
|
|
6
|
+
import {computeTimeAtSlot, getCurrentSlot, getSlotDurationMs} from "./slot.js";
|
|
7
7
|
|
|
8
8
|
type RunEveryFn = (slot: Slot, signal: AbortSignal) => Promise<void>;
|
|
9
9
|
|
|
@@ -13,6 +13,7 @@ export type ClockOptions = {
|
|
|
13
13
|
|
|
14
14
|
export interface IClock {
|
|
15
15
|
readonly genesisTime: number;
|
|
16
|
+
/** @deprecated Use getSlotDurationMs(slot) instead */
|
|
16
17
|
readonly secondsPerSlot: number;
|
|
17
18
|
|
|
18
19
|
readonly currentEpoch: number;
|
|
@@ -25,6 +26,8 @@ export interface IClock {
|
|
|
25
26
|
secFromSlot(slot: Slot): number;
|
|
26
27
|
getCurrentSlot(): Slot;
|
|
27
28
|
getCurrentEpoch(): Epoch;
|
|
29
|
+
/** Slot duration in ms for a given slot */
|
|
30
|
+
getSlotDurationMs(slot: Slot): number;
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
export enum TimeItem {
|
|
@@ -95,6 +98,11 @@ export class Clock implements IClock {
|
|
|
95
98
|
return Date.now() / 1000 - computeTimeAtSlot(this.config, slot, this.genesisTime);
|
|
96
99
|
}
|
|
97
100
|
|
|
101
|
+
/** Slot duration in ms for a given slot */
|
|
102
|
+
getSlotDurationMs(slot: Slot): number {
|
|
103
|
+
return getSlotDurationMs(this.config, slot);
|
|
104
|
+
}
|
|
105
|
+
|
|
98
106
|
/**
|
|
99
107
|
* If a task happens to take more than one slot to run, we might skip a slot. This is unfortunate,
|
|
100
108
|
* however the alternative is to *always* process every slot, which has the chance of creating a
|
|
@@ -125,7 +133,7 @@ export class Clock implements IClock {
|
|
|
125
133
|
if (timeItem === TimeItem.Slot) {
|
|
126
134
|
if (nextSlot > slot + 1) {
|
|
127
135
|
// It's not very likely that we skip more than one slot as HTTP timeout is set
|
|
128
|
-
// to
|
|
136
|
+
// to at most one slot duration so we will fail task before skipping another slot.
|
|
129
137
|
this.logger.warn("Skipped slot due to task taking more than one slot to run", {
|
|
130
138
|
skippedSlot: slot + 1,
|
|
131
139
|
});
|
|
@@ -145,20 +153,17 @@ export class Clock implements IClock {
|
|
|
145
153
|
}
|
|
146
154
|
|
|
147
155
|
private timeUntilNext(timeItem: TimeItem): number {
|
|
148
|
-
const
|
|
149
|
-
const msFromGenesis = Date.now() - this.genesisTime * 1000;
|
|
156
|
+
const currentSlot = getCurrentSlot(this.config, this.genesisTime);
|
|
150
157
|
|
|
151
158
|
if (timeItem === TimeItem.Slot) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
return Math.abs(msFromGenesis) % milliSecondsPerSlot;
|
|
159
|
+
const nextSlotTimeSec = computeTimeAtSlot(this.config, currentSlot + 1, this.genesisTime);
|
|
160
|
+
return Math.max(0, nextSlotTimeSec * 1000 - Date.now());
|
|
156
161
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return Math.
|
|
162
|
+
|
|
163
|
+
const currentEpoch = computeEpochAtSlot(currentSlot);
|
|
164
|
+
const nextEpochSlot = (currentEpoch + 1) * SLOTS_PER_EPOCH;
|
|
165
|
+
const nextEpochTimeSec = computeTimeAtSlot(this.config, nextEpochSlot, this.genesisTime);
|
|
166
|
+
return Math.max(0, nextEpochTimeSec * 1000 - Date.now());
|
|
162
167
|
}
|
|
163
168
|
}
|
|
164
169
|
|
|
@@ -166,9 +171,13 @@ export class Clock implements IClock {
|
|
|
166
171
|
* Same to the spec but we use Math.round instead of Math.floor.
|
|
167
172
|
*/
|
|
168
173
|
export function getCurrentSlotAround(config: ChainForkConfig, genesisTime: TimeSeconds): Slot {
|
|
169
|
-
const
|
|
170
|
-
const
|
|
171
|
-
|
|
174
|
+
const floorSlot = getCurrentSlot(config, genesisTime);
|
|
175
|
+
const slotStartSec = computeTimeAtSlot(config, floorSlot, genesisTime);
|
|
176
|
+
const slotDurationMs = getSlotDurationMs(config, floorSlot);
|
|
177
|
+
const slotDurationSec = slotDurationMs / 1000;
|
|
178
|
+
const elapsed = Date.now() / 1000 - slotStartSec;
|
|
179
|
+
|
|
180
|
+
return elapsed >= slotDurationSec / 2 ? floorSlot + 1 : floorSlot;
|
|
172
181
|
}
|
|
173
182
|
|
|
174
183
|
// function useEventStream() {
|
package/src/util/deposit.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {ForkSeq, MAX_DEPOSITS} from "@lodestar/params";
|
|
2
2
|
import {UintNum64, phase0} from "@lodestar/types";
|
|
3
|
-
import {
|
|
3
|
+
import {CachedBeaconStateElectra, CachedBeaconStatePreHeze} from "../types.js";
|
|
4
4
|
|
|
5
|
-
export function getEth1DepositCount(state:
|
|
5
|
+
export function getEth1DepositCount(state: CachedBeaconStatePreHeze, eth1Data?: phase0.Eth1Data): UintNum64 {
|
|
6
6
|
const eth1DataToUse = eth1Data ?? state.eth1Data;
|
|
7
7
|
// Proposer can set any value, use in bigint until the result is bounded by MAX_DEPOSITS
|
|
8
8
|
const depositCount = eth1DataToUse.depositCount;
|