fix type-conversions-to-self, unexport from nimbus_beacon_node, and rm unused vars/procs (#3211)

This commit is contained in:
tersec 2021-12-20 11:21:17 +00:00 committed by GitHub
parent c7be88b432
commit 6ef3834f4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 20 additions and 32 deletions

View File

@ -118,7 +118,7 @@ proc fromNow*(c: BeaconClock, slot: Slot): tuple[inFuture: bool, offset: Duratio
proc durationToNextSlot*(c: BeaconClock): Duration = proc durationToNextSlot*(c: BeaconClock): Duration =
let (afterGenesis, slot) = c.now().toSlot() let (afterGenesis, slot) = c.now().toSlot()
if afterGenesis: if afterGenesis:
c.fromNow(Slot(slot) + 1'u64).offset c.fromNow(slot + 1'u64).offset
else: else:
c.fromNow(Slot(0)).offset c.fromNow(Slot(0)).offset

View File

@ -56,7 +56,7 @@ import
TopicParams, validateParameters, init TopicParams, validateParameters, init
type type
RpcServer* = RpcHttpServer RpcServer = RpcHttpServer
template init(T: type RpcHttpServer, ip: ValidIpAddress, port: Port): T = template init(T: type RpcHttpServer, ip: ValidIpAddress, port: Port): T =
newRpcHttpServer([initTAddress(ip, port)]) newRpcHttpServer([initTAddress(ip, port)])
@ -112,7 +112,7 @@ const SlashingDbName = "slashing_protection"
func getBeaconTimeFn(clock: BeaconClock): GetBeaconTimeFn = func getBeaconTimeFn(clock: BeaconClock): GetBeaconTimeFn =
return proc(): BeaconTime = clock.now() return proc(): BeaconTime = clock.now()
proc init*(T: type BeaconNode, proc init(T: type BeaconNode,
cfg: RuntimeConfig, cfg: RuntimeConfig,
rng: ref BrHmacDrbgContext, rng: ref BrHmacDrbgContext,
config: BeaconNodeConf, config: BeaconNodeConf,
@ -428,7 +428,7 @@ proc init*(T: type BeaconNode,
var node = BeaconNode( var node = BeaconNode(
nickname: nickname, nickname: nickname,
graffitiBytes: if config.graffiti.isSome: config.graffiti.get.GraffitiBytes graffitiBytes: if config.graffiti.isSome: config.graffiti.get
else: defaultGraffitiBytes(), else: defaultGraffitiBytes(),
network: network, network: network,
netKeys: netKeys, netKeys: netKeys,
@ -1086,7 +1086,7 @@ proc installMessageValidators(node: BeaconNode) =
installSyncCommitteeeValidators(node.dag.forkDigests.altair) installSyncCommitteeeValidators(node.dag.forkDigests.altair)
installSyncCommitteeeValidators(node.dag.forkDigests.merge) installSyncCommitteeeValidators(node.dag.forkDigests.merge)
proc stop*(node: BeaconNode) = proc stop(node: BeaconNode) =
bnStatus = BeaconNodeStatus.Stopping bnStatus = BeaconNodeStatus.Stopping
notice "Graceful shutdown" notice "Graceful shutdown"
if not node.config.inProcessValidators: if not node.config.inProcessValidators:
@ -1103,7 +1103,7 @@ proc stop*(node: BeaconNode) =
node.db.close() node.db.close()
notice "Databases closed" notice "Databases closed"
proc run*(node: BeaconNode) {.raises: [Defect, CatchableError].} = proc run(node: BeaconNode) {.raises: [Defect, CatchableError].} =
bnStatus = BeaconNodeStatus.Running bnStatus = BeaconNodeStatus.Running
if not(isNil(node.rpcServer)): if not(isNil(node.rpcServer)):
@ -1385,7 +1385,7 @@ proc handleValidatorExitCommand(config: BeaconNodeConf) {.async.} =
keystoreDir = validatorsDir / validatorKeyAsStr keystoreDir = validatorsDir / validatorKeyAsStr
if not dirExists(keystoreDir): if not dirExists(keystoreDir):
echo "The validator keystores directory '" & config.validatorsDir.string & echo "The validator keystores directory '" & config.validatorsDir &
"' does not contain a keystore for the selected validator with public " & "' does not contain a keystore for the selected validator with public " &
"key '" & validatorKeyAsStr & "'." "key '" & validatorKeyAsStr & "'."
quit 1 quit 1

View File

@ -429,9 +429,7 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
ires ires
node.withStateForBlockSlot(bslot): node.withStateForBlockSlot(bslot):
let let validatorsCount = lenu64(getStateField(stateData.data, validators))
current_epoch = getStateField(stateData.data, slot).epoch()
validatorsCount = lenu64(getStateField(stateData.data, validators))
let indices = let indices =
block: block:

View File

@ -123,7 +123,7 @@ template withStateForBlockSlot*(node: BeaconNode,
if isState(node.dag.headState): if isState(node.dag.headState):
withStateVars(node.dag.headState): withStateVars(node.dag.headState):
var cache {.inject.}: StateCache var cache {.inject, used.}: StateCache
body body
else: else:
let rpcState = assignClone(node.dag.headState) let rpcState = assignClone(node.dag.headState)

View File

@ -21,9 +21,6 @@ logScope: topics = "configapi"
type type
RpcServer = RpcHttpServer RpcServer = RpcHttpServer
template unimplemented() =
raise (ref CatchableError)(msg: "Unimplemented")
proc installConfigApiHandlers*(rpcServer: RpcServer, node: BeaconNode) {. proc installConfigApiHandlers*(rpcServer: RpcServer, node: BeaconNode) {.
raises: [Defect, CatchableError].} = raises: [Defect, CatchableError].} =
rpcServer.rpc("get_v1_config_fork_schedule") do () -> seq[Fork]: rpcServer.rpc("get_v1_config_fork_schedule") do () -> seq[Fork]:

View File

@ -244,7 +244,7 @@ proc initialize_beacon_state_from_eth1*(
pubkeyToIndex.withValue(pubkey, foundIdx) do: pubkeyToIndex.withValue(pubkey, foundIdx) do:
# Increase balance by deposit amount # Increase balance by deposit amount
increase_balance(state, ValidatorIndex foundIdx[], amount) increase_balance(state, foundIdx[], amount)
do: do:
if skipBlsValidation in flags or if skipBlsValidation in flags or
verify_deposit_signature(cfg, deposit): verify_deposit_signature(cfg, deposit):

View File

@ -381,7 +381,7 @@ func get_active_validator_indices*(state: ForkyBeaconState, epoch: Epoch):
## Return the sequence of active validator indices at ``epoch``. ## Return the sequence of active validator indices at ``epoch``.
var res = newSeqOfCap[ValidatorIndex](state.validators.len) var res = newSeqOfCap[ValidatorIndex](state.validators.len)
for idx in get_active_validator_indices(state, epoch): for idx in get_active_validator_indices(state, epoch):
res.add idx.ValidatorIndex res.add idx
res res
func get_active_validator_indices_len*(state: ForkyBeaconState, epoch: Epoch): func get_active_validator_indices_len*(state: ForkyBeaconState, epoch: Epoch):

View File

@ -171,9 +171,6 @@ proc getBlocks*[A, B](man: SyncManager[A, B], peer: A,
template headAge(): uint64 = template headAge(): uint64 =
wallSlot - headSlot wallSlot - headSlot
template queueAge(): uint64 =
wallSlot - man.queue.outSlot
template peerStatusAge(): Duration = template peerStatusAge(): Duration =
Moment.now() - peer.state(BeaconSync).statusLastTime Moment.now() - peer.state(BeaconSync).statusLastTime

View File

@ -217,7 +217,6 @@ proc produceAndPublishAggregates(service: AttestationServiceRef,
slot = adata.slot slot = adata.slot
committeeIndex = CommitteeIndex(adata.index) committeeIndex = CommitteeIndex(adata.index)
attestationRoot = adata.hash_tree_root() attestationRoot = adata.hash_tree_root()
genesisRoot = vc.beaconGenesis.genesis_validators_root
let aggregateItems = let aggregateItems =
block: block:

View File

@ -21,7 +21,6 @@ proc checkDuty(duty: RestAttesterDuty): bool =
(uint64(duty.validator_index) <= VALIDATOR_REGISTRY_LIMIT) (uint64(duty.validator_index) <= VALIDATOR_REGISTRY_LIMIT)
proc pollForValidatorIndices*(vc: ValidatorClientRef) {.async.} = proc pollForValidatorIndices*(vc: ValidatorClientRef) {.async.} =
let stateIdent = StateIdent.init(StateIdentType.Head)
let validatorIdents = let validatorIdents =
block: block:
var res: seq[ValidatorIdent] var res: seq[ValidatorIdent]
@ -332,7 +331,6 @@ template checkAndRestart(serviceLoop: DutiesServiceLoop,
proc mainLoop(service: DutiesServiceRef) {.async.} = proc mainLoop(service: DutiesServiceRef) {.async.} =
service.state = ServiceState.Running service.state = ServiceState.Running
let vc = service.client
try: try:
var var

View File

@ -163,10 +163,10 @@ proc getAttachedValidator*(node: BeaconNode,
let key = epochRef.validatorKey(idx) let key = epochRef.validatorKey(idx)
if key.isSome(): if key.isSome():
let validator = node.getAttachedValidator(key.get().toPubKey()) let validator = node.getAttachedValidator(key.get().toPubKey())
if validator != nil and validator.index != some(idx.ValidatorIndex): if validator != nil and validator.index != some(idx):
# Update index, in case the validator was activated! # Update index, in case the validator was activated!
notice "Validator activated", pubkey = validator.pubkey, index = idx notice "Validator activated", pubkey = validator.pubkey, index = idx
validator.index = some(idx.ValidatorIndex) validator.index = some(idx)
validator validator
else: else:
warn "Validator key not found", warn "Validator key not found",
@ -1233,7 +1233,6 @@ proc sendBeaconBlock*(node: BeaconNode, forked: ForkedSignedBeaconBlock
node.network.broadcastBeaconBlock(forked) node.network.broadcastBeaconBlock(forked)
let let
head = node.dag.head
wallTime = node.beaconClock.now() wallTime = node.beaconClock.now()
accepted = withBlck(forked): accepted = withBlck(forked):
let newBlockRef = node.blockProcessor[].storeBlock( let newBlockRef = node.blockProcessor[].storeBlock(