From 14712bbbdce03c674437297ff721c3413f2e2210 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Fri, 15 Nov 2019 12:04:49 +0100 Subject: [PATCH] random warning fixes --- beacon_chain/beacon_chain_db.nim | 3 +-- beacon_chain/beacon_node.nim | 16 ++++++---------- beacon_chain/libp2p_backend.nim | 3 --- beacon_chain/libp2p_daemon_backend.nim | 3 --- beacon_chain/spec/beaconstate.nim | 4 ++-- beacon_chain/spec/state_transition_helpers.nim | 2 +- beacon_chain/ssz/navigator.nim | 16 ++++++++-------- 7 files changed, 18 insertions(+), 29 deletions(-) diff --git a/beacon_chain/beacon_chain_db.nim b/beacon_chain/beacon_chain_db.nim index 97ca63318..59e39d545 100644 --- a/beacon_chain/beacon_chain_db.nim +++ b/beacon_chain/beacon_chain_db.nim @@ -62,8 +62,7 @@ func subkey(root: Eth2Digest, slot: Slot): auto = ret proc init*(T: type BeaconChainDB, backend: TrieDatabaseRef): BeaconChainDB = - new result - result.backend = backend + T(backend: backend) proc putBlock*(db: BeaconChainDB, key: Eth2Digest, value: BeaconBlock) = db.backend.put(subkey(type value, key), SSZ.encode(value)) diff --git a/beacon_chain/beacon_node.nim b/beacon_chain/beacon_node.nim index 5992fba4d..99351bba7 100644 --- a/beacon_chain/beacon_node.nim +++ b/beacon_chain/beacon_node.nim @@ -48,9 +48,6 @@ func localValidatorsDir(conf: BeaconNodeConf): string = func databaseDir(conf: BeaconNodeConf): string = conf.dataDir / "db" -template `//`(url, fragment: string): string = - url & "/" & fragment - proc saveValidatorKey(keyName, key: string, conf: BeaconNodeConf) = let validatorsDir = conf.dataDir / dataDirValidators let outputFile = validatorsDir / keyName @@ -157,7 +154,7 @@ proc init*(T: type BeaconNode, conf: BeaconNodeConf): Future[BeaconNode] {.async result.attachedValidators = ValidatorPool.init - let trieDB = trieDB newChainDb(string conf.databaseDir) + let trieDB = trieDB newChainDb(conf.databaseDir) result.db = BeaconChainDB.init(trieDB) # TODO this is problably not the right place to ensure that db is sane.. @@ -219,10 +216,10 @@ template withState( updateStateData(pool, cache, blockSlot) - template hashedState(): HashedBeaconState {.inject.} = cache.data - template state(): BeaconState {.inject.} = cache.data.data - template blck(): BlockRef {.inject.} = cache.blck - template root(): Eth2Digest {.inject.} = cache.data.root + template hashedState(): HashedBeaconState {.inject, used.} = cache.data + template state(): BeaconState {.inject, used.} = cache.data.data + template blck(): BlockRef {.inject, used.} = cache.blck + template root(): Eth2Digest {.inject, used.} = cache.data.root body @@ -1056,8 +1053,7 @@ when isMainModule: of query: var - trieDB = trieDB newChainDb(string config.databaseDir) - db = BeaconChainDB.init(trieDB) + trieDB = trieDB newChainDb(config.databaseDir) case config.queryCmd of QueryCmd.nimQuery: diff --git a/beacon_chain/libp2p_backend.nim b/beacon_chain/libp2p_backend.nim index a0b273171..cc882c35f 100644 --- a/beacon_chain/libp2p_backend.nim +++ b/beacon_chain/libp2p_backend.nim @@ -65,9 +65,6 @@ type ProtocolInfo* = ptr ProtocolInfoObj - CompressedMsgId = tuple - protocolIdx, methodId: int - ResponseCode* = enum Success InvalidRequest diff --git a/beacon_chain/libp2p_daemon_backend.nim b/beacon_chain/libp2p_daemon_backend.nim index 48674a181..df3c932ed 100644 --- a/beacon_chain/libp2p_daemon_backend.nim +++ b/beacon_chain/libp2p_daemon_backend.nim @@ -65,9 +65,6 @@ type ProtocolInfo* = ptr ProtocolInfoObj - CompressedMsgId = tuple - protocolIdx, methodId: int - ResponseCode* = enum Success InvalidRequest diff --git a/beacon_chain/spec/beaconstate.nim b/beacon_chain/spec/beaconstate.nim index 99dadca82..2b417f852 100644 --- a/beacon_chain/spec/beaconstate.nim +++ b/beacon_chain/spec/beaconstate.nim @@ -315,7 +315,7 @@ func process_registry_updates*(state: var BeaconState) = if i.uint64 >= churn_limit: break let - (epoch, index) = epoch_and_index + (_, index) = epoch_and_index validator = addr state.validators[index] if validator.activation_epoch == FAR_FUTURE_EPOCH: validator.activation_epoch = @@ -359,7 +359,7 @@ func get_attesting_indices*(state: BeaconState, stateCache: var StateCache): HashSet[ValidatorIndex] = # Return the set of attesting indices corresponding to ``data`` and ``bits``. - result = initSet[ValidatorIndex]() + result = initHashSet[ValidatorIndex]() let committee = get_beacon_committee(state, data.slot, data.index, stateCache) for i, index in committee: if bits[i]: diff --git a/beacon_chain/spec/state_transition_helpers.nim b/beacon_chain/spec/state_transition_helpers.nim index bc7e8dd7e..9b4c32e77 100644 --- a/beacon_chain/spec/state_transition_helpers.nim +++ b/beacon_chain/spec/state_transition_helpers.nim @@ -27,7 +27,7 @@ func shortLog*(x: Checkpoint): string = func get_attesting_indices*( state: BeaconState, attestations: openarray[PendingAttestation], stateCache: var StateCache): HashSet[ValidatorIndex] = - result = initSet[ValidatorIndex]() + result = initHashSet[ValidatorIndex]() for a in attestations: result = result.union(get_attesting_indices( state, a.data, a.aggregation_bits, stateCache)) diff --git a/beacon_chain/ssz/navigator.nim b/beacon_chain/ssz/navigator.nim index 49aa422ab..6f8473e98 100644 --- a/beacon_chain/ssz/navigator.nim +++ b/beacon_chain/ssz/navigator.nim @@ -1,5 +1,5 @@ import - stew/objects, stew/ranges/ptr_arith, + stew/[ptrops, objects], stew/ranges/ptr_arith, ./types, ./bytes_reader type @@ -44,11 +44,11 @@ func navigateToField*[T](n: SszNavigator[T], when isFixedSize(SszFieldType): SszNavigator[FieldType](m: MemRange( - startAddr: shift(n.m.startAddr, boundingOffsets[0]), + startAddr: offset(n.m.startAddr, boundingOffsets[0]), length: boundingOffsets[1] - boundingOffsets[0])) else: - template readOffset(offset): int = - int fromSszBytes(uint32, makeOpenArray(shift(n.m.startAddr, offset), + template readOffset(off): int = + int fromSszBytes(uint32, makeOpenArray(offset(n.m.startAddr, off), sizeof(uint32))) let startOffset = readOffset boundingOffsets[0] @@ -59,7 +59,7 @@ func navigateToField*[T](n: SszNavigator[T], raise newException(MalformedSszError, "Incorrect offset values") SszNavigator[FieldType](m: MemRange( - startAddr: shift(n.m.startAddr, startOffset), + startAddr: offset(n.m.startAddr, startOffset), length: endOffset - startOffset)) template `.`*[T](n: SszNavigator[T], field: untyped): auto = @@ -69,7 +69,7 @@ template `.`*[T](n: SszNavigator[T], field: untyped): auto = func indexVarSizeList(m: MemRange, idx: int): MemRange = template readOffset(pos): int = - int fromSszBytes(uint32, makeOpenArray(shift(m.startAddr, pos), offsetSize)) + int fromSszBytes(uint32, makeOpenArray(offset(m.startAddr, pos), offsetSize)) let offsetPos = offsetSize * idx checkBounds(m, offsetPos + offsetSize) @@ -93,7 +93,7 @@ func indexVarSizeList(m: MemRange, idx: int): MemRange = else: m.length - MemRange(startAddr: m.startAddr.shift(elemPos), length: endPos - elemPos) + MemRange(startAddr: m.startAddr.offset(elemPos), length: endPos - elemPos) template indexList(n, idx, T: untyped): untyped = type R = T @@ -103,7 +103,7 @@ template indexList(n, idx, T: untyped): untyped = const elemSize = fixedPortionSize(ElemType) let elemPos = idx * elemSize checkBounds(n.m, elemPos + elemSize) - SszNavigator[R](m: MemRange(startAddr: shift(n.m.startAddr, elemPos), + SszNavigator[R](m: MemRange(startAddr: offset(n.m.startAddr, elemPos), length: elemSize)) else: SszNavigator[R](m: indexVarSizeList(n.m, idx))