Skip to content

Commit

Permalink
Merge branch 'master' into dapplion/typesafe-types
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed May 3, 2021
2 parents 85550fd + 8ab5df0 commit 9acf776
Show file tree
Hide file tree
Showing 107 changed files with 2,423 additions and 2,802 deletions.
6 changes: 3 additions & 3 deletions docker-compose.validator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ services:
build: .
image: lodestar
restart: always
depends_on:
- beacon_node
volumes:
- validator:/data
- logs:/logs
- ./keystores:/keystores
- ./secrets:/secrets
env_file: .env
command: validator --rootDir /data --keystoresDir /keystores --secretsDir /secrets --server http://beacon_node:9596
command: validator --rootDir /data --keystoresDir /keystores --secretsDir /secrets --server http://beacon_node:9596 --logFile /logs/validator.log --logLevelFile debug

volumes:
validator:
logs:
8 changes: 3 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ services:
restart: always
volumes:
- beacon_node:/data
- logs:/logs
env_file: .env
ports:
- "9000:9000" # P2P port
- "9596:9596" # REST API port
command: beacon --rootDir /data --api.rest.host 0.0.0.0 --metrics.enabled
command: beacon --rootDir /data --api.rest.host 0.0.0.0 --metrics.enabled --logFile /logs/beacon.log --logLevelFile debug

prometheus:
build: docker/prometheus
restart: always
volumes:
- "prometheus:/prometheus"
depends_on:
- beacon_node

grafana:
build: docker/grafana
Expand All @@ -27,10 +26,9 @@ services:
- "3000:3000"
volumes:
- "grafana:/var/lib/grafana"
depends_on:
- prometheus

