Fix some warnings and hints and partly revert #1610 (#1615)

* address some XDeclaredButNotUsed, ConvFromXtoItselfNotNeeded, and UnusedImport hints and warnings

* partly revert #1610
This commit is contained in:
tersec 2020-09-08 11:32:43 +00:00 committed by GitHub
parent b3b578501a
commit d0de1a49a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 22 additions and 23 deletions

View File

@ -1,6 +1,6 @@
import import
# Std lib # Std lib
std/[typetraits, strutils, os, algorithm, sequtils, math, sets], std/[typetraits, strutils, os, algorithm, math, sets],
std/options as stdOptions, std/options as stdOptions,
# Status libs # Status libs
@ -25,6 +25,9 @@ import
ssz/ssz_serialization, ssz/ssz_serialization,
peer_pool, spec/[datatypes, network], ./time peer_pool, spec/[datatypes, network], ./time
when chronicles.enabledLogLevel == LogLevel.TRACE:
import std/sequtils
export export
version, multiaddress, peer_pool, peerinfo, p2pProtocol, connection, version, multiaddress, peer_pool, peerinfo, p2pProtocol, connection,
libp2p_json_serialization, ssz_serialization, results libp2p_json_serialization, ssz_serialization, results
@ -744,8 +747,6 @@ proc dialPeer*(node: Eth2Node, peerAddr: PeerAddr) {.async.} =
# TODO connect is called here, but there's no guarantee that the connection # TODO connect is called here, but there's no guarantee that the connection
# we get when using dialPeer later on is the one we just connected # we get when using dialPeer later on is the one we just connected
let peer = node.getPeer(peerAddr.peerId)
await node.switch.connect(peerAddr.peerId, peerAddr.addrs) await node.switch.connect(peerAddr.peerId, peerAddr.addrs)
#let msDial = newMultistream() #let msDial = newMultistream()

View File

