Skip to content

Commit

Permalink
Merge branch 'unstable' into cayman/bump-libp2p
Browse files Browse the repository at this point in the history
  • Loading branch information
wemeetagain committed Feb 6, 2025
2 parents e64ff6f + 9c66fac commit 5366dd3
Show file tree
Hide file tree
Showing 162 changed files with 1,688 additions and 1,817 deletions.
15 changes: 8 additions & 7 deletions .benchrc.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Mocha opts
extension: ["ts"]
colors: true
node-option:
- "loader=ts-node/register"

# benchmark opts
threshold: 3
maxMs: 60_000
maxMs: 60000
minRuns: 10
# Default is set to 0.005, which is too low considering the benchmark setup we have
# Changing it to 0.05 which is 5/100, so 5% difference of moving average among run times
convergeFactor: 0.075 # 7.5 / 100
triggerGC: false
sort: true
convergence: linear
averageCalculation: clean-outliers
8 changes: 0 additions & 8 deletions biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,6 @@
}
}
},
// Dependencies still using mocha
{
"include": ["packages/**/test/perf/**/*.test.ts", "packages/state-transition/test/utils/beforeValueMocha.ts"],
"javascript": {
// These are used by mocha
"globals": ["describe", "it", "before", "after"]
}
},
{
"include": [
// These files are using mix cases e.g. `engine_newPayloadV4`
Expand Down
345 changes: 113 additions & 232 deletions dashboards/lodestar_block_processor.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
],
"npmClient": "yarn",
"useNx": true,
"version": "1.25.0",
"version": "1.26.0",
"stream": true,
"command": {
"version": {
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@
},
"devDependencies": {
"@actions/core": "^1.10.1",
"@dapplion/benchmark": "^0.2.4",
"@chainsafe/benchmark": "^1.2.3",
"@biomejs/biome": "^1.9.3",
"@types/mocha": "^10.0.6",
"@types/node": "^20.12.8",
"@vitest/browser": "^2.0.4",
"@vitest/coverage-v8": "^2.0.4",
Expand All @@ -61,7 +60,6 @@
"jsdom": "^23.0.1",
"lerna": "^7.3.0",
"libp2p": "2.5.0",
"mocha": "^10.2.0",
"node-gyp": "^9.4.0",
"npm-run-all": "^4.1.5",
"path-browserify": "^1.0.1",
Expand Down
12 changes: 6 additions & 6 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"bugs": {
"url": "https://github.com/ChainSafe/lodestar/issues"
},
"version": "1.25.0",
"version": "1.26.0",
"type": "module",
"exports": {
".": {
Expand Down Expand Up @@ -71,11 +71,11 @@
},
"dependencies": {
"@chainsafe/persistent-merkle-tree": "^1.0.1",
"@chainsafe/ssz": "^1.0.1",
"@lodestar/config": "^1.25.0",
"@lodestar/params": "^1.25.0",
"@lodestar/types": "^1.25.0",
"@lodestar/utils": "^1.25.0",
"@chainsafe/ssz": "^1.0.2",
"@lodestar/config": "^1.26.0",
"@lodestar/params": "^1.26.0",
"@lodestar/types": "^1.26.0",
"@lodestar/utils": "^1.26.0",
"eventsource": "^2.0.2",
"qs": "^6.11.1"
},
Expand Down
16 changes: 15 additions & 1 deletion packages/api/src/beacon/routes/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ export enum EventType {
* Both dependent roots use the genesis block root in the case of underflow.
*/
head = "head",
/** The node has received a valid block (from P2P or API) */
/** The node has received a block (from P2P or API) that is successfully imported on the fork-choice `on_block` handler */
block = "block",
/** The node has received a block (from P2P or API) that passes validation rules of the `beacon_block` topic */
blockGossip = "block_gossip",
/** The node has received a valid attestation (from P2P or API) */
attestation = "attestation",
/** The node has received a valid SingleAttestation (from P2P or API) */
Expand Down Expand Up @@ -81,6 +83,7 @@ export enum EventType {
export const eventTypes: {[K in EventType]: K} = {
[EventType.head]: EventType.head,
[EventType.block]: EventType.block,
[EventType.blockGossip]: EventType.blockGossip,
[EventType.attestation]: EventType.attestation,
[EventType.singleAttestation]: EventType.singleAttestation,
[EventType.voluntaryExit]: EventType.voluntaryExit,
Expand Down Expand Up @@ -111,6 +114,10 @@ export type EventData = {
block: RootHex;
executionOptimistic: boolean;
};
[EventType.blockGossip]: {
slot: Slot;
block: RootHex;
};
[EventType.attestation]: Attestation;
[EventType.singleAttestation]: electra.SingleAttestation;
[EventType.voluntaryExit]: phase0.SignedVoluntaryExit;
Expand Down Expand Up @@ -231,6 +238,13 @@ export function getTypeByEvent(config: ChainForkConfig): {[K in EventType]: Type
},
{jsonCase: "eth2"}
),
[EventType.blockGossip]: new ContainerType(
{
slot: ssz.Slot,
block: stringType,
},
{jsonCase: "eth2"}
),

[EventType.attestation]: {
toJson: (attestation) => {
Expand Down
3 changes: 2 additions & 1 deletion packages/api/test/perf/compileRouteUrlFormater.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {bench, describe} from "@chainsafe/benchmark";
import {compileRouteUrlFormatter} from "../../src/utils/urlFormat.js";

describe("route parse", () => {
it.skip("Benchmark compileRouteUrlFormatter", () => {
bench.skip("Benchmark compileRouteUrlFormatter", () => {
const path = "/eth/v1/validator/:name/attester/:epoch";
const args = {epoch: 5, name: "HEAD"};

Expand Down
8 changes: 1 addition & 7 deletions packages/api/test/unit/beacon/oapiSpec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,7 @@ const ignoredProperties: Record<string, IgnoredProperty> = {
const openApiJson = await fetchOpenApiSpec(openApiFile);
runTestCheckAgainstSpec(openApiJson, definitions, testDatas, ignoredOperations, ignoredProperties);

const ignoredTopics = [
/*
https://github.com/ChainSafe/lodestar/issues/6470
topic block_gossip not implemented
*/
"block_gossip",
];
const ignoredTopics: string[] = [];

// eventstream types are defined as comments in the description of "examples".
// The function runTestCheckAgainstSpec() can't handle those, so the custom code before:
Expand Down
4 changes: 4 additions & 0 deletions packages/api/test/unit/beacon/testData/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export const eventTestData: EventData = {
block: "0x9a2fefd2fdb57f74993c7780ea5b9030d2897b615b89f808011ca5aebed54eaf",
executionOptimistic: false,
},
[EventType.blockGossip]: {
slot: 10,
block: "0x9a2fefd2fdb57f74993c7780ea5b9030d2897b615b89f808011ca5aebed54eaf",
},
[EventType.attestation]: ssz.phase0.Attestation.fromJson({
aggregation_bits: "0x01",
signature:
Expand Down
28 changes: 14 additions & 14 deletions packages/beacon-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"bugs": {
"url": "https://github.com/ChainSafe/lodestar/issues"
},
"version": "1.25.0",
"version": "1.26.0",
"type": "module",
"exports": {
".": {
Expand Down Expand Up @@ -103,7 +103,7 @@
"@chainsafe/persistent-merkle-tree": "^1.0.1",
"@chainsafe/prometheus-gc-stats": "^1.0.0",
"@chainsafe/pubkey-index-map": "2.0.0",
"@chainsafe/ssz": "^1.0.1",
"@chainsafe/ssz": "^1.0.2",
"@chainsafe/threads": "^1.11.1",
"@ethersproject/abi": "^5.7.0",
"@fastify/bearer-auth": "^10.0.1",
Expand All @@ -119,18 +119,18 @@
"@libp2p/peer-id": "^5.0.4",
"@libp2p/prometheus-metrics": "^4.1.2",
"@libp2p/tcp": "10.0.4",
"@lodestar/api": "^1.25.0",
"@lodestar/config": "^1.25.0",
"@lodestar/db": "^1.25.0",
"@lodestar/fork-choice": "^1.25.0",
"@lodestar/light-client": "^1.25.0",
"@lodestar/logger": "^1.25.0",
"@lodestar/params": "^1.25.0",
"@lodestar/reqresp": "^1.25.0",
"@lodestar/state-transition": "^1.25.0",
"@lodestar/types": "^1.25.0",
"@lodestar/utils": "^1.25.0",
"@lodestar/validator": "^1.25.0",
"@lodestar/api": "^1.26.0",
"@lodestar/config": "^1.26.0",
"@lodestar/db": "^1.26.0",
"@lodestar/fork-choice": "^1.26.0",
"@lodestar/light-client": "^1.26.0",
"@lodestar/logger": "^1.26.0",
"@lodestar/params": "^1.26.0",
"@lodestar/reqresp": "^1.26.0",
"@lodestar/state-transition": "^1.26.0",
"@lodestar/types": "^1.26.0",
"@lodestar/utils": "^1.26.0",
"@lodestar/validator": "^1.26.0",
"@multiformats/multiaddr": "^12.1.3",
"c-kzg": "^2.1.2",
"datastore-core": "^10.0.0",
Expand Down
16 changes: 5 additions & 11 deletions packages/beacon-node/src/api/impl/beacon/blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function getBeaconBlockApi({
>): ApplicationMethods<routes.beacon.block.Endpoints> {
const publishBlock: ApplicationMethods<routes.beacon.block.Endpoints>["publishBlockV2"] = async (
{signedBlockOrContents, broadcastValidation},
context,
_context,
opts: PublishBlockOpts = {}
) => {
const seenTimestampSec = Date.now() / 1000;
Expand All @@ -75,20 +75,12 @@ export function getBeaconBlockApi({
fork: config.getForkName(signedBlock.message.slot),
blobs: blobSidecars,
blobsSource: BlobsSource.api,
blobsBytes: blobSidecars.map(() => null),
} as BlockInputDataBlobs;
blockForImport = getBlockInput.availableData(
config,
signedBlock,
BlockSource.api,
// don't bundle any bytes for block and blobs
null,
blockData
);
blockForImport = getBlockInput.availableData(config, signedBlock, BlockSource.api, blockData);
} else {
signedBlock = signedBlockOrContents;
blobSidecars = [];
blockForImport = getBlockInput.preData(config, signedBlock, BlockSource.api, context?.sszBytes ?? null);
blockForImport = getBlockInput.preData(config, signedBlock, BlockSource.api);
}

// check what validations have been requested before broadcasting and publishing the block
Expand Down Expand Up @@ -207,6 +199,8 @@ export function getBeaconBlockApi({
await sleep(msToBlockSlot);
}

chain.emitter.emit(routes.events.EventType.blockGossip, {slot, block: blockRoot});

// TODO: Validate block
metrics?.registerBeaconBlock(OpSource.api, seenTimestampSec, blockForImport.block.message);
chain.logger.info("Publishing block", valLogMeta);
Expand Down
23 changes: 16 additions & 7 deletions packages/beacon-node/src/api/impl/beacon/pool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,21 @@ export function getBeaconPoolApi({
},

async getPoolAttesterSlashings() {
const fork = chain.config.getForkName(chain.clock.currentSlot);

if (isForkPostElectra(fork)) {
throw new ApiError(
400,
`Use getPoolAttesterSlashingsV2 to retrieve pool attester slashings for post-electra fork=${fork}`
);
}

return {data: chain.opPool.getAllAttesterSlashings()};
},

async getPoolAttesterSlashingsV2() {
// TODO Electra: Determine fork based on data returned by api
return {data: chain.opPool.getAllAttesterSlashings(), meta: {version: ForkName.phase0}};
const fork = chain.config.getForkName(chain.clock.currentSlot);
return {data: chain.opPool.getAllAttesterSlashings(), meta: {version: fork}};
},

async getPoolProposerSlashings() {
Expand Down Expand Up @@ -162,14 +171,14 @@ export function getBeaconPoolApi({
},

async submitPoolAttesterSlashings({attesterSlashing}) {
await validateApiAttesterSlashing(chain, attesterSlashing);
chain.opPool.insertAttesterSlashing(attesterSlashing);
await network.publishAttesterSlashing(attesterSlashing);
await this.submitPoolAttesterSlashingsV2({attesterSlashing});
},

async submitPoolAttesterSlashingsV2({attesterSlashing}) {
// TODO Electra: Refactor submitPoolAttesterSlashings and submitPoolAttesterSlashingsV2
await this.submitPoolAttesterSlashings({attesterSlashing});
await validateApiAttesterSlashing(chain, attesterSlashing);
const fork = chain.config.getForkName(Number(attesterSlashing.attestation1.data.slot));
chain.opPool.insertAttesterSlashing(fork, attesterSlashing);
await network.publishAttesterSlashing(attesterSlashing);
},

async submitPoolProposerSlashings({proposerSlashing}) {
Expand Down
6 changes: 3 additions & 3 deletions packages/beacon-node/src/api/impl/validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ export const SYNC_TOLERANCE_EPOCHS = 1;
* Post this time, race execution and builder to pick whatever resolves first
*
* Empirically the builder block resolves in ~1.5+ seconds, and execution should resolve <1 sec.
* So lowering the cutoff to 2 sec from 3 seconds to publish faster for successful proposal
* as proposals post 4 seconds into the slot seems to be not being included
* So lowering the cutoff to 2.5 sec from 3 seconds to publish faster for successful proposal
* as proposals post 4 seconds into the slot will likely be orphaned due to proposer boost reorg.
*/
const BLOCK_PRODUCTION_RACE_CUTOFF_MS = 2_000;
const BLOCK_PRODUCTION_RACE_CUTOFF_MS = 2_500;
/** Overall timeout for execution and block production apis */
const BLOCK_PRODUCTION_RACE_TIMEOUT_MS = 12_000;

Expand Down
Loading

0 comments on commit 5366dd3

Please sign in to comment.