@lodestar/fork-choice 1.47.0-dev.9572bcc698 → 1.47.0-dev.9ba9a5ce85
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/forkChoice.d.ts +34 -1
- package/lib/forkChoice/forkChoice.d.ts.map +1 -1
- package/lib/forkChoice/forkChoice.js +147 -26
- package/lib/forkChoice/forkChoice.js.map +1 -1
- package/lib/protoArray/interface.d.ts +3 -1
- package/lib/protoArray/interface.d.ts.map +1 -1
- package/lib/protoArray/protoArray.d.ts +10 -1
- package/lib/protoArray/protoArray.d.ts.map +1 -1
- package/lib/protoArray/protoArray.js +27 -0
- package/lib/protoArray/protoArray.js.map +1 -1
- package/package.json +7 -7
- package/src/forkChoice/forkChoice.ts +173 -28
- package/src/protoArray/interface.ts +8 -1
- package/src/protoArray/protoArray.ts +36 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {DataAvailabilityStatus} from "@lodestar/state-transition";
|
|
2
|
-
import {Epoch, RootHex, Slot, UintNum64} from "@lodestar/types";
|
|
2
|
+
import {Epoch, RootHex, Slot, UintNum64, ValidatorIndex} from "@lodestar/types";
|
|
3
3
|
|
|
4
4
|
// RootHex is a root as a hex string
|
|
5
5
|
// Used for lightweight and easy comparison
|
|
@@ -144,6 +144,13 @@ export type ProtoBlock = BlockExtraMeta & {
|
|
|
144
144
|
// Indicate whether block arrives in a timely manner ie. before the 4 second mark
|
|
145
145
|
timeliness: boolean;
|
|
146
146
|
|
|
147
|
+
// Indicate whether block arrives before the PTC deadline
|
|
148
|
+
// Spec: gloas/fork-choice.md#modified-record_block_timeliness (block_timeliness[PTC_TIMELINESS_INDEX])
|
|
149
|
+
ptcTimeliness: boolean;
|
|
150
|
+
|
|
151
|
+
// The index of the block proposer. Used by should_apply_proposer_boost to detect proposer equivocations
|
|
152
|
+
proposerIndex: ValidatorIndex;
|
|
153
|
+
|
|
147
154
|
/** Payload status for this node (Gloas fork). Always FULL in pre-gloas */
|
|
148
155
|
payloadStatus: PayloadStatus;
|
|
149
156
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {BitArray} from "@chainsafe/ssz";
|
|
2
2
|
import {EFFECTIVE_BALANCE_INCREMENT, GENESIS_EPOCH, GENESIS_SLOT, PTC_SIZE} from "@lodestar/params";
|
|
3
3
|
import {DataAvailabilityStatus, computeEpochAtSlot, computeStartSlotAtEpoch} from "@lodestar/state-transition";
|
|
4
|
-
import {Epoch, RootHex, Slot} from "@lodestar/types";
|
|
4
|
+
import {Epoch, RootHex, Slot, ValidatorIndex} from "@lodestar/types";
|
|
5
5
|
import {bitCount, toRootHex} from "@lodestar/utils";
|
|
6
6
|
import {ForkChoiceError, ForkChoiceErrorCode} from "../forkChoice/errors.js";
|
|
7
7
|
import {LVHExecError, LVHExecErrorCode, ProtoArrayError, ProtoArrayErrorCode} from "./errors.js";
|
|
@@ -2007,6 +2007,41 @@ export class ProtoArray {
|
|
|
2007
2007
|
return this.getNodeByIndex(nodeIndex);
|
|
2008
2008
|
}
|
|
2009
2009
|
|
|
2010
|
+
/**
|
|
2011
|
+
* Return true if a block other than `excludeRoot` at `slot` was proposed by `proposerIndex`.
|
|
2012
|
+
* `should_apply_proposer_boost` only counts PTC-timely blocks (`ptcTimelyOnly`), `is_proposer_equivocation`
|
|
2013
|
+
* counts any known block.
|
|
2014
|
+
*
|
|
2015
|
+
* Iterates unique block roots (via the canonical variant) since `slot`, `proposerIndex` and
|
|
2016
|
+
* `ptcTimeliness` are block-level properties identical across payload-status variants.
|
|
2017
|
+
*/
|
|
2018
|
+
hasEquivocatingBlock(
|
|
2019
|
+
proposerIndex: ValidatorIndex,
|
|
2020
|
+
slot: Slot,
|
|
2021
|
+
excludeRoot: RootHex,
|
|
2022
|
+
ptcTimelyOnly: boolean
|
|
2023
|
+
): boolean {
|
|
2024
|
+
for (const root of this.indices.keys()) {
|
|
2025
|
+
if (root === excludeRoot) {
|
|
2026
|
+
continue;
|
|
2027
|
+
}
|
|
2028
|
+
const nodeIndex = this.getDefaultNodeIndex(root);
|
|
2029
|
+
if (nodeIndex === undefined) {
|
|
2030
|
+
continue;
|
|
2031
|
+
}
|
|
2032
|
+
const node = this.nodes[nodeIndex];
|
|
2033
|
+
if (
|
|
2034
|
+
node !== undefined &&
|
|
2035
|
+
node.slot === slot &&
|
|
2036
|
+
node.proposerIndex === proposerIndex &&
|
|
2037
|
+
(node.ptcTimeliness || !ptcTimelyOnly)
|
|
2038
|
+
) {
|
|
2039
|
+
return true;
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
2042
|
+
return false;
|
|
2043
|
+
}
|
|
2044
|
+
|
|
2010
2045
|
/**
|
|
2011
2046
|
* Return MUTABLE ProtoBlock for blockRoot with explicit payload status
|
|
2012
2047
|
*
|