@lodestar/beacon-node 1.36.0-dev.793f92c091 → 1.36.0-dev.9dbc67b579
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/api/impl/config/constants.d.ts +4 -2
- package/lib/api/impl/config/constants.d.ts.map +1 -1
- package/lib/api/impl/config/constants.js +6 -3
- package/lib/api/impl/config/constants.js.map +1 -1
- package/lib/api/impl/lodestar/index.d.ts +5 -0
- package/lib/api/impl/lodestar/index.d.ts.map +1 -1
- package/lib/api/impl/lodestar/index.js +35 -10
- package/lib/api/impl/lodestar/index.js.map +1 -1
- package/lib/api/impl/node/utils.js +1 -1
- package/lib/api/impl/node/utils.js.map +1 -1
- package/lib/api/impl/validator/index.d.ts.map +1 -1
- package/lib/api/impl/validator/index.js +2 -2
- package/lib/api/impl/validator/index.js.map +1 -1
- package/lib/chain/archiveStore/archiveStore.d.ts +9 -0
- package/lib/chain/archiveStore/archiveStore.d.ts.map +1 -1
- package/lib/chain/archiveStore/archiveStore.js +24 -0
- package/lib/chain/archiveStore/archiveStore.js.map +1 -1
- package/lib/chain/archiveStore/strategies/frequencyStateArchiveStrategy.d.ts +7 -0
- package/lib/chain/archiveStore/strategies/frequencyStateArchiveStrategy.d.ts.map +1 -1
- package/lib/chain/archiveStore/strategies/frequencyStateArchiveStrategy.js +31 -5
- package/lib/chain/archiveStore/strategies/frequencyStateArchiveStrategy.js.map +1 -1
- package/lib/chain/beaconProposerCache.d.ts +3 -0
- package/lib/chain/beaconProposerCache.d.ts.map +1 -1
- package/lib/chain/beaconProposerCache.js +4 -6
- package/lib/chain/beaconProposerCache.js.map +1 -1
- package/lib/chain/chain.d.ts +5 -2
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +29 -14
- package/lib/chain/chain.js.map +1 -1
- package/lib/chain/errors/dataColumnSidecarError.d.ts +7 -0
- package/lib/chain/errors/dataColumnSidecarError.d.ts.map +1 -1
- package/lib/chain/errors/dataColumnSidecarError.js +1 -0
- package/lib/chain/errors/dataColumnSidecarError.js.map +1 -1
- package/lib/chain/errors/voluntaryExitError.d.ts +16 -2
- package/lib/chain/errors/voluntaryExitError.d.ts.map +1 -1
- package/lib/chain/errors/voluntaryExitError.js +22 -1
- package/lib/chain/errors/voluntaryExitError.js.map +1 -1
- package/lib/chain/forkChoice/index.d.ts +9 -1
- package/lib/chain/forkChoice/index.d.ts.map +1 -1
- package/lib/chain/forkChoice/index.js +109 -4
- package/lib/chain/forkChoice/index.js.map +1 -1
- package/lib/chain/interface.d.ts +2 -0
- package/lib/chain/interface.d.ts.map +1 -1
- package/lib/chain/lightClient/index.d.ts +3 -0
- package/lib/chain/lightClient/index.d.ts.map +1 -1
- package/lib/chain/lightClient/index.js +24 -13
- package/lib/chain/lightClient/index.js.map +1 -1
- package/lib/chain/opPools/syncContributionAndProofPool.d.ts +3 -1
- package/lib/chain/opPools/syncContributionAndProofPool.d.ts.map +1 -1
- package/lib/chain/opPools/syncContributionAndProofPool.js +4 -3
- package/lib/chain/opPools/syncContributionAndProofPool.js.map +1 -1
- package/lib/chain/stateCache/datastore/db.d.ts +12 -0
- package/lib/chain/stateCache/datastore/db.d.ts.map +1 -1
- package/lib/chain/stateCache/datastore/db.js +70 -0
- package/lib/chain/stateCache/datastore/db.js.map +1 -1
- package/lib/chain/stateCache/datastore/file.d.ts +1 -0
- package/lib/chain/stateCache/datastore/file.d.ts.map +1 -1
- package/lib/chain/stateCache/datastore/file.js +7 -0
- package/lib/chain/stateCache/datastore/file.js.map +1 -1
- package/lib/chain/stateCache/datastore/types.d.ts +1 -0
- package/lib/chain/stateCache/datastore/types.d.ts.map +1 -1
- package/lib/chain/validation/attestation.d.ts.map +1 -1
- package/lib/chain/validation/attestation.js +6 -7
- package/lib/chain/validation/attestation.js.map +1 -1
- package/lib/chain/validation/block.d.ts.map +1 -1
- package/lib/chain/validation/block.js +1 -2
- package/lib/chain/validation/block.js.map +1 -1
- package/lib/chain/validation/dataColumnSidecar.d.ts.map +1 -1
- package/lib/chain/validation/dataColumnSidecar.js +14 -3
- package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
- package/lib/chain/validation/lightClientOptimisticUpdate.d.ts.map +1 -1
- package/lib/chain/validation/lightClientOptimisticUpdate.js +1 -2
- package/lib/chain/validation/lightClientOptimisticUpdate.js.map +1 -1
- package/lib/chain/validation/voluntaryExit.d.ts.map +1 -1
- package/lib/chain/validation/voluntaryExit.js +5 -4
- package/lib/chain/validation/voluntaryExit.js.map +1 -1
- package/lib/constants/constants.d.ts +0 -5
- package/lib/constants/constants.d.ts.map +1 -1
- package/lib/constants/constants.js +0 -5
- package/lib/constants/constants.js.map +1 -1
- package/lib/constants/network.d.ts +0 -14
- package/lib/constants/network.d.ts.map +1 -1
- package/lib/constants/network.js +0 -15
- package/lib/constants/network.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/metrics/metrics/lodestar.d.ts +11 -0
- package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
- package/lib/metrics/metrics/lodestar.js +19 -1
- package/lib/metrics/metrics/lodestar.js.map +1 -1
- package/lib/network/core/networkCoreWorker.js +2 -7
- package/lib/network/core/networkCoreWorker.js.map +1 -1
- package/lib/network/discv5/utils.d.ts.map +1 -1
- package/lib/network/discv5/utils.js +1 -2
- package/lib/network/discv5/utils.js.map +1 -1
- package/lib/network/discv5/worker.js +2 -7
- package/lib/network/discv5/worker.js.map +1 -1
- package/lib/network/gossip/gossipsub.d.ts.map +1 -1
- package/lib/network/gossip/gossipsub.js +1 -7
- package/lib/network/gossip/gossipsub.js.map +1 -1
- package/lib/network/network.d.ts.map +1 -1
- package/lib/network/network.js +1 -0
- package/lib/network/network.js.map +1 -1
- package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
- package/lib/network/processor/gossipHandlers.js +14 -8
- package/lib/network/processor/gossipHandlers.js.map +1 -1
- package/lib/network/reqresp/handlers/beaconBlocksByRange.d.ts.map +1 -1
- package/lib/network/reqresp/handlers/beaconBlocksByRange.js +3 -1
- package/lib/network/reqresp/handlers/beaconBlocksByRange.js.map +1 -1
- package/lib/network/reqresp/handlers/blobSidecarsByRange.js +5 -5
- package/lib/network/reqresp/handlers/blobSidecarsByRange.js.map +1 -1
- package/lib/network/reqresp/handlers/blobSidecarsByRoot.js +4 -4
- package/lib/network/reqresp/handlers/blobSidecarsByRoot.js.map +1 -1
- package/lib/network/subnets/attnetsService.d.ts +1 -1
- package/lib/network/subnets/attnetsService.js +6 -6
- package/lib/network/subnets/attnetsService.js.map +1 -1
- package/lib/network/subnets/util.d.ts +3 -2
- package/lib/network/subnets/util.d.ts.map +1 -1
- package/lib/network/subnets/util.js +6 -6
- package/lib/network/subnets/util.js.map +1 -1
- package/lib/node/nodejs.d.ts +2 -1
- package/lib/node/nodejs.d.ts.map +1 -1
- package/lib/node/nodejs.js +2 -1
- package/lib/node/nodejs.js.map +1 -1
- package/lib/sync/range/range.d.ts.map +1 -1
- package/lib/sync/range/range.js +2 -1
- package/lib/sync/range/range.js.map +1 -1
- package/lib/sync/utils/remoteSyncType.d.ts +2 -1
- package/lib/sync/utils/remoteSyncType.d.ts.map +1 -1
- package/lib/sync/utils/remoteSyncType.js +19 -4
- package/lib/sync/utils/remoteSyncType.js.map +1 -1
- package/lib/util/clock.d.ts.map +1 -1
- package/lib/util/clock.js +3 -4
- package/lib/util/clock.js.map +1 -1
- package/lib/util/profile.d.ts +6 -4
- package/lib/util/profile.d.ts.map +1 -1
- package/lib/util/profile.js +40 -3
- package/lib/util/profile.js.map +1 -1
- package/lib/util/sszBytes.d.ts +2 -0
- package/lib/util/sszBytes.d.ts.map +1 -1
- package/lib/util/sszBytes.js +25 -0
- package/lib/util/sszBytes.js.map +1 -1
- package/package.json +26 -24
- package/src/api/impl/config/constants.ts +10 -4
- package/src/api/impl/lodestar/index.ts +42 -10
- package/src/api/impl/node/utils.ts +1 -1
- package/src/api/impl/validator/index.ts +5 -2
- package/src/chain/archiveStore/archiveStore.ts +27 -0
- package/src/chain/archiveStore/strategies/frequencyStateArchiveStrategy.ts +32 -5
- package/src/chain/beaconProposerCache.ts +4 -8
- package/src/chain/chain.ts +45 -20
- package/src/chain/errors/dataColumnSidecarError.ts +8 -0
- package/src/chain/errors/voluntaryExitError.ts +30 -2
- package/src/chain/forkChoice/index.ts +178 -2
- package/src/chain/interface.ts +2 -0
- package/src/chain/lightClient/index.ts +26 -12
- package/src/chain/opPools/syncContributionAndProofPool.ts +3 -2
- package/src/chain/stateCache/datastore/db.ts +89 -1
- package/src/chain/stateCache/datastore/file.ts +8 -0
- package/src/chain/stateCache/datastore/types.ts +1 -0
- package/src/chain/validation/attestation.ts +6 -7
- package/src/chain/validation/block.ts +1 -2
- package/src/chain/validation/dataColumnSidecar.ts +21 -4
- package/src/chain/validation/lightClientOptimisticUpdate.ts +3 -2
- package/src/chain/validation/voluntaryExit.ts +14 -4
- package/src/constants/constants.ts +0 -6
- package/src/constants/network.ts +0 -19
- package/src/index.ts +2 -0
- package/src/metrics/metrics/lodestar.ts +22 -1
- package/src/network/core/networkCoreWorker.ts +2 -7
- package/src/network/discv5/utils.ts +1 -2
- package/src/network/discv5/worker.ts +2 -7
- package/src/network/gossip/gossipsub.ts +1 -10
- package/src/network/network.ts +1 -0
- package/src/network/processor/gossipHandlers.ts +16 -7
- package/src/network/reqresp/handlers/beaconBlocksByRange.ts +3 -1
- package/src/network/reqresp/handlers/blobSidecarsByRange.ts +6 -6
- package/src/network/reqresp/handlers/blobSidecarsByRoot.ts +5 -5
- package/src/network/subnets/attnetsService.ts +6 -6
- package/src/network/subnets/util.ts +12 -12
- package/src/node/nodejs.ts +3 -0
- package/src/sync/range/range.ts +2 -1
- package/src/sync/utils/remoteSyncType.ts +23 -4
- package/src/util/clock.ts +3 -4
- package/src/util/profile.ts +45 -3
- package/src/util/sszBytes.ts +30 -0
|
@@ -1,13 +1,41 @@
|
|
|
1
|
+
import {VoluntaryExitValidity} from "@lodestar/state-transition";
|
|
1
2
|
import {GossipActionError} from "./gossipValidation.js";
|
|
2
3
|
|
|
3
4
|
export enum VoluntaryExitErrorCode {
|
|
4
5
|
ALREADY_EXISTS = "VOLUNTARY_EXIT_ERROR_ALREADY_EXISTS",
|
|
5
|
-
|
|
6
|
+
INACTIVE = "VOLUNTARY_EXIT_ERROR_INACTIVE",
|
|
7
|
+
ALREADY_EXITED = "VOLUNTARY_EXIT_ERROR_ALREADY_EXITED",
|
|
8
|
+
EARLY_EPOCH = "VOLUNTARY_EXIT_ERROR_EARLY_EPOCH",
|
|
9
|
+
SHORT_TIME_ACTIVE = "VOLUNTARY_EXIT_ERROR_SHORT_TIME_ACTIVE",
|
|
10
|
+
PENDING_WITHDRAWALS = "VOLUNTARY_EXIT_ERROR_PENDING_WITHDRAWALS",
|
|
6
11
|
INVALID_SIGNATURE = "VOLUNTARY_EXIT_ERROR_INVALID_SIGNATURE",
|
|
7
12
|
}
|
|
8
13
|
export type VoluntaryExitErrorType =
|
|
9
14
|
| {code: VoluntaryExitErrorCode.ALREADY_EXISTS}
|
|
10
|
-
| {code: VoluntaryExitErrorCode.
|
|
15
|
+
| {code: VoluntaryExitErrorCode.INACTIVE}
|
|
16
|
+
| {code: VoluntaryExitErrorCode.ALREADY_EXITED}
|
|
17
|
+
| {code: VoluntaryExitErrorCode.EARLY_EPOCH}
|
|
18
|
+
| {code: VoluntaryExitErrorCode.SHORT_TIME_ACTIVE}
|
|
19
|
+
| {code: VoluntaryExitErrorCode.PENDING_WITHDRAWALS}
|
|
11
20
|
| {code: VoluntaryExitErrorCode.INVALID_SIGNATURE};
|
|
12
21
|
|
|
13
22
|
export class VoluntaryExitError extends GossipActionError<VoluntaryExitErrorType> {}
|
|
23
|
+
|
|
24
|
+
export function voluntaryExitValidityToErrorCode(
|
|
25
|
+
validity: Exclude<VoluntaryExitValidity, VoluntaryExitValidity.valid>
|
|
26
|
+
): VoluntaryExitErrorCode {
|
|
27
|
+
switch (validity) {
|
|
28
|
+
case VoluntaryExitValidity.inactive:
|
|
29
|
+
return VoluntaryExitErrorCode.INACTIVE;
|
|
30
|
+
case VoluntaryExitValidity.alreadyExited:
|
|
31
|
+
return VoluntaryExitErrorCode.ALREADY_EXITED;
|
|
32
|
+
case VoluntaryExitValidity.earlyEpoch:
|
|
33
|
+
return VoluntaryExitErrorCode.EARLY_EPOCH;
|
|
34
|
+
case VoluntaryExitValidity.shortTimeActive:
|
|
35
|
+
return VoluntaryExitErrorCode.SHORT_TIME_ACTIVE;
|
|
36
|
+
case VoluntaryExitValidity.pendingWithdrawals:
|
|
37
|
+
return VoluntaryExitErrorCode.PENDING_WITHDRAWALS;
|
|
38
|
+
case VoluntaryExitValidity.invalidSignature:
|
|
39
|
+
return VoluntaryExitErrorCode.INVALID_SIGNATURE;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -5,17 +5,22 @@ import {
|
|
|
5
5
|
ForkChoiceStore,
|
|
6
6
|
JustifiedBalancesGetter,
|
|
7
7
|
ProtoArray,
|
|
8
|
+
ProtoBlock,
|
|
8
9
|
ForkChoiceOpts as RawForkChoiceOpts,
|
|
9
10
|
} from "@lodestar/fork-choice";
|
|
11
|
+
import {ZERO_HASH_HEX} from "@lodestar/params";
|
|
10
12
|
import {
|
|
11
13
|
CachedBeaconStateAllForks,
|
|
12
14
|
DataAvailabilityStatus,
|
|
13
15
|
computeAnchorCheckpoint,
|
|
16
|
+
computeEpochAtSlot,
|
|
17
|
+
computeStartSlotAtEpoch,
|
|
18
|
+
getBlockRootAtSlot,
|
|
14
19
|
getEffectiveBalanceIncrementsZeroInactive,
|
|
15
20
|
isExecutionStateType,
|
|
16
21
|
isMergeTransitionComplete,
|
|
17
22
|
} from "@lodestar/state-transition";
|
|
18
|
-
import {Slot} from "@lodestar/types";
|
|
23
|
+
import {Slot, ssz} from "@lodestar/types";
|
|
19
24
|
import {Logger, toRootHex} from "@lodestar/utils";
|
|
20
25
|
import {GENESIS_SLOT} from "../../constants/index.js";
|
|
21
26
|
import {Metrics} from "../../metrics/index.js";
|
|
@@ -35,6 +40,43 @@ export enum ForkchoiceCaller {
|
|
|
35
40
|
* Fork Choice extended with a ChainEventEmitter
|
|
36
41
|
*/
|
|
37
42
|
export function initializeForkChoice(
|
|
43
|
+
config: ChainForkConfig,
|
|
44
|
+
emitter: ChainEventEmitter,
|
|
45
|
+
currentSlot: Slot,
|
|
46
|
+
state: CachedBeaconStateAllForks,
|
|
47
|
+
isFinalizedState: boolean,
|
|
48
|
+
opts: ForkChoiceOpts,
|
|
49
|
+
justifiedBalancesGetter: JustifiedBalancesGetter,
|
|
50
|
+
metrics: Metrics | null,
|
|
51
|
+
logger?: Logger
|
|
52
|
+
): ForkChoice {
|
|
53
|
+
return isFinalizedState
|
|
54
|
+
? initializeForkChoiceFromFinalizedState(
|
|
55
|
+
config,
|
|
56
|
+
emitter,
|
|
57
|
+
currentSlot,
|
|
58
|
+
state,
|
|
59
|
+
opts,
|
|
60
|
+
justifiedBalancesGetter,
|
|
61
|
+
metrics,
|
|
62
|
+
logger
|
|
63
|
+
)
|
|
64
|
+
: initializeForkChoiceFromUnfinalizedState(
|
|
65
|
+
config,
|
|
66
|
+
emitter,
|
|
67
|
+
currentSlot,
|
|
68
|
+
state,
|
|
69
|
+
opts,
|
|
70
|
+
justifiedBalancesGetter,
|
|
71
|
+
metrics,
|
|
72
|
+
logger
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Initialize forkchoice from a finalized state.
|
|
78
|
+
*/
|
|
79
|
+
export function initializeForkChoiceFromFinalizedState(
|
|
38
80
|
config: ChainForkConfig,
|
|
39
81
|
emitter: ChainEventEmitter,
|
|
40
82
|
currentSlot: Slot,
|
|
@@ -82,7 +124,7 @@ export function initializeForkChoice(
|
|
|
82
124
|
parentRoot: toRootHex(blockHeader.parentRoot),
|
|
83
125
|
stateRoot: toRootHex(blockHeader.stateRoot),
|
|
84
126
|
blockRoot: toRootHex(checkpoint.root),
|
|
85
|
-
timeliness: true, //
|
|
127
|
+
timeliness: true, // Optimistically assume is timely
|
|
86
128
|
|
|
87
129
|
justifiedEpoch: justifiedCheckpoint.epoch,
|
|
88
130
|
justifiedRoot: toRootHex(justifiedCheckpoint.root),
|
|
@@ -105,6 +147,140 @@ export function initializeForkChoice(
|
|
|
105
147
|
},
|
|
106
148
|
currentSlot
|
|
107
149
|
),
|
|
150
|
+
state.validators.length,
|
|
151
|
+
metrics,
|
|
152
|
+
opts,
|
|
153
|
+
logger
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Initialize forkchoice from an unfinalized state.
|
|
159
|
+
*/
|
|
160
|
+
export function initializeForkChoiceFromUnfinalizedState(
|
|
161
|
+
config: ChainForkConfig,
|
|
162
|
+
emitter: ChainEventEmitter,
|
|
163
|
+
currentSlot: Slot,
|
|
164
|
+
unfinalizedState: CachedBeaconStateAllForks,
|
|
165
|
+
opts: ForkChoiceOpts,
|
|
166
|
+
justifiedBalancesGetter: JustifiedBalancesGetter,
|
|
167
|
+
metrics: Metrics | null,
|
|
168
|
+
logger?: Logger
|
|
169
|
+
): ForkChoice {
|
|
170
|
+
const {blockHeader} = computeAnchorCheckpoint(config, unfinalizedState);
|
|
171
|
+
const finalizedCheckpoint = unfinalizedState.finalizedCheckpoint.toValue();
|
|
172
|
+
const justifiedCheckpoint = unfinalizedState.currentJustifiedCheckpoint.toValue();
|
|
173
|
+
const headRoot = toRootHex(ssz.phase0.BeaconBlockHeader.hashTreeRoot(blockHeader));
|
|
174
|
+
|
|
175
|
+
const logCtx = {
|
|
176
|
+
currentSlot: currentSlot,
|
|
177
|
+
stateSlot: unfinalizedState.slot,
|
|
178
|
+
headSlot: blockHeader.slot,
|
|
179
|
+
headRoot: headRoot,
|
|
180
|
+
finalizedEpoch: finalizedCheckpoint.epoch,
|
|
181
|
+
finalizedRoot: toRootHex(finalizedCheckpoint.root),
|
|
182
|
+
justifiedEpoch: justifiedCheckpoint.epoch,
|
|
183
|
+
justifiedRoot: toRootHex(justifiedCheckpoint.root),
|
|
184
|
+
};
|
|
185
|
+
logger?.warn("Initializing fork choice from unfinalized state", logCtx);
|
|
186
|
+
|
|
187
|
+
// this is not the justified state, but there is no other ways to get justified balances
|
|
188
|
+
const justifiedBalances = getEffectiveBalanceIncrementsZeroInactive(unfinalizedState);
|
|
189
|
+
const store = new ForkChoiceStore(
|
|
190
|
+
currentSlot,
|
|
191
|
+
justifiedCheckpoint,
|
|
192
|
+
finalizedCheckpoint,
|
|
193
|
+
justifiedBalances,
|
|
194
|
+
justifiedBalancesGetter,
|
|
195
|
+
{
|
|
196
|
+
onJustified: (cp) => emitter.emit(ChainEvent.forkChoiceJustified, cp),
|
|
197
|
+
onFinalized: (cp) => emitter.emit(ChainEvent.forkChoiceFinalized, cp),
|
|
198
|
+
}
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
// this is the same to the finalized state
|
|
202
|
+
const headBlock: ProtoBlock = {
|
|
203
|
+
slot: blockHeader.slot,
|
|
204
|
+
parentRoot: toRootHex(blockHeader.parentRoot),
|
|
205
|
+
stateRoot: toRootHex(blockHeader.stateRoot),
|
|
206
|
+
blockRoot: headRoot,
|
|
207
|
+
targetRoot: headRoot,
|
|
208
|
+
timeliness: true, // Optimistically assume is timely
|
|
209
|
+
|
|
210
|
+
justifiedEpoch: justifiedCheckpoint.epoch,
|
|
211
|
+
justifiedRoot: toRootHex(justifiedCheckpoint.root),
|
|
212
|
+
finalizedEpoch: finalizedCheckpoint.epoch,
|
|
213
|
+
finalizedRoot: toRootHex(finalizedCheckpoint.root),
|
|
214
|
+
unrealizedJustifiedEpoch: justifiedCheckpoint.epoch,
|
|
215
|
+
unrealizedJustifiedRoot: toRootHex(justifiedCheckpoint.root),
|
|
216
|
+
unrealizedFinalizedEpoch: finalizedCheckpoint.epoch,
|
|
217
|
+
unrealizedFinalizedRoot: toRootHex(finalizedCheckpoint.root),
|
|
218
|
+
|
|
219
|
+
...(isExecutionStateType(unfinalizedState) && isMergeTransitionComplete(unfinalizedState)
|
|
220
|
+
? {
|
|
221
|
+
executionPayloadBlockHash: toRootHex(unfinalizedState.latestExecutionPayloadHeader.blockHash),
|
|
222
|
+
executionPayloadNumber: unfinalizedState.latestExecutionPayloadHeader.blockNumber,
|
|
223
|
+
executionStatus: blockHeader.slot === GENESIS_SLOT ? ExecutionStatus.Valid : ExecutionStatus.Syncing,
|
|
224
|
+
}
|
|
225
|
+
: {executionPayloadBlockHash: null, executionStatus: ExecutionStatus.PreMerge}),
|
|
226
|
+
|
|
227
|
+
dataAvailabilityStatus: DataAvailabilityStatus.PreData,
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const parentSlot = blockHeader.slot - 1;
|
|
231
|
+
const parentEpoch = computeEpochAtSlot(parentSlot);
|
|
232
|
+
// parent of head block
|
|
233
|
+
const parentBlock: ProtoBlock = {
|
|
234
|
+
...headBlock,
|
|
235
|
+
slot: parentSlot,
|
|
236
|
+
// link this to the dummy justified block
|
|
237
|
+
parentRoot: toRootHex(justifiedCheckpoint.root),
|
|
238
|
+
// dummy data, we're not able to regen state before headBlock
|
|
239
|
+
stateRoot: ZERO_HASH_HEX,
|
|
240
|
+
blockRoot: headBlock.parentRoot,
|
|
241
|
+
targetRoot: toRootHex(getBlockRootAtSlot(unfinalizedState, computeStartSlotAtEpoch(parentEpoch))),
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
const justifiedBlock: ProtoBlock = {
|
|
245
|
+
...headBlock,
|
|
246
|
+
slot: computeStartSlotAtEpoch(justifiedCheckpoint.epoch),
|
|
247
|
+
// link this to the finalized root so that getAncestors can find the finalized block
|
|
248
|
+
parentRoot: toRootHex(finalizedCheckpoint.root),
|
|
249
|
+
// dummy data, we're not able to regen state before headBlock
|
|
250
|
+
stateRoot: ZERO_HASH_HEX,
|
|
251
|
+
blockRoot: toRootHex(justifiedCheckpoint.root),
|
|
252
|
+
// same to blockRoot
|
|
253
|
+
targetRoot: toRootHex(justifiedCheckpoint.root),
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
const finalizedBlock: ProtoBlock = {
|
|
257
|
+
...headBlock,
|
|
258
|
+
slot: computeStartSlotAtEpoch(finalizedCheckpoint.epoch),
|
|
259
|
+
// we don't care parent of finalized block
|
|
260
|
+
parentRoot: ZERO_HASH_HEX,
|
|
261
|
+
// dummy data, we're not able to regen state before headBlock
|
|
262
|
+
stateRoot: ZERO_HASH_HEX,
|
|
263
|
+
blockRoot: toRootHex(finalizedCheckpoint.root),
|
|
264
|
+
// same to blockRoot
|
|
265
|
+
targetRoot: toRootHex(finalizedCheckpoint.root),
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
const protoArray = ProtoArray.initialize(finalizedBlock, currentSlot);
|
|
269
|
+
protoArray.onBlock(justifiedBlock, currentSlot);
|
|
270
|
+
protoArray.onBlock(parentBlock, currentSlot);
|
|
271
|
+
protoArray.onBlock(headBlock, currentSlot);
|
|
272
|
+
|
|
273
|
+
logger?.verbose("Initialized protoArray successfully", {...logCtx, length: protoArray.length()});
|
|
274
|
+
|
|
275
|
+
// forkchoiceConstructor is only used for some test cases
|
|
276
|
+
// production code use ForkChoice constructor directly
|
|
277
|
+
const forkchoiceConstructor = opts.forkchoiceConstructor ?? ForkChoice;
|
|
278
|
+
|
|
279
|
+
return new forkchoiceConstructor(
|
|
280
|
+
config,
|
|
281
|
+
store,
|
|
282
|
+
protoArray,
|
|
283
|
+
unfinalizedState.validators.length,
|
|
108
284
|
metrics,
|
|
109
285
|
opts,
|
|
110
286
|
logger
|
package/src/chain/interface.ts
CHANGED
|
@@ -178,6 +178,8 @@ export interface IBeaconChain {
|
|
|
178
178
|
stateRoot: RootHex,
|
|
179
179
|
opts?: StateGetOpts
|
|
180
180
|
): Promise<{state: BeaconStateAllForks; executionOptimistic: boolean; finalized: boolean} | null>;
|
|
181
|
+
/** Return serialized bytes of a persisted checkpoint state */
|
|
182
|
+
getPersistedCheckpointState(checkpoint?: phase0.Checkpoint): Promise<Uint8Array | null>;
|
|
181
183
|
/** Returns a cached state by checkpoint */
|
|
182
184
|
getStateByCheckpoint(
|
|
183
185
|
checkpoint: CheckpointWithHex
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
ForkPreGloas,
|
|
15
15
|
ForkSeq,
|
|
16
16
|
MIN_SYNC_COMMITTEE_PARTICIPANTS,
|
|
17
|
+
SLOTS_PER_EPOCH,
|
|
17
18
|
SYNC_COMMITTEE_SIZE,
|
|
18
19
|
forkPostAltair,
|
|
19
20
|
highestFork,
|
|
@@ -51,6 +52,7 @@ import {IBeaconDb} from "../../db/index.js";
|
|
|
51
52
|
import {NUM_WITNESS, NUM_WITNESS_ELECTRA} from "../../db/repositories/lightclientSyncCommitteeWitness.js";
|
|
52
53
|
import {Metrics} from "../../metrics/index.js";
|
|
53
54
|
import {byteArrayEquals} from "../../util/bytes.js";
|
|
55
|
+
import {IClock} from "../../util/clock.js";
|
|
54
56
|
import {ChainEventEmitter} from "../emitter.js";
|
|
55
57
|
import {LightClientServerError, LightClientServerErrorCode} from "../errors/lightClientError.js";
|
|
56
58
|
import {
|
|
@@ -86,6 +88,7 @@ export type SyncAttestedData = {
|
|
|
86
88
|
|
|
87
89
|
type LightClientServerModules = {
|
|
88
90
|
config: ChainForkConfig;
|
|
91
|
+
clock: IClock;
|
|
89
92
|
db: IBeaconDb;
|
|
90
93
|
metrics: Metrics | null;
|
|
91
94
|
emitter: ChainEventEmitter;
|
|
@@ -201,6 +204,7 @@ export class LightClientServer {
|
|
|
201
204
|
private readonly metrics: Metrics | null;
|
|
202
205
|
private readonly emitter: ChainEventEmitter;
|
|
203
206
|
private readonly logger: Logger;
|
|
207
|
+
private readonly clock: IClock;
|
|
204
208
|
private readonly knownSyncCommittee = new MapDef<SyncPeriod, Set<DependentRootHex>>(() => new Set());
|
|
205
209
|
private storedCurrentSyncCommittee = false;
|
|
206
210
|
|
|
@@ -221,8 +225,9 @@ export class LightClientServer {
|
|
|
221
225
|
private readonly opts: LightClientServerOpts,
|
|
222
226
|
modules: LightClientServerModules
|
|
223
227
|
) {
|
|
224
|
-
const {config, db, metrics, emitter, logger} = modules;
|
|
228
|
+
const {config, clock, db, metrics, emitter, logger} = modules;
|
|
225
229
|
this.config = config;
|
|
230
|
+
this.clock = clock;
|
|
226
231
|
this.db = db;
|
|
227
232
|
this.metrics = metrics;
|
|
228
233
|
this.emitter = emitter;
|
|
@@ -533,12 +538,19 @@ export class LightClientServer {
|
|
|
533
538
|
// Fork of LightClientOptimisticUpdate and LightClientFinalityUpdate is based off on attested header's fork
|
|
534
539
|
const attestedFork = this.config.getForkName(attestedHeader.beacon.slot);
|
|
535
540
|
|
|
536
|
-
//
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
541
|
+
// Check if node is syncing / too far behind to avoid emitting stale light client updates
|
|
542
|
+
const isStaleLightClientUpdate = this.clock.currentSlot - signatureSlot > SLOTS_PER_EPOCH;
|
|
543
|
+
|
|
544
|
+
if (!isStaleLightClientUpdate) {
|
|
545
|
+
// Emit update
|
|
546
|
+
// Note: Always emit optimistic update even if we have emitted one with higher or equal attested_header.slot
|
|
547
|
+
this.emitter.emit(routes.events.EventType.lightClientOptimisticUpdate, {
|
|
548
|
+
version: attestedFork,
|
|
549
|
+
data: headerUpdate,
|
|
550
|
+
});
|
|
551
|
+
} else {
|
|
552
|
+
this.metrics?.lightclientServer.staleLightClientUpdates.inc();
|
|
553
|
+
}
|
|
542
554
|
|
|
543
555
|
// Persist latest best update for getLatestHeadUpdate()
|
|
544
556
|
// TODO: Once SyncAggregate are constructed from P2P too, count bits to decide "best"
|
|
@@ -569,11 +581,13 @@ export class LightClientServer {
|
|
|
569
581
|
};
|
|
570
582
|
this.metrics?.lightclientServer.onSyncAggregate.inc({event: "update_latest_finalized_update"});
|
|
571
583
|
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
584
|
+
if (!isStaleLightClientUpdate) {
|
|
585
|
+
// Note: Ignores gossip rule to always emit finality_update with higher finalized_header.slot, for simplicity
|
|
586
|
+
this.emitter.emit(routes.events.EventType.lightClientFinalityUpdate, {
|
|
587
|
+
version: attestedFork,
|
|
588
|
+
data: this.finalized,
|
|
589
|
+
});
|
|
590
|
+
}
|
|
577
591
|
}
|
|
578
592
|
}
|
|
579
593
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {Signature, aggregateSignatures} from "@chainsafe/blst";
|
|
2
2
|
import {BitArray} from "@chainsafe/ssz";
|
|
3
|
+
import {ChainForkConfig} from "@lodestar/config";
|
|
3
4
|
import {SYNC_COMMITTEE_SIZE, SYNC_COMMITTEE_SUBNET_SIZE} from "@lodestar/params";
|
|
4
5
|
import {G2_POINT_AT_INFINITY} from "@lodestar/state-transition";
|
|
5
6
|
import {Root, Slot, SubnetID, altair, ssz} from "@lodestar/types";
|
|
6
7
|
import {Logger, MapDef, toRootHex} from "@lodestar/utils";
|
|
7
|
-
import {MAXIMUM_GOSSIP_CLOCK_DISPARITY} from "../../constants/constants.js";
|
|
8
8
|
import {Metrics} from "../../metrics/metrics.js";
|
|
9
9
|
import {IClock} from "../../util/clock.js";
|
|
10
10
|
import {InsertOutcome, OpPoolError, OpPoolErrorCode} from "./types.js";
|
|
@@ -51,6 +51,7 @@ export class SyncContributionAndProofPool {
|
|
|
51
51
|
private lowestPermissibleSlot = 0;
|
|
52
52
|
|
|
53
53
|
constructor(
|
|
54
|
+
private readonly config: ChainForkConfig,
|
|
54
55
|
private readonly clock: IClock,
|
|
55
56
|
private readonly metrics: Metrics | null = null,
|
|
56
57
|
private logger: Logger | null = null
|
|
@@ -92,7 +93,7 @@ export class SyncContributionAndProofPool {
|
|
|
92
93
|
|
|
93
94
|
// Reject ContributionAndProofs of previous slots
|
|
94
95
|
// for api ContributionAndProofs, we allow them to be added to the pool
|
|
95
|
-
if (!priority && slot < this.clock.slotWithPastTolerance(MAXIMUM_GOSSIP_CLOCK_DISPARITY)) {
|
|
96
|
+
if (!priority && slot < this.clock.slotWithPastTolerance(this.config.MAXIMUM_GOSSIP_CLOCK_DISPARITY / 1000)) {
|
|
96
97
|
return InsertOutcome.Late;
|
|
97
98
|
}
|
|
98
99
|
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {SLOTS_PER_EPOCH} from "@lodestar/params";
|
|
2
|
+
import {Epoch, phase0, ssz} from "@lodestar/types";
|
|
3
|
+
import {MapDef} from "@lodestar/utils";
|
|
2
4
|
import {IBeaconDb} from "../../../db/interface.js";
|
|
5
|
+
import {
|
|
6
|
+
getLastProcessedSlotFromBeaconStateSerialized,
|
|
7
|
+
getSlotFromBeaconStateSerialized,
|
|
8
|
+
} from "../../../util/sszBytes.js";
|
|
3
9
|
import {CPStateDatastore, DatastoreKey} from "./types.js";
|
|
4
10
|
|
|
5
11
|
/**
|
|
@@ -22,6 +28,13 @@ export class DbCPStateDatastore implements CPStateDatastore {
|
|
|
22
28
|
return this.db.checkpointState.getBinary(serializedCheckpoint);
|
|
23
29
|
}
|
|
24
30
|
|
|
31
|
+
async readLatestSafe(): Promise<Uint8Array | null> {
|
|
32
|
+
const allKeys = await this.readKeys();
|
|
33
|
+
if (allKeys.length === 0) return null;
|
|
34
|
+
|
|
35
|
+
return getLatestSafeDatastoreKey(allKeys, this.read.bind(this));
|
|
36
|
+
}
|
|
37
|
+
|
|
25
38
|
async readKeys(): Promise<DatastoreKey[]> {
|
|
26
39
|
return this.db.checkpointState.keys();
|
|
27
40
|
}
|
|
@@ -34,3 +47,78 @@ export function datastoreKeyToCheckpoint(key: DatastoreKey): phase0.Checkpoint {
|
|
|
34
47
|
export function checkpointToDatastoreKey(cp: phase0.Checkpoint): DatastoreKey {
|
|
35
48
|
return ssz.phase0.Checkpoint.serialize(cp);
|
|
36
49
|
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Get the latest safe checkpoint state the node can use to boot from
|
|
53
|
+
* - it should be the checkpoint state that's unique in its epoch
|
|
54
|
+
* - its last processed block slot should be at epoch boundary or last slot of previous epoch
|
|
55
|
+
* - state slot should be at epoch boundary
|
|
56
|
+
* - state slot should be equal to epoch * SLOTS_PER_EPOCH
|
|
57
|
+
*
|
|
58
|
+
* return the serialized data of Current Root Checkpoint State (CRCS) or Previous Root Checkpoint State (PRCS)
|
|
59
|
+
*
|
|
60
|
+
*/
|
|
61
|
+
export async function getLatestSafeDatastoreKey(
|
|
62
|
+
allKeys: DatastoreKey[],
|
|
63
|
+
readFn: (key: DatastoreKey) => Promise<Uint8Array | null>
|
|
64
|
+
): Promise<Uint8Array | null> {
|
|
65
|
+
const checkpointsByEpoch = new MapDef<Epoch, DatastoreKey[]>(() => []);
|
|
66
|
+
for (const key of allKeys) {
|
|
67
|
+
const cp = datastoreKeyToCheckpoint(key);
|
|
68
|
+
checkpointsByEpoch.getOrDefault(cp.epoch).push(key);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const dataStoreKeyByEpoch: Map<Epoch, DatastoreKey> = new Map();
|
|
72
|
+
for (const [epoch, keys] of checkpointsByEpoch.entries()) {
|
|
73
|
+
// only consider epochs with a single checkpoint to avoid ambiguity from forks
|
|
74
|
+
if (keys.length === 1) {
|
|
75
|
+
dataStoreKeyByEpoch.set(epoch, keys[0]);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const epochsDesc = Array.from(dataStoreKeyByEpoch.keys()).sort((a, b) => b - a);
|
|
80
|
+
for (const epoch of epochsDesc) {
|
|
81
|
+
const datastoreKey = dataStoreKeyByEpoch.get(epoch);
|
|
82
|
+
if (datastoreKey == null) {
|
|
83
|
+
// should not happen
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const stateBytes = await readFn(datastoreKey);
|
|
88
|
+
if (stateBytes == null) {
|
|
89
|
+
// should not happen
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const lastProcessedSlot = getLastProcessedSlotFromBeaconStateSerialized(stateBytes);
|
|
94
|
+
if (lastProcessedSlot == null) {
|
|
95
|
+
// cannot extract last processed slot from serialized state, skip
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const stateSlot = getSlotFromBeaconStateSerialized(stateBytes);
|
|
100
|
+
if (stateSlot == null) {
|
|
101
|
+
// cannot extract slot from serialized state, skip
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (lastProcessedSlot !== stateSlot && lastProcessedSlot !== stateSlot - 1) {
|
|
106
|
+
// not CRCS or PRCS, skip
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (stateSlot % SLOTS_PER_EPOCH !== 0) {
|
|
111
|
+
// not at epoch boundary, skip
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (stateSlot !== SLOTS_PER_EPOCH * epoch) {
|
|
116
|
+
// should not happen after above checks, but just to be safe
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return stateBytes;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
@@ -2,6 +2,7 @@ import path from "node:path";
|
|
|
2
2
|
import {phase0, ssz} from "@lodestar/types";
|
|
3
3
|
import {fromHex, toHex} from "@lodestar/utils";
|
|
4
4
|
import {ensureDir, readFile, readFileNames, removeFile, writeIfNotExist} from "../../../util/file.js";
|
|
5
|
+
import {getLatestSafeDatastoreKey} from "./db.js";
|
|
5
6
|
import {CPStateDatastore, DatastoreKey} from "./types.js";
|
|
6
7
|
|
|
7
8
|
const CHECKPOINT_STATES_FOLDER = "checkpoint_states";
|
|
@@ -44,6 +45,13 @@ export class FileCPStateDatastore implements CPStateDatastore {
|
|
|
44
45
|
return readFile(filePath);
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
async readLatestSafe(): Promise<Uint8Array | null> {
|
|
49
|
+
const allKeys = await this.readKeys();
|
|
50
|
+
if (allKeys.length === 0) return null;
|
|
51
|
+
|
|
52
|
+
return getLatestSafeDatastoreKey(allKeys, this.read.bind(this));
|
|
53
|
+
}
|
|
54
|
+
|
|
47
55
|
async readKeys(): Promise<DatastoreKey[]> {
|
|
48
56
|
const fileNames = await readFileNames(this.folderPath);
|
|
49
57
|
return fileNames
|
|
@@ -8,6 +8,7 @@ export interface CPStateDatastore {
|
|
|
8
8
|
write: (cpKey: phase0.Checkpoint, stateBytes: Uint8Array) => Promise<DatastoreKey>;
|
|
9
9
|
remove: (key: DatastoreKey) => Promise<void>;
|
|
10
10
|
read: (key: DatastoreKey) => Promise<Uint8Array | null>;
|
|
11
|
+
readLatestSafe: () => Promise<Uint8Array | null>;
|
|
11
12
|
readKeys: () => Promise<DatastoreKey[]>;
|
|
12
13
|
init?: () => Promise<void>;
|
|
13
14
|
}
|
|
@@ -36,7 +36,6 @@ import {
|
|
|
36
36
|
ssz,
|
|
37
37
|
} from "@lodestar/types";
|
|
38
38
|
import {assert, toRootHex} from "@lodestar/utils";
|
|
39
|
-
import {MAXIMUM_GOSSIP_CLOCK_DISPARITY_SEC} from "../../constants/index.js";
|
|
40
39
|
import {sszDeserializeSingleAttestation} from "../../network/gossip/topic.js";
|
|
41
40
|
import {getShufflingDependentRoot} from "../../util/dependentRoot.js";
|
|
42
41
|
import {
|
|
@@ -570,8 +569,8 @@ async function validateAttestationNoSignatureCheck(
|
|
|
570
569
|
* Note: We do not queue future attestations for later processing
|
|
571
570
|
*/
|
|
572
571
|
export function verifyPropagationSlotRange(fork: ForkName, chain: IBeaconChain, attestationSlot: Slot): void {
|
|
573
|
-
// slot with future tolerance of
|
|
574
|
-
const latestPermissibleSlot = chain.clock.slotWithFutureTolerance(
|
|
572
|
+
// slot with future tolerance of MAXIMUM_GOSSIP_CLOCK_DISPARITY
|
|
573
|
+
const latestPermissibleSlot = chain.clock.slotWithFutureTolerance(chain.config.MAXIMUM_GOSSIP_CLOCK_DISPARITY / 1000);
|
|
575
574
|
if (attestationSlot > latestPermissibleSlot) {
|
|
576
575
|
throw new AttestationError(GossipAction.IGNORE, {
|
|
577
576
|
code: AttestationErrorCode.FUTURE_SLOT,
|
|
@@ -586,9 +585,9 @@ export function verifyPropagationSlotRange(fork: ForkName, chain: IBeaconChain,
|
|
|
586
585
|
// see: https://github.com/ethereum/consensus-specs/pull/3360
|
|
587
586
|
if (ForkSeq[fork] < ForkSeq.deneb) {
|
|
588
587
|
const earliestPermissibleSlot = Math.max(
|
|
589
|
-
// slot with past tolerance of
|
|
590
|
-
|
|
591
|
-
|
|
588
|
+
// slot with past tolerance of MAXIMUM_GOSSIP_CLOCK_DISPARITY
|
|
589
|
+
chain.clock.slotWithPastTolerance(chain.config.MAXIMUM_GOSSIP_CLOCK_DISPARITY / 1000) -
|
|
590
|
+
chain.config.ATTESTATION_PROPAGATION_SLOT_RANGE,
|
|
592
591
|
0
|
|
593
592
|
);
|
|
594
593
|
|
|
@@ -614,7 +613,7 @@ export function verifyPropagationSlotRange(fork: ForkName, chain: IBeaconChain,
|
|
|
614
613
|
|
|
615
614
|
// lower bound for previous epoch is same as epoch of earliestPermissibleSlot
|
|
616
615
|
const currentEpochWithPastTolerance = computeEpochAtSlot(
|
|
617
|
-
chain.clock.slotWithPastTolerance(
|
|
616
|
+
chain.clock.slotWithPastTolerance(chain.config.MAXIMUM_GOSSIP_CLOCK_DISPARITY / 1000)
|
|
618
617
|
);
|
|
619
618
|
|
|
620
619
|
const earliestPermissiblePreviousEpoch = Math.max(currentEpochWithPastTolerance - 1, 0);
|
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
} from "@lodestar/state-transition";
|
|
12
12
|
import {SignedBeaconBlock, deneb} from "@lodestar/types";
|
|
13
13
|
import {sleep, toRootHex} from "@lodestar/utils";
|
|
14
|
-
import {MAXIMUM_GOSSIP_CLOCK_DISPARITY} from "../../constants/index.js";
|
|
15
14
|
import {BlockErrorCode, BlockGossipError, GossipAction} from "../errors/index.js";
|
|
16
15
|
import {IBeaconChain} from "../interface.js";
|
|
17
16
|
import {RegenCaller} from "../regen/index.js";
|
|
@@ -179,7 +178,7 @@ export async function validateGossipBlock(
|
|
|
179
178
|
// gossip validation promise without any extra infrastructure.
|
|
180
179
|
// Do the sleep at the end, since regen and signature validation can already take longer than `msToBlockSlot`.
|
|
181
180
|
const msToBlockSlot = computeTimeAtSlot(config, blockSlot, chain.genesisTime) * 1000 - Date.now();
|
|
182
|
-
if (msToBlockSlot <= MAXIMUM_GOSSIP_CLOCK_DISPARITY && msToBlockSlot > 0) {
|
|
181
|
+
if (msToBlockSlot <= config.MAXIMUM_GOSSIP_CLOCK_DISPARITY && msToBlockSlot > 0) {
|
|
183
182
|
// If block is between 0 and 500 ms early, hold it in a promise. Equivalent to a pending queue.
|
|
184
183
|
await sleep(msToBlockSlot);
|
|
185
184
|
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import {ChainConfig} from "@lodestar/config";
|
|
1
|
+
import {ChainConfig, ChainForkConfig} from "@lodestar/config";
|
|
2
2
|
import {
|
|
3
3
|
KZG_COMMITMENTS_INCLUSION_PROOF_DEPTH,
|
|
4
4
|
KZG_COMMITMENTS_SUBTREE_INDEX,
|
|
5
5
|
NUMBER_OF_COLUMNS,
|
|
6
6
|
} from "@lodestar/params";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
computeEpochAtSlot,
|
|
9
|
+
computeStartSlotAtEpoch,
|
|
10
|
+
getBlockHeaderProposerSignatureSet,
|
|
11
|
+
} from "@lodestar/state-transition";
|
|
8
12
|
import {Root, Slot, SubnetID, fulu, ssz} from "@lodestar/types";
|
|
9
13
|
import {toRootHex, verifyMerkleBranch} from "@lodestar/utils";
|
|
10
14
|
import {Metrics} from "../../metrics/metrics.js";
|
|
@@ -29,7 +33,7 @@ export async function validateGossipDataColumnSidecar(
|
|
|
29
33
|
const blockHeader = dataColumnSidecar.signedBlockHeader.message;
|
|
30
34
|
|
|
31
35
|
// 1) [REJECT] The sidecar is valid as verified by verify_data_column_sidecar
|
|
32
|
-
verifyDataColumnSidecar(dataColumnSidecar);
|
|
36
|
+
verifyDataColumnSidecar(chain.config, dataColumnSidecar);
|
|
33
37
|
|
|
34
38
|
// 2) [REJECT] The sidecar is for the correct subnet -- i.e. compute_subnet_for_data_column_sidecar(sidecar.index) == subnet_id
|
|
35
39
|
if (computeSubnetForDataColumnSidecar(chain.config, dataColumnSidecar) !== gossipSubnet) {
|
|
@@ -184,7 +188,7 @@ export async function validateGossipDataColumnSidecar(
|
|
|
184
188
|
* SPEC FUNCTION
|
|
185
189
|
* https://github.com/ethereum/consensus-specs/blob/v1.6.0-alpha.4/specs/fulu/p2p-interface.md#verify_data_column_sidecar
|
|
186
190
|
*/
|
|
187
|
-
function verifyDataColumnSidecar(dataColumnSidecar: fulu.DataColumnSidecar): void {
|
|
191
|
+
function verifyDataColumnSidecar(config: ChainForkConfig, dataColumnSidecar: fulu.DataColumnSidecar): void {
|
|
188
192
|
if (dataColumnSidecar.index >= NUMBER_OF_COLUMNS) {
|
|
189
193
|
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
|
|
190
194
|
code: DataColumnSidecarErrorCode.INVALID_INDEX,
|
|
@@ -201,6 +205,19 @@ function verifyDataColumnSidecar(dataColumnSidecar: fulu.DataColumnSidecar): voi
|
|
|
201
205
|
});
|
|
202
206
|
}
|
|
203
207
|
|
|
208
|
+
const epoch = computeEpochAtSlot(dataColumnSidecar.signedBlockHeader.message.slot);
|
|
209
|
+
const maxBlobsPerBlock = config.getMaxBlobsPerBlock(epoch);
|
|
210
|
+
|
|
211
|
+
if (dataColumnSidecar.kzgCommitments.length > maxBlobsPerBlock) {
|
|
212
|
+
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
|
|
213
|
+
code: DataColumnSidecarErrorCode.TOO_MANY_KZG_COMMITMENTS,
|
|
214
|
+
slot: dataColumnSidecar.signedBlockHeader.message.slot,
|
|
215
|
+
columnIdx: dataColumnSidecar.index,
|
|
216
|
+
count: dataColumnSidecar.kzgCommitments.length,
|
|
217
|
+
limit: maxBlobsPerBlock,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
204
221
|
if (
|
|
205
222
|
dataColumnSidecar.column.length !== dataColumnSidecar.kzgCommitments.length ||
|
|
206
223
|
dataColumnSidecar.column.length !== dataColumnSidecar.kzgProofs.length
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {ChainForkConfig} from "@lodestar/config";
|
|
2
2
|
import {LightClientOptimisticUpdate} from "@lodestar/types";
|
|
3
|
-
import {MAXIMUM_GOSSIP_CLOCK_DISPARITY} from "../../constants/index.js";
|
|
4
3
|
import {assertLightClientServer} from "../../node/utils/lightclient.js";
|
|
5
4
|
import {IClock} from "../../util/clock.js";
|
|
6
5
|
import {GossipAction} from "../errors/index.js";
|
|
@@ -64,5 +63,7 @@ export function updateReceivedTooEarly(
|
|
|
64
63
|
update: Pick<LightClientOptimisticUpdate, "signatureSlot">
|
|
65
64
|
): boolean {
|
|
66
65
|
const fork = config.getForkName(update.signatureSlot);
|
|
67
|
-
return
|
|
66
|
+
return (
|
|
67
|
+
clock.msFromSlot(update.signatureSlot) < config.getSyncMessageDueMs(fork) - config.MAXIMUM_GOSSIP_CLOCK_DISPARITY
|
|
68
|
+
);
|
|
68
69
|
}
|