diff --git a/beacon_chain/eth2_network.nim b/beacon_chain/eth2_network.nim index b63a10dd6..4fe9dcbd5 100644 --- a/beacon_chain/eth2_network.nim +++ b/beacon_chain/eth2_network.nim @@ -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() diff --git a/beacon_chain/inspector.nim b/beacon_chain/inspector.nim index 3904aecbc..f34e0f09f 100644 --- a/beacon_chain/inspector.nim +++ b/beacon_chain/inspector.nim @@ -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) diff --git a/beacon_chain/keystore_management.nim b/beacon_chain/keystore_management.nim index 044f1e4c5..804f6318b 100644 --- a/beacon_chain/keystore_management.nim +++ b/beacon_chain/keystore_management.nim @@ -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 " & diff --git a/beacon_chain/mainchain_monitor.nim b/beacon_chain/mainchain_monitor.nim index f799fe3d1..97c72a1c9 100644 --- a/beacon_chain/mainchain_monitor.nim +++ b/beacon_chain/mainchain_monitor.nim @@ -92,7 +92,6 @@ type signature: Bytes96, merkleTreeIndex: Bytes8, j: JsonNode) {.raises: [Defect], gcsafe.} const - reorgDepthLimit = 1000 web3Timeouts = 5.seconds # TODO: Add preset validation diff --git a/beacon_chain/spec/datatypes.nim b/beacon_chain/spec/datatypes.nim index c43382ca6..c4d418100 100644 --- a/beacon_chain/spec/datatypes.nim +++ b/beacon_chain/spec/datatypes.nim @@ -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") diff --git a/beacon_chain/spec/keystore.nim b/beacon_chain/spec/keystore.nim index 7ea53dcf5..985360c3b 100644 --- a/beacon_chain/spec/keystore.nim +++ b/beacon_chain/spec/keystore.nim @@ -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 '"' diff --git a/beacon_chain/spec/state_transition.nim b/beacon_chain/spec/state_transition.nim index 51000988a..eca3f020f 100644 --- a/beacon_chain/spec/state_transition.nim +++ b/beacon_chain/spec/state_transition.nim @@ -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: diff --git a/beacon_chain/validator_client.nim b/beacon_chain/validator_client.nim index 999ab9ea9..5ffbe2dbd 100644 --- a/beacon_chain/validator_client.nim +++ b/beacon_chain/validator_client.nim @@ -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 diff --git a/tests/test_beacon_chain_db.nim b/tests/test_beacon_chain_db.nim index d4736a0cc..a59645f01 100644 --- a/tests/test_beacon_chain_db.nim +++ b/tests/test_beacon_chain_db.nim @@ -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)) == []