volumes:
beacon_node:
logs:
prometheus:
grafana:
37 changes: 32 additions & 5 deletions docker/grafana/provisioning/dashboards/lodestar.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@
"type": "row"
},
{
"aliasColors": {},
"aliasColors": {
"(time() - lodestar_genesis_time) / 12": "rgba(48, 208, 255, 0.51)",
"clock slot": "rgba(105, 220, 255, 0.53)",
"head slot": "green",
"process restart": "dark-red"
},
"bars": false,
"dashLength": 10,
"dashes": false,
Expand Down Expand Up @@ -75,16 +80,37 @@
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"seriesOverrides": [
{
"alias": "process restart",
"yaxis": 2
}
],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "(time() - lodestar_genesis_time) / 12",
"hide": false,
"instant": false,
"interval": "",
"legendFormat": "clock slot",
"refId": "C"
},
{
"expr": "beacon_head_slot",
"hide": false,
"interval": "",
"legendFormat": "",
"legendFormat": "head slot",
"refId": "A"
},
{
"expr": "changes(process_start_time_seconds[5m])",
"hide": false,
"interval": "",
"legendFormat": "process restart",
"refId": "B"
}
],
"thresholds": [],
Expand Down Expand Up @@ -115,11 +141,12 @@
"show": true
},
{
"decimals": 0,
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"max": "1",
"min": "0.1",
"show": true
}
],
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/cmds/dev/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ const devOwnOptions: ICliCommandOptions<IDevOwnArgs> = {
* Note: use beaconNodeOptions and globalOptions to make sure option key is correct
*/
const externalOptionsOverrides: {[k: string]: Options} = {
"sync.minPeers": {
...beaconNodeOptions["sync.minPeers"],
"sync.isSingleNode": {
...beaconNodeOptions["sync.isSingleNode"],
defaultDescription: undefined,
default: 0,
default: true,
},
"network.maxPeers": {
...beaconNodeOptions["network.maxPeers"],
Expand Down
15 changes: 9 additions & 6 deletions packages/cli/src/options/beaconNodeOptions/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@ import {defaultOptions, IBeaconNodeOptions} from "@chainsafe/lodestar";
import {ICliCommandOptions} from "../../util";

export interface ISyncArgs {
"sync.minPeers": number;
"sync.isSingleNode": boolean;
}

export function parseArgs(args: ISyncArgs): IBeaconNodeOptions["sync"] {
return {
minPeers: args["sync.minPeers"],
isSingleNode: args["sync.isSingleNode"],
};
}

export const options: ICliCommandOptions<ISyncArgs> = {
"sync.minPeers": {
type: "number",
description: "Minimum number of peers before the beacon chain starts syncing",
defaultDescription: String(defaultOptions.sync.minPeers),
"sync.isSingleNode": {
hidden: true,
type: "boolean",
description:
"Allow node to consider itself synced without being connected to a peer. \
Use only for local networks with a single node, can be dangerous in regular networks.",
defaultDescription: String(defaultOptions.sync.isSingleNode),
group: "sync",
},
};
4 changes: 2 additions & 2 deletions packages/cli/test/unit/options/beaconNodeOptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("options / beaconNodeOptions", () => {
"network.bootMultiaddrs": [],
"network.localMultiaddrs": [],

"sync.minPeers": 17,
"sync.isSingleNode": true,
} as IBeaconNodeArgs;

const expectedOptions: RecursivePartial<IBeaconNodeOptions> = {
Expand Down Expand Up @@ -76,7 +76,7 @@ describe("options / beaconNodeOptions", () => {
localMultiaddrs: [],
},
sync: {
minPeers: 17,
isSingleNode: true,
},
};

Expand Down
15 changes: 12 additions & 3 deletions packages/lodestar/src/api/impl/lodestar/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import {IBeaconConfig} from "@chainsafe/lodestar-config";
import {Epoch} from "@chainsafe/lodestar-types";
import {IApiModules} from "..";
import {IApiModules} from "../interface";
import {getLatestWeakSubjectivityCheckpointEpoch} from "../../../../../beacon-state-transition/lib/fast/util/weakSubjectivity";
import {IBeaconChain} from "../../../chain";
import {IBeaconSync} from "../../../sync";
import {SyncChainDebugState} from "../../../sync/range/chain";

/* eslint-disable @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access */
export interface ILodestarApi {
getWtfNode(): string;
getLatestWeakSubjectivityCheckpointEpoch(): Promise<Epoch>;
getSyncChainsDebugState(): SyncChainDebugState[];
}

export class LodestarApi implements ILodestarApi {
private readonly config: IBeaconConfig;
private readonly chain: IBeaconChain;
private readonly sync: IBeaconSync;

constructor(modules: Pick<IApiModules, "config" | "chain">) {
constructor(modules: Pick<IApiModules, "config" | "chain" | "sync">) {
this.config = modules.config;
this.chain = modules.chain;
this.sync = modules.sync;

// Allows to load wtfnode listeners immedeatelly. Usefull when dockerized,
// so after an unexpected restart wtfnode becomes properly loaded again
Expand All @@ -41,6 +45,7 @@ export class LodestarApi implements ILodestarApi {
function logger(...args: string[]): void {
for (const arg of args) logs.push(arg);
}
/* eslint-disable @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access */
wtfnode.setLogger("info", logger);
wtfnode.setLogger("warn", logger);
wtfnode.setLogger("error", logger);
Expand All @@ -52,4 +57,8 @@ export class LodestarApi implements ILodestarApi {
const state = this.chain.getHeadState();
return getLatestWeakSubjectivityCheckpointEpoch(this.config, state);
}

getSyncChainsDebugState(): SyncChainDebugState[] {
return this.sync.getSyncChainsDebugState();
}
}
36 changes: 6 additions & 30 deletions packages/lodestar/src/api/impl/validator/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import bls, {Signature} from "@chainsafe/bls";
import {
CachedBeaconState,
computeStartSlotAtEpoch,
computeSubnetForCommitteesAtSlot,
proposerShufflingDecisionRoot,
attesterShufflingDecisionRoot,
} from "@chainsafe/lodestar-beacon-state-transition";
Expand All @@ -25,7 +24,7 @@ import {ZERO_HASH} from "../../../constants";
import {IBeaconDb} from "../../../db";
import {IEth1ForBlockProduction} from "../../../eth1";
import {INetwork} from "../../../network";
import {IBeaconSync, SyncMode} from "../../../sync";
import {IBeaconSync, SyncState} from "../../../sync";
import {toGraffitiBuffer} from "../../../util/graffiti";
import {IApiOptions} from "../../options";
import {ApiError} from "../errors";
Expand Down Expand Up @@ -255,27 +254,7 @@ export class ValidatorApi implements IValidatorApi {
async prepareBeaconCommitteeSubnet(subscriptions: phase0.BeaconCommitteeSubscription[]): Promise<void> {
this.notWhileSyncing();

// Determine if the validator is an aggregator. If so, we subscribe to the subnet and
// if successful add the validator to a mapping of known aggregators for that exact
// subnet.
for (const {isAggregator, slot, committeeIndex} of subscriptions) {
if (isAggregator) {
this.sync.collectAttestations(slot, committeeIndex);
}
}

this.network.requestAttSubnets(
subscriptions.map(({slot, committeesAtSlot, committeeIndex}) => ({
subnetId: computeSubnetForCommitteesAtSlot(this.config, slot, committeesAtSlot, committeeIndex),
// Network should keep finding peers for this subnet until `toSlot`
// add one slot to ensure we keep the peer for the subscription slot
toSlot: slot + 1,
}))
);

// TODO:
// Update the `known_validators` mapping and subscribes to a set of random subnets if required
// It must also update the ENR to indicate our long-lived subscription to the subnet
this.network.prepareBeaconCommitteeSubnet(subscriptions);

// TODO:
// If the discovery mechanism isn't disabled, attempt to set up a peer discovery for the
Expand Down Expand Up @@ -338,8 +317,8 @@ export class ValidatorApi implements IValidatorApi {

const syncState = this.sync.state;
switch (syncState) {
case SyncMode.INITIAL_SYNCING:
case SyncMode.REGULAR_SYNCING: {
case SyncState.SyncingFinalized:
case SyncState.SyncingHead: {
const currentSlot = this.chain.clock.currentSlot;
const headSlot = this.chain.forkChoice.getHead().slot;
if (currentSlot - headSlot > SYNC_TOLERANCE_EPOCHS * this.config.params.SLOTS_PER_EPOCH) {
Expand All @@ -349,14 +328,11 @@ export class ValidatorApi implements IValidatorApi {
}
}

case SyncMode.SYNCED:
case SyncState.Synced:
return;

case SyncMode.WAITING_PEERS:
case SyncState.Stalled:
throw new ApiError(503, "Node is waiting for peers");

case SyncMode.STOPPED:
throw new ApiError(503, "Node is stopped");
}
}
}
2 changes: 1 addition & 1 deletion packages/lodestar/src/api/rest/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ export interface IRestApiModules {
config: IBeaconConfig;
logger: ILogger;
api: IApi;
metrics?: IMetrics;
metrics: IMetrics | null;
}
16 changes: 9 additions & 7 deletions packages/lodestar/src/chain/blocks/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type BlockProcessorModules = {
regen: IStateRegenerator;
emitter: ChainEventEmitter;
bls: IBlsVerifier;
metrics?: IMetrics;
metrics: IMetrics | null;
clock: IBeaconClock;
checkpointStateCache: CheckpointStateCache;
};
Expand All @@ -46,12 +46,14 @@ export class BlockProcessor {
this.modules = modules;
this.jobQueue = new JobQueue(
{maxLength, signal},
modules.metrics && {
length: modules.metrics.blockProcessorQueueLength,
droppedJobs: modules.metrics.blockProcessorQueueDroppedJobs,
jobTime: modules.metrics.blockProcessorQueueJobTime,
jobWaitTime: modules.metrics.blockProcessorQueueJobWaitTime,
}
modules.metrics
? {
length: modules.metrics.blockProcessorQueueLength,
droppedJobs: modules.metrics.blockProcessorQueueDroppedJobs,
jobTime: modules.metrics.blockProcessorQueueJobTime,
jobWaitTime: modules.metrics.blockProcessorQueueJobWaitTime,
}
: undefined
);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/lodestar/src/chain/bls/multithread/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {IMetrics} from "../../../metrics";

export type BlsMultiThreadWorkerPoolModules = {
logger: ILogger;
metrics?: IMetrics;
metrics: IMetrics | null;
signal: AbortSignal;
};

Expand Down Expand Up @@ -69,7 +69,7 @@ type WorkerDescriptor = {
*/
export class BlsMultiThreadWorkerPool {
private readonly logger: ILogger;
private readonly metrics?: IMetrics;
private readonly metrics: IMetrics | null;
private readonly signal: AbortSignal;

private readonly format: PointFormat;
Expand Down

0 comments on commit 9acf776

Please sign in to comment.