Skip to content

Commit 0280d6c

Browse files
authored
Revisiting log levels (#1788)
* Update log level - #1779 #1785 * Address review comments * Document the logging strategy [skip ci]
1 parent 13d4831 commit 0280d6c

19 files changed

+120
-74
lines changed

beacon_chain/attestation_pool.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ proc init*(T: type AttestationPool, chainDag: ChainDAGRef, quarantine: Quarantin
5555

5656
doAssert status.isOk(), "Error in preloading the fork choice: " & $status.error
5757

58-
info "Fork choice initialized",
58+
debug "Fork choice initialized",
5959
justified_epoch = chainDag.headState.data.data.current_justified_checkpoint.epoch,
6060
finalized_epoch = chainDag.headState.data.data.finalized_checkpoint.epoch,
6161
finalized_root = shortlog(chainDag.finalizedHead.blck.root)
@@ -184,7 +184,7 @@ proc addAttestation*(pool: var AttestationPool,
184184
attestation.data.slot, participants, attestation.data.beacon_block_root,
185185
wallSlot)
186186

187-
info "Attestation resolved",
187+
debug "Attestation resolved",
188188
attestation = shortLog(attestation),
189189
validations = a.validations.len()
190190

@@ -201,7 +201,7 @@ proc addAttestation*(pool: var AttestationPool,
201201
attestation.data.slot, participants, attestation.data.beacon_block_root,
202202
wallSlot)
203203

204-
info "Attestation resolved",
204+
debug "Attestation resolved",
205205
attestation = shortLog(attestation),
206206
validations = 1
207207

beacon_chain/beacon_node.nim

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ proc init*(T: type BeaconNode,
186186
if bnStatus == BeaconNodeStatus.Stopping:
187187
return nil
188188

189-
info "Eth2 genesis state detected",
189+
notice "Eth2 genesis state detected",
190190
genesisTime = genesisState.genesisTime,
191191
eth1Block = genesisState.eth1_data.block_hash,
192192
totalDeposits = genesisState.eth1_data.deposit_count
@@ -619,7 +619,7 @@ proc onSlotStart(node: BeaconNode, lastSlot, scheduledSlot: Slot) {.async.} =
619619
proc handleMissingBlocks(node: BeaconNode) =
620620
let missingBlocks = node.quarantine.checkMissing()
621621
if missingBlocks.len > 0:
622-
info "Requesting detected missing blocks", blocks = shortLog(missingBlocks)
622+
debug "Requesting detected missing blocks", blocks = shortLog(missingBlocks)
623623
node.requestManager.fetchAncestorBlocks(missingBlocks)
624624

625625
proc onSecond(node: BeaconNode) =
@@ -639,7 +639,7 @@ proc runOnSecondLoop(node: BeaconNode) {.async.} =
639639
let finished = chronos.now(chronos.Moment)
640640
let processingTime = finished - afterSleep
641641
ticks_delay.set(sleepTime.nanoseconds.float / nanosecondsIn1s)
642-
debug "onSecond task completed", sleepTime, processingTime
642+
trace "onSecond task completed", sleepTime, processingTime
643643

644644
proc startSyncManager(node: BeaconNode) =
645645
func getLocalHeadSlot(): Slot =
@@ -845,12 +845,12 @@ proc installMessageValidators(node: BeaconNode) =
845845

846846
proc stop*(node: BeaconNode) =
847847
bnStatus = BeaconNodeStatus.Stopping
848-
info "Graceful shutdown"
848+
notice "Graceful shutdown"
849849
if not node.config.inProcessValidators:
850850
node.vcProcess.close()
851851
waitFor node.network.stop()
852852
node.db.close()
853-
info "Database closed"
853+
notice "Database closed"
854854

855855
proc run*(node: BeaconNode) =
856856
if bnStatus == BeaconNodeStatus.Starting:
@@ -907,7 +907,7 @@ proc initializeNetworking(node: BeaconNode) {.async.} =
907907

908908
await node.network.start()
909909

910-
info "Networking initialized",
910+
notice "Networking initialized",
911911
enr = node.network.announcedENR.toURI,
912912
libp2p = shortLog(node.network.switch.peerInfo)
913913

@@ -917,7 +917,7 @@ proc start(node: BeaconNode) =
917917
finalizedHead = node.chainDag.finalizedHead
918918
genesisTime = node.beaconClock.fromNow(toBeaconTime(Slot 0))
919919

920-
info "Starting beacon node",
920+
notice "Starting beacon node",
921921
version = fullVersionStr,
922922
nim = shortNimBanner(),
923923
timeSinceFinalization =
@@ -1202,14 +1202,14 @@ programMain:
12021202
when defined(windows):
12031203
# workaround for https://github.com/nim-lang/Nim/issues/4057
12041204
setupForeignThreadGc()
1205-
info "Shutting down after having received SIGINT"
1205+
notice "Shutting down after having received SIGINT"
12061206
bnStatus = BeaconNodeStatus.Stopping
12071207
setControlCHook(controlCHandler)
12081208

12091209
when useInsecureFeatures:
12101210
if config.metricsEnabled:
12111211
let metricsAddress = config.metricsAddress
1212-
info "Starting metrics HTTP server",
1212+
notice "Starting metrics HTTP server",
12131213
address = metricsAddress, port = config.metricsPort
12141214
metrics.startHttpServer($metricsAddress, config.metricsPort)
12151215

@@ -1282,7 +1282,7 @@ programMain:
12821282
mapIt(deposits.value, LaunchPadDeposit.init(config.runtimePreset, it))
12831283

12841284
Json.saveFile(depositDataPath, launchPadDeposits)
1285-
info "Deposit data written", filename = depositDataPath
1285+
notice "Deposit data written", filename = depositDataPath
12861286

12871287
walletPath.wallet.nextAccount += deposits.value.len
12881288
let status = saveWallet(walletPath)

beacon_chain/block_pools/chain_dag.nim

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ proc putState*(dag: ChainDAGRef, state: StateData) =
487487
if dag.db.containsState(state.data.root):
488488
return
489489

490-
info "Storing state"
490+
debug "Storing state"
491491
# Ideally we would save the state and the root lookup cache in a single
492492
# transaction to prevent database inconsistencies, but the state loading code
493493
# is resilient against one or the other going missing
@@ -626,7 +626,7 @@ proc updateStateData*(
626626

627627
return
628628

629-
debug "UpdateStateData miss",
629+
debug "UpdateStateData cache miss",
630630
bs, stateBlock = state.blck, stateSlot = state.data.data.slot
631631

632632
# Either the state is too new or was created by applying a different block.
@@ -676,7 +676,7 @@ proc updateStateData*(
676676

677677
beacon_state_rewinds.inc()
678678

679-
debug "State reloaded from database",
679+
trace "State reloaded from database",
680680
blocks = ancestors.len,
681681
slots = state.data.data.slot - startSlot,
682682
stateRoot = shortLog(state.data.root),
@@ -707,7 +707,7 @@ proc updateHead*(
707707
newHead = shortLog(newHead)
708708

709709
if dag.head == newHead:
710-
debug "No head block update"
710+
trace "No head block update"
711711

712712
return
713713

@@ -730,7 +730,7 @@ proc updateHead*(
730730
dag.head = newHead
731731

732732
if not lastHead.isAncestorOf(newHead):
733-
info "Updated head block with reorg",
733+
notice "Updated head block with chain reorg",
734734
lastHead = shortLog(lastHead),
735735
headParent = shortLog(newHead.parent),
736736
stateRoot = shortLog(dag.headState.data.root),
@@ -743,7 +743,7 @@ proc updateHead*(
743743
quarantine.clearQuarantine()
744744
beacon_reorgs_total.inc()
745745
else:
746-
info "Updated head block",
746+
debug "Updated head block",
747747
stateRoot = shortLog(dag.headState.data.root),
748748
headBlock = shortLog(dag.headState.blck),
749749
stateSlot = shortLog(dag.headState.data.data.slot),
@@ -818,7 +818,7 @@ proc updateHead*(
818818

819819
dag.finalizedHead = finalizedHead
820820

821-
info "Reached new finalization checkpoint",
821+
notice "Reached new finalization checkpoint",
822822
finalizedHead = shortLog(finalizedHead),
823823
heads = dag.heads.len
824824

beacon_chain/block_pools/clearance.nim

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ proc addResolvedBlock(
8888
foundHead = blockRef
8989
dag.heads.add(foundHead)
9090

91-
info "Block resolved",
91+
debug "Block resolved",
9292
blck = shortLog(signedBlock.message),
9393
blockRoot = shortLog(blockRoot),
9494
heads = dag.heads.len()
@@ -165,7 +165,7 @@ proc addRawBlock*(
165165
if parent.slot >= blck.slot:
166166
# A block whose parent is newer than the block itself is clearly invalid -
167167
# discard it immediately
168-
notice "Invalid block slot",
168+
debug "Invalid block slot",
169169
parentBlock = shortLog(parent)
170170

171171
return err((EVRESULT_REJECT, Invalid))
@@ -211,7 +211,7 @@ proc addRawBlock*(
211211

212212
if not state_transition(dag.runtimePreset, dag.clearanceState.data, signedBlock,
213213
cache, dag.updateFlags + {slotProcessed}, restore):
214-
notice "Invalid block"
214+
info "Invalid block"
215215

216216
return err((EVRESULT_REJECT, Invalid))
217217

@@ -329,7 +329,7 @@ proc isValidBeaconBlock*(
329329
signed_beacon_block.message.proposer_index and
330330
blck.message.slot == signed_beacon_block.message.slot and
331331
blck.signature.toRaw() != signed_beacon_block.signature.toRaw():
332-
debug "block isn't first block with valid signature received for the proposer",
332+
notice "block isn't first block with valid signature received for the proposer",
333333
blckRef = slotBlockRef,
334334
existing_block = shortLog(blck.message)
335335
return err((EVRESULT_IGNORE, Invalid))
@@ -348,7 +348,7 @@ proc isValidBeaconBlock*(
348348
debug "parent unknown, putting block in quarantine",
349349
current_slot = shortLog(current_slot)
350350
if not quarantine.add(dag, signed_beacon_block):
351-
debug "Block quarantine full"
351+
warn "Block quarantine full"
352352
return err((EVRESULT_IGNORE, MissingParent))
353353

354354
# [REJECT] The current finalized_checkpoint is an ancestor of block -- i.e.
@@ -378,12 +378,12 @@ proc isValidBeaconBlock*(
378378
proposer = getProposer(dag, parent_ref, signed_beacon_block.message.slot)
379379

380380
if proposer.isNone:
381-
notice "cannot compute proposer for message"
381+
warn "cannot compute proposer for message"
382382
return err((EVRESULT_IGNORE, Invalid)) # basically an internal issue
383383

384384
if proposer.get()[0] !=
385385
ValidatorIndex(signed_beacon_block.message.proposer_index):
386-
debug "block had unexpected proposer",
386+
notice "block had unexpected proposer",
387387
expected_proposer = proposer.get()[0]
388388
return err((EVRESULT_REJECT, Invalid))
389389

beacon_chain/deposit_contract.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ proc sendDeposits*(deposits: seq[LaunchPadDeposit],
139139
web3Url, privateKey: string,
140140
depositContractAddress: Eth1Address,
141141
delayGenerator: DelayGenerator = nil) {.async.} =
142-
info "Sending deposits",
142+
notice "Sending deposits",
143143
web3 = web3Url,
144144
depositContract = depositContractAddress
145145

@@ -197,7 +197,7 @@ proc main() {.async.} =
197197
mapIt(deposits.value, LaunchPadDeposit.init(runtimePreset, it))
198198

199199
Json.saveFile(string cfg.outDepositsFile, launchPadDeposits)
200-
info "Deposit data written", filename = cfg.outDepositsFile
200+
notice "Deposit data written", filename = cfg.outDepositsFile
201201
quit 0
202202

203203
var deposits: seq[LaunchPadDeposit]

beacon_chain/eth2_network.nim

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ proc runDiscoveryLoop*(node: Eth2Node) {.async.} =
822822
debug "Failed to decode discovery's node address",
823823
node = $discnode, errMsg = res.error
824824

825-
debug "Discovery tick", wanted_peers = node.wantedPeers,
825+
trace "Discovery tick", wanted_peers = node.wantedPeers,
826826
space = node.peerPool.shortLogSpace(),
827827
acquired = node.peerPool.shortLogAcquired(),
828828
available = node.peerPool.shortLogAvailable(),
@@ -832,9 +832,10 @@ proc runDiscoveryLoop*(node: Eth2Node) {.async.} =
832832
new_peers = newPeers
833833

834834
if newPeers == 0:
835-
warn "Could not discover any new nodes in network, waiting",
836-
discovered = len(discoveredNodes), new_peers = newPeers,
837-
wanted_peers = node.wantedPeers
835+
if node.peerPool.lenSpace() <= node.wantedPeers shr 2:
836+
warn "Less than 25% wanted peers and could not discover new nodes",
837+
discovered = len(discoveredNodes), new_peers = newPeers,
838+
wanted_peers = node.wantedPeers
838839
await sleepAsync(5.seconds)
839840
else:
840841
await sleepAsync(1.seconds)
@@ -980,7 +981,7 @@ proc start*(node: Eth2Node) {.async.} =
980981
node.discovery.start()
981982
traceAsyncErrors node.runDiscoveryLoop()
982983
else:
983-
debug "Discovery disabled, trying bootstrap nodes",
984+
notice "Discovery disabled; trying bootstrap nodes",
984985
nodes = node.discovery.bootstrapRecords.len
985986
for enr in node.discovery.bootstrapRecords:
986987
let tr = enr.toTypedRecord()
@@ -1232,7 +1233,7 @@ proc createEth2Node*(
12321233
announcedAddresses = if extIp.isNone(): @[]
12331234
else: @[tcpEndPoint(extIp.get(), extTcpPort)]
12341235

1235-
info "Initializing networking", hostAddress,
1236+
notice "Initializing networking", hostAddress,
12361237
announcedAddresses
12371238

12381239
let keys = getPersistentNetKeys(rng[], conf)

beacon_chain/eth2_processor.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ proc attestationValidator*(
301301

302302
# Potential under/overflows are fine; would just create odd metrics and logs
303303
let delay = wallTime - attestation.data.slot.toBeaconTime
304-
debug "Attestation received", delay
304+
trace "Attestation received", delay
305305
let v = self.attestationPool[].validateAttestation(
306306
attestation, wallTime, committeeIndex)
307307
if v.isErr():

beacon_chain/fork_choice/fork_choice.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ proc find_head*(
343343
? self.proto_array.find_head(new_head, justified_root)
344344

345345
{.noSideEffect.}:
346-
debug "Fork choice requested",
346+
trace "Fork choice requested",
347347
justified_epoch = justified_epoch,
348348
justified_root = shortLog(justified_root),
349349
finalized_epoch = finalized_epoch,

beacon_chain/keystore_management.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ proc generateDeposits*(preset: RuntimePreset,
157157
secretsDir: string): Result[seq[DepositData], KeystoreGenerationError] =
158158
var deposits: seq[DepositData]
159159

160-
info "Generating deposits", totalNewValidators, validatorsDir, secretsDir
160+
notice "Generating deposits", totalNewValidators, validatorsDir, secretsDir
161161

162162
let withdrawalKeyPath = makeKeyPath(0, withdrawalKeyKind)
163163
# TODO: Explain why we are using an empty password
@@ -256,7 +256,7 @@ proc importKeystoresFromDir*(rng: var BrHmacDrbgContext,
256256
let keystore = try:
257257
Json.loadFile(file, Keystore)
258258
except SerializationError as e:
259-
trace "Invalid keystore", err = e.formatMsg(file)
259+
warn "Invalid keystore", err = e.formatMsg(file)
260260
continue
261261
except IOError as e:
262262
warn "Failed to read keystore file", file, err = e.msg
@@ -292,7 +292,7 @@ proc importKeystoresFromDir*(rng: var BrHmacDrbgContext,
292292
privKey.value, pubKey,
293293
keystore.path)
294294
if status.isOk:
295-
info "Keystore imported", file
295+
notice "Keystore imported", file
296296
else:
297297
error "Failed to import keystore", file, err = status.error
298298
else:
@@ -398,7 +398,7 @@ proc pickPasswordAndSaveWallet(rng: var BrHmacDrbgContext,
398398
if status.isErr:
399399
return err("failure to create wallet file due to " & status.error)
400400

401-
info "Wallet file written", path = outWalletFile
401+
notice "Wallet file written", path = outWalletFile
402402
return ok WalletPathPair(wallet: wallet, path: outWalletFile)
403403
finally:
404404
burnMem(password)

0 commit comments

Comments
 (0)