@lodestar/state-transition 1.45.0 → 1.46.0-dev.4191d8e353
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/processAttestationsAltair.d.ts +4 -1
- package/lib/block/processAttestationsAltair.d.ts.map +1 -1
- package/lib/block/processAttestationsAltair.js +7 -5
- package/lib/block/processAttestationsAltair.js.map +1 -1
- package/lib/block/processBuilderDepositRequest.d.ts.map +1 -1
- package/lib/block/processBuilderDepositRequest.js +13 -7
- package/lib/block/processBuilderDepositRequest.js.map +1 -1
- package/lib/block/processOperations.d.ts.map +1 -1
- package/lib/block/processOperations.js +17 -1
- package/lib/block/processOperations.js.map +1 -1
- package/lib/block/processParentExecutionPayload.d.ts.map +1 -1
- package/lib/block/processParentExecutionPayload.js +15 -1
- package/lib/block/processParentExecutionPayload.js.map +1 -1
- package/lib/block/processWithdrawals.js +1 -1
- package/lib/block/processWithdrawals.js.map +1 -1
- package/lib/cache/epochCache.d.ts.map +1 -1
- package/lib/cache/epochCache.js +18 -19
- package/lib/cache/epochCache.js.map +1 -1
- package/lib/cache/stateCache.d.ts.map +1 -1
- package/lib/cache/stateCache.js +2 -4
- package/lib/cache/stateCache.js.map +1 -1
- package/lib/epoch/processParticipationFlagUpdates.d.ts +2 -2
- package/lib/epoch/processParticipationFlagUpdates.d.ts.map +1 -1
- package/lib/epoch/processParticipationFlagUpdates.js +13 -0
- package/lib/epoch/processParticipationFlagUpdates.js.map +1 -1
- package/lib/epoch/processRewardsAndPenalties.d.ts.map +1 -1
- package/lib/epoch/processRewardsAndPenalties.js +1 -2
- package/lib/epoch/processRewardsAndPenalties.js.map +1 -1
- package/lib/lightClient/proofs.d.ts.map +1 -1
- package/lib/lightClient/proofs.js +28 -2
- package/lib/lightClient/proofs.js.map +1 -1
- package/lib/lightClient/spec/index.d.ts.map +1 -1
- package/lib/lightClient/spec/index.js +7 -4
- package/lib/lightClient/spec/index.js.map +1 -1
- package/lib/lightClient/spec/processLightClientUpdate.d.ts.map +1 -1
- package/lib/lightClient/spec/processLightClientUpdate.js +8 -2
- package/lib/lightClient/spec/processLightClientUpdate.js.map +1 -1
- package/lib/lightClient/spec/utils.d.ts +7 -2
- package/lib/lightClient/spec/utils.d.ts.map +1 -1
- package/lib/lightClient/spec/utils.js +130 -19
- package/lib/lightClient/spec/utils.js.map +1 -1
- package/lib/lightClient/spec/validateLightClientBootstrap.d.ts.map +1 -1
- package/lib/lightClient/spec/validateLightClientBootstrap.js +2 -7
- package/lib/lightClient/spec/validateLightClientBootstrap.js.map +1 -1
- package/lib/lightClient/spec/validateLightClientUpdate.d.ts.map +1 -1
- package/lib/lightClient/spec/validateLightClientUpdate.js +6 -5
- package/lib/lightClient/spec/validateLightClientUpdate.js.map +1 -1
- package/lib/lightClient/types.d.ts +3 -1
- package/lib/lightClient/types.d.ts.map +1 -1
- package/lib/metrics.js +2 -4
- package/lib/metrics.js.map +1 -1
- package/lib/slot/upgradeStateToAltair.js +1 -1
- package/lib/slot/upgradeStateToAltair.js.map +1 -1
- package/lib/slot/upgradeStateToGloas.d.ts.map +1 -1
- package/lib/slot/upgradeStateToGloas.js +48 -9
- package/lib/slot/upgradeStateToGloas.js.map +1 -1
- package/lib/util/execution.d.ts.map +1 -1
- package/lib/util/execution.js +7 -2
- package/lib/util/execution.js.map +1 -1
- package/lib/util/gloas.d.ts +3 -1
- package/lib/util/gloas.d.ts.map +1 -1
- package/lib/util/gloas.js +8 -11
- 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/ssz.d.ts +9 -0
- package/lib/util/ssz.d.ts.map +1 -0
- package/lib/util/ssz.js +39 -0
- package/lib/util/ssz.js.map +1 -0
- package/package.json +14 -14
- package/src/block/processAttestationsAltair.ts +9 -6
- package/src/block/processBuilderDepositRequest.ts +21 -8
- package/src/block/processOperations.ts +28 -1
- package/src/block/processParentExecutionPayload.ts +26 -1
- package/src/block/processWithdrawals.ts +1 -1
- package/src/cache/epochCache.ts +19 -22
- package/src/cache/stateCache.ts +2 -4
- package/src/epoch/processParticipationFlagUpdates.ts +20 -2
- package/src/epoch/processRewardsAndPenalties.ts +1 -2
- package/src/lightClient/proofs.ts +36 -1
- package/src/lightClient/spec/index.ts +8 -4
- package/src/lightClient/spec/processLightClientUpdate.ts +13 -1
- package/src/lightClient/spec/utils.ts +200 -30
- package/src/lightClient/spec/validateLightClientBootstrap.ts +3 -10
- package/src/lightClient/spec/validateLightClientUpdate.ts +11 -21
- package/src/lightClient/types.ts +3 -1
- package/src/metrics.ts +2 -4
- package/src/slot/upgradeStateToAltair.ts +1 -1
- package/src/slot/upgradeStateToGloas.ts +84 -9
- package/src/util/execution.ts +9 -4
- package/src/util/gloas.ts +9 -14
- package/src/util/index.ts +1 -0
- package/src/util/ssz.ts +42 -0
package/src/util/gloas.ts
CHANGED
|
@@ -18,7 +18,6 @@ import {AttestationData} from "@lodestar/types/phase0";
|
|
|
18
18
|
import {byteArrayEquals} from "@lodestar/utils";
|
|
19
19
|
import {ZERO_HASH} from "../constants/index.js";
|
|
20
20
|
import {CachedBeaconStateFulu, CachedBeaconStateGloas} from "../types.js";
|
|
21
|
-
import {getBlockRootAtSlot} from "./blockRoot.js";
|
|
22
21
|
import {computeDomain} from "./domain.js";
|
|
23
22
|
import {computeEpochAtSlot} from "./epoch.js";
|
|
24
23
|
import {computeEpochShuffling} from "./epochShuffling.js";
|
|
@@ -32,11 +31,13 @@ export function isBuilderWithdrawalCredential(withdrawalCredentials: Uint8Array)
|
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
export function getBuilderPaymentQuorumThreshold(state: CachedBeaconStateGloas): number {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
// total active balance exceeds Number.MAX_SAFE_INTEGER at mainnet scale, keep the intermediate math in bigint
|
|
35
|
+
const perSlotBalance =
|
|
36
|
+
(BigInt(state.epochCtx.totalActiveBalanceIncrements) * BigInt(EFFECTIVE_BALANCE_INCREMENT)) /
|
|
37
|
+
BigInt(SLOTS_PER_EPOCH);
|
|
38
|
+
const quorum = perSlotBalance * BigInt(BUILDER_PAYMENT_THRESHOLD_NUMERATOR);
|
|
38
39
|
|
|
39
|
-
return
|
|
40
|
+
return Number(quorum / BigInt(BUILDER_PAYMENT_THRESHOLD_DENOMINATOR));
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
function hasBuilderIndexFlag(index: number): boolean {
|
|
@@ -188,15 +189,9 @@ export function findBuilderIndexByPubkey(state: CachedBeaconStateGloas, pubkey:
|
|
|
188
189
|
return null;
|
|
189
190
|
}
|
|
190
191
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const isMatchingBlockRoot = byteArrayEquals(data.beaconBlockRoot, getBlockRootAtSlot(state, data.slot));
|
|
195
|
-
const isCurrentBlockRoot = !byteArrayEquals(data.beaconBlockRoot, getBlockRootAtSlot(state, data.slot - 1));
|
|
196
|
-
|
|
197
|
-
return isMatchingBlockRoot && isCurrentBlockRoot;
|
|
198
|
-
}
|
|
199
|
-
|
|
192
|
+
/**
|
|
193
|
+
* Use cached block roots to avoid repeated state root lookups while matching the spec's is_attestation_same_slot behavior.
|
|
194
|
+
*/
|
|
200
195
|
export function isAttestationSameSlotRootCache(rootCache: RootCache, data: AttestationData): boolean {
|
|
201
196
|
if (data.slot === 0) return true;
|
|
202
197
|
|
package/src/util/index.ts
CHANGED
|
@@ -25,6 +25,7 @@ export * from "./shuffling.js";
|
|
|
25
25
|
export * from "./signatureSets.js";
|
|
26
26
|
export * from "./signingRoot.js";
|
|
27
27
|
export * from "./slot.js";
|
|
28
|
+
export * from "./ssz.js";
|
|
28
29
|
export * from "./syncCommittee.js";
|
|
29
30
|
export * from "./validator.js";
|
|
30
31
|
export * from "./weakSubjectivity.js";
|
package/src/util/ssz.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {BranchNode, LeafNode, Node, zeroNode} from "@chainsafe/persistent-merkle-tree";
|
|
2
|
+
import {progressiveSubtreeFillToContents} from "@chainsafe/ssz";
|
|
3
|
+
|
|
4
|
+
// TODO: move these utils to @chainsafe/ssz (progressive.ts, next to progressiveSubtreeFillToContents)
|
|
5
|
+
|
|
6
|
+
/** Root node (chunks + length mix-in) of a zero-filled ProgressiveListBasicType of `length` items */
|
|
7
|
+
export function zeroProgressiveListBasicRootNode(itemsPerChunk: number, length: number): Node {
|
|
8
|
+
const chunkCount = Math.ceil(length / itemsPerChunk);
|
|
9
|
+
// mirrors ssz's progressiveSubtreeCount (subtree capacities 1, 4, 16, ...)
|
|
10
|
+
let numSubtrees = 0;
|
|
11
|
+
for (let remaining = chunkCount, subtreeLength = 1; remaining > 0; subtreeLength *= 4) {
|
|
12
|
+
remaining -= Math.min(remaining, subtreeLength);
|
|
13
|
+
numSubtrees++;
|
|
14
|
+
}
|
|
15
|
+
return new BranchNode(zeroProgressiveNode(numSubtrees), LeafNode.fromUint32(length));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Root node of a progressive list from its chunk/element nodes + length mix-in.
|
|
20
|
+
* `nodes` are packed 32-byte chunk leaves for basic lists, or element root nodes for composite lists.
|
|
21
|
+
*/
|
|
22
|
+
export function progressiveListRootNode(nodes: Node[], length: number): Node {
|
|
23
|
+
return new BranchNode(progressiveSubtreeFillToContents(nodes), LeafNode.fromUint32(length));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Return the chunks node of a zero-filled progressive merkle list spanning `numSubtrees`
|
|
28
|
+
* balanced subtrees (chunk capacities 1, 4, 16, ... = 4^i; depths 0, 2, 4, ... = 2i).
|
|
29
|
+
*
|
|
30
|
+
* Not memoized: the zero data is already fully shared via the cached zeroNode(2i) subtrees;
|
|
31
|
+
* only the O(numSubtrees) spine BranchNodes (~10 at 2M validators) are allocated per call.
|
|
32
|
+
*/
|
|
33
|
+
function zeroProgressiveNode(numSubtrees: number): Node {
|
|
34
|
+
// chain(k) = B(zeroNode(0), B(zeroNode(2), ... B(zeroNode(2(k-1)), zeroNode(0))))
|
|
35
|
+
let node: Node = zeroNode(0); // terminator
|
|
36
|
+
for (let i = numSubtrees - 1; i >= 0; i--) {
|
|
37
|
+
// BranchNode(left: balanced subtree i, right: rest of chain) — chain grows to the right,
|
|
38
|
+
// same as ssz progressiveSubtreeFillToContents: `root = new BranchNode(subtreeRoots[i], root)`
|
|
39
|
+
node = new BranchNode(zeroNode(2 * i), node);
|
|
40
|
+
}
|
|
41
|
+
return node;
|
|
42
|
+
}
|