From 7f42d38219092e24a65c220b244bbc96c0ae6f2f Mon Sep 17 00:00:00 2001 From: Dustin Brody Date: Mon, 26 Apr 2021 21:41:35 +0200 Subject: [PATCH] rename initialize_beacon_state{_from_eth1,}; suppress warnings when doppelganger detection disabled --- AllTests-mainnet.md | 2 +- beacon_chain/eth1/eth1_monitor.nim | 2 +- beacon_chain/gossip_processing/eth2_processor.nim | 15 +++++---------- beacon_chain/nimbus_beacon_node.nim | 2 +- beacon_chain/spec/beaconstate.nim | 4 ++-- research/simutils.nim | 2 +- tests/test_beacon_chain_db.nim | 2 +- tests/test_beaconstate.nim | 6 +++--- tests/test_interop.nim | 2 +- tests/testutil.nim | 4 ++-- 10 files changed, 18 insertions(+), 23 deletions(-) diff --git a/AllTests-mainnet.md b/AllTests-mainnet.md index 1f7d4dc0c..bb2e34832 100644 --- a/AllTests-mainnet.md +++ b/AllTests-mainnet.md @@ -35,7 +35,7 @@ OK: 9/9 Fail: 0/9 Skip: 0/9 OK: 1/1 Fail: 0/1 Skip: 0/1 ## Beacon state [Preset: mainnet] ```diff -+ Smoke test initialize_beacon_state_from_eth1 [Preset: mainnet] OK ++ Smoke test initialize_beacon_state [Preset: mainnet] OK ``` OK: 1/1 Fail: 0/1 Skip: 0/1 ## Block pool processing [Preset: mainnet] diff --git a/beacon_chain/eth1/eth1_monitor.nim b/beacon_chain/eth1/eth1_monitor.nim index 86a2bfde0..933d66328 100644 --- a/beacon_chain/eth1/eth1_monitor.nim +++ b/beacon_chain/eth1/eth1_monitor.nim @@ -195,7 +195,7 @@ when hasGenesisDetection: var deposits = m.allGenesisDepositsUpTo(eth1Block.voteData.deposit_count) - result = initialize_beacon_state_from_eth1( + result = initialize_beacon_state( m.preset, eth1Block.voteData.block_hash, eth1Block.timestamp.uint64, diff --git a/beacon_chain/gossip_processing/eth2_processor.nim b/beacon_chain/gossip_processing/eth2_processor.nim index 55f55bb0c..5f62e992b 100644 --- a/beacon_chain/gossip_processing/eth2_processor.nim +++ b/beacon_chain/gossip_processing/eth2_processor.nim @@ -33,9 +33,6 @@ declareCounter beacon_proposer_slashings_received, declareCounter beacon_voluntary_exits_received, "Number of beacon chain voluntary exits received by this peer" -declareCounter doppelganger_detection_activated, - "Number of times doppelganger detection was activated" - const delayBuckets = [2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, Inf] declareHistogram beacon_attestation_delay, @@ -176,16 +173,14 @@ proc checkForPotentialDoppelganger( tgtBlck, attestationData.target.epoch) for validatorIndex in attesterIndices: let validatorPubkey = epochRef.validator_keys[validatorIndex] - if self.validatorPool[].getValidator(validatorPubkey) != - default(AttachedValidator): - warn "Duplicate validator detected; would be slashed", + if self.doppelgangerDetectionEnabled and + self.validatorPool[].getValidator(validatorPubkey) != + default(AttachedValidator): + warn "We believe you are currently running another instance of the same validator. We've disconnected you from the network as this presents a significant slashing risk. Possible next steps are (a) making sure you've disconnected your validator from your old machine before restarting the client; and (b) running the client again with the gossip-slashing-protection option disabled, only if you are absolutely sure this is the only instance of your validator running, and reporting the issue at https://github.com/status-im/nimbus-eth2/issues.", validatorIndex, validatorPubkey, attestationSlot = attestationData.slot - doppelganger_detection_activated.inc() - if self.doppelgangerDetectionEnabled: - warn "We believe you are currently running another instance of the same validator. We've disconnected you from the network as this presents a significant slashing risk. Possible next steps are (a) making sure you've disconnected your validator from your old machine before restarting the client; and (b) running the client again with the gossip-slashing-protection option disabled, only if you are absolutely sure this is the only instance of your validator running, and reporting the issue at https://github.com/status-im/nimbus-eth2/issues." - quit QuitFailure + quit QuitFailure {.pop.} # async can raise anything diff --git a/beacon_chain/nimbus_beacon_node.nim b/beacon_chain/nimbus_beacon_node.nim index 85779b913..4f0ac0cc0 100644 --- a/beacon_chain/nimbus_beacon_node.nim +++ b/beacon_chain/nimbus_beacon_node.nim @@ -1748,7 +1748,7 @@ proc doCreateTestnet(config: BeaconNodeConf, rng: var BrHmacDrbgContext) {.raise else: (waitFor getEth1BlockHash(config.web3Urls[0], blockId("latest"))).asEth2Digest runtimePreset = getRuntimePresetForNetwork(config.eth2Network) var - initialState = initialize_beacon_state_from_eth1( + initialState = initialize_beacon_state( runtimePreset, eth1Hash, startTime, deposits, {skipBlsValidation}) # https://github.com/ethereum/eth2.0-pm/tree/6e41fcf383ebeb5125938850d8e9b4e9888389b4/interop/mocked_start#create-genesis-state diff --git a/beacon_chain/spec/beaconstate.nim b/beacon_chain/spec/beaconstate.nim index 55f4e1453..86035162c 100644 --- a/beacon_chain/spec/beaconstate.nim +++ b/beacon_chain/spec/beaconstate.nim @@ -240,7 +240,7 @@ func genesis_time_from_eth1_timestamp*(preset: RuntimePreset, eth1_timestamp: ui eth1_timestamp + preset.GENESIS_DELAY # https://github.com/ethereum/eth2.0-specs/blob/v1.0.1/specs/phase0/beacon-chain.md#genesis -proc initialize_beacon_state_from_eth1*( +proc initialize_beacon_state*( preset: RuntimePreset, eth1_block_hash: Eth2Digest, eth1_timestamp: uint64, @@ -335,7 +335,7 @@ proc initialize_hashed_beacon_state_from_eth1*( eth1_timestamp: uint64, deposits: openArray[DepositData], flags: UpdateFlags = {}): HashedBeaconState = - let genesisState = initialize_beacon_state_from_eth1( + let genesisState = initialize_beacon_state( preset, eth1_block_hash, eth1_timestamp, deposits, flags) HashedBeaconState(data: genesisState[], root: hash_tree_root(genesisState[])) diff --git a/research/simutils.nim b/research/simutils.nim index a9cf23863..f0d91b2a7 100644 --- a/research/simutils.nim +++ b/research/simutils.nim @@ -102,7 +102,7 @@ proc loadGenesis*(validators: Natural, validate: bool): let contractSnapshot = DepositContractSnapshot( depositContractState: merkleizer.toDepositContractState) - res.data = initialize_beacon_state_from_eth1( + res.data = initialize_beacon_state( defaultRuntimePreset, Eth2Digest(), 0, diff --git a/tests/test_beacon_chain_db.nim b/tests/test_beacon_chain_db.nim index d7c7a146a..ac7981748 100644 --- a/tests/test_beacon_chain_db.nim +++ b/tests/test_beacon_chain_db.nim @@ -221,7 +221,7 @@ suiteReport "Beacon chain DB" & preset(): db = BeaconChainDB.new(defaultRuntimePreset, "", inMemory = true) let - state = initialize_beacon_state_from_eth1( + state = initialize_beacon_state( defaultRuntimePreset, eth1BlockHash, 0, makeInitialDeposits(SLOTS_PER_EPOCH), {skipBlsValidation}) root = hash_tree_root(state[]) diff --git a/tests/test_beaconstate.nim b/tests/test_beaconstate.nim index 593f79121..da8a9a10a 100644 --- a/tests/test_beaconstate.nim +++ b/tests/test_beaconstate.nim @@ -1,5 +1,5 @@ # beacon_chain -# Copyright (c) 2018-2020 Status Research & Development GmbH +# Copyright (c) 2018-2021 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). @@ -13,7 +13,7 @@ import ../beacon_chain/spec/[beaconstate, datatypes, digest, presets] suiteReport "Beacon state" & preset(): - timedTest "Smoke test initialize_beacon_state_from_eth1" & preset(): - let state = initialize_beacon_state_from_eth1( + timedTest "Smoke test initialize_beacon_state" & preset(): + let state = initialize_beacon_state( defaultRuntimePreset, Eth2Digest(), 0, makeInitialDeposits(SLOTS_PER_EPOCH, {}), {}) check: state.validators.lenu64 == SLOTS_PER_EPOCH diff --git a/tests/test_interop.nim b/tests/test_interop.nim index 4964e82eb..017976431 100644 --- a/tests/test_interop.nim +++ b/tests/test_interop.nim @@ -150,7 +150,7 @@ suiteReport "Interop": const genesis_time = 1570500000 var - initialState = initialize_beacon_state_from_eth1( + initialState = initialize_beacon_state( defaultRuntimePreset, eth1BlockHash, genesis_time, deposits, {}) # https://github.com/ethereum/eth2.0-pm/tree/6e41fcf383ebeb5125938850d8e9b4e9888389b4/interop/mocked_start#create-genesis-state diff --git a/tests/testutil.nim b/tests/testutil.nim index 8d298eb73..ef4820afd 100644 --- a/tests/testutil.nim +++ b/tests/testutil.nim @@ -1,5 +1,5 @@ # beacon_chain -# Copyright (c) 2018-2019 Status Research & Development GmbH +# Copyright (c) 2018-2021 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). @@ -97,7 +97,7 @@ proc makeTestDB*(tailState: var BeaconState, tailBlock: SignedBeaconBlock): Beac proc makeTestDB*(validators: Natural): BeaconChainDB = let - genState = initialize_beacon_state_from_eth1( + genState = initialize_beacon_state( defaultRuntimePreset, Eth2Digest(), 0,