From c36d2aa10301c9cab99bc5d9e502f597a68f38a1 Mon Sep 17 00:00:00 2001 From: tersec Date: Tue, 5 Dec 2023 11:45:47 +0000 Subject: [PATCH] fix XDeclaredButNotUsed warnings (#5648) --- .../light_client_processor.nim | 5 +- beacon_chain/nimbus_signing_node.nim | 2 +- beacon_chain/rpc/rest_beacon_api.nim | 1 - beacon_chain/validator_client/api.nim | 1 - .../validator_client/block_service.nim | 12 +-- beacon_chain/validator_client/common.nim | 2 - .../validator_client/fallback_service.nim | 2 +- beacon_chain/validators/beacon_validators.nim | 4 +- ncli/ncli_split_keystore.nim | 7 -- ncli/validator_db_aggregator.nim | 97 ++++++++++--------- 10 files changed, 62 insertions(+), 71 deletions(-) diff --git a/beacon_chain/gossip_processing/light_client_processor.nim b/beacon_chain/gossip_processing/light_client_processor.nim index 34b20f4b8..c4205f684 100644 --- a/beacon_chain/gossip_processing/light_client_processor.nim +++ b/beacon_chain/gossip_processing/light_client_processor.nim @@ -214,7 +214,6 @@ proc processObject( obj: SomeForkedLightClientObject, wallTime: BeaconTime): Result[void, VerifierError] = let - wallSlot = wallTime.slotOrZero() res = withForkyObject(obj): when lcDataFork > LightClientDataFork.None: when forkyObject is ForkyLightClientBootstrap: @@ -242,7 +241,9 @@ proc processObject( self.store[].migrateToDataFork(lcDataFork) withForkyStore(self.store[]): when lcDataFork > LightClientDataFork.None: - let upgradedObject = obj.migratingToDataFork(lcDataFork) + let + wallSlot = wallTime.slotOrZero() + upgradedObject = obj.migratingToDataFork(lcDataFork) process_light_client_update( forkyStore, upgradedObject.forky(lcDataFork), wallSlot, self.cfg, self.genesis_validators_root) diff --git a/beacon_chain/nimbus_signing_node.nim b/beacon_chain/nimbus_signing_node.nim index 1b1e5b7d7..4c6fdfc13 100644 --- a/beacon_chain/nimbus_signing_node.nim +++ b/beacon_chain/nimbus_signing_node.nim @@ -427,7 +427,7 @@ template runWithSignals(sn: SigningNodeRef, body: untyped): bool = discard await race(future, sn.sigintHandleFut, sn.sigtermHandleFut) if future.finished(): if future.failed() or future.cancelled(): - let exc = future.readError() + discard future.readError() debug "Signing node initialization failed" var pending: seq[Future[void]] if not(sn.sigintHandleFut.finished()): diff --git a/beacon_chain/rpc/rest_beacon_api.nim b/beacon_chain/rpc/rest_beacon_api.nim index 16cb88ed1..fe102fd9d 100644 --- a/beacon_chain/rpc/rest_beacon_api.nim +++ b/beacon_chain/rpc/rest_beacon_api.nim @@ -289,7 +289,6 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) = node.withStateForBlockSlotId(bslot): let stateEpoch = getStateField(state, slot).epoch() - validatorsCount = lenu64(getStateField(state, validators)) indices = node.getIndices(validatorIds, state).valueOr: return RestApiResponse.jsonError(error) response = diff --git a/beacon_chain/validator_client/api.nim b/beacon_chain/validator_client/api.nim index dab2b896b..79fd585aa 100644 --- a/beacon_chain/validator_client/api.nim +++ b/beacon_chain/validator_client/api.nim @@ -14,7 +14,6 @@ import "."/[common, fallback_service, scoring] export eth2_rest_serialization, common const - ResponseSuccess = "Received successful response" ResponseInvalidError = "Received invalid request response" ResponseInternalError = "Received internal error response" ResponseUnexpectedError = "Received unexpected error response" diff --git a/beacon_chain/validator_client/block_service.nim b/beacon_chain/validator_client/block_service.nim index a05464777..11b9d52c2 100644 --- a/beacon_chain/validator_client/block_service.nim +++ b/beacon_chain/validator_client/block_service.nim @@ -243,8 +243,8 @@ proc publishBlock(vc: ValidatorClientRef, currentSlot, slot: Slot, if not(normalBlockFut.finished()): await normalBlockFut.cancelAndWait() raise exc - except CatchableError as exc: - # This should not be happened, because all the exceptions handled. + except CatchableError: + # This should not happen, because all the exceptions are handled. Opt.none(PreparedBlindedBeaconBlock) let normalBlock = @@ -253,8 +253,8 @@ proc publishBlock(vc: ValidatorClientRef, currentSlot, slot: Slot, await normalBlockFut except CancelledError as exc: raise exc - except CatchableError as exc: - # This should not be happened, because all the exceptions handled. + except CatchableError: + # This should not happen, because all the exceptions are handled. Opt.none(PreparedBeaconBlock) else: if not(normalBlockFut.finished()): @@ -449,7 +449,7 @@ proc proposeBlock(vc: ValidatorClientRef, slot: Slot, debug "Block proposing process was interrupted", slot = slot, validator = shortLog(proposerKey) raise exc - except CatchableError as exc: + except CatchableError: error "Unexpected error encountered while proposing block", slot = slot, validator = shortLog(validator) @@ -814,7 +814,7 @@ proc mainLoop(service: BlockServiceRef) {.async.} = # Future is not going to be completed, so the only way to exit, is to # cancel it. await future - except CancelledError as exc: + except CancelledError: debug "Service interrupted" except CatchableError as exc: error "Service crashed with unexpected error", err_name = exc.name, diff --git a/beacon_chain/validator_client/common.nim b/beacon_chain/validator_client/common.nim index 133f33809..7a81dadcc 100644 --- a/beacon_chain/validator_client/common.nim +++ b/beacon_chain/validator_client/common.nim @@ -406,7 +406,6 @@ func getFailureReason*(failure: ApiNodeFailure): string = [failure.reason, status, request, $failure.failure].join(";") proc getFailureReason*(exc: ref ValidatorApiError): string = - var counts: array[int(high(ApiFailure)) + 1, int] let errors = exc[].data errorsCount = len(errors) @@ -825,7 +824,6 @@ proc getDurationToNextAttestation*(vc: ValidatorClientRef, for key, item in vc.attesters: let duty = item.duties.getOrDefault(epoch, DefaultDutyAndProof) if not(duty.isDefault()): - let dutySlotTime = duty.data.slot if (duty.data.slot < minSlot) and (duty.data.slot >= slot): minSlot = duty.data.slot if minSlot != FAR_FUTURE_SLOT: diff --git a/beacon_chain/validator_client/fallback_service.nim b/beacon_chain/validator_client/fallback_service.nim index 59f729cd8..0471263e8 100644 --- a/beacon_chain/validator_client/fallback_service.nim +++ b/beacon_chain/validator_client/fallback_service.nim @@ -484,7 +484,7 @@ proc mainLoop(service: FallbackServiceRef) {.async.} = if await service.checkNodes(): service.changesEvent.fire() await sleepAsync(2.seconds) false - except CancelledError as exc: + except CancelledError: debug "Service interrupted" if not(timeMonitorFut.finished()): await timeMonitorFut.cancelAndWait() true diff --git a/beacon_chain/validators/beacon_validators.nim b/beacon_chain/validators/beacon_validators.nim index 9039d672b..d97c3ab7e 100644 --- a/beacon_chain/validators/beacon_validators.nim +++ b/beacon_chain/validators/beacon_validators.nim @@ -1815,9 +1815,7 @@ proc handleValidatorDuties*(node: BeaconNode, lastSlot, slot: Slot) {.async.} = curSlot += 1 - let - newHead = await handleProposal(node, head, slot) - didSubmitBlock = (newHead != head) + let newHead = await handleProposal(node, head, slot) head = newHead let diff --git a/ncli/ncli_split_keystore.nim b/ncli/ncli_split_keystore.nim index f3ab8f99d..87f54b54b 100644 --- a/ncli/ncli_split_keystore.nim +++ b/ncli/ncli_split_keystore.nim @@ -44,13 +44,6 @@ type desc: "A directory to store the generated validator keystores" name: "out-dir" }: OutDir -template valueOr(x: Option, elseBlock: untyped): untyped = - let val = x - if val.isSome: - val.get - else: - elseBlock - proc main = let conf = load Config if conf.threshold == 0: diff --git a/ncli/validator_db_aggregator.nim b/ncli/validator_db_aggregator.nim index 9a93986c2..9ee202d07 100644 --- a/ncli/validator_db_aggregator.nim +++ b/ncli/validator_db_aggregator.nim @@ -6,13 +6,13 @@ # at your option. This file may not be copied, modified, or distributed except according to those terms. import - std/[os, strutils, streams, parsecsv], + std/[parsecsv, streams], stew/[io2, byteutils], chronicles, confutils, snappy, ../beacon_chain/spec/datatypes/base, ./ncli_common -when defined(posix): - import system/ansi_c +from std/os import fileExists +from std/strutils import parseBiggestInt, parseBiggestUInt type AggregatorConf = object @@ -199,51 +199,54 @@ proc advanceEpochs*(aggregator: var ValidatorDbAggregator, epoch: Epoch, aggregator.inclusionDelaysCount.setLen(0) aggregator.epochsAggregated = 0 -proc aggregateEpochs(startEpoch, endEpoch: Epoch, resolution: uint, - inputDir, outputDir: string) = - if startEpoch > endEpoch: - fatal "Start epoch cannot be larger than the end one.", - startEpoch = startEpoch, endEpoch = endEpoch - quit QuitFailure - - info "Aggregating epochs ...", startEpoch = startEpoch, endEpoch = endEpoch, - inputDir = inputDir, outputDir = outputDir - - var aggregator = ValidatorDbAggregator.init(outputDir, resolution, endEpoch) - - for epoch in startEpoch .. endEpoch: - let filePath = getFilePathForEpoch(epoch, inputDir) - info "Processing file ...", file = filePath - - let data = io2.readAllBytes(filePath) - doAssert data.isOk - let dataStream = newStringStream( - string.fromBytes(snappy.decode( - data.get.toOpenArray(0, data.get.len - 1)))) - - var csvParser: CsvParser - csvParser.open(dataStream, filePath) - - var validatorsCount = 0 - while csvParser.readRow: - inc validatorsCount - let rp = parseRow(csvParser.row) - aggregator.addValidatorData(validatorsCount - 1, rp) - - aggregator.advanceEpochs(epoch, shouldShutDown) - - if shouldShutDown: - quit QuitSuccess - -proc controlCHook {.noconv.} = - notice "Shutting down after having received SIGINT." - shouldShutDown = true - -proc exitOnSigterm(signal: cint) {.noconv.} = - notice "Shutting down after having received SIGTERM." - shouldShutDown = true - when isMainModule: + when defined(posix): + import system/ansi_c + + proc aggregateEpochs(startEpoch, endEpoch: Epoch, resolution: uint, + inputDir, outputDir: string) = + if startEpoch > endEpoch: + fatal "Start epoch cannot be larger than the end one.", + startEpoch = startEpoch, endEpoch = endEpoch + quit QuitFailure + + info "Aggregating epochs ...", startEpoch = startEpoch, endEpoch = endEpoch, + inputDir = inputDir, outputDir = outputDir + + var aggregator = ValidatorDbAggregator.init(outputDir, resolution, endEpoch) + + for epoch in startEpoch .. endEpoch: + let filePath = getFilePathForEpoch(epoch, inputDir) + info "Processing file ...", file = filePath + + let data = io2.readAllBytes(filePath) + doAssert data.isOk + let dataStream = newStringStream( + string.fromBytes(snappy.decode( + data.get.toOpenArray(0, data.get.len - 1)))) + + var csvParser: CsvParser + csvParser.open(dataStream, filePath) + + var validatorsCount = 0 + while csvParser.readRow: + inc validatorsCount + let rp = parseRow(csvParser.row) + aggregator.addValidatorData(validatorsCount - 1, rp) + + aggregator.advanceEpochs(epoch, shouldShutDown) + + if shouldShutDown: + quit QuitSuccess + + proc controlCHook {.noconv.} = + notice "Shutting down after having received SIGINT." + shouldShutDown = true + + proc exitOnSigterm(signal: cint) {.noconv.} = + notice "Shutting down after having received SIGTERM." + shouldShutDown = true + proc main = setControlCHook(controlCHook) when defined(posix):