Skip to content

Commit

Permalink
feat: add network.targetColumnSubnetPeers cli flag
Browse files Browse the repository at this point in the history
  • Loading branch information
twoeths committed Dec 3, 2024
1 parent a7423f6 commit 64aeadb
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
2 changes: 2 additions & 0 deletions packages/beacon-node/src/network/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ export const defaultNetworkOptions: NetworkOptions = {
beaconAttestationBatchValidation: true,
// This will enable the light client server by default
disableLightClientServer: false,
// for PeerDAS, this is the same to TARGET_SUBNET_PEERS, should reavaluate after devnets
targetColumnSubnetPeers: 6,
};
7 changes: 2 additions & 5 deletions packages/beacon-node/src/network/peers/peerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
assertPeerRelevance,
prioritizePeers,
renderIrrelevantPeerType,
PrioritizePeersOpts,
} from "./utils/index.js";
import {IPeerRpcScoreStore, PeerAction, PeerScoreStats, ScoreState, updateGossipsubScores} from "./score/index.js";

Expand Down Expand Up @@ -65,10 +66,6 @@ const ALLOWED_NEGATIVE_GOSSIPSUB_FACTOR = 0.1;
// to terminal if it deviates significantly from the user's settings

export type PeerManagerOpts = {
/** The target number of peers we would like to connect to. */
targetPeers: number;
/** The maximum number of peers we allow (exceptions for subnet peers) */
maxPeers: number;
/**
* Delay the 1st query after starting discv5
* See https://github.com/ChainSafe/lodestar/issues/3423
Expand All @@ -82,7 +79,7 @@ export type PeerManagerOpts = {
* If set to true, connect to Discv5 bootnodes. If not set or false, do not connect
*/
connectToDiscv5Bootnodes?: boolean;
};
} & PrioritizePeersOpts;

/**
* ReqResp methods used only be PeerManager, so the main thread never has to call them
Expand Down
14 changes: 8 additions & 6 deletions packages/beacon-node/src/network/peers/utils/prioritizePeers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ type PeerInfo = {
score: number;
};

export interface PrioritizePeersOpts {
export type PrioritizePeersOpts = {
targetPeers: number;
maxPeers: number;
targetColumnSubnetPeers: number;
outboundPeersRatio?: number;
targetSubnetPeers?: number;
}
};

export enum ExcessPeerDisconnectReason {
LOW_SCORE = "low_score",
Expand Down Expand Up @@ -118,7 +119,7 @@ export function prioritizePeers(
})
);

const {attnetQueries, syncnetQueries, columnSubnetQueries, dutiesByPeer} = requestAttnetPeers(
const {attnetQueries, syncnetQueries, columnSubnetQueries, dutiesByPeer} = requestSubnetPeers(
connectedPeers,
activeAttnets,
activeSyncnets,
Expand Down Expand Up @@ -155,7 +156,7 @@ export function prioritizePeers(
/**
* If more peers are needed in attnets and syncnets and column subnets, create SubnetDiscvQuery for each subnet
*/
function requestAttnetPeers(
function requestSubnetPeers(
connectedPeers: PeerInfo[],
activeAttnets: RequestedSubnet[],
activeSyncnets: RequestedSubnet[],
Expand Down Expand Up @@ -231,6 +232,7 @@ function requestAttnetPeers(
}

// column subnets, do we need queries for more peers
const targetColumnSubnetPeers = opts.targetColumnSubnetPeers;
const columnSubnetQueries: ColumnSubnetQueries = new Map();
const peersPerColumnSubnet = new Map<ColumnSubnetId, number>();
for (const peer of connectedPeers) {
Expand All @@ -242,9 +244,9 @@ function requestAttnetPeers(

for (const columnSubnet of samplingSubnets) {
const peersInColumnSubnet = peersPerColumnSubnet.get(columnSubnet) ?? 0;
if (peersInColumnSubnet < targetSubnetPeers) {
if (peersInColumnSubnet < targetColumnSubnetPeers) {
// We need more peers
columnSubnetQueries.set(columnSubnet, targetSubnetPeers - peersInColumnSubnet);
columnSubnetQueries.set(columnSubnet, targetColumnSubnetPeers - peersInColumnSubnet);
}
}

Expand Down
10 changes: 10 additions & 0 deletions packages/cli/src/options/beaconNodeOptions/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type NetworkArgs = {
"network.maxGossipTopicConcurrency"?: number;
"network.useWorker"?: boolean;
"network.maxYoungGenerationSizeMb"?: number;
"network.targetColumnSubnetPeers"?: number;

/** @deprecated This option is deprecated and should be removed in next major release. */
"network.requestCountPeerLimit"?: number;
Expand Down Expand Up @@ -156,6 +157,7 @@ export function parseArgs(args: NetworkArgs): IBeaconNodeOptions["network"] {
maxGossipTopicConcurrency: args["network.maxGossipTopicConcurrency"],
useWorker: args["network.useWorker"],
maxYoungGenerationSizeMb: args["network.maxYoungGenerationSizeMb"],
targetColumnSubnetPeers: args["network.targetColumnSubnetPeers"] ?? defaultOptions.network.targetColumnSubnetPeers,
};
}

Expand Down Expand Up @@ -396,4 +398,12 @@ export const options: CliCommandOptions<NetworkArgs> = {
description: "Max size of young generation in megabytes. Defaults to 152mb",
defaultDescription: String(defaultOptions.network.maxYoungGenerationSizeMb),
},

"network.targetColumnSubnetPeers": {
type: "number",
hidden: true,
group: "network",
description: "Target number of peers per sampling column subnet",
defaultDescription: String(defaultOptions.network.targetColumnSubnetPeers),
},
};
2 changes: 2 additions & 0 deletions packages/cli/test/unit/options/beaconNodeOptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ describe("options / beaconNodeOptions", () => {
"network.maxGossipTopicConcurrency": 64,
"network.useWorker": true,
"network.maxYoungGenerationSizeMb": 152,
"network.targetColumnSubnetPeers": 12,

"sync.isSingleNode": true,
"sync.disableProcessAsChainSegment": true,
Expand Down Expand Up @@ -215,6 +216,7 @@ describe("options / beaconNodeOptions", () => {
maxGossipTopicConcurrency: 64,
useWorker: true,
maxYoungGenerationSizeMb: 152,
targetColumnSubnetPeers: 12,
},
sync: {
isSingleNode: true,
Expand Down

0 comments on commit 64aeadb

Please sign in to comment.