Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanups: unused and duplicate imports, inconsistent naming, URL updates #3724

Merged
merged 1 commit into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions beacon_chain/beacon_chain_db_immutable.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
{.push raises: [Defect].}

import
stew/results,
serialization,
eth/db/kvstore,
./spec/datatypes/[base, altair, bellatrix],
./spec/[eth2_ssz_serialization, eth2_merkleization]

Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/consensus_object_pools/attestation_pool.nim
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ func init(
if participation_bitmap[validator_index] != 0:
# If any flag got set, there was an attestation from this validator.
validator_bits[index_in_committee] = true
result.add((slot, committee_index.uint64), validator_bits)
result[(slot, committee_index.uint64)] = validator_bits

# This treats all types of rewards as equivalent, which isn't ideal
update_attestation_pool_cache(
Expand Down
6 changes: 3 additions & 3 deletions beacon_chain/consensus_object_pools/blockchain_dag.nim
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export
eth2_merkleization, eth2_ssz_serialization,
block_pools_types, results, beacon_chain_db

# https://github.com/ethereum/eth2.0-metrics/blob/master/metrics.md#interop-metrics
# https://github.com/ethereum/beacon-metrics/blob/master/metrics.md#interop-metrics
declareGauge beacon_head_root, "Root of the head block of the beacon chain"
declareGauge beacon_head_slot, "Slot of the head block of the beacon chain"

# https://github.com/ethereum/eth2.0-metrics/blob/master/metrics.md#interop-metrics
# https://github.com/ethereum/beacon-metrics/blob/master/metrics.md#interop-metrics
declareGauge beacon_finalized_epoch, "Current finalized epoch" # On epoch transition
declareGauge beacon_finalized_root, "Current finalized root" # On epoch transition
declareGauge beacon_current_justified_epoch, "Current justified epoch" # On epoch transition
Expand Down Expand Up @@ -542,7 +542,7 @@ proc currentSyncCommitteeForPeriod*(

proc updateBeaconMetrics(
state: ForkedHashedBeaconState, bid: BlockId, cache: var StateCache) =
# https://github.com/ethereum/eth2.0-metrics/blob/master/metrics.md#additional-metrics
# https://github.com/ethereum/beacon-metrics/blob/master/metrics.md#additional-metrics
# both non-negative, so difference can't overflow or underflow int64

beacon_head_root.set(bid.root.toGaugeValue)
Expand Down
4 changes: 2 additions & 2 deletions beacon_chain/era_db.nim
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,10 @@ proc getPartialState(
false

iterator getBlockIds*(
db: EraDB, historical_roots: openArray[Eth2Digest], startSlot: Slot): BlockId =
db: EraDB, historical_roots: openArray[Eth2Digest], start_slot: Slot): BlockId =
var
state = (ref PartialBeaconState)() # avoid stack overflow
slot = startSlot
slot = start_slot

while true:
# `case` ensures we're on a fork for which the `PartialBeaconState`
Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/eth1/eth1_monitor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import
std/[deques, options, strformat, strutils, sequtils, tables,
typetraits, uri, json],
# Nimble packages:
chronos, json, metrics, chronicles/timings, stint/endians2,
chronos, metrics, chronicles/timings, stint/endians2,
web3, web3/ethtypes as web3Types, web3/ethhexstrings, web3/engine_api,
eth/common/eth_types,
eth/async_utils, stew/[byteutils, objects, shims/hashes],
Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/fork_choice/proto_array.nim
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func init*(T: type ProtoArray,
indices: {node.root: 0}.toTable()
)

# https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/fork-choice.md#configuration
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/fork-choice.md#configuration
# https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/fork-choice.md#get_latest_attesting_balance
const PROPOSER_SCORE_BOOST* = 40
func calculateProposerBoost(validatorBalances: openArray[Gwei]): int64 =
Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/gossip_processing/block_processor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ proc runForkchoiceUpdated(
# block hash provided by this event is stubbed with
# `0x0000000000000000000000000000000000000000000000000000000000000000`."
# and
# https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/bellatrix/validator.md#executionpayload
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/bellatrix/validator.md#executionpayload
# notes "`finalized_block_hash` is the hash of the latest finalized execution
# payload (`Hash32()` if none yet finalized)"
if headBlockRoot.isZero:
Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/networking/eth2_network.nim
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ type
MounterProc* = proc(network: Eth2Node) {.gcsafe, raises: [Defect, CatchableError].}
MessageContentPrinter* = proc(msg: pointer): string {.gcsafe, raises: [Defect].}

# https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#goodbye
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#goodbye
DisconnectionReason* = enum
# might see other values on the wire!
ClientShutDown = 1
Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/nimbus_beacon_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ template init(T: type RestServerRef,

res.get()

# https://github.com/ethereum/eth2.0-metrics/blob/master/metrics.md#interop-metrics
# https://github.com/ethereum/beacon-metrics/blob/master/metrics.md#interop-metrics
declareGauge beacon_slot, "Latest slot of the beacon chain state"
declareGauge beacon_current_epoch, "Current epoch"

Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/spec/beaconstate.nim
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ proc is_valid_indexed_attestation*(
# Attestation validation
# ------------------------------------------------------------------------------------------
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#attestations
# https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#beacon_attestation_subnet_id
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#beacon_attestation_subnet_id

func check_attestation_slot_target*(data: AttestationData): Result[Slot, cstring] =
if not (data.target.epoch == epoch(data.slot)):
Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/spec/digest.nim
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,5 @@ proc readValue*(r: var JsonReader, a: var Eth2Digest) {.raises: [Defect, IOError
func toGaugeValue*(hash: Eth2Digest): int64 =
# Only the last 8 bytes are taken into consideration in accordance
# to the ETH2 metrics spec:
# https://github.com/ethereum/eth2.0-metrics/blob/6a79914cb31f7d54858c7dd57eee75b6162ec737/metrics.md#interop-metrics
# https://github.com/ethereum/beacon-metrics/blob/6a79914cb31f7d54858c7dd57eee75b6162ec737/metrics.md#interop-metrics
cast[int64](uint64.fromBytesLE(hash.data.toOpenArray(24, 31)))
3 changes: 1 addition & 2 deletions beacon_chain/spec/eth2_apis/rest_remote_signer_calls.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2018-2021 Status Research & Development GmbH
# Copyright (c) 2018-2022 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
Expand All @@ -9,7 +9,6 @@
import
std/strutils, chronicles, metrics,
chronos, chronos/apps/http/httpclient, presto, presto/client,
nimcrypto/utils as ncrutils,
serialization, json_serialization,
json_serialization/std/[options, net, sets],
stew/[results, base10, byteutils],
Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/spec/keystore.nim
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import nimcrypto/utils as ncrutils
export
results, burnMem, writeValue, readValue

{.localPassc: "-fno-lto".} # no LTO for crypto
{.localPassC: "-fno-lto".} # no LTO for crypto

type
KeystoreMode* = enum
Expand Down
4 changes: 2 additions & 2 deletions beacon_chain/spec/network.nim
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ func getAttestationTopic*(forkDigest: ForkDigest,
## For subscribing and unsubscribing to/from a subnet.
eth2Prefix(forkDigest) & "beacon_attestation_" & $(subnetId) & "/ssz_snappy"

# https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/altair/p2p-interface.md#topics-and-messages
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/altair/p2p-interface.md#topics-and-messages
func getSyncCommitteeTopic*(forkDigest: ForkDigest,
subcommitteeIdx: SyncSubcommitteeIndex): string =
## For subscribing and unsubscribing to/from a subnet.
eth2Prefix(forkDigest) & "sync_committee_" & $subcommitteeIdx & "/ssz_snappy"

# https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/altair/p2p-interface.md#topics-and-messages
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/altair/p2p-interface.md#topics-and-messages
func getSyncCommitteeContributionAndProofTopic*(forkDigest: ForkDigest): string =
## For subscribing and unsubscribing to/from a subnet.
eth2Prefix(forkDigest) & "sync_committee_contribution_and_proof/ssz_snappy"
Expand Down
14 changes: 7 additions & 7 deletions beacon_chain/spec/state_transition_epoch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1038,23 +1038,23 @@ func process_inactivity_updates*(
proc process_epoch*(
cfg: RuntimeConfig, state: var phase0.BeaconState, flags: UpdateFlags,
cache: var StateCache, info: var phase0.EpochInfo): Result[void, cstring] =
let currentEpoch = get_current_epoch(state)
let current_epoch = get_current_epoch(state)
trace "process_epoch",
current_epoch = currentEpoch
current_epoch
init(info, state)
info.process_attestations(state, cache)

process_justification_and_finalization(state, info.balances, flags)

# state.slot hasn't been incremented yet.
if verifyFinalization in flags and currentEpoch >= 2:
doAssert state.current_justified_checkpoint.epoch + 2 >= currentEpoch
if verifyFinalization in flags and current_epoch >= 2:
doAssert state.current_justified_checkpoint.epoch + 2 >= current_epoch

if verifyFinalization in flags and currentEpoch >= 3:
if verifyFinalization in flags and current_epoch >= 3:
# Rule 2/3/4 finalization results in the most pessimal case. The other
# three finalization rules finalize more quickly as long as the any of
# the finalization rules triggered.
doAssert state.finalized_checkpoint.epoch + 3 >= currentEpoch
doAssert state.finalized_checkpoint.epoch + 3 >= current_epoch

process_rewards_and_penalties(state, info)
? process_registry_updates(cfg, state, cache)
Expand Down Expand Up @@ -1115,7 +1115,7 @@ proc process_epoch*(

process_inactivity_updates(cfg, state, info) # [New in Altair]

# https://github.com/ethereum/consensus-specs/blob/v1.1.1/specs/phase0/beacon-chain.md#rewards-and-penalties-1
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#process_rewards_and_penalties
process_rewards_and_penalties(cfg, state, info)

# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#registry-updates
Expand Down