@ -339,7 +339,7 @@ proc connectToNetwork(switch: Switch, nodes: seq[PeerInfo],
var timed, succeed, failed: int var timed, succeed, failed: int
for pinfo in nodes: for pinfo in nodes:
pending.add(switch.connect(pinfo)) pending.add(switch.connect(pinfo.peerId, pinfo.addrs))
debug "Connecting to peers", count = $len(pending), peers = nodes debug "Connecting to peers", count = $len(pending), peers = nodes
@ -571,7 +571,7 @@ proc discoveryLoop(conf: InspectorConf,
if pinfoOpt.isOk(): if pinfoOpt.isOk():
let pinfo = pinfoOpt.get() let pinfo = pinfoOpt.get()
if pinfo.hasTCP(): if pinfo.hasTCP():
if not switch.isConnected(pinfo): if not switch.isConnected(pinfo.peerId):
debug "Discovered new peer", peer = pinfo, debug "Discovered new peer", peer = pinfo,
peers_count = len(peers) peers_count = len(peers)
await connQueue.addLast(pinfo) await connQueue.addLast(pinfo)

View File

@ -215,7 +215,7 @@ proc readPasswordInput(prompt: string, password: var TaintedString): bool =
true true
else: else:
readPasswordFromStdin(prompt, password) readPasswordFromStdin(prompt, password)
except IOError as exc: except IOError:
false false
proc setStyleNoError(styles: set[Style]) = proc setStyleNoError(styles: set[Style]) =
@ -341,7 +341,7 @@ proc pickPasswordAndSaveWallet(rng: var BrHmacDrbgContext,
try: try:
echo "The entered password should be at least $1 characters." % echo "The entered password should be at least $1 characters." %
[$minPasswordLen] [$minPasswordLen]
except ValueError as err: except ValueError:
raiseAssert "The format string above is correct" raiseAssert "The format string above is correct"
elif password in mostCommonPasswords: elif password in mostCommonPasswords:
echo80 "The entered password is too commonly used and it would be easy " & echo80 "The entered password is too commonly used and it would be easy " &

View File

@ -92,7 +92,6 @@ type
signature: Bytes96, merkleTreeIndex: Bytes8, j: JsonNode) {.raises: [Defect], gcsafe.} signature: Bytes96, merkleTreeIndex: Bytes8, j: JsonNode) {.raises: [Defect], gcsafe.}
const const
reorgDepthLimit = 1000
web3Timeouts = 5.seconds web3Timeouts = 5.seconds
# TODO: Add preset validation # TODO: Add preset validation

View File

@ -726,7 +726,7 @@ func init*(T: type GraffitiBytes, input: string): GraffitiBytes
elif input.len mod 2 != 0: elif input.len mod 2 != 0:
raise newException(ValueError, "The graffiti hex string should have an even length") raise newException(ValueError, "The graffiti hex string should have an even length")
hexToByteArray(string input, distinctBase(result)) hexToByteArray(input, distinctBase(result))
else: else:
if input.len > 32: if input.len > 32:
raise newException(ValueError, "The graffiti value should be 32 characters or less") raise newException(ValueError, "The graffiti value should be 32 characters or less")

View File

@ -355,12 +355,6 @@ proc shaChecksum(key, cipher: openarray[byte]): Sha256Digest =
result = ctx.finish() result = ctx.finish()
ctx.clear() ctx.clear()
template hexToBytes(data, name: string): untyped =
try:
hexToSeqByte(data)
except ValueError:
return err "ks: failed to parse " & name
proc writeJsonHexString(s: OutputStream, data: openarray[byte]) proc writeJsonHexString(s: OutputStream, data: openarray[byte])
{.raises: [IOError, Defect].} = {.raises: [IOError, Defect].} =
s.write '"' s.write '"'

View File

@ -124,6 +124,15 @@ func process_slot*(state: var HashedBeaconState) {.nbench.} =
state.data.block_roots[state.data.slot mod SLOTS_PER_HISTORICAL_ROOT] = state.data.block_roots[state.data.slot mod SLOTS_PER_HISTORICAL_ROOT] =
hash_tree_root(state.data.latest_block_header) hash_tree_root(state.data.latest_block_header)
func clear_epoch_from_cache(cache: var StateCache, epoch: Epoch) =
cache.shuffled_active_validator_indices.del epoch
let
start_slot = epoch.compute_start_slot_at_epoch
end_slot = (epoch + 1).compute_start_slot_at_epoch
for i in start_slot ..< end_slot:
cache.beacon_proposer_indices.del i
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function # https://github.com/ethereum/eth2.0-specs/blob/v0.12.2/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
proc advance_slot*( proc advance_slot*(
state: var HashedBeaconState, updateFlags: UpdateFlags, state: var HashedBeaconState, updateFlags: UpdateFlags,
@ -137,11 +146,8 @@ proc advance_slot*(
# Note: Genesis epoch = 0, no need to test if before Genesis # Note: Genesis epoch = 0, no need to test if before Genesis
beacon_previous_validators.set(get_epoch_validator_count(state.data)) beacon_previous_validators.set(get_epoch_validator_count(state.data))
process_epoch(state.data, updateFlags, epochCache) process_epoch(state.data, updateFlags, epochCache)
clear_epoch_from_cache(
# Current EpochRef system doesn't look ahead within individual BlockRefs epochCache, (state.data.slot + 1).compute_epoch_at_slot)
doAssert (state.data.slot + 1).compute_epoch_at_slot notin
epochCache.shuffled_active_validator_indices
doAssert state.data.slot + 1 notin epochCache.beacon_proposer_indices
state.data.slot += 1 state.data.slot += 1
if is_epoch_transition: if is_epoch_transition:

View File

@ -213,14 +213,14 @@ programMain:
var vc = ValidatorClient( var vc = ValidatorClient(
config: config, config: config,
client: newRpcHttpClient(), client: newRpcHttpClient(),
graffitiBytes: if config.graffiti.isSome: config.graffiti.get.GraffitiBytes graffitiBytes: if config.graffiti.isSome: config.graffiti.get
else: defaultGraffitiBytes()) else: defaultGraffitiBytes())
# load all the validators from the data dir into memory # load all the validators from the data dir into memory
for curr in vc.config.validatorKeys: for curr in vc.config.validatorKeys:
vc.attachedValidators.addLocalValidator(curr.toPubKey.initPubKey, curr) vc.attachedValidators.addLocalValidator(curr.toPubKey.initPubKey, curr)
waitFor vc.client.connect($vc.config.rpcAddress, Port(vc.config.rpcPort)) waitFor vc.client.connect($vc.config.rpcAddress, vc.config.rpcPort)
info "Connected to BN", info "Connected to BN",
port = vc.config.rpcPort, port = vc.config.rpcPort,
address = vc.config.rpcAddress address = vc.config.rpcAddress

View File

@ -91,7 +91,6 @@ suiteReport "Beacon chain DB" & preset():
TrustedBeaconBlock(slot: GENESIS_SLOT + 1, parent_root: a0.root)) TrustedBeaconBlock(slot: GENESIS_SLOT + 1, parent_root: a0.root))
a2 = withDigest( a2 = withDigest(
TrustedBeaconBlock(slot: GENESIS_SLOT + 2, parent_root: a1.root)) TrustedBeaconBlock(slot: GENESIS_SLOT + 2, parent_root: a1.root))
a2r = hash_tree_root(a2.message)
doAssert toSeq(db.getAncestors(a0.root)) == [] doAssert toSeq(db.getAncestors(a0.root)) == []
doAssert toSeq(db.getAncestors(a2.root)) == [] doAssert toSeq(db.getAncestors(a2.root)) == []