diff --git a/packages/beacon-node/src/network/processor/gossipHandlers.ts b/packages/beacon-node/src/network/processor/gossipHandlers.ts index bdd5f1917dc5..2bf9178a0567 100644 --- a/packages/beacon-node/src/network/processor/gossipHandlers.ts +++ b/packages/beacon-node/src/network/processor/gossipHandlers.ts @@ -1,6 +1,6 @@ import {toHexString} from "@chainsafe/ssz"; import {BeaconConfig} from "@lodestar/config"; -import {Logger, prettyBytes} from "@lodestar/utils"; +import {LogLevel, Logger, prettyBytes} from "@lodestar/utils"; import {Root, Slot, ssz, allForks, deneb} from "@lodestar/types"; import {ForkName, ForkSeq} from "@lodestar/params"; import {routes} from "@lodestar/api"; @@ -255,6 +255,9 @@ function getDefaultHandlers(modules: ValidatorFnsModules, options: GossipHandler chain.seenGossipBlockInput.prune(); }) .catch((e) => { + // Adjust verbosity based on error type + let logLevel: LogLevel; + if (e instanceof BlockError) { switch (e.type.code) { case BlockErrorCode.DATA_UNAVAILABLE: { @@ -264,6 +267,9 @@ function getDefaultHandlers(modules: ValidatorFnsModules, options: GossipHandler const rootHex = toHexString(forkTypes.BeaconBlock.hashTreeRoot(signedBlock.message)); events.emit(NetworkEvent.unknownBlock, {rootHex, peer: peerIdStr}); + + // Error is quite frequent and not critical + logLevel = LogLevel.debug; break; } // ALREADY_KNOWN should not happen with ignoreIfKnown=true above @@ -272,14 +278,21 @@ function getDefaultHandlers(modules: ValidatorFnsModules, options: GossipHandler case BlockErrorCode.PARENT_UNKNOWN: case BlockErrorCode.PRESTATE_MISSING: case BlockErrorCode.EXECUTION_ENGINE_ERROR: + // Errors might indicate an issue with our node or the connected EL client + logLevel = LogLevel.error; break; default: // TODO: Should it use PeerId or string? core.reportPeer(peerIdStr, PeerAction.LowToleranceError, "BadGossipBlock"); + // Misbehaving peer, but could highlight an issue in another client + logLevel = LogLevel.warn; } + } else { + // Any unexpected error + logLevel = LogLevel.error; } metrics?.gossipBlock.processBlockErrors.inc({error: e instanceof BlockError ? e.type.code : "NOT_BLOCK_ERROR"}); - logger.error("Error receiving block", {slot: signedBlock.message.slot, peer: peerIdStr}, e as Error); + logger[logLevel]("Error receiving block", {slot: signedBlock.message.slot, peer: peerIdStr}, e as Error); chain.seenGossipBlockInput.prune(); }); }