Skip to content

Commit

Permalink
Merge branch 'unstable' into nc/slashing-calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
ensi321 committed Sep 20, 2024
2 parents e16e9ca + bb40ef7 commit 224dbd5
Show file tree
Hide file tree
Showing 109 changed files with 1,555 additions and 574 deletions.
491 changes: 480 additions & 11 deletions dashboards/lodestar_state_cache_regen.json

Large diffs are not rendered by default.

268 changes: 128 additions & 140 deletions docs/yarn.lock

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.21.0",
"version": "1.22.0",
"stream": true,
"command": {
"version": {
Expand Down
10 changes: 5 additions & 5 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.21.0",
"version": "1.22.0",
"type": "module",
"exports": {
".": {
Expand Down Expand Up @@ -72,10 +72,10 @@
"dependencies": {
"@chainsafe/persistent-merkle-tree": "^0.8.0",
"@chainsafe/ssz": "^0.17.1",
"@lodestar/config": "^1.21.0",
"@lodestar/params": "^1.21.0",
"@lodestar/types": "^1.21.0",
"@lodestar/utils": "^1.21.0",
"@lodestar/config": "^1.22.0",
"@lodestar/params": "^1.22.0",
"@lodestar/types": "^1.22.0",
"@lodestar/utils": "^1.22.0",
"eventsource": "^2.0.2",
"qs": "^6.11.1"
},
Expand Down
11 changes: 6 additions & 5 deletions packages/api/src/beacon/routes/proof.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/naming-convention */
import {CompactMultiProof, ProofType} from "@chainsafe/persistent-merkle-tree";
import {ByteListType, ContainerType, fromHexString, toHexString} from "@chainsafe/ssz";
import {ByteListType, ContainerType} from "@chainsafe/ssz";
import {fromHex, toHex} from "@lodestar/utils";
import {ChainForkConfig} from "@lodestar/config";
import {ssz} from "@lodestar/types";
import {Endpoint, RouteDefinitions, Schema} from "../../utils/index.js";
Expand Down Expand Up @@ -45,8 +46,8 @@ export function getDefinitions(_config: ChainForkConfig): RouteDefinitions<Endpo
url: "/eth/v0/beacon/proof/state/{state_id}",
method: "GET",
req: {
writeReq: ({stateId, descriptor}) => ({params: {state_id: stateId}, query: {format: toHexString(descriptor)}}),
parseReq: ({params, query}) => ({stateId: params.state_id, descriptor: fromHexString(query.format)}),
writeReq: ({stateId, descriptor}) => ({params: {state_id: stateId}, query: {format: toHex(descriptor)}}),
parseReq: ({params, query}) => ({stateId: params.state_id, descriptor: fromHex(query.format)}),
schema: {params: {state_id: Schema.StringRequired}, query: {format: Schema.StringRequired}},
},
resp: {
Expand All @@ -63,8 +64,8 @@ export function getDefinitions(_config: ChainForkConfig): RouteDefinitions<Endpo
url: "/eth/v0/beacon/proof/block/{block_id}",
method: "GET",
req: {
writeReq: ({blockId, descriptor}) => ({params: {block_id: blockId}, query: {format: toHexString(descriptor)}}),
parseReq: ({params, query}) => ({blockId: params.block_id, descriptor: fromHexString(query.format)}),
writeReq: ({blockId, descriptor}) => ({params: {block_id: blockId}, query: {format: toHex(descriptor)}}),
parseReq: ({params, query}) => ({blockId: params.block_id, descriptor: fromHex(query.format)}),
schema: {params: {block_id: Schema.StringRequired}, query: {format: Schema.StringRequired}},
},
resp: {
Expand Down
27 changes: 14 additions & 13 deletions packages/api/src/beacon/routes/validator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/naming-convention */
import {ContainerType, fromHexString, toHexString, Type, ValueOf} from "@chainsafe/ssz";
import {ContainerType, Type, ValueOf} from "@chainsafe/ssz";
import {ChainForkConfig} from "@lodestar/config";
import {isForkBlobs, isForkPostElectra} from "@lodestar/params";
import {
Expand All @@ -20,6 +20,7 @@ import {
Attestation,
sszTypesFor,
} from "@lodestar/types";
import {fromHex, toHex, toRootHex} from "@lodestar/utils";
import {Endpoint, RouteDefinitions, Schema} from "../../utils/index.js";
import {fromGraffitiHex, toBoolean, toGraffitiHex} from "../../utils/serdes.js";
import {getExecutionForkTypes, toForkName} from "../../utils/fork.js";
Expand Down Expand Up @@ -623,7 +624,7 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions<Endpoi
writeReq: ({slot, randaoReveal, graffiti, feeRecipient, builderSelection, strictFeeRecipientCheck}) => ({
params: {slot},
query: {
randao_reveal: toHexString(randaoReveal),
randao_reveal: toHex(randaoReveal),
graffiti: toGraffitiHex(graffiti),
fee_recipient: feeRecipient,
builder_selection: builderSelection,
Expand All @@ -632,7 +633,7 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions<Endpoi
}),
parseReq: ({params, query}) => ({
slot: params.slot,
randaoReveal: fromHexString(query.randao_reveal),
randaoReveal: fromHex(query.randao_reveal),
graffiti: fromGraffitiHex(query.graffiti),
feeRecipient: query.fee_recipient,
builderSelection: query.builder_selection as BuilderSelection,
Expand Down Expand Up @@ -674,7 +675,7 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions<Endpoi
}) => ({
params: {slot},
query: {
randao_reveal: toHexString(randaoReveal),
randao_reveal: toHex(randaoReveal),
graffiti: toGraffitiHex(graffiti),
skip_randao_verification: writeSkipRandaoVerification(skipRandaoVerification),
fee_recipient: feeRecipient,
Expand All @@ -686,7 +687,7 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions<Endpoi
}),
parseReq: ({params, query}) => ({
slot: params.slot,
randaoReveal: fromHexString(query.randao_reveal),
randaoReveal: fromHex(query.randao_reveal),
graffiti: fromGraffitiHex(query.graffiti),
skipRandaoVerification: parseSkipRandaoVerification(query.skip_randao_verification),
feeRecipient: query.fee_recipient,
Expand Down Expand Up @@ -765,11 +766,11 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions<Endpoi
req: {
writeReq: ({slot, randaoReveal, graffiti}) => ({
params: {slot},
query: {randao_reveal: toHexString(randaoReveal), graffiti: toGraffitiHex(graffiti)},
query: {randao_reveal: toHex(randaoReveal), graffiti: toGraffitiHex(graffiti)},
}),
parseReq: ({params, query}) => ({
slot: params.slot,
randaoReveal: fromHexString(query.randao_reveal),
randaoReveal: fromHex(query.randao_reveal),
graffiti: fromGraffitiHex(query.graffiti),
}),
schema: {
Expand Down Expand Up @@ -805,12 +806,12 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions<Endpoi
method: "GET",
req: {
writeReq: ({slot, subcommitteeIndex, beaconBlockRoot}) => ({
query: {slot, subcommittee_index: subcommitteeIndex, beacon_block_root: toHexString(beaconBlockRoot)},
query: {slot, subcommittee_index: subcommitteeIndex, beacon_block_root: toRootHex(beaconBlockRoot)},
}),
parseReq: ({query}) => ({
slot: query.slot,
subcommitteeIndex: query.subcommittee_index,
beaconBlockRoot: fromHexString(query.beacon_block_root),
beaconBlockRoot: fromHex(query.beacon_block_root),
}),
schema: {
query: {
Expand All @@ -830,10 +831,10 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions<Endpoi
method: "GET",
req: {
writeReq: ({attestationDataRoot, slot}) => ({
query: {attestation_data_root: toHexString(attestationDataRoot), slot},
query: {attestation_data_root: toRootHex(attestationDataRoot), slot},
}),
parseReq: ({query}) => ({
attestationDataRoot: fromHexString(query.attestation_data_root),
attestationDataRoot: fromHex(query.attestation_data_root),
slot: query.slot,
}),
schema: {
Expand All @@ -853,10 +854,10 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions<Endpoi
method: "GET",
req: {
writeReq: ({attestationDataRoot, slot, committeeIndex}) => ({
query: {attestation_data_root: toHexString(attestationDataRoot), slot, committee_index: committeeIndex},
query: {attestation_data_root: toHex(attestationDataRoot), slot, committee_index: committeeIndex},
}),
parseReq: ({query}) => ({
attestationDataRoot: fromHexString(query.attestation_data_root),
attestationDataRoot: fromHex(query.attestation_data_root),
slot: query.slot,
committeeIndex: query.committee_index,
}),
Expand Down
9 changes: 4 additions & 5 deletions packages/api/src/builder/routes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable @typescript-eslint/naming-convention */
import {fromHexString, toHexString} from "@chainsafe/ssz";
import {
ssz,
bellatrix,
Expand All @@ -13,7 +12,7 @@ import {
} from "@lodestar/types";
import {ForkName, isForkBlobs} from "@lodestar/params";
import {ChainForkConfig} from "@lodestar/config";
import {toPubkeyHex} from "@lodestar/utils";
import {fromHex, toPubkeyHex, toRootHex} from "@lodestar/utils";

import {Endpoint, RouteDefinitions, Schema} from "../utils/index.js";
import {MetaHeader, VersionCodec, VersionMeta} from "../utils/metadata.js";
Expand Down Expand Up @@ -106,12 +105,12 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions<Endpoi
method: "GET",
req: {
writeReq: ({slot, parentHash, proposerPubkey: proposerPubKey}) => ({
params: {slot, parent_hash: toHexString(parentHash), pubkey: toPubkeyHex(proposerPubKey)},
params: {slot, parent_hash: toRootHex(parentHash), pubkey: toPubkeyHex(proposerPubKey)},
}),
parseReq: ({params}) => ({
slot: params.slot,
parentHash: fromHexString(params.parent_hash),
proposerPubkey: fromHexString(params.pubkey),
parentHash: fromHex(params.parent_hash),
proposerPubkey: fromHex(params.pubkey),
}),
schema: {
params: {slot: Schema.UintRequired, parent_hash: Schema.StringRequired, pubkey: Schema.StringRequired},
Expand Down
7 changes: 4 additions & 3 deletions packages/api/src/utils/serdes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {fromHexString, JsonPath, toHexString} from "@chainsafe/ssz";
import {JsonPath} from "@chainsafe/ssz";
import {fromHex, toHex} from "@lodestar/utils";

/**
* Serialize proof path to JSON.
Expand Down Expand Up @@ -82,7 +83,7 @@ export function toGraffitiHex(utf8?: string): string | undefined {
return undefined;
}

const hex = toHexString(new TextEncoder().encode(utf8));
const hex = toHex(new TextEncoder().encode(utf8));

if (hex.length > GRAFFITI_HEX_LENGTH) {
// remove characters from the end if hex string is too long
Expand All @@ -102,7 +103,7 @@ export function fromGraffitiHex(hex?: string): string | undefined {
return undefined;
}
try {
return new TextDecoder("utf8").decode(fromHexString(hex));
return new TextDecoder("utf8").decode(fromHex(hex));
} catch {
// allow malformed graffiti hex string
return hex;
Expand Down
26 changes: 13 additions & 13 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.21.0",
"version": "1.22.0",
"type": "module",
"exports": {
".": {
Expand Down Expand Up @@ -119,18 +119,18 @@
"@libp2p/peer-id-factory": "^4.1.0",
"@libp2p/prometheus-metrics": "^3.0.21",
"@libp2p/tcp": "9.0.23",
"@lodestar/api": "^1.21.0",
"@lodestar/config": "^1.21.0",
"@lodestar/db": "^1.21.0",
"@lodestar/fork-choice": "^1.21.0",
"@lodestar/light-client": "^1.21.0",
"@lodestar/logger": "^1.21.0",
"@lodestar/params": "^1.21.0",
"@lodestar/reqresp": "^1.21.0",
"@lodestar/state-transition": "^1.21.0",
"@lodestar/types": "^1.21.0",
"@lodestar/utils": "^1.21.0",
"@lodestar/validator": "^1.21.0",
"@lodestar/api": "^1.22.0",
"@lodestar/config": "^1.22.0",
"@lodestar/db": "^1.22.0",
"@lodestar/fork-choice": "^1.22.0",
"@lodestar/light-client": "^1.22.0",
"@lodestar/logger": "^1.22.0",
"@lodestar/params": "^1.22.0",
"@lodestar/reqresp": "^1.22.0",
"@lodestar/state-transition": "^1.22.0",
"@lodestar/types": "^1.22.0",
"@lodestar/utils": "^1.22.0",
"@lodestar/validator": "^1.22.0",
"@multiformats/multiaddr": "^12.1.3",
"c-kzg": "^2.1.2",
"datastore-core": "^9.1.1",
Expand Down
9 changes: 4 additions & 5 deletions packages/beacon-node/src/chain/archiver/archiveBlocks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {fromHexString} from "@chainsafe/ssz";
import {Epoch, Slot, RootHex} from "@lodestar/types";
import {IForkChoice} from "@lodestar/fork-choice";
import {Logger, toRootHex} from "@lodestar/utils";
import {Logger, fromHex, toRootHex} from "@lodestar/utils";
import {ForkSeq, SLOTS_PER_EPOCH} from "@lodestar/params";
import {computeEpochAtSlot, computeStartSlotAtEpoch} from "@lodestar/state-transition";
import {KeyValue} from "@lodestar/db";
Expand Down Expand Up @@ -48,7 +47,7 @@ export async function archiveBlocks(

const finalizedCanonicalBlockRoots: BlockRootSlot[] = finalizedCanonicalBlocks.map((block) => ({
slot: block.slot,
root: fromHexString(block.blockRoot),
root: fromHex(block.blockRoot),
}));

if (finalizedCanonicalBlockRoots.length > 0) {
Expand All @@ -68,7 +67,7 @@ export async function archiveBlocks(
// deleteNonCanonicalBlocks
// loop through forkchoice single time

const nonCanonicalBlockRoots = finalizedNonCanonicalBlocks.map((summary) => fromHexString(summary.blockRoot));
const nonCanonicalBlockRoots = finalizedNonCanonicalBlocks.map((summary) => fromHex(summary.blockRoot));
if (nonCanonicalBlockRoots.length > 0) {
await db.block.batchDelete(nonCanonicalBlockRoots);
logger.verbose("Deleted non canonical blocks from hot DB", {
Expand Down Expand Up @@ -144,7 +143,7 @@ async function migrateBlocksFromHotToColdDb(db: IBeaconDb, blocks: BlockRootSlot
value: blockBuffer,
slot: block.slot,
blockRoot: block.root,
// TODO: Benchmark if faster to slice Buffer or fromHexString()
// TODO: Benchmark if faster to slice Buffer or fromHex()
parentRoot: getParentRootFromSignedBlock(blockBuffer),
};
})
Expand Down
7 changes: 3 additions & 4 deletions packages/beacon-node/src/chain/blocks/importBlock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {toHexString} from "@chainsafe/ssz";
import {capella, ssz, altair, BeaconBlock} from "@lodestar/types";
import {ForkLightClient, ForkSeq, INTERVALS_PER_SLOT, MAX_SEED_LOOKAHEAD, SLOTS_PER_EPOCH} from "@lodestar/params";
import {
Expand All @@ -10,7 +9,7 @@ import {
} from "@lodestar/state-transition";
import {routes} from "@lodestar/api";
import {ForkChoiceError, ForkChoiceErrorCode, EpochDifference, AncestorStatus} from "@lodestar/fork-choice";
import {isErrorAborted, toRootHex} from "@lodestar/utils";
import {isErrorAborted, toHex, toRootHex} from "@lodestar/utils";
import {ZERO_HASH_HEX} from "../../constants/index.js";
import {toCheckpointHex} from "../stateCache/index.js";
import {isOptimisticBlock} from "../../util/forkChoice.js";
Expand Down Expand Up @@ -433,8 +432,8 @@ export async function importBlock(
blockRoot: blockRootHex,
slot: blockSlot,
index,
kzgCommitment: toHexString(kzgCommitment),
versionedHash: toHexString(kzgCommitmentToVersionedHash(kzgCommitment)),
kzgCommitment: toHex(kzgCommitment),
versionedHash: toHex(kzgCommitmentToVersionedHash(kzgCommitment)),
});
}
}
Expand Down
16 changes: 8 additions & 8 deletions packages/beacon-node/src/chain/chain.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "node:path";
import {CompositeTypeAny, fromHexString, TreeView, Type} from "@chainsafe/ssz";
import {CompositeTypeAny, TreeView, Type} from "@chainsafe/ssz";
import {
BeaconStateAllForks,
CachedBeaconStateAllForks,
Expand Down Expand Up @@ -35,7 +35,7 @@ import {
} from "@lodestar/types";
import {CheckpointWithHex, ExecutionStatus, IForkChoice, ProtoBlock, UpdateHeadOpt} from "@lodestar/fork-choice";
import {ProcessShutdownCallback} from "@lodestar/validator";
import {Logger, gweiToWei, isErrorAborted, pruneSetToMax, sleep, toRootHex} from "@lodestar/utils";
import {Logger, fromHex, gweiToWei, isErrorAborted, pruneSetToMax, sleep, toRootHex} from "@lodestar/utils";
import {ForkSeq, GENESIS_SLOT, SLOTS_PER_EPOCH} from "@lodestar/params";

import {GENESIS_EPOCH, ZERO_HASH} from "../constants/index.js";
Expand Down Expand Up @@ -521,7 +521,7 @@ export class BeaconChain implements IBeaconChain {
};
}

const data = await this.db.stateArchive.getByRoot(fromHexString(stateRoot));
const data = await this.db.stateArchive.getByRoot(fromHex(stateRoot));
return data && {state: data, executionOptimistic: false, finalized: true};
}

Expand Down Expand Up @@ -568,7 +568,7 @@ export class BeaconChain implements IBeaconChain {
// Unfinalized slot, attempt to find in fork-choice
const block = this.forkChoice.getCanonicalBlockAtSlot(slot);
if (block) {
const data = await this.db.block.get(fromHexString(block.blockRoot));
const data = await this.db.block.get(fromHex(block.blockRoot));
if (data) {
return {block: data, executionOptimistic: isOptimisticBlock(block), finalized: false};
}
Expand All @@ -587,15 +587,15 @@ export class BeaconChain implements IBeaconChain {
): Promise<{block: SignedBeaconBlock; executionOptimistic: boolean; finalized: boolean} | null> {
const block = this.forkChoice.getBlockHex(root);
if (block) {
const data = await this.db.block.get(fromHexString(root));
const data = await this.db.block.get(fromHex(root));
if (data) {
return {block: data, executionOptimistic: isOptimisticBlock(block), finalized: false};
}
// If block is not found in hot db, try cold db since there could be an archive cycle happening
// TODO: Add a lock to the archiver to have deterministic behavior on where are blocks
}

const data = await this.db.blockArchive.getByRoot(fromHexString(root));
const data = await this.db.blockArchive.getByRoot(fromHex(root));
return data && {block: data, executionOptimistic: false, finalized: true};
}

Expand Down Expand Up @@ -768,7 +768,7 @@ export class BeaconChain implements IBeaconChain {
finalizedRoot: finalizedCheckpoint.epoch === GENESIS_EPOCH ? ZERO_HASH : finalizedCheckpoint.root,
finalizedEpoch: finalizedCheckpoint.epoch,
// TODO: PERFORMANCE: Memoize to prevent re-computing every time
headRoot: fromHexString(head.blockRoot),
headRoot: fromHex(head.blockRoot),
headSlot: head.slot,
};
}
Expand Down Expand Up @@ -1120,7 +1120,7 @@ export class BeaconChain implements IBeaconChain {
// TODO: Improve using regen here
const {blockRoot, stateRoot, slot} = this.forkChoice.getHead();
const headState = this.regen.getStateSync(stateRoot);
const headBlock = await this.db.block.get(fromHexString(blockRoot));
const headBlock = await this.db.block.get(fromHex(blockRoot));
if (headBlock == null) {
throw Error(`Head block ${slot} ${headBlock} is not available in database`);
}
Expand Down
Loading

0 comments on commit 224dbd5

Please sign in to comment.