Skip to content

Commit

Permalink
fix: reduce verbosity of gossip block errors (#6430)
Browse files Browse the repository at this point in the history
* Log gossip block errors as warnings

* Only log to debug if blobs are unavailable

* Always prune cache and track error in metrics

* Adapt log level (verbosity) based on error

* Do not initialize log level to ensure each case is handled explicitly

* Update comments

* Update comment
  • Loading branch information
nflaig authored Feb 15, 2024
1 parent e0b6e28 commit 48871eb
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/beacon-node/src/network/processor/gossipHandlers.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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: {
Expand All @@ -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
Expand All @@ -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();
});
}
Expand Down

0 comments on commit 48871eb

Please sign in to comment.