@lodestar/fork-choice 1.52.0-dev.c90a21c764 → 1.52.0-dev.dad8e3af98
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/forkChoice/fastConfirmation/utils.d.ts +12 -12
- package/lib/forkChoice/fastConfirmation/utils.d.ts.map +1 -1
- package/lib/forkChoice/fastConfirmation/utils.js +48 -61
- package/lib/forkChoice/fastConfirmation/utils.js.map +1 -1
- package/lib/forkChoice/forkChoice.d.ts +3 -1
- package/lib/forkChoice/forkChoice.d.ts.map +1 -1
- package/lib/forkChoice/forkChoice.js +12 -2
- package/lib/forkChoice/forkChoice.js.map +1 -1
- package/lib/forkChoice/interface.d.ts +1 -1
- package/lib/protoArray/protoArray.d.ts.map +1 -1
- package/lib/protoArray/protoArray.js +8 -2
- package/lib/protoArray/protoArray.js.map +1 -1
- package/package.json +8 -8
- package/src/forkChoice/fastConfirmation/utils.ts +84 -94
- package/src/forkChoice/forkChoice.ts +11 -2
- package/src/forkChoice/interface.ts +1 -1
- package/src/protoArray/protoArray.ts +8 -2
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"bugs": {
|
|
12
12
|
"url": "https://github.com/ChainSafe/lodestar/issues"
|
|
13
13
|
},
|
|
14
|
-
"version": "1.52.0-dev.
|
|
14
|
+
"version": "1.52.0-dev.dad8e3af98",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
@@ -39,12 +39,12 @@
|
|
|
39
39
|
"check-readme": "pnpm exec tsx ../../scripts/check_readme.ts"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@chainsafe/ssz": "^1.9.
|
|
43
|
-
"@lodestar/config": "^1.52.0-dev.
|
|
44
|
-
"@lodestar/params": "^1.52.0-dev.
|
|
45
|
-
"@lodestar/state-transition": "^1.52.0-dev.
|
|
46
|
-
"@lodestar/types": "^1.52.0-dev.
|
|
47
|
-
"@lodestar/utils": "^1.52.0-dev.
|
|
42
|
+
"@chainsafe/ssz": "^1.9.1",
|
|
43
|
+
"@lodestar/config": "^1.52.0-dev.dad8e3af98",
|
|
44
|
+
"@lodestar/params": "^1.52.0-dev.dad8e3af98",
|
|
45
|
+
"@lodestar/state-transition": "^1.52.0-dev.dad8e3af98",
|
|
46
|
+
"@lodestar/types": "^1.52.0-dev.dad8e3af98",
|
|
47
|
+
"@lodestar/utils": "^1.52.0-dev.dad8e3af98"
|
|
48
48
|
},
|
|
49
49
|
"keywords": [
|
|
50
50
|
"ethereum",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"beacon",
|
|
53
53
|
"blockchain"
|
|
54
54
|
],
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "3839b605a06b630f1c8e23b3f68a9091e178416e"
|
|
56
56
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {SLOTS_PER_EPOCH} from "@lodestar/params";
|
|
1
|
+
import {EFFECTIVE_BALANCE_INCREMENT, SLOTS_PER_EPOCH} from "@lodestar/params";
|
|
2
2
|
import {
|
|
3
3
|
EffectiveBalanceIncrements,
|
|
4
4
|
IBeaconStateView,
|
|
@@ -24,14 +24,16 @@ import {
|
|
|
24
24
|
|
|
25
25
|
// Spec: adjust_committee_weight_estimate_to_ensure_safety
|
|
26
26
|
// https://github.com/ethereum/consensus-specs/blob/master/specs/phase0/fast-confirmation.md#adjust_committee_weight_estimate_to_ensure_safety
|
|
27
|
-
const COMMITTEE_WEIGHT_ESTIMATION_ADJUSTMENT_FACTOR =
|
|
27
|
+
const COMMITTEE_WEIGHT_ESTIMATION_ADJUSTMENT_FACTOR = 5n;
|
|
28
|
+
|
|
29
|
+
const EFFECTIVE_BALANCE_INCREMENT_BIGINT = BigInt(EFFECTIVE_BALANCE_INCREMENT);
|
|
28
30
|
|
|
29
31
|
const SAFETY_THRESHOLD_UNREACHABLE = Object.freeze({
|
|
30
|
-
threshold:
|
|
31
|
-
proposerScore:
|
|
32
|
-
maximumSupport:
|
|
33
|
-
supportDiscount:
|
|
34
|
-
adversarialWeight:
|
|
32
|
+
threshold: 2n ** 64n,
|
|
33
|
+
proposerScore: 0n,
|
|
34
|
+
maximumSupport: 0n,
|
|
35
|
+
supportDiscount: 0n,
|
|
36
|
+
adversarialWeight: 0n,
|
|
35
37
|
});
|
|
36
38
|
|
|
37
39
|
export function getBlock(ctx: FastConfirmationContext, cache: FastConfirmationCache, root: RootHex): ProtoBlock | null {
|
|
@@ -299,9 +301,9 @@ export function estimateCommitteeWeightBetweenSlots(
|
|
|
299
301
|
cache: FastConfirmationCache,
|
|
300
302
|
startSlot: Slot,
|
|
301
303
|
endSlot: Slot
|
|
302
|
-
):
|
|
303
|
-
if (startSlot > endSlot) return
|
|
304
|
-
const totalActiveBalance = getTotalActiveBalance(balanceSource, cache);
|
|
304
|
+
): bigint {
|
|
305
|
+
if (startSlot > endSlot) return 0n;
|
|
306
|
+
const totalActiveBalance = BigInt(getTotalActiveBalance(balanceSource, cache)) * EFFECTIVE_BALANCE_INCREMENT_BIGINT;
|
|
305
307
|
const startEpoch = computeEpochAtSlot(startSlot);
|
|
306
308
|
const endEpoch = computeEpochAtSlot(endSlot);
|
|
307
309
|
|
|
@@ -309,41 +311,30 @@ export function estimateCommitteeWeightBetweenSlots(
|
|
|
309
311
|
return totalActiveBalance;
|
|
310
312
|
}
|
|
311
313
|
|
|
312
|
-
const committeeWeightPerSlot =
|
|
314
|
+
const committeeWeightPerSlot = totalActiveBalance / BigInt(SLOTS_PER_EPOCH);
|
|
313
315
|
|
|
314
316
|
if (startEpoch === endEpoch) {
|
|
315
|
-
return committeeWeightPerSlot * (endSlot - startSlot + 1);
|
|
317
|
+
return committeeWeightPerSlot * BigInt(endSlot - startSlot + 1);
|
|
316
318
|
}
|
|
317
319
|
|
|
318
320
|
const numSlotsInStartEpoch = SLOTS_PER_EPOCH - computeSlotsSinceEpochStart(startSlot);
|
|
319
321
|
const numSlotsInEndEpoch = computeSlotsSinceEpochStart(endSlot) + 1;
|
|
320
322
|
const remainingSlotsInEndEpoch = SLOTS_PER_EPOCH - numSlotsInEndEpoch;
|
|
321
323
|
|
|
322
|
-
const startEpochWeight = committeeWeightPerSlot * numSlotsInStartEpoch;
|
|
323
|
-
const endEpochWeight = committeeWeightPerSlot * numSlotsInEndEpoch;
|
|
324
|
+
const startEpochWeight = committeeWeightPerSlot * BigInt(numSlotsInStartEpoch);
|
|
325
|
+
const endEpochWeight = committeeWeightPerSlot * BigInt(numSlotsInEndEpoch);
|
|
324
326
|
// For ranges that cross exactly one epoch boundary without covering a full epoch,
|
|
325
327
|
// the spec models overlap as:
|
|
326
328
|
// startEpochWeightProRated = startEpochWeight * (1 - numSlotsInEndEpoch / SLOTS_PER_EPOCH)
|
|
327
329
|
// = startEpochWeight * remainingSlotsInEndEpoch / SLOTS_PER_EPOCH
|
|
328
330
|
// We keep the spec's "pro-rate the start epoch" form so integer rounding matches it exactly.
|
|
329
|
-
const startEpochWeightProRated =
|
|
331
|
+
const startEpochWeightProRated = (startEpochWeight / BigInt(SLOTS_PER_EPOCH)) * BigInt(remainingSlotsInEndEpoch);
|
|
330
332
|
|
|
331
333
|
return adjustCommitteeWeightEstimateToEnsureSafety(startEpochWeightProRated + endEpochWeight);
|
|
332
334
|
}
|
|
333
335
|
|
|
334
|
-
export function adjustCommitteeWeightEstimateToEnsureSafety(estimate:
|
|
335
|
-
|
|
336
|
-
// ceil(estimate_gwei / 1000) * (1000 + factor)
|
|
337
|
-
//
|
|
338
|
-
// Lodestar carries effective balance increments instead, where:
|
|
339
|
-
// 1 increment = EFFECTIVE_BALANCE_INCREMENT = 1e9 Gwei
|
|
340
|
-
//
|
|
341
|
-
// Since each increment is already far larger than 1000 Gwei, the spec's
|
|
342
|
-
// `ceil(... / 1000)` becomes a no-op at our unit scale. The equivalent
|
|
343
|
-
// conservative adjustment in increments is therefore:
|
|
344
|
-
// ceil(estimate_increments * (1000 + factor) / 1000)
|
|
345
|
-
// The `+ 999` is integer ceiling division by 1000.
|
|
346
|
-
return Math.floor((estimate * (1000 + COMMITTEE_WEIGHT_ESTIMATION_ADJUSTMENT_FACTOR) + 999) / 1000);
|
|
336
|
+
export function adjustCommitteeWeightEstimateToEnsureSafety(estimate: bigint): bigint {
|
|
337
|
+
return ((estimate + 999n) / 1000n) * (1000n + COMMITTEE_WEIGHT_ESTIMATION_ADJUSTMENT_FACTOR);
|
|
347
338
|
}
|
|
348
339
|
|
|
349
340
|
export function isFullValidatorSetCovered(startSlot: Slot, endSlot: Slot): boolean {
|
|
@@ -356,10 +347,10 @@ export function computeProposerScore(
|
|
|
356
347
|
ctx: FastConfirmationContext,
|
|
357
348
|
balanceSource: FastConfirmationBalanceSource,
|
|
358
349
|
cache: FastConfirmationCache
|
|
359
|
-
):
|
|
360
|
-
const totalActiveBalance = getTotalActiveBalance(balanceSource, cache);
|
|
361
|
-
const committeeWeight =
|
|
362
|
-
return
|
|
350
|
+
): bigint {
|
|
351
|
+
const totalActiveBalance = BigInt(getTotalActiveBalance(balanceSource, cache)) * EFFECTIVE_BALANCE_INCREMENT_BIGINT;
|
|
352
|
+
const committeeWeight = totalActiveBalance / BigInt(SLOTS_PER_EPOCH);
|
|
353
|
+
return (committeeWeight * BigInt(ctx.config.PROPOSER_SCORE_BOOST)) / 100n;
|
|
363
354
|
}
|
|
364
355
|
|
|
365
356
|
/**
|
|
@@ -485,14 +476,13 @@ export function computeAdversarialWeight(
|
|
|
485
476
|
balanceSource: FastConfirmationBalanceSource,
|
|
486
477
|
startSlot: Slot,
|
|
487
478
|
endSlot: Slot
|
|
488
|
-
):
|
|
479
|
+
): bigint {
|
|
489
480
|
const maximumWeight = estimateCommitteeWeightBetweenSlots(balanceSource, cache, startSlot, endSlot);
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
return maxAdversarialWeight > equivocationScore ? maxAdversarialWeight - equivocationScore : 0;
|
|
481
|
+
const maxAdversarialWeight = (maximumWeight / 100n) * BigInt(ctx.config.CONFIRMATION_BYZANTINE_THRESHOLD);
|
|
482
|
+
const equivocationScore =
|
|
483
|
+
BigInt(getEquivocationScore(ctx, store, cache, balanceSource, startSlot, endSlot)) *
|
|
484
|
+
EFFECTIVE_BALANCE_INCREMENT_BIGINT;
|
|
485
|
+
return maxAdversarialWeight > equivocationScore ? maxAdversarialWeight - equivocationScore : 0n;
|
|
496
486
|
}
|
|
497
487
|
|
|
498
488
|
export function getAdversarialWeight(
|
|
@@ -501,13 +491,13 @@ export function getAdversarialWeight(
|
|
|
501
491
|
cache: FastConfirmationCache,
|
|
502
492
|
balanceSource: FastConfirmationBalanceSource,
|
|
503
493
|
blockRoot: RootHex
|
|
504
|
-
):
|
|
494
|
+
): bigint {
|
|
505
495
|
const currentSlot = ctx.getCurrentSlot();
|
|
506
|
-
if (currentSlot === 0) return
|
|
496
|
+
if (currentSlot === 0) return 0n;
|
|
507
497
|
const block = getBlock(ctx, cache, blockRoot);
|
|
508
|
-
if (!block) return
|
|
498
|
+
if (!block) return 0n;
|
|
509
499
|
const parentBlock = getBlock(ctx, cache, block.parentRoot);
|
|
510
|
-
if (!parentBlock) return
|
|
500
|
+
if (!parentBlock) return 0n;
|
|
511
501
|
const blockEpoch = computeEpochAtSlot(block.slot);
|
|
512
502
|
const parentEpoch = computeEpochAtSlot(parentBlock.slot);
|
|
513
503
|
|
|
@@ -524,31 +514,34 @@ export function computeEmptySlotSupportDiscount(
|
|
|
524
514
|
cache: FastConfirmationCache,
|
|
525
515
|
balanceSource: FastConfirmationBalanceSource,
|
|
526
516
|
blockRoot: RootHex
|
|
527
|
-
):
|
|
517
|
+
): bigint {
|
|
528
518
|
const block = getBlock(ctx, cache, blockRoot);
|
|
529
|
-
if (!block) return
|
|
519
|
+
if (!block) return 0n;
|
|
530
520
|
const parentBlock = getBlock(ctx, cache, block.parentRoot);
|
|
531
|
-
if (!parentBlock) return
|
|
521
|
+
if (!parentBlock) return 0n;
|
|
532
522
|
|
|
533
523
|
if (parentBlock.slot + 1 === block.slot) {
|
|
534
|
-
return
|
|
524
|
+
return 0n;
|
|
535
525
|
}
|
|
536
526
|
|
|
537
527
|
// Post-Gloas the parent block has PENDING, EMPTY and FULL nodes. Only the support of the node this
|
|
538
528
|
// block actually extends is discounted; votes for the other parent nodes are not support for it.
|
|
539
529
|
const parentNodePayloadStatus = ctx.getParentNodePayloadStatus(blockRoot);
|
|
540
|
-
if (parentNodePayloadStatus === null) return
|
|
541
|
-
|
|
542
|
-
const parentSupportInEmptySlots =
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
530
|
+
if (parentNodePayloadStatus === null) return 0n;
|
|
531
|
+
|
|
532
|
+
const parentSupportInEmptySlots =
|
|
533
|
+
BigInt(
|
|
534
|
+
getNodeSupportBetweenSlots(
|
|
535
|
+
ctx,
|
|
536
|
+
store,
|
|
537
|
+
cache,
|
|
538
|
+
balanceSource,
|
|
539
|
+
block.parentRoot,
|
|
540
|
+
parentNodePayloadStatus,
|
|
541
|
+
(parentBlock.slot + 1) as Slot,
|
|
542
|
+
(block.slot - 1) as Slot
|
|
543
|
+
)
|
|
544
|
+
) * EFFECTIVE_BALANCE_INCREMENT_BIGINT;
|
|
552
545
|
const adversarialWeight = computeAdversarialWeight(
|
|
553
546
|
ctx,
|
|
554
547
|
store,
|
|
@@ -558,7 +551,7 @@ export function computeEmptySlotSupportDiscount(
|
|
|
558
551
|
(block.slot - 1) as Slot
|
|
559
552
|
);
|
|
560
553
|
|
|
561
|
-
return parentSupportInEmptySlots > adversarialWeight ? parentSupportInEmptySlots - adversarialWeight :
|
|
554
|
+
return parentSupportInEmptySlots > adversarialWeight ? parentSupportInEmptySlots - adversarialWeight : 0n;
|
|
562
555
|
}
|
|
563
556
|
|
|
564
557
|
export function computeSafetyThreshold(
|
|
@@ -568,11 +561,11 @@ export function computeSafetyThreshold(
|
|
|
568
561
|
balanceSource: FastConfirmationBalanceSource,
|
|
569
562
|
blockRoot: RootHex
|
|
570
563
|
): {
|
|
571
|
-
threshold:
|
|
572
|
-
proposerScore:
|
|
573
|
-
maximumSupport:
|
|
574
|
-
supportDiscount:
|
|
575
|
-
adversarialWeight:
|
|
564
|
+
threshold: bigint;
|
|
565
|
+
proposerScore: bigint;
|
|
566
|
+
maximumSupport: bigint;
|
|
567
|
+
supportDiscount: bigint;
|
|
568
|
+
adversarialWeight: bigint;
|
|
576
569
|
} {
|
|
577
570
|
const currentSlot = ctx.getCurrentSlot();
|
|
578
571
|
const block = getBlock(ctx, cache, blockRoot);
|
|
@@ -600,9 +593,9 @@ export function computeSafetyThreshold(
|
|
|
600
593
|
// Spec underflow guard:
|
|
601
594
|
// if the discount alone already exceeds the threshold budget, the safety threshold is zero.
|
|
602
595
|
const threshold =
|
|
603
|
-
supportDiscount > maximumSupport + proposerScore +
|
|
604
|
-
?
|
|
605
|
-
:
|
|
596
|
+
supportDiscount > maximumSupport + proposerScore + 2n * adversarialWeight
|
|
597
|
+
? 0n
|
|
598
|
+
: (maximumSupport + proposerScore + 2n * adversarialWeight - supportDiscount) / 2n;
|
|
606
599
|
|
|
607
600
|
return {threshold, proposerScore, maximumSupport, supportDiscount, adversarialWeight};
|
|
608
601
|
}
|
|
@@ -626,7 +619,8 @@ export function isOneConfirmed(
|
|
|
626
619
|
|
|
627
620
|
// Spec: is_one_confirmed(store, balance_source, block_root)
|
|
628
621
|
// Compare actual support for this block against the computed LMD-GHOST safety threshold.
|
|
629
|
-
const support =
|
|
622
|
+
const support =
|
|
623
|
+
BigInt(getAttestationScore(ctx, cache, balanceSource, blockRoot, sourceKey)) * EFFECTIVE_BALANCE_INCREMENT_BIGINT;
|
|
630
624
|
const {threshold, proposerScore, maximumSupport, supportDiscount, adversarialWeight} = computeSafetyThreshold(
|
|
631
625
|
ctx,
|
|
632
626
|
store,
|
|
@@ -709,18 +703,15 @@ export function getCurrentTargetScore(
|
|
|
709
703
|
}
|
|
710
704
|
|
|
711
705
|
function computeHonestFfgSupport(
|
|
712
|
-
totalActiveBalance:
|
|
713
|
-
ffgSupport:
|
|
714
|
-
ffgWeightTillNow:
|
|
715
|
-
adversarialWeight:
|
|
706
|
+
totalActiveBalance: bigint,
|
|
707
|
+
ffgSupport: bigint,
|
|
708
|
+
ffgWeightTillNow: bigint,
|
|
709
|
+
adversarialWeight: bigint,
|
|
716
710
|
byzantineThreshold: number
|
|
717
|
-
):
|
|
711
|
+
): bigint {
|
|
718
712
|
const remainingFfgWeight = totalActiveBalance - ffgWeightTillNow;
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
// to preserve the same percentage semantics at our coarser unit scale.
|
|
722
|
-
const remainingHonestFfgWeight = Math.floor((remainingFfgWeight * (100 - byzantineThreshold)) / 100);
|
|
723
|
-
const minHonestFfgSupport = ffgSupport - Math.min(adversarialWeight, ffgSupport);
|
|
713
|
+
const remainingHonestFfgWeight = (remainingFfgWeight / 100n) * BigInt(100 - byzantineThreshold);
|
|
714
|
+
const minHonestFfgSupport = ffgSupport > adversarialWeight ? ffgSupport - adversarialWeight : 0n;
|
|
724
715
|
return minHonestFfgSupport + remainingHonestFfgWeight;
|
|
725
716
|
}
|
|
726
717
|
|
|
@@ -728,15 +719,16 @@ export function computeHonestFfgSupportForCurrentTarget(
|
|
|
728
719
|
ctx: FastConfirmationContext,
|
|
729
720
|
store: IFastConfirmationStore,
|
|
730
721
|
cache: FastConfirmationCache
|
|
731
|
-
):
|
|
722
|
+
): bigint {
|
|
732
723
|
const currentSlot = ctx.getCurrentSlot();
|
|
733
|
-
if (currentSlot === 0) return
|
|
724
|
+
if (currentSlot === 0) return 0n;
|
|
734
725
|
const currentEpoch = computeEpochAtSlot(currentSlot);
|
|
735
726
|
const targetState = getCurrentEpochState(ctx, store, cache);
|
|
736
|
-
if (!targetState) return
|
|
727
|
+
if (!targetState) return 0n;
|
|
737
728
|
const targetBalanceSource = {state: targetState, balances: targetState.effectiveBalanceIncrements};
|
|
738
|
-
const totalActiveBalance =
|
|
739
|
-
|
|
729
|
+
const totalActiveBalance =
|
|
730
|
+
BigInt(getTotalActiveBalance(targetBalanceSource, cache)) * EFFECTIVE_BALANCE_INCREMENT_BIGINT;
|
|
731
|
+
const ffgSupport = BigInt(getCurrentTargetScore(ctx, store, cache)) * EFFECTIVE_BALANCE_INCREMENT_BIGINT;
|
|
740
732
|
const tillNowFFGWeight = estimateCommitteeWeightBetweenSlots(
|
|
741
733
|
targetBalanceSource,
|
|
742
734
|
cache,
|
|
@@ -772,12 +764,11 @@ export function willNoConflictingCheckpointBeJustified(
|
|
|
772
764
|
}
|
|
773
765
|
const targetState = getCurrentEpochState(ctx, store, cache);
|
|
774
766
|
if (!targetState) return false;
|
|
775
|
-
const totalActiveBalance =
|
|
776
|
-
{state: targetState, balances: targetState.effectiveBalanceIncrements},
|
|
777
|
-
|
|
778
|
-
);
|
|
767
|
+
const totalActiveBalance =
|
|
768
|
+
BigInt(getTotalActiveBalance({state: targetState, balances: targetState.effectiveBalanceIncrements}, cache)) *
|
|
769
|
+
EFFECTIVE_BALANCE_INCREMENT_BIGINT;
|
|
779
770
|
const honestSupport = computeHonestFfgSupportForCurrentTarget(ctx, store, cache);
|
|
780
|
-
return
|
|
771
|
+
return 3n * honestSupport > 1n * totalActiveBalance;
|
|
781
772
|
}
|
|
782
773
|
|
|
783
774
|
export function willCurrentTargetBeJustified(
|
|
@@ -787,12 +778,11 @@ export function willCurrentTargetBeJustified(
|
|
|
787
778
|
): boolean {
|
|
788
779
|
const targetState = getCurrentEpochState(ctx, store, cache);
|
|
789
780
|
if (!targetState) return false;
|
|
790
|
-
const totalActiveBalance =
|
|
791
|
-
{state: targetState, balances: targetState.effectiveBalanceIncrements},
|
|
792
|
-
|
|
793
|
-
);
|
|
781
|
+
const totalActiveBalance =
|
|
782
|
+
BigInt(getTotalActiveBalance({state: targetState, balances: targetState.effectiveBalanceIncrements}, cache)) *
|
|
783
|
+
EFFECTIVE_BALANCE_INCREMENT_BIGINT;
|
|
794
784
|
const honestSupport = computeHonestFfgSupportForCurrentTarget(ctx, store, cache);
|
|
795
|
-
return
|
|
785
|
+
return 3n * honestSupport >= 2n * totalActiveBalance;
|
|
796
786
|
}
|
|
797
787
|
|
|
798
788
|
export function isConfirmedChainSafe(
|
|
@@ -150,6 +150,8 @@ export class ForkChoice implements IForkChoice {
|
|
|
150
150
|
|
|
151
151
|
/** Cached head */
|
|
152
152
|
private head: ProtoBlock;
|
|
153
|
+
/** Slot of the last `updateHead()`, scores and best child links reflect votes, boost and viability at that slot */
|
|
154
|
+
private updateHeadSlot = 0;
|
|
153
155
|
/**
|
|
154
156
|
* Only cache attestation data root hex if it's tree backed since it's available.
|
|
155
157
|
**/
|
|
@@ -694,6 +696,7 @@ export class ForkChoice implements IForkChoice {
|
|
|
694
696
|
|
|
695
697
|
// findHead returns the ProtoNode representing the head
|
|
696
698
|
this.head = this.protoArray.findHead(this.fcStore.justified.checkpoint.rootHex, currentSlot);
|
|
699
|
+
this.updateHeadSlot = currentSlot;
|
|
697
700
|
return this.head;
|
|
698
701
|
}
|
|
699
702
|
|
|
@@ -1148,7 +1151,7 @@ export class ForkChoice implements IForkChoice {
|
|
|
1148
1151
|
|
|
1149
1152
|
/**
|
|
1150
1153
|
* Notify fork choice that an execution payload has arrived (Gloas fork)
|
|
1151
|
-
* Creates the FULL variant of a Gloas block when the payload becomes available
|
|
1154
|
+
* Creates the FULL variant of a Gloas block when the payload becomes available and refreshes the cached head
|
|
1152
1155
|
* Spec: gloas/fork-choice.md#new-on_execution_payload
|
|
1153
1156
|
*/
|
|
1154
1157
|
onExecutionPayload(
|
|
@@ -1172,9 +1175,10 @@ export class ForkChoice implements IForkChoice {
|
|
|
1172
1175
|
});
|
|
1173
1176
|
}
|
|
1174
1177
|
|
|
1178
|
+
const currentSlot = this.fcStore.currentSlot;
|
|
1175
1179
|
this.protoArray.onExecutionPayload(
|
|
1176
1180
|
blockRoot,
|
|
1177
|
-
|
|
1181
|
+
currentSlot,
|
|
1178
1182
|
executionPayloadBlockHash,
|
|
1179
1183
|
executionPayloadNumber,
|
|
1180
1184
|
executionPayloadGasLimit,
|
|
@@ -1182,6 +1186,11 @@ export class ForkChoice implements IForkChoice {
|
|
|
1182
1186
|
executionStatus,
|
|
1183
1187
|
dataAvailabilityStatus
|
|
1184
1188
|
);
|
|
1189
|
+
if (currentSlot === this.updateHeadSlot) {
|
|
1190
|
+
this.head = this.protoArray.findHead(this.fcStore.justified.checkpoint.rootHex, currentSlot);
|
|
1191
|
+
} else {
|
|
1192
|
+
this.updateHead();
|
|
1193
|
+
}
|
|
1185
1194
|
}
|
|
1186
1195
|
|
|
1187
1196
|
/**
|
|
@@ -211,7 +211,7 @@ export interface IForkChoice {
|
|
|
211
211
|
): void;
|
|
212
212
|
/**
|
|
213
213
|
* Notify fork choice that an execution payload has arrived (Gloas fork)
|
|
214
|
-
* Creates the FULL variant of a Gloas block when the payload becomes available
|
|
214
|
+
* Creates the FULL variant of a Gloas block when the payload becomes available and refreshes the cached head
|
|
215
215
|
*
|
|
216
216
|
* ## Specification
|
|
217
217
|
*
|
|
@@ -711,8 +711,14 @@ export class ProtoArray {
|
|
|
711
711
|
this.propagateValidExecutionStatusByIndex(pendingIndex);
|
|
712
712
|
}
|
|
713
713
|
|
|
714
|
-
//
|
|
715
|
-
|
|
714
|
+
// A zero-weight leaf only changes best child and descendant links on its path to the root
|
|
715
|
+
let childIndex = fullIndex;
|
|
716
|
+
let parentIndex: number | undefined = pendingIndex;
|
|
717
|
+
while (parentIndex !== undefined) {
|
|
718
|
+
this.maybeUpdateBestChildAndDescendant(parentIndex, childIndex, currentSlot, proposerBoostRoot);
|
|
719
|
+
childIndex = parentIndex;
|
|
720
|
+
parentIndex = this.nodes[childIndex].parent;
|
|
721
|
+
}
|
|
716
722
|
}
|
|
717
723
|
|
|
718
724
|
/** Count blocks selected as FULL or EMPTY by the supplied head chain in the inclusive slot range. */
|