Skip to content

Commit

Permalink
feat: update configs to be able to support Deneb on all networks (Cha…
Browse files Browse the repository at this point in the history
…inSafe#6328)

* Move `MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS` from constants to config

* Align structure / comments with consensus spec

* Add references to preset / config files

* Rename directory and files that contain config values

* Add comment to networking params
  • Loading branch information
nflaig authored Jan 23, 2024
1 parent 1f38b1b commit 9b44056
Show file tree
Hide file tree
Showing 25 changed files with 86 additions and 37 deletions.
4 changes: 2 additions & 2 deletions packages/beacon-node/src/chain/archiver/archiveBlocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {fromHexString} from "@chainsafe/ssz";
import {Epoch, Slot, RootHex} from "@lodestar/types";
import {IForkChoice} from "@lodestar/fork-choice";
import {Logger, toHex} from "@lodestar/utils";
import {ForkSeq, SLOTS_PER_EPOCH, MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS} from "@lodestar/params";
import {ForkSeq, SLOTS_PER_EPOCH} from "@lodestar/params";
import {computeEpochAtSlot, computeStartSlotAtEpoch} from "@lodestar/state-transition";
import {KeyValue} from "@lodestar/db";
import {ChainForkConfig} from "@lodestar/config";
Expand Down Expand Up @@ -83,7 +83,7 @@ export async function archiveBlocks(
// Delete expired blobs
// Keep only `[max(GENESIS_EPOCH, current_epoch - MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS), current_epoch]`
if (finalizedPostDeneb) {
const blobSidecarsMinEpoch = currentEpoch - MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS;
const blobSidecarsMinEpoch = currentEpoch - config.MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS;
if (blobSidecarsMinEpoch >= config.DENEB_FORK_EPOCH) {
const slotsToDelete = await db.blobSidecarsArchive.keys({lt: computeStartSlotAtEpoch(blobSidecarsMinEpoch)});
if (slotsToDelete.length > 0) {
Expand Down
4 changes: 2 additions & 2 deletions packages/beacon-node/src/chain/blocks/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {CachedBeaconStateAllForks, computeEpochAtSlot, DataAvailableStatus} from "@lodestar/state-transition";
import {MaybeValidExecutionStatus} from "@lodestar/fork-choice";
import {allForks, deneb, Slot} from "@lodestar/types";
import {ForkSeq, MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS} from "@lodestar/params";
import {ForkSeq} from "@lodestar/params";
import {ChainForkConfig} from "@lodestar/config";

export enum BlockInputType {
Expand Down Expand Up @@ -36,7 +36,7 @@ export function blockRequiresBlobs(config: ChainForkConfig, blockSlot: Slot, clo
return (
config.getForkSeq(blockSlot) >= ForkSeq.deneb &&
// Only request blobs if they are recent enough
computeEpochAtSlot(blockSlot) >= computeEpochAtSlot(clockSlot) - MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS
computeEpochAtSlot(blockSlot) >= computeEpochAtSlot(clockSlot) - config.MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {ChainForkConfig} from "@lodestar/config";
import {deneb, Epoch, phase0, allForks, Slot} from "@lodestar/types";
import {ForkSeq, MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS} from "@lodestar/params";
import {ForkSeq} from "@lodestar/params";
import {computeEpochAtSlot} from "@lodestar/state-transition";

import {BlockInput, BlockSource, getBlockInput} from "../../chain/blocks/types.js";
Expand Down Expand Up @@ -37,7 +37,7 @@ export async function beaconBlocksMaybeBlobsByRange(
}

// Only request blobs if they are recent enough
else if (computeEpochAtSlot(startSlot) >= currentEpoch - MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS) {
else if (computeEpochAtSlot(startSlot) >= currentEpoch - config.MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS) {
const [allBlocks, allBlobSidecars] = await Promise.all([
network.sendBeaconBlocksByRange(peerId, request),
network.sendBlobSidecarsByRange(peerId, request),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {describe, it, expect} from "vitest";
import {TopicScoreParams} from "@chainsafe/libp2p-gossipsub/score";
import {ATTESTATION_SUBNET_COUNT, ForkName, SLOTS_PER_EPOCH} from "@lodestar/params";
import {createBeaconConfig} from "@lodestar/config";
import {mainnetChainConfig} from "@lodestar/config/presets";
import {mainnetChainConfig} from "@lodestar/config/configs";
import {computeGossipPeerScoreParams, gossipScoreThresholds} from "../../../../src/network/gossip/scoringParameters.js";
import {stringifyGossipTopic} from "../../../../src/network/gossip/topic.js";
import {GossipType} from "../../../../src/network/index.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/networks/dev.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {gnosisChainConfig} from "@lodestar/config/networks";
import {minimalChainConfig, mainnetChainConfig} from "@lodestar/config/presets";
import {minimalChainConfig, mainnetChainConfig} from "@lodestar/config/configs";
import {ACTIVE_PRESET, PresetName} from "@lodestar/params";

let chainConfig;
Expand Down
4 changes: 2 additions & 2 deletions packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"./networks": {
"import": "./lib/networks.js"
},
"./presets": {
"import": "./lib/presets.js"
"./configs": {
"import": "./lib/configs.js"
}
},
"typesVersions": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import {fromHexString as b} from "@chainsafe/ssz";
import {PresetName} from "@lodestar/params";
import {ChainConfig} from "../types.js";

// Mainnet config
// https://github.com/ethereum/consensus-specs/blob/dev/configs/mainnet.yaml

export const chainConfig: ChainConfig = {
// Extends the mainnet preset
PRESET_BASE: PresetName.mainnet,
CONFIG_NAME: "mainnet",

Expand Down Expand Up @@ -41,7 +45,7 @@ export const chainConfig: ChainConfig = {
CAPELLA_FORK_VERSION: b("0x03000000"),
CAPELLA_FORK_EPOCH: 194048, // April 12 (epoch: 194048 slot: 6209536 UTC: 4/12/2023, 10:27:35 PM)

// DENEB
// Deneb
DENEB_FORK_VERSION: b("0x04000000"),
DENEB_FORK_EPOCH: Infinity,

Expand All @@ -68,9 +72,14 @@ export const chainConfig: ChainConfig = {
EJECTION_BALANCE: 16000000000,
// 2**2 (= 4)
MIN_PER_EPOCH_CHURN_LIMIT: 4,
// 2**3 (= 8)
MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT: 8,
// 2**16 (= 65,536)
CHURN_LIMIT_QUOTIENT: 65536,

// Fork choice
// ---------------------------------------------------------------
// 40%
PROPOSER_SCORE_BOOST: 40,

// Deposit contract
Expand All @@ -79,4 +88,11 @@ export const chainConfig: ChainConfig = {
DEPOSIT_CHAIN_ID: 1,
DEPOSIT_NETWORK_ID: 1,
DEPOSIT_CONTRACT_ADDRESS: b("0x00000000219ab540356cBB839Cbe05303d7705Fa"),

// Networking
// ---------------------------------------------------------------

// Deneb
// `2**12` (= 4096 epochs, ~18 days)
MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS: 4096,
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import {fromHexString as b} from "@chainsafe/ssz";
import {PresetName} from "@lodestar/params";
import {ChainConfig} from "../types.js";

// Minimal config
// https://github.com/ethereum/consensus-specs/blob/dev/configs/minimal.yaml

export const chainConfig: ChainConfig = {
// Extends the minimal preset
PRESET_BASE: PresetName.minimal,
Expand Down Expand Up @@ -66,9 +69,14 @@ export const chainConfig: ChainConfig = {
EJECTION_BALANCE: 16000000000,
// 2**2 (= 4)
MIN_PER_EPOCH_CHURN_LIMIT: 2,
// [customized]
MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT: 4,
// [customized] scale queue churn at much lower validator counts for testing
CHURN_LIMIT_QUOTIENT: 32,

// Fork choice
// ---------------------------------------------------------------
// 40%
PROPOSER_SCORE_BOOST: 40,

// Deposit contract
Expand All @@ -78,4 +86,11 @@ export const chainConfig: ChainConfig = {
DEPOSIT_NETWORK_ID: 5,
// Configured on a per testnet basis
DEPOSIT_CONTRACT_ADDRESS: b("0x1234567890123456789012345678901234567890"),

// Networking
// ---------------------------------------------------------------

// Deneb
// `2**12` (= 4096 epochs, ~18 days)
MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS: 4096,
};
4 changes: 2 additions & 2 deletions packages/config/src/chainConfig/default.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ACTIVE_PRESET, PresetName} from "@lodestar/params";
import {ChainConfig} from "./types.js";
import {chainConfig as mainnet} from "./presets/mainnet.js";
import {chainConfig as minimal} from "./presets/minimal.js";
import {chainConfig as mainnet} from "./configs/mainnet.js";
import {chainConfig as minimal} from "./configs/minimal.js";

let defaultChainConfig: ChainConfig;

Expand Down
3 changes: 3 additions & 0 deletions packages/config/src/chainConfig/networks/chiado.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import {fromHexString as b} from "@chainsafe/ssz";
import {ChainConfig} from "../types.js";
import {gnosisChainConfig as gnosis} from "./gnosis.js";

// Chiado beacon chain config:
// https://github.com/gnosischain/configs/blob/main/chiado/config.yaml

export const chiadoChainConfig: ChainConfig = {
...gnosis,

Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/chainConfig/networks/ephemery.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/naming-convention */
import {fromHexString as b} from "@chainsafe/ssz";
import {ChainConfig} from "../types.js";
import {chainConfig as mainnet} from "../presets/mainnet.js";
import {chainConfig as mainnet} from "../configs/mainnet.js";

// Ephemery dynamic beacon chain config:
// https://github.com/ephemery-testnet/ephemery-genesis/blob/master/cl-config.yaml
Expand Down
5 changes: 4 additions & 1 deletion packages/config/src/chainConfig/networks/gnosis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import {fromHexString as b} from "@chainsafe/ssz";
import {PresetName} from "@lodestar/params";
import {ChainConfig} from "../types.js";
import {chainConfig as mainnet} from "../presets/mainnet.js";
import {chainConfig as mainnet} from "../configs/mainnet.js";

// Gnosis beacon chain config:
// https://github.com/gnosischain/configs/blob/main/mainnet/config.yaml

export const gnosisChainConfig: ChainConfig = {
...mainnet,
Expand Down
5 changes: 4 additions & 1 deletion packages/config/src/chainConfig/networks/goerli.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/* eslint-disable @typescript-eslint/naming-convention */
import {fromHexString as b} from "@chainsafe/ssz";
import {ChainConfig} from "../types.js";
import {chainConfig as mainnet} from "../presets/mainnet.js";
import {chainConfig as mainnet} from "../configs/mainnet.js";

// Goerli beacon chain config:
// https://github.com/eth-clients/goerli/blob/main/prater/config.yaml

export const goerliChainConfig: ChainConfig = {
...mainnet,
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/chainConfig/networks/holesky.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/naming-convention */
import {fromHexString as b} from "@chainsafe/ssz";
import {ChainConfig} from "../types.js";
import {chainConfig as mainnet} from "../presets/mainnet.js";
import {chainConfig as mainnet} from "../configs/mainnet.js";

// Holesky beacon chain config:
// https://github.com/eth-clients/holesky/blob/main/custom_config_data/config.yaml
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/chainConfig/networks/mainnet.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/naming-convention */
import {fromHexString as b} from "@chainsafe/ssz";
import {ChainConfig} from "../types.js";
import {chainConfig as mainnet} from "../presets/mainnet.js";
import {chainConfig as mainnet} from "../configs/mainnet.js";

export const mainnetChainConfig: ChainConfig = {
...mainnet,
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/chainConfig/networks/ropsten.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/naming-convention */
import {fromHexString as b} from "@chainsafe/ssz";
import {ChainConfig} from "../types.js";
import {chainConfig as mainnet} from "../presets/mainnet.js";
import {chainConfig as mainnet} from "../configs/mainnet.js";

// Ropsten beacon chain config:
// https://github.com/eth-clients/merge-testnets/blob/main/ropsten-beacon-chain/config.yaml
Expand Down
4 changes: 2 additions & 2 deletions packages/config/src/chainConfig/networks/sepolia.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable @typescript-eslint/naming-convention */
import {fromHexString as b} from "@chainsafe/ssz";
import {ChainConfig} from "../types.js";
import {chainConfig as mainnet} from "../presets/mainnet.js";
import {chainConfig as mainnet} from "../configs/mainnet.js";

// Sepolia beacon chain config:
// https://github.com/eth-clients/merge-testnets/blob/main/sepolia-beacon-chain/config.yaml
// https://github.com/eth-clients/sepolia/blob/main/bepolia/config.yaml

export const sepoliaChainConfig: ChainConfig = {
...mainnet,
Expand Down
10 changes: 8 additions & 2 deletions packages/config/src/chainConfig/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,16 @@ export type ChainConfig = {
MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT: number;
CHURN_LIMIT_QUOTIENT: number;

// Proposer boost
// Fork choice
PROPOSER_SCORE_BOOST: number;

// Deposit contract
DEPOSIT_CHAIN_ID: number;
DEPOSIT_NETWORK_ID: number;
DEPOSIT_CONTRACT_ADDRESS: Uint8Array;

// Networking
MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS: number;
};

export const chainConfigTypes: SpecTypes<ChainConfig> = {
Expand Down Expand Up @@ -109,13 +112,16 @@ export const chainConfigTypes: SpecTypes<ChainConfig> = {
MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT: "number",
CHURN_LIMIT_QUOTIENT: "number",

// Proposer boost
// Fork choice
PROPOSER_SCORE_BOOST: "number",

// Deposit contract
DEPOSIT_CHAIN_ID: "number",
DEPOSIT_NETWORK_ID: "number",
DEPOSIT_CONTRACT_ADDRESS: "bytes",

// Networking
MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS: "number",
};

/** Allows values in a Spec file */
Expand Down
4 changes: 4 additions & 0 deletions packages/config/src/configs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {chainConfig as mainnetChainConfig} from "./chainConfig/configs/mainnet.js";
import {chainConfig as minimalChainConfig} from "./chainConfig/configs/minimal.js";

export {mainnetChainConfig, minimalChainConfig};
4 changes: 0 additions & 4 deletions packages/config/src/presets.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/params/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ export const SYNC_COMMITTEE_SUBNET_SIZE = Math.floor(SYNC_COMMITTEE_SIZE / SYNC_
export const MAX_REQUEST_BLOCKS = 2 ** 10; // 1024
export const MAX_REQUEST_BLOCKS_DENEB = 2 ** 7; // 128
export const MAX_REQUEST_BLOB_SIDECARS = MAX_REQUEST_BLOCKS_DENEB * MAX_BLOBS_PER_BLOCK;
export const MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS = 2 ** 12; // 4096 epochs, ~18 days

// Lightclient pre-computed
/**
Expand Down
3 changes: 3 additions & 0 deletions packages/params/src/presets/gnosis.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {BeaconPreset} from "../types.js";
import {mainnetPreset} from "./mainnet.js";

// Gnosis preset
// https://github.com/gnosischain/specs/tree/master/consensus/preset/gnosis

/* eslint-disable @typescript-eslint/naming-convention */
export const gnosisPreset: BeaconPreset = {
...mainnetPreset,
Expand Down
4 changes: 3 additions & 1 deletion packages/params/src/presets/mainnet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import {BeaconPreset} from "../types.js";

// Mainnet preset
// https://github.com/ethereum/consensus-specs/tree/dev/presets/mainnet

/* eslint-disable @typescript-eslint/naming-convention */
export const mainnetPreset: BeaconPreset = {
// Misc
Expand Down Expand Up @@ -111,7 +114,6 @@ export const mainnetPreset: BeaconPreset = {

// DENEB
///////////
// https://github.com/ethereum/consensus-specs/blob/dev/presets/mainnet/eip4844.yaml
FIELD_ELEMENTS_PER_BLOB: 4096,
MAX_BLOB_COMMITMENTS_PER_BLOCK: 4096,
MAX_BLOBS_PER_BLOCK: 6,
Expand Down
10 changes: 3 additions & 7 deletions packages/params/src/presets/minimal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import {BeaconPreset} from "../types.js";

// Minimal preset
// https://github.com/ethereum/consensus-specs/tree/dev/presets/minimal

/* eslint-disable @typescript-eslint/naming-convention */
export const minimalPreset: BeaconPreset = {
// Misc
Expand Down Expand Up @@ -42,12 +45,6 @@ export const minimalPreset: BeaconPreset = {
EPOCHS_PER_ETH1_VOTING_PERIOD: 4,
// [customized] smaller state
SLOTS_PER_HISTORICAL_ROOT: 64,
/*
// 2**8 (= 256) epochs
MIN_VALIDATOR_WITHDRAWABILITY_DELAY: 256,
// [customized] higher frequency of committee turnover and faster time to acceptable voluntary exit
SHARD_COMMITTEE_PERIOD: 64,
*/
// 2**2 (= 4) epochs
MIN_EPOCHS_TO_INACTIVITY_PENALTY: 4,

Expand Down Expand Up @@ -118,7 +115,6 @@ export const minimalPreset: BeaconPreset = {

// DENEB
///////////
// https://github.com/ethereum/consensus-specs/blob/dev/presets/minimal/eip4844.yaml
FIELD_ELEMENTS_PER_BLOB: 4096,
MAX_BLOB_COMMITMENTS_PER_BLOCK: 16,
MAX_BLOBS_PER_BLOCK: 6,
Expand Down
5 changes: 4 additions & 1 deletion packages/validator/src/util/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,17 @@ function getSpecCriticalParams(localConfig: ChainConfig): Record<keyof ConfigWit
MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT: denebForkRelevant,
CHURN_LIMIT_QUOTIENT: true,

// Proposer boost
// Fork choice
PROPOSER_SCORE_BOOST: false, // Ignored as it's changing https://github.com/ethereum/consensus-specs/pull/2895

// Deposit contract
DEPOSIT_CHAIN_ID: false, // Non-critical
DEPOSIT_NETWORK_ID: false, // Non-critical
DEPOSIT_CONTRACT_ADDRESS: true,

// Networking (non-critical as those do not affect consensus)
MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS: false,

// # Phase0Preset
/////////////////

Expand Down

0 comments on commit 9b44056

Please sign in to comment.