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 Mamy Ratsimbazafy
parent 45dd971955
commit cb1a5cf2ca
9 changed files with 22 additions and 23 deletions

View File

@ -1,6 +1,6 @@
import
# Std lib
std/[typetraits, strutils, os, algorithm, sequtils, math, sets],
std/[typetraits, strutils, os, algorithm, math, sets],
std/options as stdOptions,
# Status libs
@ -25,6 +25,9 @@ import
ssz/ssz_serialization,
peer_pool, spec/[datatypes, network], ./time
when chronicles.enabledLogLevel == LogLevel.TRACE:
import std/sequtils
export
version, multiaddress, peer_pool, peerinfo, p2pProtocol, connection,
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
# 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)
#let msDial = newMultistream()

View File

@ -339,7 +339,7 @@ proc connectToNetwork(switch: Switch, nodes: seq[PeerInfo],
var timed, succeed, failed: int
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
@ -571,7 +571,7 @@ proc discoveryLoop(conf: InspectorConf,
if pinfoOpt.isOk():
let pinfo = pinfoOpt.get()
if pinfo.hasTCP():
if not switch.isConnected(pinfo):
if not switch.isConnected(pinfo.peerId):
debug "Discovered new peer", peer = pinfo,
peers_count = len(peers)
await connQueue.addLast(pinfo)

View File

@ -215,7 +215,7 @@ proc readPasswordInput(prompt: string, password: var TaintedString): bool =
true
else:
readPasswordFromStdin(prompt, password)
except IOError as exc:
except IOError:
false
proc setStyleNoError(styles: set[Style]) =
@ -341,7 +341,7 @@ proc pickPasswordAndSaveWallet(rng: var BrHmacDrbgContext,
try:
echo "The entered password should be at least $1 characters." %
[$minPasswordLen]
except ValueError as err:
except ValueError:
raiseAssert "The format string above is correct"
elif password in mostCommonPasswords:
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.}
const
reorgDepthLimit = 1000
web3Timeouts = 5.seconds
# TODO: Add preset validation

View File

@ -726,7 +726,7 @@ func init*(T: type GraffitiBytes, input: string): GraffitiBytes
elif input.len mod 2 != 0:
raise newException(ValueError, "The graffiti hex string should have an even length")
hexToByteArray(string input, distinctBase(result))
hexToByteArray(input, distinctBase(result))
else:
if input.len > 32:
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()
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])
{.raises: [IOError, Defect].} =
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] =
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
proc advance_slot*(
state: var HashedBeaconState, updateFlags: UpdateFlags,
@ -137,11 +146,8 @@ proc advance_slot*(
# Note: Genesis epoch = 0, no need to test if before Genesis
beacon_previous_validators.set(get_epoch_validator_count(state.data))
process_epoch(state.data, updateFlags, epochCache)
# Current EpochRef system doesn't look ahead within individual BlockRefs
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
clear_epoch_from_cache(
epochCache, (state.data.slot + 1).compute_epoch_at_slot)
state.data.slot += 1
if is_epoch_transition:

View File

@ -213,14 +213,14 @@ programMain:
var vc = ValidatorClient(
config: config,
client: newRpcHttpClient(),
graffitiBytes: if config.graffiti.isSome: config.graffiti.get.GraffitiBytes
graffitiBytes: if config.graffiti.isSome: config.graffiti.get
else: defaultGraffitiBytes())
# load all the validators from the data dir into memory
for curr in vc.config.validatorKeys:
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",
port = vc.config.rpcPort,
address = vc.config.rpcAddress

View File

@ -91,7 +91,6 @@ suiteReport "Beacon chain DB" & preset():
TrustedBeaconBlock(slot: GENESIS_SLOT + 1, parent_root: a0.root))
a2 = withDigest(
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(a2.root)) == []