@lodestar/state-transition 1.43.0-rc.5 → 1.44.0-dev.1a8c38ee36
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/processDepositRequest.d.ts +3 -11
- package/lib/block/processDepositRequest.d.ts.map +1 -1
- package/lib/block/processDepositRequest.js +27 -35
- package/lib/block/processDepositRequest.js.map +1 -1
- package/lib/block/processParentExecutionPayload.d.ts.map +1 -1
- package/lib/block/processParentExecutionPayload.js +4 -3
- package/lib/block/processParentExecutionPayload.js.map +1 -1
- package/lib/lightClient/spec/index.d.ts +22 -0
- package/lib/lightClient/spec/index.d.ts.map +1 -0
- package/lib/lightClient/spec/index.js +58 -0
- package/lib/lightClient/spec/index.js.map +1 -0
- package/lib/lightClient/spec/isBetterUpdate.d.ts +23 -0
- package/lib/lightClient/spec/isBetterUpdate.d.ts.map +1 -0
- package/lib/lightClient/spec/isBetterUpdate.js +66 -0
- package/lib/lightClient/spec/isBetterUpdate.js.map +1 -0
- package/lib/lightClient/spec/processLightClientUpdate.d.ts +12 -0
- package/lib/lightClient/spec/processLightClientUpdate.d.ts.map +1 -0
- package/lib/lightClient/spec/processLightClientUpdate.js +80 -0
- package/lib/lightClient/spec/processLightClientUpdate.js.map +1 -0
- package/lib/lightClient/spec/store.d.ts +45 -0
- package/lib/lightClient/spec/store.d.ts.map +1 -0
- package/lib/lightClient/spec/store.js +56 -0
- package/lib/lightClient/spec/store.js.map +1 -0
- package/lib/lightClient/spec/utils.d.ts +47 -0
- package/lib/lightClient/spec/utils.d.ts.map +1 -0
- package/lib/lightClient/spec/utils.js +197 -0
- package/lib/lightClient/spec/utils.js.map +1 -0
- package/lib/lightClient/spec/validateLightClientBootstrap.d.ts +4 -0
- package/lib/lightClient/spec/validateLightClientBootstrap.d.ts.map +1 -0
- package/lib/lightClient/spec/validateLightClientBootstrap.js +22 -0
- package/lib/lightClient/spec/validateLightClientBootstrap.js.map +1 -0
- package/lib/lightClient/spec/validateLightClientUpdate.d.ts +5 -0
- package/lib/lightClient/spec/validateLightClientUpdate.d.ts.map +1 -0
- package/lib/lightClient/spec/validateLightClientUpdate.js +88 -0
- package/lib/lightClient/spec/validateLightClientUpdate.js.map +1 -0
- package/lib/slot/upgradeStateToGloas.d.ts.map +1 -1
- package/lib/slot/upgradeStateToGloas.js +35 -29
- package/lib/slot/upgradeStateToGloas.js.map +1 -1
- package/lib/stateView/beaconStateView.d.ts +8 -3
- package/lib/stateView/beaconStateView.d.ts.map +1 -1
- package/lib/stateView/beaconStateView.js +15 -4
- package/lib/stateView/beaconStateView.js.map +1 -1
- package/lib/stateView/interface.d.ts +1 -1
- package/lib/stateView/interface.d.ts.map +1 -1
- package/lib/util/gloas.d.ts +14 -0
- package/lib/util/gloas.d.ts.map +1 -1
- package/lib/util/gloas.js +24 -0
- package/lib/util/gloas.js.map +1 -1
- 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/pendingDepositsLookup.d.ts +40 -0
- package/lib/util/pendingDepositsLookup.d.ts.map +1 -0
- package/lib/util/pendingDepositsLookup.js +84 -0
- package/lib/util/pendingDepositsLookup.js.map +1 -0
- package/lib/util/shuffling.d.ts +6 -5
- package/lib/util/shuffling.d.ts.map +1 -1
- package/lib/util/shuffling.js +13 -15
- package/lib/util/shuffling.js.map +1 -1
- package/package.json +12 -7
- package/src/block/processDepositRequest.ts +29 -47
- package/src/block/processParentExecutionPayload.ts +4 -3
- package/src/lightClient/spec/index.ts +101 -0
- package/src/lightClient/spec/isBetterUpdate.ts +94 -0
- package/src/lightClient/spec/processLightClientUpdate.ts +119 -0
- package/src/lightClient/spec/store.ts +106 -0
- package/src/lightClient/spec/utils.ts +317 -0
- package/src/lightClient/spec/validateLightClientBootstrap.ts +39 -0
- package/src/lightClient/spec/validateLightClientUpdate.ts +145 -0
- package/src/slot/upgradeStateToGloas.ts +43 -45
- package/src/stateView/beaconStateView.ts +15 -4
- package/src/stateView/interface.ts +1 -1
- package/src/util/gloas.ts +28 -0
- package/src/util/index.ts +1 -0
- package/src/util/pendingDepositsLookup.ts +105 -0
- package/src/util/shuffling.ts +17 -15
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
import { BeaconConfig } from "@lodestar/config";
|
|
2
1
|
import { ForkSeq } from "@lodestar/params";
|
|
3
|
-
import { BLSPubkey, Bytes32,
|
|
2
|
+
import { BLSPubkey, Bytes32, UintNum64, electra } from "@lodestar/types";
|
|
4
3
|
import { CachedBeaconStateElectra, CachedBeaconStateGloas } from "../types.js";
|
|
4
|
+
import { PendingDepositsLookup } from "../util/pendingDepositsLookup.js";
|
|
5
5
|
/**
|
|
6
6
|
* Apply a deposit for a builder. Either increases balance for existing builder or adds new builder to registry.
|
|
7
7
|
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/gloas/beacon-chain.md#new-apply_deposit_for_builder
|
|
8
8
|
*/
|
|
9
9
|
export declare function applyDepositForBuilder(state: CachedBeaconStateGloas, pubkey: BLSPubkey, withdrawalCredentials: Bytes32, amount: UintNum64, signature: Bytes32, slot: UintNum64): void;
|
|
10
|
-
export declare function processDepositRequest(fork: ForkSeq, state: CachedBeaconStateElectra | CachedBeaconStateGloas, depositRequest: electra.DepositRequest,
|
|
11
|
-
/**
|
|
12
|
-
* Build a set of pubkeys (hex-encoded) from pending deposits that have valid signatures.
|
|
13
|
-
* This is computed once and passed to each processDepositRequest call to avoid
|
|
14
|
-
* repeatedly iterating state.pendingDeposits.
|
|
15
|
-
*
|
|
16
|
-
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.3/specs/gloas/beacon-chain.md#new-is_pending_validator
|
|
17
|
-
*/
|
|
18
|
-
export declare function getPendingValidatorPubkeys(config: BeaconConfig, state: CachedBeaconStateGloas): Set<PubkeyHex>;
|
|
10
|
+
export declare function processDepositRequest(fork: ForkSeq, state: CachedBeaconStateElectra | CachedBeaconStateGloas, depositRequest: electra.DepositRequest, pendingDepositsLookup?: PendingDepositsLookup): void;
|
|
19
11
|
//# sourceMappingURL=processDepositRequest.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processDepositRequest.d.ts","sourceRoot":"","sources":["../../src/block/processDepositRequest.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"processDepositRequest.d.ts","sourceRoot":"","sources":["../../src/block/processDepositRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,OAAO,EAAqC,MAAM,kBAAkB,CAAC;AAC/F,OAAO,EAAC,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAM,MAAM,iBAAiB,CAAC;AAE5E,OAAO,EAAC,wBAAwB,EAAE,sBAAsB,EAAC,MAAM,aAAa,CAAC;AAG7E,OAAO,EAAC,qBAAqB,EAAC,MAAM,kCAAkC,CAAC;AAGvE;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,sBAAsB,EAC7B,MAAM,EAAE,SAAS,EACjB,qBAAqB,EAAE,OAAO,EAC9B,MAAM,EAAE,SAAS,EACjB,SAAS,EAAE,OAAO,EAClB,IAAI,EAAE,SAAS,GACd,IAAI,CAaN;AAiDD,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,wBAAwB,GAAG,sBAAsB,EACxD,cAAc,EAAE,OAAO,CAAC,cAAc,EACtC,qBAAqB,CAAC,EAAE,qBAAqB,GAC5C,IAAI,CAyDN"}
|
|
@@ -3,6 +3,7 @@ import { ssz } from "@lodestar/types";
|
|
|
3
3
|
import { toPubkeyHex } from "@lodestar/utils";
|
|
4
4
|
import { findBuilderIndexByPubkey, isBuilderWithdrawalCredential } from "../util/gloas.js";
|
|
5
5
|
import { computeEpochAtSlot, isValidatorKnown } from "../util/index.js";
|
|
6
|
+
import { PendingDepositsLookup } from "../util/pendingDepositsLookup.js";
|
|
6
7
|
import { isValidDepositSignature } from "./processDeposit.js";
|
|
7
8
|
/**
|
|
8
9
|
* Apply a deposit for a builder. Either increases balance for existing builder or adds new builder to registry.
|
|
@@ -56,40 +57,47 @@ function addBuilderToRegistry(state, pubkey, withdrawalCredentials, amount, slot
|
|
|
56
57
|
state.builders.push(newBuilder);
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
|
-
// TODO GLOAS:
|
|
60
|
-
//
|
|
61
|
-
//
|
|
60
|
+
// TODO GLOAS: the PendingDepositsLookup is currently scoped to a single envelope of
|
|
61
|
+
// deposit-requests. We can track it as ephemeral within EpochCache and transfer to the next block
|
|
62
|
+
// transition to reuse cached signature verifications.
|
|
62
63
|
// See https://github.com/ChainSafe/lodestar/issues/9181
|
|
63
|
-
export function processDepositRequest(fork, state, depositRequest,
|
|
64
|
+
export function processDepositRequest(fork, state, depositRequest, pendingDepositsLookup) {
|
|
64
65
|
const { pubkey, withdrawalCredentials, amount, signature } = depositRequest;
|
|
65
|
-
// Check if this is a builder or validator deposit
|
|
66
66
|
if (fork >= ForkSeq.gloas) {
|
|
67
67
|
const stateGloas = state;
|
|
68
|
-
const
|
|
68
|
+
const lookup = pendingDepositsLookup ?? PendingDepositsLookup.build(stateGloas);
|
|
69
69
|
const pubkeyHex = toPubkeyHex(pubkey);
|
|
70
70
|
const builderIndex = findBuilderIndexByPubkey(stateGloas, pubkey);
|
|
71
71
|
const validatorIndex = state.epochCtx.getValidatorIndex(pubkey);
|
|
72
|
-
// Regardless of the withdrawal credentials prefix, if a builder/validator
|
|
73
|
-
// already exists with this pubkey, apply the deposit to their balance
|
|
74
72
|
const isBuilder = builderIndex !== null;
|
|
75
73
|
const isValidator = isValidatorKnown(state, validatorIndex);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// Apply builder deposits immediately
|
|
74
|
+
if (isBuilder) {
|
|
75
|
+
// Top up an existing builder regardless of withdrawal credential prefix
|
|
79
76
|
applyDepositForBuilder(stateGloas, pubkey, withdrawalCredentials, amount, signature, state.slot);
|
|
80
77
|
return;
|
|
81
78
|
}
|
|
82
|
-
//
|
|
83
|
-
|
|
84
|
-
if (pendingValidatorPubkeysCache &&
|
|
79
|
+
// Only check the (expensive) "pending validator" condition when needed
|
|
80
|
+
if (isBuilderWithdrawalCredential(withdrawalCredentials) &&
|
|
85
81
|
!isValidator &&
|
|
86
|
-
!
|
|
87
|
-
|
|
88
|
-
|
|
82
|
+
!lookup.hasPendingValidator(state.config, pubkeyHex)) {
|
|
83
|
+
applyDepositForBuilder(stateGloas, pubkey, withdrawalCredentials, amount, signature, state.slot);
|
|
84
|
+
return;
|
|
89
85
|
}
|
|
86
|
+
const pendingDeposit = ssz.electra.PendingDeposit.toViewDU({
|
|
87
|
+
pubkey,
|
|
88
|
+
withdrawalCredentials,
|
|
89
|
+
amount,
|
|
90
|
+
signature,
|
|
91
|
+
slot: state.slot,
|
|
92
|
+
});
|
|
93
|
+
// Keep the lookup in sync with state.pendingDeposits so later deposit-requests
|
|
94
|
+
// in the same envelope see this deposit
|
|
95
|
+
lookup.add(pendingDeposit, pubkeyHex);
|
|
96
|
+
state.pendingDeposits.push(pendingDeposit);
|
|
97
|
+
return;
|
|
90
98
|
}
|
|
91
|
-
//
|
|
92
|
-
if (
|
|
99
|
+
// Pre-Gloas (Electra) path
|
|
100
|
+
if (state.depositRequestsStartIndex === UNSET_DEPOSIT_REQUESTS_START_INDEX) {
|
|
93
101
|
state.depositRequestsStartIndex = depositRequest.index;
|
|
94
102
|
}
|
|
95
103
|
// Add validator deposits to the queue
|
|
@@ -102,20 +110,4 @@ export function processDepositRequest(fork, state, depositRequest, pendingValida
|
|
|
102
110
|
});
|
|
103
111
|
state.pendingDeposits.push(pendingDeposit);
|
|
104
112
|
}
|
|
105
|
-
/**
|
|
106
|
-
* Build a set of pubkeys (hex-encoded) from pending deposits that have valid signatures.
|
|
107
|
-
* This is computed once and passed to each processDepositRequest call to avoid
|
|
108
|
-
* repeatedly iterating state.pendingDeposits.
|
|
109
|
-
*
|
|
110
|
-
* Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.3/specs/gloas/beacon-chain.md#new-is_pending_validator
|
|
111
|
-
*/
|
|
112
|
-
export function getPendingValidatorPubkeys(config, state) {
|
|
113
|
-
const result = new Set();
|
|
114
|
-
for (const pendingDeposit of state.pendingDeposits.getAllReadonly()) {
|
|
115
|
-
if (isValidDepositSignature(config, pendingDeposit.pubkey, pendingDeposit.withdrawalCredentials, pendingDeposit.amount, pendingDeposit.signature)) {
|
|
116
|
-
result.add(toPubkeyHex(pendingDeposit.pubkey));
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return result;
|
|
120
|
-
}
|
|
121
113
|
//# sourceMappingURL=processDepositRequest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processDepositRequest.js","sourceRoot":"","sources":["../../src/block/processDepositRequest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"processDepositRequest.js","sourceRoot":"","sources":["../../src/block/processDepositRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAE,OAAO,EAAE,kCAAkC,EAAC,MAAM,kBAAkB,CAAC;AAC/F,OAAO,EAAyC,GAAG,EAAC,MAAM,iBAAiB,CAAC;AAC5E,OAAO,EAAC,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAC,wBAAwB,EAAE,6BAA6B,EAAC,MAAM,kBAAkB,CAAC;AACzF,OAAO,EAAC,kBAAkB,EAAE,gBAAgB,EAAC,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAC,qBAAqB,EAAC,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAC,uBAAuB,EAAC,MAAM,qBAAqB,CAAC;AAE5D;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CACpC,KAA6B,EAC7B,MAAiB,EACjB,qBAA8B,EAC9B,MAAiB,EACjB,SAAkB,EAClB,IAAe,EACT;IACN,MAAM,YAAY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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processParentExecutionPayload.d.ts","sourceRoot":"","sources":["../../src/block/processParentExecutionPayload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAA6C,MAAM,kBAAkB,CAAC;AAC3F,OAAO,EAAC,WAAW,EAAE,OAAO,EAAM,MAAM,iBAAiB,CAAC;AAE1D,OAAO,EAAC,sBAAsB,EAAC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"processParentExecutionPayload.d.ts","sourceRoot":"","sources":["../../src/block/processParentExecutionPayload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAA6C,MAAM,kBAAkB,CAAC;AAC3F,OAAO,EAAC,WAAW,EAAE,OAAO,EAAM,MAAM,iBAAiB,CAAC;AAE1D,OAAO,EAAC,sBAAsB,EAAC,MAAM,aAAa,CAAC;AAOnD;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,sBAAsB,EAAE,KAAK,EAAE,WAAW,CAAC,aAAa,CAAC,GAAG,IAAI,CAqBpH;AAED;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,sBAAsB,EAAE,QAAQ,EAAE,OAAO,CAAC,iBAAiB,GAAG,IAAI,CA4CpH"}
|
|
@@ -2,8 +2,9 @@ import { SLOTS_PER_EPOCH, SLOTS_PER_HISTORICAL_ROOT } from "@lodestar/params";
|
|
|
2
2
|
import { ssz } from "@lodestar/types";
|
|
3
3
|
import { byteArrayEquals, toRootHex } from "@lodestar/utils";
|
|
4
4
|
import { computeEpochAtSlot } from "../util/epoch.js";
|
|
5
|
+
import { PendingDepositsLookup } from "../util/pendingDepositsLookup.js";
|
|
5
6
|
import { processConsolidationRequest } from "./processConsolidationRequest.js";
|
|
6
|
-
import {
|
|
7
|
+
import { processDepositRequest } from "./processDepositRequest.js";
|
|
7
8
|
import { processWithdrawalRequest } from "./processWithdrawalRequest.js";
|
|
8
9
|
/**
|
|
9
10
|
* Process parent execution payload effects as the first step of processBlock.
|
|
@@ -45,9 +46,9 @@ export function applyParentExecutionPayload(state, requests) {
|
|
|
45
46
|
// Process execution requests from parent's payload. The execution
|
|
46
47
|
// requests are processed at state.slot (child's slot), not the parent's slot.
|
|
47
48
|
if (requests.deposits.length > 0) {
|
|
48
|
-
const
|
|
49
|
+
const pendingDepositsLookup = PendingDepositsLookup.build(state);
|
|
49
50
|
for (const deposit of requests.deposits) {
|
|
50
|
-
processDepositRequest(fork, state, deposit,
|
|
51
|
+
processDepositRequest(fork, state, deposit, pendingDepositsLookup);
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
54
|
for (const withdrawal of requests.withdrawals) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processParentExecutionPayload.js","sourceRoot":"","sources":["../../src/block/processParentExecutionPayload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,eAAe,EAAE,yBAAyB,EAAC,MAAM,kBAAkB,CAAC;AAC3F,OAAO,EAAuB,GAAG,EAAC,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAC,eAAe,EAAE,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAE3D,OAAO,EAAC,kBAAkB,EAAC,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAC,2BAA2B,EAAC,MAAM,kCAAkC,CAAC;AAC7E,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"processParentExecutionPayload.js","sourceRoot":"","sources":["../../src/block/processParentExecutionPayload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,eAAe,EAAE,yBAAyB,EAAC,MAAM,kBAAkB,CAAC;AAC3F,OAAO,EAAuB,GAAG,EAAC,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAC,eAAe,EAAE,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAE3D,OAAO,EAAC,kBAAkB,EAAC,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAC,qBAAqB,EAAC,MAA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;IACxF,CAAC;AAAA,CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BeaconConfig } from "@lodestar/config";
|
|
2
|
+
import { LightClientBootstrap, LightClientFinalityUpdate, LightClientOptimisticUpdate, LightClientUpdate, Slot } from "@lodestar/types";
|
|
3
|
+
import { type ProcessUpdateOpts } from "./processLightClientUpdate.js";
|
|
4
|
+
import { type ILightClientStore, type LightClientStoreEvents } from "./store.js";
|
|
5
|
+
export type { LightClientUpdateSummary } from "./isBetterUpdate.js";
|
|
6
|
+
export { isBetterUpdate, toLightClientUpdateSummary } from "./isBetterUpdate.js";
|
|
7
|
+
export { type ProcessUpdateOpts, getSyncCommitteeAtPeriod, isSafeLightClientUpdate, processLightClientUpdate, } from "./processLightClientUpdate.js";
|
|
8
|
+
export { type ILightClientStore, LightClientStore, type LightClientStoreEvents, type LightClientUpdateWithSummary, type SyncCommitteeFast, } from "./store.js";
|
|
9
|
+
export { getSafetyThreshold, isFinalityUpdate, isSyncCommitteeUpdate, isValidLightClientHeader, normalizeMerkleBranch, upgradeLightClientFinalityUpdate, upgradeLightClientHeader, upgradeLightClientOptimisticUpdate, upgradeLightClientStore, upgradeLightClientUpdate, } from "./utils.js";
|
|
10
|
+
export { validateLightClientBootstrap } from "./validateLightClientBootstrap.js";
|
|
11
|
+
export { validateLightClientUpdate } from "./validateLightClientUpdate.js";
|
|
12
|
+
export declare class LightclientSpec {
|
|
13
|
+
private readonly opts;
|
|
14
|
+
readonly store: ILightClientStore;
|
|
15
|
+
readonly config: BeaconConfig;
|
|
16
|
+
constructor(config: BeaconConfig, opts: ProcessUpdateOpts & LightClientStoreEvents, bootstrap: LightClientBootstrap);
|
|
17
|
+
onUpdate(currentSlot: Slot, update: LightClientUpdate): void;
|
|
18
|
+
onFinalityUpdate(currentSlot: Slot, finalityUpdate: LightClientFinalityUpdate): void;
|
|
19
|
+
onOptimisticUpdate(currentSlot: Slot, optimisticUpdate: LightClientOptimisticUpdate): void;
|
|
20
|
+
forceUpdate(currentSlot: Slot): void;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lightClient/spec/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EACzB,2BAA2B,EAC3B,iBAAiB,EACjB,IAAI,EACL,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,KAAK,iBAAiB,EAGvB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAC,KAAK,iBAAiB,EAAoB,KAAK,sBAAsB,EAAC,MAAM,YAAY,CAAC;AAGjG,YAAY,EAAC,wBAAwB,EAAC,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAC,cAAc,EAAE,0BAA0B,EAAC,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EACL,KAAK,iBAAiB,EACtB,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,GACzB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,KAAK,iBAAiB,EACtB,gBAAgB,EAChB,KAAK,sBAAsB,EAC3B,KAAK,4BAA4B,EACjC,KAAK,iBAAiB,GACvB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,qBAAqB,EACrB,wBAAwB,EACxB,qBAAqB,EACrB,gCAAgC,EAChC,wBAAwB,EACxB,kCAAkC,EAClC,uBAAuB,EACvB,wBAAwB,GACzB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAC,4BAA4B,EAAC,MAAM,mCAAmC,CAAC;AAC/E,OAAO,EAAC,yBAAyB,EAAC,MAAM,gCAAgC,CAAC;AAEzE,qBAAa,eAAe;IAMxB,OAAO,CAAC,QAAQ,CAAC,IAAI;IALvB,QAAQ,CAAC,KAAK,EAAE,iBAAiB,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAE9B,YACE,MAAM,EAAE,YAAY,EACH,IAAI,EAAE,iBAAiB,GAAG,sBAAsB,EACjE,SAAS,EAAE,oBAAoB,EAIhC;IAED,QAAQ,CAAC,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAE3D;IAED,gBAAgB,CAAC,WAAW,EAAE,IAAI,EAAE,cAAc,EAAE,yBAAyB,GAAG,IAAI,CAUnF;IAED,kBAAkB,CAAC,WAAW,EAAE,IAAI,EAAE,gBAAgB,EAAE,2BAA2B,GAAG,IAAI,CAUzF;IAED,WAAW,CAAC,WAAW,EAAE,IAAI,GAAG,IAAI,CAUnC;CACF"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { UPDATE_TIMEOUT } from "@lodestar/params";
|
|
2
|
+
import { computeSyncPeriodAtSlot } from "../../util/epoch.js";
|
|
3
|
+
import { getSyncCommitteeAtPeriod, processLightClientUpdate, } from "./processLightClientUpdate.js";
|
|
4
|
+
import { LightClientStore } from "./store.js";
|
|
5
|
+
import { ZERO_HEADER, ZERO_SYNC_COMMITTEE, getZeroFinalityBranch, getZeroSyncCommitteeBranch } from "./utils.js";
|
|
6
|
+
export { isBetterUpdate, toLightClientUpdateSummary } from "./isBetterUpdate.js";
|
|
7
|
+
export { getSyncCommitteeAtPeriod, isSafeLightClientUpdate, processLightClientUpdate, } from "./processLightClientUpdate.js";
|
|
8
|
+
export { LightClientStore, } from "./store.js";
|
|
9
|
+
export { getSafetyThreshold, isFinalityUpdate, isSyncCommitteeUpdate, isValidLightClientHeader, normalizeMerkleBranch, upgradeLightClientFinalityUpdate, upgradeLightClientHeader, upgradeLightClientOptimisticUpdate, upgradeLightClientStore, upgradeLightClientUpdate, } from "./utils.js";
|
|
10
|
+
export { validateLightClientBootstrap } from "./validateLightClientBootstrap.js";
|
|
11
|
+
export { validateLightClientUpdate } from "./validateLightClientUpdate.js";
|
|
12
|
+
export class LightclientSpec {
|
|
13
|
+
opts;
|
|
14
|
+
store;
|
|
15
|
+
config;
|
|
16
|
+
constructor(config, opts, bootstrap) {
|
|
17
|
+
this.opts = opts;
|
|
18
|
+
this.store = new LightClientStore(config, bootstrap, opts);
|
|
19
|
+
this.config = config;
|
|
20
|
+
}
|
|
21
|
+
onUpdate(currentSlot, update) {
|
|
22
|
+
processLightClientUpdate(this.config, this.store, currentSlot, this.opts, update);
|
|
23
|
+
}
|
|
24
|
+
onFinalityUpdate(currentSlot, finalityUpdate) {
|
|
25
|
+
this.onUpdate(currentSlot, {
|
|
26
|
+
attestedHeader: finalityUpdate.attestedHeader,
|
|
27
|
+
nextSyncCommittee: ZERO_SYNC_COMMITTEE,
|
|
28
|
+
nextSyncCommitteeBranch: getZeroSyncCommitteeBranch(this.config.getForkName(finalityUpdate.signatureSlot)),
|
|
29
|
+
finalizedHeader: finalityUpdate.finalizedHeader,
|
|
30
|
+
finalityBranch: finalityUpdate.finalityBranch,
|
|
31
|
+
syncAggregate: finalityUpdate.syncAggregate,
|
|
32
|
+
signatureSlot: finalityUpdate.signatureSlot,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
onOptimisticUpdate(currentSlot, optimisticUpdate) {
|
|
36
|
+
this.onUpdate(currentSlot, {
|
|
37
|
+
attestedHeader: optimisticUpdate.attestedHeader,
|
|
38
|
+
nextSyncCommittee: ZERO_SYNC_COMMITTEE,
|
|
39
|
+
nextSyncCommitteeBranch: getZeroSyncCommitteeBranch(this.config.getForkName(optimisticUpdate.signatureSlot)),
|
|
40
|
+
finalizedHeader: { beacon: ZERO_HEADER },
|
|
41
|
+
finalityBranch: getZeroFinalityBranch(this.config.getForkName(optimisticUpdate.signatureSlot)),
|
|
42
|
+
syncAggregate: optimisticUpdate.syncAggregate,
|
|
43
|
+
signatureSlot: optimisticUpdate.signatureSlot,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
forceUpdate(currentSlot) {
|
|
47
|
+
for (const bestValidUpdate of this.store.bestValidUpdates.values()) {
|
|
48
|
+
if (currentSlot > bestValidUpdate.update.finalizedHeader.beacon.slot + UPDATE_TIMEOUT) {
|
|
49
|
+
const updatePeriod = computeSyncPeriodAtSlot(bestValidUpdate.update.signatureSlot);
|
|
50
|
+
// Simulate process_light_client_store_force_update() by forcing to apply a bestValidUpdate
|
|
51
|
+
// https://github.com/ethereum/consensus-specs/blob/a57e15636013eeba3610ff3ade41781dba1bb0cd/specs/altair/light-client/sync-protocol.md?plain=1#L394
|
|
52
|
+
// Call for `updatePeriod + 1` to force the update at `update.signatureSlot` to be applied
|
|
53
|
+
getSyncCommitteeAtPeriod(this.store, updatePeriod + 1, this.opts);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lightClient/spec/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAQhD,OAAO,EAAC,uBAAuB,EAAC,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAEL,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAyB,gBAAgB,EAA8B,MAAM,YAAY,CAAC;AACjG,OAAO,EAAC,WAAW,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,0BAA0B,EAAC,MAAM,YAAY,CAAC;AAG/G,OAAO,EAAC,cAAc,EAAE,0BAA0B,EAAC,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAEL,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,GACzB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAEL,gBAAgB,GAIjB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,qBAAqB,EACrB,wBAAwB,EACxB,qBAAqB,EACrB,gCA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YAC/C,iBAAiB,EAAE,mBAAmB;YACtC,uBAAuB,EAAE,0BAA0B,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;YAC5G,eAAe,EAAE,EAAC,MAAM,EAAE,WAAW,EAAC;YACtC,cAAc,EAAE,qBAAqB,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;YAC9F,aAAa,EAAE,gBAAgB,CAAC,aAAa;YAC7C,aAAa,EAAE,gBAAgB,CAAC,aAAa;SAC9C,CAAC,CAAC;IAAA,CACJ;IAED,WAAW,CAAC,WAAiB,EAAQ;QACnC,KAAK,MAAM,eAAe,IAAI,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,MAAM,EAAE,EAAE,CAAC;YACnE,IAAI,WAAW,GAAG,eAAe,CAAC,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC,IAAI,GAAG,cAAc,EAAE,CAAC;gBACtF,MAAM,YAAY,GAAG,uBAAuB,CAAC,eAAe,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;gBACnF,2FAA2F;gBAC3F,oJAAoJ;gBACpJ,0FAA0F;gBAC1F,wBAAwB,CAAC,IAAI,CAAC,KAAK,EAAE,YAAY,GAAG,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YACpE,CAAC;QACH,CAAC;IAAA,CACF;CACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { LightClientUpdate, Slot } from "@lodestar/types";
|
|
2
|
+
/**
|
|
3
|
+
* Wrapper type for `isBetterUpdate()` so we can apply its logic without requiring the full LightClientUpdate type.
|
|
4
|
+
*/
|
|
5
|
+
export type LightClientUpdateSummary = {
|
|
6
|
+
activeParticipants: number;
|
|
7
|
+
attestedHeaderSlot: Slot;
|
|
8
|
+
signatureSlot: Slot;
|
|
9
|
+
finalizedHeaderSlot: Slot;
|
|
10
|
+
/** `if update.next_sync_committee_branch != [Bytes32() for _ in range(floorlog2(NEXT_SYNC_COMMITTEE_INDEX))]` */
|
|
11
|
+
isSyncCommitteeUpdate: boolean;
|
|
12
|
+
/** `if update.finality_branch != [Bytes32() for _ in range(floorlog2(FINALIZED_ROOT_INDEX))]` */
|
|
13
|
+
isFinalityUpdate: boolean;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Returns the update with more bits. On ties, prevUpdate is the better
|
|
17
|
+
*
|
|
18
|
+
* https://github.com/ethereum/consensus-specs/blob/be3c774069e16e89145660be511c1b183056017e/specs/altair/light-client/sync-protocol.md#is_better_update
|
|
19
|
+
*/
|
|
20
|
+
export declare function isBetterUpdate(newUpdate: LightClientUpdateSummary, oldUpdate: LightClientUpdateSummary): boolean;
|
|
21
|
+
export declare function isSafeLightClientUpdate(update: LightClientUpdateSummary): boolean;
|
|
22
|
+
export declare function toLightClientUpdateSummary(update: LightClientUpdate): LightClientUpdateSummary;
|
|
23
|
+
//# sourceMappingURL=isBetterUpdate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isBetterUpdate.d.ts","sourceRoot":"","sources":["../../../src/lightClient/spec/isBetterUpdate.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,iBAAiB,EAAE,IAAI,EAAC,MAAM,iBAAiB,CAAC;AAIxD;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,kBAAkB,EAAE,IAAI,CAAC;IACzB,aAAa,EAAE,IAAI,CAAC;IACpB,mBAAmB,EAAE,IAAI,CAAC;IAC1B,iHAAiH;IACjH,qBAAqB,EAAE,OAAO,CAAC;IAC/B,iGAAiG;IACjG,gBAAgB,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,wBAAwB,EAAE,SAAS,EAAE,wBAAwB,GAAG,OAAO,CAoDhH;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,wBAAwB,GAAG,OAAO,CAIjF;AAED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,iBAAiB,GAAG,wBAAwB,CAS9F"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { SYNC_COMMITTEE_SIZE } from "@lodestar/params";
|
|
2
|
+
import { computeSyncPeriodAtSlot } from "../../util/epoch.js";
|
|
3
|
+
import { isFinalityUpdate, isSyncCommitteeUpdate, sumBits } from "./utils.js";
|
|
4
|
+
/**
|
|
5
|
+
* Returns the update with more bits. On ties, prevUpdate is the better
|
|
6
|
+
*
|
|
7
|
+
* https://github.com/ethereum/consensus-specs/blob/be3c774069e16e89145660be511c1b183056017e/specs/altair/light-client/sync-protocol.md#is_better_update
|
|
8
|
+
*/
|
|
9
|
+
export function isBetterUpdate(newUpdate, oldUpdate) {
|
|
10
|
+
// Compare supermajority (> 2/3) sync committee participation
|
|
11
|
+
const newNumActiveParticipants = newUpdate.activeParticipants;
|
|
12
|
+
const oldNumActiveParticipants = oldUpdate.activeParticipants;
|
|
13
|
+
const newHasSupermajority = newNumActiveParticipants * 3 >= SYNC_COMMITTEE_SIZE * 2;
|
|
14
|
+
const oldHasSupermajority = oldNumActiveParticipants * 3 >= SYNC_COMMITTEE_SIZE * 2;
|
|
15
|
+
if (newHasSupermajority !== oldHasSupermajority) {
|
|
16
|
+
return newHasSupermajority;
|
|
17
|
+
}
|
|
18
|
+
if (!newHasSupermajority && newNumActiveParticipants !== oldNumActiveParticipants) {
|
|
19
|
+
return newNumActiveParticipants > oldNumActiveParticipants;
|
|
20
|
+
}
|
|
21
|
+
// Compare presence of relevant sync committee
|
|
22
|
+
const newHasRelevantSyncCommittee = newUpdate.isSyncCommitteeUpdate &&
|
|
23
|
+
computeSyncPeriodAtSlot(newUpdate.attestedHeaderSlot) === computeSyncPeriodAtSlot(newUpdate.signatureSlot);
|
|
24
|
+
const oldHasRelevantSyncCommittee = oldUpdate.isSyncCommitteeUpdate &&
|
|
25
|
+
computeSyncPeriodAtSlot(oldUpdate.attestedHeaderSlot) === computeSyncPeriodAtSlot(oldUpdate.signatureSlot);
|
|
26
|
+
if (newHasRelevantSyncCommittee !== oldHasRelevantSyncCommittee) {
|
|
27
|
+
return newHasRelevantSyncCommittee;
|
|
28
|
+
}
|
|
29
|
+
// Compare indication of any finality
|
|
30
|
+
const newHasFinality = newUpdate.isFinalityUpdate;
|
|
31
|
+
const oldHasFinality = oldUpdate.isFinalityUpdate;
|
|
32
|
+
if (newHasFinality !== oldHasFinality) {
|
|
33
|
+
return newHasFinality;
|
|
34
|
+
}
|
|
35
|
+
// Compare sync committee finality
|
|
36
|
+
if (newHasFinality) {
|
|
37
|
+
const newHasSyncCommitteeFinality = computeSyncPeriodAtSlot(newUpdate.finalizedHeaderSlot) === computeSyncPeriodAtSlot(newUpdate.attestedHeaderSlot);
|
|
38
|
+
const oldHasSyncCommitteeFinality = computeSyncPeriodAtSlot(oldUpdate.finalizedHeaderSlot) === computeSyncPeriodAtSlot(oldUpdate.attestedHeaderSlot);
|
|
39
|
+
if (newHasSyncCommitteeFinality !== oldHasSyncCommitteeFinality) {
|
|
40
|
+
return newHasSyncCommitteeFinality;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Tiebreaker 1: Sync committee participation beyond supermajority
|
|
44
|
+
if (newNumActiveParticipants !== oldNumActiveParticipants) {
|
|
45
|
+
return newNumActiveParticipants > oldNumActiveParticipants;
|
|
46
|
+
}
|
|
47
|
+
// Tiebreaker 2: Prefer older data (fewer changes to best)
|
|
48
|
+
if (newUpdate.attestedHeaderSlot !== oldUpdate.attestedHeaderSlot) {
|
|
49
|
+
return newUpdate.attestedHeaderSlot < oldUpdate.attestedHeaderSlot;
|
|
50
|
+
}
|
|
51
|
+
return newUpdate.signatureSlot < oldUpdate.signatureSlot;
|
|
52
|
+
}
|
|
53
|
+
export function isSafeLightClientUpdate(update) {
|
|
54
|
+
return (update.activeParticipants * 3 >= SYNC_COMMITTEE_SIZE * 2 && update.isFinalityUpdate && update.isSyncCommitteeUpdate);
|
|
55
|
+
}
|
|
56
|
+
export function toLightClientUpdateSummary(update) {
|
|
57
|
+
return {
|
|
58
|
+
activeParticipants: sumBits(update.syncAggregate.syncCommitteeBits),
|
|
59
|
+
attestedHeaderSlot: update.attestedHeader.beacon.slot,
|
|
60
|
+
signatureSlot: update.signatureSlot,
|
|
61
|
+
finalizedHeaderSlot: update.finalizedHeader.beacon.slot,
|
|
62
|
+
isSyncCommitteeUpdate: isSyncCommitteeUpdate(update),
|
|
63
|
+
isFinalityUpdate: isFinalityUpdate(update),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=isBetterUpdate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isBetterUpdate.js","sourceRoot":"","sources":["../../../src/lightClient/spec/isBetterUpdate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAC,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAC,uBAAuB,EAAC,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAC,gBAAgB,EAAE,qBAAqB,EAAE,OAAO,EAAC,MAAM,YAAY,CAAC;AAgB5E;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,SAAmC,EAAE,SAAmC,EAAW;IAChH,6DAA6D;IAC7D,MAAM,wBAAwB,GAAG,SAAS,CAAC,kBAAkB,CAAC;IAC9D,MAAM,wBAAwB,GAAG,SAAS,CAAC,kBAAkB,CAAC;IAC9D,MAAM,mBAAmB,GAAG,wBAAwB,GAAG,CAAC,IAAI,mBAAmB,GAAG,CAAC,CAAC;IACpF,MAAM,mBAAmB,GAAG,wBAAwB,GAAG,CAAC,IAAI,mBAAmB,GAAG,CAAC,CAAC;IACpF,IAAI,mBAAmB,KAAK,mBAAmB,EAAE,CAAC;QAChD,OAAO,mBAAmB,CAAC;IAC7B,CAAC;IACD,IAAI,CAAC,mBAAmB,IAAI,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S,CAAC,kBAAkB,EAAE,CAAC;QAClE,OAAO,SAAS,CAAC,kBAAkB,GAAG,SAAS,CAAC,kBAAkB,CAAC;IACrE,CAAC;IACD,OAAO,SAAS,CAAC,aAAa,GAAG,SAAS,CAAC,aAAa,CAAC;AAAA,CAC1D;AAED,MAAM,UAAU,uBAAuB,CAAC,MAAgC,EAAW;IACjF,OAAO,CACL,MAAM,CAAC,kBAAkB,GAAG,CAAC,IAAI,mBAAmB,GAAG,CAAC,IAAI,MAAM,CAAC,gBAAgB,IAAI,MAAM,CAAC,qBAAqB,CACpH,CAAC;AAAA,CACH;AAED,MAAM,UAAU,0BAA0B,CAAC,MAAyB,EAA4B;IAC9F,OAAO;QACL,kBAAkB,EAAE,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,iBAAiB,CAAC;QACnE,kBAAkB,EAAE,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI;QACrD,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,mBAAmB,EAAE,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC,IAAI;QACvD,qBAAqB,EAAE,qBAAqB,CAAC,MAAM,CAAC;QACpD,gBAAgB,EAAE,gBAAgB,CAAC,MAAM,CAAC;KAC3C,CAAC;AAAA,CACH"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ChainForkConfig } from "@lodestar/config";
|
|
2
|
+
import { LightClientUpdate, Slot, SyncPeriod } from "@lodestar/types";
|
|
3
|
+
import { LightClientUpdateSummary } from "./isBetterUpdate.js";
|
|
4
|
+
import { type ILightClientStore, type SyncCommitteeFast } from "./store.js";
|
|
5
|
+
export interface ProcessUpdateOpts {
|
|
6
|
+
allowForcedUpdates?: boolean;
|
|
7
|
+
updateHeadersOnForcedUpdate?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function processLightClientUpdate(config: ChainForkConfig, store: ILightClientStore, currentSlot: Slot, opts: ProcessUpdateOpts, update: LightClientUpdate): void;
|
|
10
|
+
export declare function getSyncCommitteeAtPeriod(store: ILightClientStore, period: SyncPeriod, opts: ProcessUpdateOpts): SyncCommitteeFast;
|
|
11
|
+
export declare function isSafeLightClientUpdate(update: LightClientUpdateSummary): boolean;
|
|
12
|
+
//# sourceMappingURL=processLightClientUpdate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processLightClientUpdate.d.ts","sourceRoot":"","sources":["../../../src/lightClient/spec/processLightClientUpdate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAC,iBAAiB,EAAE,IAAI,EAAE,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAGpE,OAAO,EAAC,wBAAwB,EAA6C,MAAM,qBAAqB,CAAC;AACzG,OAAO,EAAC,KAAK,iBAAiB,EAA0B,KAAK,iBAAiB,EAAC,MAAM,YAAY,CAAC;AAIlG,MAAM,WAAW,iBAAiB;IAChC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,2BAA2B,CAAC,EAAE,OAAO,CAAC;CACvC;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,eAAe,EACvB,KAAK,EAAE,iBAAiB,EACxB,WAAW,EAAE,IAAI,EACjB,IAAI,EAAE,iBAAiB,EACvB,MAAM,EAAE,iBAAiB,GACxB,IAAI,CA8CN;AAED,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,iBAAiB,EACxB,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,iBAAiB,GACtB,iBAAiB,CAuCnB;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,wBAAwB,GAAG,OAAO,CAIjF"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { SYNC_COMMITTEE_SIZE } from "@lodestar/params";
|
|
2
|
+
import { pruneSetToMax } from "@lodestar/utils";
|
|
3
|
+
import { computeSyncPeriodAtSlot } from "../../util/epoch.js";
|
|
4
|
+
import { isBetterUpdate, toLightClientUpdateSummary } from "./isBetterUpdate.js";
|
|
5
|
+
import { MAX_SYNC_PERIODS_CACHE } from "./store.js";
|
|
6
|
+
import { deserializeSyncCommittee, getSafetyThreshold, isSyncCommitteeUpdate, sumBits } from "./utils.js";
|
|
7
|
+
import { validateLightClientUpdate } from "./validateLightClientUpdate.js";
|
|
8
|
+
export function processLightClientUpdate(config, store, currentSlot, opts, update) {
|
|
9
|
+
if (update.signatureSlot > currentSlot) {
|
|
10
|
+
throw Error(`update slot ${update.signatureSlot} must not be in the future, current slot ${currentSlot}`);
|
|
11
|
+
}
|
|
12
|
+
const updateSignaturePeriod = computeSyncPeriodAtSlot(update.signatureSlot);
|
|
13
|
+
// TODO: Consider attempting to retrieve LightClientUpdate from transport if missing
|
|
14
|
+
// Note: store.getSyncCommitteeAtPeriod() may advance store
|
|
15
|
+
const syncCommittee = getSyncCommitteeAtPeriod(store, updateSignaturePeriod, opts);
|
|
16
|
+
validateLightClientUpdate(config, store, update, syncCommittee);
|
|
17
|
+
// Track the maximum number of active participants in the committee signatures
|
|
18
|
+
const syncCommitteeTrueBits = sumBits(update.syncAggregate.syncCommitteeBits);
|
|
19
|
+
store.setActiveParticipants(updateSignaturePeriod, syncCommitteeTrueBits);
|
|
20
|
+
// Update the optimistic header
|
|
21
|
+
if (syncCommitteeTrueBits > getSafetyThreshold(store.getMaxActiveParticipants(updateSignaturePeriod)) &&
|
|
22
|
+
update.attestedHeader.beacon.slot > store.optimisticHeader.beacon.slot) {
|
|
23
|
+
store.optimisticHeader = update.attestedHeader;
|
|
24
|
+
}
|
|
25
|
+
// Update finalized header
|
|
26
|
+
if (syncCommitteeTrueBits * 3 >= SYNC_COMMITTEE_SIZE * 2 &&
|
|
27
|
+
update.finalizedHeader.beacon.slot > store.finalizedHeader.beacon.slot) {
|
|
28
|
+
store.finalizedHeader = update.finalizedHeader;
|
|
29
|
+
if (store.finalizedHeader.beacon.slot > store.optimisticHeader.beacon.slot) {
|
|
30
|
+
store.optimisticHeader = store.finalizedHeader;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (isSyncCommitteeUpdate(update)) {
|
|
34
|
+
// Update the best update in case we have to force-update to it if the timeout elapses
|
|
35
|
+
const bestValidUpdate = store.bestValidUpdates.get(updateSignaturePeriod);
|
|
36
|
+
const updateSummary = toLightClientUpdateSummary(update);
|
|
37
|
+
if (!bestValidUpdate || isBetterUpdate(updateSummary, bestValidUpdate.summary)) {
|
|
38
|
+
store.bestValidUpdates.set(updateSignaturePeriod, { update, summary: updateSummary });
|
|
39
|
+
pruneSetToMax(store.bestValidUpdates, MAX_SYNC_PERIODS_CACHE);
|
|
40
|
+
}
|
|
41
|
+
// Note: defer update next sync committee to a future getSyncCommitteeAtPeriod() call
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export function getSyncCommitteeAtPeriod(store, period, opts) {
|
|
45
|
+
const syncCommittee = store.syncCommittees.get(period);
|
|
46
|
+
if (syncCommittee) {
|
|
47
|
+
return syncCommittee;
|
|
48
|
+
}
|
|
49
|
+
const bestValidUpdate = store.bestValidUpdates.get(period - 1);
|
|
50
|
+
if (bestValidUpdate && (isSafeLightClientUpdate(bestValidUpdate.summary) || opts.allowForcedUpdates)) {
|
|
51
|
+
const { update } = bestValidUpdate;
|
|
52
|
+
const syncCommittee = deserializeSyncCommittee(update.nextSyncCommittee);
|
|
53
|
+
store.syncCommittees.set(period, syncCommittee);
|
|
54
|
+
pruneSetToMax(store.syncCommittees, MAX_SYNC_PERIODS_CACHE);
|
|
55
|
+
store.bestValidUpdates.delete(period - 1);
|
|
56
|
+
if (opts.updateHeadersOnForcedUpdate) {
|
|
57
|
+
// From https://github.com/ethereum/consensus-specs/blob/a57e15636013eeba3610ff3ade41781dba1bb0cd/specs/altair/light-client/sync-protocol.md?plain=1#L403
|
|
58
|
+
if (update.finalizedHeader.beacon.slot <= store.finalizedHeader.beacon.slot) {
|
|
59
|
+
update.finalizedHeader = update.attestedHeader;
|
|
60
|
+
}
|
|
61
|
+
// From https://github.com/ethereum/consensus-specs/blob/a57e15636013eeba3610ff3ade41781dba1bb0cd/specs/altair/light-client/sync-protocol.md?plain=1#L374
|
|
62
|
+
if (update.finalizedHeader.beacon.slot > store.finalizedHeader.beacon.slot) {
|
|
63
|
+
store.finalizedHeader = update.finalizedHeader;
|
|
64
|
+
}
|
|
65
|
+
if (store.finalizedHeader.beacon.slot > store.optimisticHeader.beacon.slot) {
|
|
66
|
+
store.optimisticHeader = store.finalizedHeader;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return syncCommittee;
|
|
70
|
+
}
|
|
71
|
+
const availableSyncCommittees = Array.from(store.syncCommittees.keys());
|
|
72
|
+
const availableBestValidUpdates = Array.from(store.bestValidUpdates.keys());
|
|
73
|
+
throw Error(`No SyncCommittee for period ${period}` +
|
|
74
|
+
` available syncCommittees ${JSON.stringify(availableSyncCommittees)}` +
|
|
75
|
+
` available bestValidUpdates ${JSON.stringify(availableBestValidUpdates)}`);
|
|
76
|
+
}
|
|
77
|
+
export function isSafeLightClientUpdate(update) {
|
|
78
|
+
return (update.activeParticipants * 3 >= SYNC_COMMITTEE_SIZE * 2 && update.isFinalityUpdate && update.isSyncCommitteeUpdate);
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=processLightClientUpdate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processLightClientUpdate.js","sourceRoot":"","sources":["../../../src/lightClient/spec/processLightClientUpdate.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,mBAAmB,EAAC,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAC,uBAAuB,EAAC,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAA2B,cAAc,EAAE,0BAA0B,EAAC,MAAM,qBAAqB,CAAC;AACzG,OAAO,EAAyB,sBAAsB,EAAyB,MAAM,YAAY,CAAC;AAClG,OAAO,EAAC,wBAA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EAAE;QACrC,6BAA6B,IAAI,CAAC,SAAS,CAAC,uBAAuB,CAAC,EAAE;QACtE,+BAA+B,IAAI,CAAC,SAAS,CAAC,yBAAyB,CAAC,EAAE,CAC7E,CAAC;AAAA,CACH;AAED,MAAM,UAAU,uBAAuB,CAAC,MAAgC,EAAW;IACjF,OAAO,CACL,MAAM,CAAC,kBAAkB,GAAG,CAAC,IAAI,mBAAmB,GAAG,CAAC,IAAI,MAAM,CAAC,gBAAgB,IAAI,MAAM,CAAC,qBAAqB,CACpH,CAAC;AAAA,CACH"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { PublicKey } from "@chainsafe/blst";
|
|
2
|
+
import { BeaconConfig } from "@lodestar/config";
|
|
3
|
+
import { LightClientBootstrap, LightClientHeader, LightClientUpdate, SyncPeriod } from "@lodestar/types";
|
|
4
|
+
import type { LightClientUpdateSummary } from "./isBetterUpdate.js";
|
|
5
|
+
export declare const MAX_SYNC_PERIODS_CACHE = 2;
|
|
6
|
+
export interface ILightClientStore {
|
|
7
|
+
readonly config: BeaconConfig;
|
|
8
|
+
/** Map of trusted SyncCommittee to be used for sig validation */
|
|
9
|
+
readonly syncCommittees: Map<SyncPeriod, SyncCommitteeFast>;
|
|
10
|
+
/** Map of best valid updates */
|
|
11
|
+
readonly bestValidUpdates: Map<SyncPeriod, LightClientUpdateWithSummary>;
|
|
12
|
+
getMaxActiveParticipants(period: SyncPeriod): number;
|
|
13
|
+
setActiveParticipants(period: SyncPeriod, activeParticipants: number): void;
|
|
14
|
+
finalizedHeader: LightClientHeader;
|
|
15
|
+
optimisticHeader: LightClientHeader;
|
|
16
|
+
}
|
|
17
|
+
export interface LightClientStoreEvents {
|
|
18
|
+
onSetFinalizedHeader?: (header: LightClientHeader) => void;
|
|
19
|
+
onSetOptimisticHeader?: (header: LightClientHeader) => void;
|
|
20
|
+
}
|
|
21
|
+
export declare class LightClientStore implements ILightClientStore {
|
|
22
|
+
readonly config: BeaconConfig;
|
|
23
|
+
private readonly events;
|
|
24
|
+
readonly syncCommittees: Map<number, SyncCommitteeFast>;
|
|
25
|
+
readonly bestValidUpdates: Map<number, LightClientUpdateWithSummary>;
|
|
26
|
+
private finalizedHeaderValue;
|
|
27
|
+
private optimisticHeaderValue;
|
|
28
|
+
private readonly maxActiveParticipants;
|
|
29
|
+
constructor(config: BeaconConfig, bootstrap: LightClientBootstrap, events: LightClientStoreEvents);
|
|
30
|
+
get finalizedHeader(): LightClientHeader;
|
|
31
|
+
set finalizedHeader(value: LightClientHeader);
|
|
32
|
+
get optimisticHeader(): LightClientHeader;
|
|
33
|
+
set optimisticHeader(value: LightClientHeader);
|
|
34
|
+
getMaxActiveParticipants(period: SyncPeriod): number;
|
|
35
|
+
setActiveParticipants(period: SyncPeriod, activeParticipants: number): void;
|
|
36
|
+
}
|
|
37
|
+
export type SyncCommitteeFast = {
|
|
38
|
+
pubkeys: PublicKey[];
|
|
39
|
+
aggregatePubkey: PublicKey;
|
|
40
|
+
};
|
|
41
|
+
export type LightClientUpdateWithSummary = {
|
|
42
|
+
update: LightClientUpdate;
|
|
43
|
+
summary: LightClientUpdateSummary;
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/lightClient/spec/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAC,oBAAoB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAEvG,OAAO,KAAK,EAAC,wBAAwB,EAAC,MAAM,qBAAqB,CAAC;AAGlE,eAAO,MAAM,sBAAsB,IAAI,CAAC;AAExC,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC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