fix: lint

This commit is contained in:
Tuyen Nguyen
2025-05-14 17:07:32 +07:00
parent d4d0bc5b47
commit 30400be52e
13 changed files with 398 additions and 69 deletions

View File

@@ -1,8 +1,8 @@
import type {ChainForkConfig} from "@lodestar/config";
import {MaybeValidExecutionStatus} from "@lodestar/fork-choice";
import {type ForkPostDeneb, ForkPostFulu, ForkPreFulu, ForkSeq} from "@lodestar/params";
import type {ColumnIndex, RootHex, SignedBeaconBlock, Slot, deneb, fulu} from "@lodestar/types";
import {CachedBeaconStateAllForks, DataAvailabilityStatus, computeEpochAtSlot} from "@lodestar/state-transition";
import type {ColumnIndex, RootHex, SignedBeaconBlock, Slot, deneb, fulu} from "@lodestar/types";
export enum BlockInputType {
// preData is preDeneb

View File

@@ -1,4 +1,5 @@
import {ChainForkConfig} from "@lodestar/config";
import {ForkName} from "@lodestar/params";
import {DataAvailabilityStatus, computeTimeAtSlot} from "@lodestar/state-transition";
import {UintNum64, deneb} from "@lodestar/types";
import {ErrorAborted, Logger} from "@lodestar/utils";
@@ -15,7 +16,6 @@ import {
ImportBlockOpts,
getBlockInput,
} from "./types.js";
import { ForkName } from "@lodestar/params";
// we can now wait for full 12 seconds because unavailable block sync will try pulling
// the blobs from the network anyway after 500ms of seeing the block

View File

@@ -41,6 +41,7 @@ import {
import {Logger, fromHex, gweiToWei, isErrorAborted, pruneSetToMax, sleep, toRootHex} from "@lodestar/utils";
import {ProcessShutdownCallback} from "@lodestar/validator";
import {PrivateKey} from "@libp2p/interface";
import {LoggerNode} from "@lodestar/logger/node";
import {GENESIS_EPOCH, ZERO_HASH} from "../constants/index.js";
import {IBeaconDb} from "../db/index.js";
@@ -107,7 +108,6 @@ import {FIFOBlockStateCache} from "./stateCache/fifoBlockStateCache.js";
import {InMemoryCheckpointStateCache} from "./stateCache/inMemoryCheckpointsCache.js";
import {PersistentCheckpointStateCache} from "./stateCache/persistentCheckpointsCache.js";
import {ValidatorMonitor} from "./validatorMonitor.js";
import { PrivateKey } from "@libp2p/interface";
/**
* Arbitrary constants, blobs and payloads should be consumed immediately in the same slot

View File

@@ -1,6 +1,7 @@
import {PeerScoreStatsDump} from "@chainsafe/libp2p-gossipsub/dist/src/score/peer-score.js";
import {PublishOpts} from "@chainsafe/libp2p-gossipsub/types";
import {Connection, PrivateKey} from "@libp2p/interface";
import {peerIdFromPrivateKey} from "@libp2p/peer-id";
import {routes} from "@lodestar/api";
import {BeaconConfig} from "@lodestar/config";
import type {LoggerNode} from "@lodestar/logger/node";
@@ -33,7 +34,6 @@ import {SyncnetsService} from "../subnets/syncnetsService.js";
import {getConnectionsMap} from "../util.js";
import {NetworkCoreMetrics, createNetworkCoreMetrics} from "./metrics.js";
import {INetworkCore, MultiaddrStr} from "./types.js";
import { peerIdFromPrivateKey } from "@libp2p/peer-id";
type Mods = {
libp2p: Libp2p;

View File

@@ -2,8 +2,8 @@ import {BitArray, toHexString} from "@chainsafe/ssz";
import {Connection, PeerId, PrivateKey} from "@libp2p/interface";
import {BeaconConfig} from "@lodestar/config";
import {LoggerNode} from "@lodestar/logger/node";
import {Metadata, fulu, phase0} from "@lodestar/types";
import {ForkSeq, SLOTS_PER_EPOCH, SYNC_COMMITTEE_SUBNET_COUNT} from "@lodestar/params";
import {Metadata, fulu, phase0} from "@lodestar/types";
import {withTimeout} from "@lodestar/utils";
import {GOODBYE_KNOWN_CODES, GoodByeReasonCode, Libp2pEvent} from "../../constants/index.js";
import {IClock} from "../../util/clock.js";

View File

@@ -348,7 +348,9 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
events.emit(NetworkEvent.unknownBlockInput, {blockInput, peer: peerIdStr});
} else if (blockInput.type === BlockInputType.availableData) {
metrics?.blockInputFetchStats.totalDataAvailableBlockInputs.inc();
metrics?.blockInputFetchStats.totalDataAvailableBlockInputBlobs.inc((blockInput.block.message as deneb.BeaconBlock).body.blobKzgCommitments.length);
metrics?.blockInputFetchStats.totalDataAvailableBlockInputBlobs.inc(
(blockInput.block.message as deneb.BeaconBlock).body.blobKzgCommitments.length
);
}
chain

View File

@@ -2,17 +2,7 @@ import {Type} from "@chainsafe/ssz";
import {BeaconConfig} from "@lodestar/config";
import {ForkName, ForkPostAltair, isForkPostAltair} from "@lodestar/params";
import {Protocol, ProtocolHandler, ReqRespRequest} from "@lodestar/reqresp";
import {
Metadata,
Root,
SignedBeaconBlock,
altair,
deneb,
fulu,
phase0,
ssz,
sszTypesFor,
} from "@lodestar/types";
import {Metadata, Root, SignedBeaconBlock, altair, deneb, fulu, phase0, ssz, sszTypesFor} from "@lodestar/types";
import {BlobSidecarsByRootRequest, BlobSidecarsByRootRequestType} from "../../util/types.js";
export type ProtocolNoHandler = Omit<Protocol, "handler">;

View File

@@ -1,6 +1,6 @@
import {generateKeyPair} from "@libp2p/crypto/keys";
import {afterAll, beforeAll, bench, describe} from "@chainsafe/benchmark";
import {fromHexString} from "@chainsafe/ssz";
import {generateKeyPair} from "@libp2p/crypto/keys";
import {config} from "@lodestar/config/default";
import {LevelDbController} from "@lodestar/db";
import {SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY} from "@lodestar/params";

View File

@@ -1,5 +1,5 @@
import {generateKeyPair} from "@libp2p/crypto/keys";
import {afterAll, beforeAll, bench, describe, setBenchOpts} from "@chainsafe/benchmark";
import {generateKeyPair} from "@libp2p/crypto/keys";
import {config} from "@lodestar/config/default";
import {LevelDbController} from "@lodestar/db";
import {SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY, SLOTS_PER_EPOCH} from "@lodestar/params";

View File

@@ -119,13 +119,20 @@ describe("prioritizePeers", () => {
return {connectedPeers, attnets, syncnets, samplingGroups: []};
},
fn: ({connectedPeers, attnets, syncnets, samplingGroups}) => {
prioritizePeers(connectedPeers, attnets, syncnets, samplingGroups, {
...defaultNetworkOptions,
status: ssz.phase0.Status.defaultValue(),
starved: false,
starvationPruneRatio: 0.05,
starvationThresholdSlots: SLOTS_PER_EPOCH * 2,
}, null);
prioritizePeers(
connectedPeers,
attnets,
syncnets,
samplingGroups,
{
...defaultNetworkOptions,
status: ssz.phase0.Status.defaultValue(),
starved: false,
starvationPruneRatio: 0.05,
starvationThresholdSlots: SLOTS_PER_EPOCH * 2,
},
null
);
},
});
}

View File

@@ -1,6 +1,6 @@
import {generateKeyPair} from "@libp2p/crypto/keys";
import path from "node:path";
import {toHexString} from "@chainsafe/ssz";
import {generateKeyPair} from "@libp2p/crypto/keys";
import {createBeaconConfig} from "@lodestar/config";
import {CheckpointWithHex, ForkChoice} from "@lodestar/fork-choice";
import {ACTIVE_PRESET, ForkName, ForkSeq, isForkPostDeneb} from "@lodestar/params";

View File

@@ -62,7 +62,17 @@ describe("network / peers / priorization", async () => {
},
{
id: "Don't request a subnet query when enough peers are connected to it",
connectedPeers: [{id: peers[0], direction: null, syncnets: none, attnets: getAttnets([3]), custodyGroups: null, score: 0, status}],
connectedPeers: [
{
id: peers[0],
direction: null,
syncnets: none,
attnets: getAttnets([3]),
custodyGroups: null,
score: 0,
status,
},
],
activeAttnets: [3],
activeSyncnets: [],
opts: defaultOpts,
@@ -77,10 +87,42 @@ describe("network / peers / priorization", async () => {
{
id: "Disconnect low score peers without duty",
connectedPeers: [
{id: peers[0], direction: null, syncnets: none, attnets: getAttnets([3]), custodyGroups: null, score: 0, status},
{id: peers[1], direction: null, syncnets: none, attnets: getAttnets([5]), custodyGroups: null, score: -5, status},
{id: peers[2], direction: null, syncnets: none, attnets: getAttnets([5]), custodyGroups: null, score: -10, status},
{id: peers[3], direction: null, syncnets: none, attnets: getAttnets([5, 6, 7]), custodyGroups: null, score: -19, status},
{
id: peers[0],
direction: null,
syncnets: none,
attnets: getAttnets([3]),
custodyGroups: null,
score: 0,
status,
},
{
id: peers[1],
direction: null,
syncnets: none,
attnets: getAttnets([5]),
custodyGroups: null,
score: -5,
status,
},
{
id: peers[2],
direction: null,
syncnets: none,
attnets: getAttnets([5]),
custodyGroups: null,
score: -10,
status,
},
{
id: peers[3],
direction: null,
syncnets: none,
attnets: getAttnets([5, 6, 7]),
custodyGroups: null,
score: -19,
status,
},
],
activeAttnets: [3],
activeSyncnets: [],
@@ -100,7 +142,15 @@ describe("network / peers / priorization", async () => {
{
id: "Disconnect no long-lived-subnet peers without duty",
connectedPeers: [
{id: peers[0], direction: null, syncnets: none, attnets: getAttnets([3]), custodyGroups: null, score: 0, status},
{
id: peers[0],
direction: null,
syncnets: none,
attnets: getAttnets([3]),
custodyGroups: null,
score: 0,
status,
},
{id: peers[1], direction: null, syncnets: none, attnets: none, custodyGroups: null, score: -0.1, status},
{id: peers[2], direction: null, syncnets: none, attnets: none, custodyGroups: null, score: -0.2, status},
{id: peers[3], direction: null, syncnets: none, attnets: none, custodyGroups: null, score: -0.3, status},
@@ -123,13 +173,53 @@ describe("network / peers / priorization", async () => {
id: "Disconnect no-duty peers that's too grouped in a subnet",
connectedPeers: [
// should not drop this peer or duty peers drop below min value
{id: peers[0], direction: null, syncnets: none, attnets: getAttnets([1, 3]), custodyGroups: null, score: 0, status},
{
id: peers[0],
direction: null,
syncnets: none,
attnets: getAttnets([1, 3]),
custodyGroups: null,
score: 0,
status,
},
// below peers are too grouped into subnet 1
{id: peers[1], direction: null, syncnets: none, attnets: getAttnets([1, 4, 6]), custodyGroups: null, score: 0, status},
{id: peers[2], direction: null, syncnets: none, attnets: getAttnets([1, 4]), custodyGroups: null, score: 0, status},
{id: peers[3], direction: null, syncnets: none, attnets: getAttnets([1]), custodyGroups: null, score: 0, status},
{
id: peers[1],
direction: null,
syncnets: none,
attnets: getAttnets([1, 4, 6]),
custodyGroups: null,
score: 0,
status,
},
{
id: peers[2],
direction: null,
syncnets: none,
attnets: getAttnets([1, 4]),
custodyGroups: null,
score: 0,
status,
},
{
id: peers[3],
direction: null,
syncnets: none,
attnets: getAttnets([1]),
custodyGroups: null,
score: 0,
status,
},
// should not remove this peer due or syncnet peers would drop below min value
{id: peers[4], direction: null, syncnets: getSyncnets([2, 3]), attnets: getAttnets([1]), custodyGroups: null, score: 0, status},
{
id: peers[4],
direction: null,
syncnets: getSyncnets([2, 3]),
attnets: getAttnets([1]),
custodyGroups: null,
score: 0,
status,
},
],
activeAttnets: [3],
activeSyncnets: [2],
@@ -149,16 +239,56 @@ describe("network / peers / priorization", async () => {
id: "Disconnect no-duty peers that's too grouped in a subnet - ignore maxPeersSubnet",
connectedPeers: [
// should not drop this peer or duty peers drop below min value
{id: peers[0], direction: null, syncnets: none, attnets: getAttnets([1, 3]), custodyGroups: null, score: 0, status},
{
id: peers[0],
direction: null,
syncnets: none,
attnets: getAttnets([1, 3]),
custodyGroups: null,
score: 0,
status,
},
// below peers are too grouped into subnet 1
// but cannot remove them due to syncnet requirement
{id: peers[1], direction: null, syncnets: getSyncnets([2]), attnets: getAttnets([1, 4, 6]), custodyGroups: null, score: 0, status},
{id: peers[2], direction: null, syncnets: getSyncnets([2]), attnets: getAttnets([1, 4]), custodyGroups: null, score: 0, status},
{
id: peers[1],
direction: null,
syncnets: getSyncnets([2]),
attnets: getAttnets([1, 4, 6]),
custodyGroups: null,
score: 0,
status,
},
{
id: peers[2],
direction: null,
syncnets: getSyncnets([2]),
attnets: getAttnets([1, 4]),
custodyGroups: null,
score: 0,
status,
},
// biggest maxPeerSubnet is 1 (3 peers) but cannot remove all of them
// 2nd biggest maxPeerSubnet is 7, should remove peers from that subnet
{id: peers[3], direction: null, syncnets: none, attnets: getAttnets([7]), custodyGroups: null, score: 0, status},
{
id: peers[3],
direction: null,
syncnets: none,
attnets: getAttnets([7]),
custodyGroups: null,
score: 0,
status,
},
// peer 4 has more long lived subnets than peer 3, should not remove it
{id: peers[4], direction: null, syncnets: none, attnets: getAttnets([7, 8]), custodyGroups: null, score: 0, status},
{
id: peers[4],
direction: null,
syncnets: none,
attnets: getAttnets([7, 8]),
custodyGroups: null,
score: 0,
status,
},
],
activeAttnets: [3],
activeSyncnets: [2],
@@ -177,11 +307,51 @@ describe("network / peers / priorization", async () => {
{
id: "Ensure to prune to target peers",
connectedPeers: [
{id: peers[0], direction: null, syncnets: none, attnets: getAttnets([1, 2, 3]), custodyGroups: null, score: 0, status},
{id: peers[1], direction: null, syncnets: none, attnets: getAttnets([1, 2]), custodyGroups: null, score: -1.9, status},
{id: peers[2], direction: null, syncnets: none, attnets: getAttnets([3, 4]), custodyGroups: null, score: -1.8, status},
{id: peers[3], direction: null, syncnets: none, attnets: getAttnets([4]), custodyGroups: null, score: -1, status},
{id: peers[4], direction: null, syncnets: none, attnets: getAttnets([5]), custodyGroups: null, score: -1.5, status},
{
id: peers[0],
direction: null,
syncnets: none,
attnets: getAttnets([1, 2, 3]),
custodyGroups: null,
score: 0,
status,
},
{
id: peers[1],
direction: null,
syncnets: none,
attnets: getAttnets([1, 2]),
custodyGroups: null,
score: -1.9,
status,
},
{
id: peers[2],
direction: null,
syncnets: none,
attnets: getAttnets([3, 4]),
custodyGroups: null,
score: -1.8,
status,
},
{
id: peers[3],
direction: null,
syncnets: none,
attnets: getAttnets([4]),
custodyGroups: null,
score: -1,
status,
},
{
id: peers[4],
direction: null,
syncnets: none,
attnets: getAttnets([5]),
custodyGroups: null,
score: -1.5,
status,
},
],
activeAttnets: [1, 2, 3],
activeSyncnets: [],
@@ -203,14 +373,78 @@ describe("network / peers / priorization", async () => {
// Peers with a least one attnet, distributed such that 1 peer / subnet.
// Target to disconnect 4 of them, while keeping 25% outbound = 2.
// So should disconnect 4 peers with worse score while keeping 2 outbound with best score.
{id: peers[0], direction: "inbound", syncnets: none, attnets: getAttnets([0]), custodyGroups: null, score: 0, status},
{id: peers[1], direction: "inbound", syncnets: none, attnets: getAttnets([1]), custodyGroups: null, score: -10, status},
{id: peers[2], direction: "inbound", syncnets: none, attnets: getAttnets([2]), custodyGroups: null, score: -20, status},
{id: peers[3], direction: "inbound", syncnets: none, attnets: getAttnets([3]), custodyGroups: null, score: -30, status},
{id: peers[4], direction: "outbound", syncnets: none, attnets: getAttnets([4]), custodyGroups: null, score: -40, status},
{id: peers[5], direction: "outbound", syncnets: none, attnets: getAttnets([5]), custodyGroups: null, score: -50, status},
{id: peers[6], direction: "outbound", syncnets: none, attnets: getAttnets([6]), custodyGroups: null, score: -60, status},
{id: peers[7], direction: "outbound", syncnets: none, attnets: getAttnets([7]), custodyGroups: null, score: -70, status},
{
id: peers[0],
direction: "inbound",
syncnets: none,
attnets: getAttnets([0]),
custodyGroups: null,
score: 0,
status,
},
{
id: peers[1],
direction: "inbound",
syncnets: none,
attnets: getAttnets([1]),
custodyGroups: null,
score: -10,
status,
},
{
id: peers[2],
direction: "inbound",
syncnets: none,
attnets: getAttnets([2]),
custodyGroups: null,
score: -20,
status,
},
{
id: peers[3],
direction: "inbound",
syncnets: none,
attnets: getAttnets([3]),
custodyGroups: null,
score: -30,
status,
},
{
id: peers[4],
direction: "outbound",
syncnets: none,
attnets: getAttnets([4]),
custodyGroups: null,
score: -40,
status,
},
{
id: peers[5],
direction: "outbound",
syncnets: none,
attnets: getAttnets([5]),
custodyGroups: null,
score: -50,
status,
},
{
id: peers[6],
direction: "outbound",
syncnets: none,
attnets: getAttnets([6]),
custodyGroups: null,
score: -60,
status,
},
{
id: peers[7],
direction: "outbound",
syncnets: none,
attnets: getAttnets([7]),
custodyGroups: null,
score: -70,
status,
},
],
activeAttnets: [],
activeSyncnets: [],
@@ -230,14 +464,78 @@ describe("network / peers / priorization", async () => {
{
id: "Complete example: Disconnect peers and request a subnet query",
connectedPeers: [
{id: peers[0], direction: null, syncnets: none, attnets: getAttnets([0, 1, 2]), custodyGroups: null, score: 0, status},
{id: peers[1], direction: null, syncnets: none, attnets: getAttnets([0, 1, 2]), custodyGroups: null, score: -10, status},
{id: peers[2], direction: null, syncnets: none, attnets: getAttnets([0, 1]), custodyGroups: null, score: 0, status},
{id: peers[3], direction: null, syncnets: none, attnets: getAttnets([0]), custodyGroups: null, score: -10, status},
{id: peers[4], direction: null, syncnets: none, attnets: getAttnets([2]), custodyGroups: null, score: 0, status},
{id: peers[5], direction: null, syncnets: none, attnets: getAttnets([0, 2]), custodyGroups: null, score: -20, status},
{id: peers[6], direction: null, syncnets: none, attnets: getAttnets([1, 2, 3]), custodyGroups: null, score: 0, status},
{id: peers[7], direction: null, syncnets: none, attnets: getAttnets([1, 2]), custodyGroups: null, score: -10, status},
{
id: peers[0],
direction: null,
syncnets: none,
attnets: getAttnets([0, 1, 2]),
custodyGroups: null,
score: 0,
status,
},
{
id: peers[1],
direction: null,
syncnets: none,
attnets: getAttnets([0, 1, 2]),
custodyGroups: null,
score: -10,
status,
},
{
id: peers[2],
direction: null,
syncnets: none,
attnets: getAttnets([0, 1]),
custodyGroups: null,
score: 0,
status,
},
{
id: peers[3],
direction: null,
syncnets: none,
attnets: getAttnets([0]),
custodyGroups: null,
score: -10,
status,
},
{
id: peers[4],
direction: null,
syncnets: none,
attnets: getAttnets([2]),
custodyGroups: null,
score: 0,
status,
},
{
id: peers[5],
direction: null,
syncnets: none,
attnets: getAttnets([0, 2]),
custodyGroups: null,
score: -20,
status,
},
{
id: peers[6],
direction: null,
syncnets: none,
attnets: getAttnets([1, 2, 3]),
custodyGroups: null,
score: 0,
status,
},
{
id: peers[7],
direction: null,
syncnets: none,
attnets: getAttnets([1, 2]),
custodyGroups: null,
score: -10,
status,
},
],
activeAttnets: [1, 3],
activeSyncnets: [],
@@ -343,10 +641,42 @@ describe("sortPeersToPrune", async () => {
it("should sort peers by dutied subnets then long lived subnets then score", () => {
const connectedPeers = [
{id: peers[3], direction: null, syncnets: none, attnets: getAttnets([0, 4]), score: -1, custodyGroups: [], statusScore: -1},
{id: peers[2], direction: null, syncnets: none, attnets: getAttnets([2, 3, 5]), score: 0, custodyGroups: [], statusScore: -1},
{id: peers[1], direction: null, syncnets: none, attnets: getAttnets([3, 5]), score: -1, custodyGroups: [], statusScore: -1},
{id: peers[0], direction: null, syncnets: none, attnets: getAttnets([6, 7]), score: -1.9, custodyGroups: [], statusScore: -1},
{
id: peers[3],
direction: null,
syncnets: none,
attnets: getAttnets([0, 4]),
score: -1,
custodyGroups: [],
statusScore: -1,
},
{
id: peers[2],
direction: null,
syncnets: none,
attnets: getAttnets([2, 3, 5]),
score: 0,
custodyGroups: [],
statusScore: -1,
},
{
id: peers[1],
direction: null,
syncnets: none,
attnets: getAttnets([3, 5]),
score: -1,
custodyGroups: [],
statusScore: -1,
},
{
id: peers[0],
direction: null,
syncnets: none,
attnets: getAttnets([6, 7]),
score: -1.9,
custodyGroups: [],
statusScore: -1,
},
].map((p) => ({
...p,
attnetsTrueBitIndices: p.attnets?.getTrueBitIndexes() ?? [],

View File

@@ -3,8 +3,8 @@ import os from "node:os";
import path from "node:path";
import {SignableENR} from "@chainsafe/enr";
import {generateKeyPair} from "@libp2p/crypto/keys";
import {Logger} from "@lodestar/utils";
import type {PrivateKey} from "@libp2p/interface";
import {Logger} from "@lodestar/utils";
import {Multiaddr} from "@multiformats/multiaddr";
import {exportToJSON, readPrivateKey} from "../../config/index.js";
import {parseListenArgs} from "../../options/beaconNodeOptions/network.js";