From a7a1f784991d25bbb5c57dba76e96505e514281c Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Mon, 23 Sep 2019 17:00:10 +0200 Subject: [PATCH] Fix TRACE chronicles_log_level (#451) --- beacon_chain/spec/state_transition_block.nim | 11 +---- beacon_chain/spec/state_transition_epoch.nim | 24 +---------- .../spec/state_transition_helpers.nim | 40 +++++++++++++++++++ 3 files changed, 44 insertions(+), 31 deletions(-) create mode 100644 beacon_chain/spec/state_transition_helpers.nim diff --git a/beacon_chain/spec/state_transition_block.nim b/beacon_chain/spec/state_transition_block.nim index 2109030cf..c45728dba 100644 --- a/beacon_chain/spec/state_transition_block.nim +++ b/beacon_chain/spec/state_transition_block.nim @@ -35,7 +35,8 @@ import # TODO - cleanup imports algorithm, collections/sets, chronicles, math, options, sequtils, sets, tables, ../extras, ../ssz, ../beacon_node_types, - beaconstate, crypto, datatypes, digest, helpers, validator + beaconstate, crypto, datatypes, digest, helpers, validator, + state_transition_helpers # https://github.com/ethereum/eth2.0-specs/blob/v0.8.3/specs/core/0_beacon-chain.md#block-header proc process_block_header*( @@ -263,14 +264,6 @@ proc processAttesterSlashings(state: var BeaconState, blck: BeaconBlock, return false return true -func get_attesting_indices( - state: BeaconState, attestations: openarray[PendingAttestation], - stateCache: var StateCache): HashSet[ValidatorIndex] = - result = initSet[ValidatorIndex]() - for a in attestations: - result = result.union(get_attesting_indices( - state, a.data, a.aggregation_bits, stateCache)) - # https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#attestations proc processAttestations*( state: var BeaconState, blck: BeaconBlock, flags: UpdateFlags, diff --git a/beacon_chain/spec/state_transition_epoch.nim b/beacon_chain/spec/state_transition_epoch.nim index 1803b1ae9..d86fe0766 100644 --- a/beacon_chain/spec/state_transition_epoch.nim +++ b/beacon_chain/spec/state_transition_epoch.nim @@ -36,18 +36,14 @@ import # TODO - cleanup imports algorithm, math, options, sequtils, tables, stew/[bitseqs, bitops2], chronicles, json_serialization/std/sets, ../extras, ../ssz, ../beacon_node_types, - beaconstate, crypto, datatypes, digest, helpers, validator + beaconstate, crypto, datatypes, digest, helpers, validator, + state_transition_helpers # Logging utilities # -------------------------------------------------------- logScope: topics = "consens" -# TODO: gather all logging utilities -# from crypto, digest, etc in a single file -func shortLog(x: Checkpoint): string = - "(epoch: " & $x.epoch & ", root: \"" & shortLog(x.root) & "\")" - # Spec # -------------------------------------------------------- @@ -81,22 +77,6 @@ func get_matching_head_attestations(state: BeaconState, epoch: Epoch): get_block_root_at_slot(state, get_attestation_data_slot(state, it.data)) ) -func get_attesting_indices( - state: BeaconState, attestations: openarray[PendingAttestation], - stateCache: var StateCache): HashSet[ValidatorIndex] = - result = initSet[ValidatorIndex]() - for a in attestations: - result = result.union(get_attesting_indices( - state, a.data, a.aggregation_bits, stateCache)) - -func get_unslashed_attesting_indices*( - state: BeaconState, attestations: openarray[PendingAttestation], - stateCache: var StateCache): HashSet[ValidatorIndex] = - result = get_attesting_indices(state, attestations, stateCache) - for index in result: - if state.validators[index].slashed: - result.excl index - func get_attesting_balance( state: BeaconState, attestations: seq[PendingAttestation], stateCache: var StateCache): Gwei = diff --git a/beacon_chain/spec/state_transition_helpers.nim b/beacon_chain/spec/state_transition_helpers.nim new file mode 100644 index 000000000..ea7492955 --- /dev/null +++ b/beacon_chain/spec/state_transition_helpers.nim @@ -0,0 +1,40 @@ +# beacon_chain +# Copyright (c) 2018-2019 Status Research & Development GmbH +# Licensed and distributed under either of +# * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT). +# * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0). +# at your option. This file may not be copied, modified, or distributed except according to those terms. + +import + # Standard library + sets, + # Internals + ./datatypes, ./digest, ./beaconstate + +# Logging utilities +# -------------------------------------------------------- + +# TODO: gather all logging utilities +# from crypto, digest, etc in a single file +func shortLog*(x: Checkpoint): string = + "(epoch: " & $x.epoch & ", root: \"" & shortLog(x.root) & "\")" + +# Helpers used in epoch transition and trace-level block transition +# -------------------------------------------------------- + +# https://github.com/ethereum/eth2.0-specs/blob/v0.8.3/specs/core/0_beacon-chain.md#helper-functions-1 +func get_attesting_indices*( + state: BeaconState, attestations: openarray[PendingAttestation], + stateCache: var StateCache): HashSet[ValidatorIndex] = + result = initSet[ValidatorIndex]() + for a in attestations: + result = result.union(get_attesting_indices( + state, a.data, a.aggregation_bits, stateCache)) + +func get_unslashed_attesting_indices*( + state: BeaconState, attestations: openarray[PendingAttestation], + stateCache: var StateCache): HashSet[ValidatorIndex] = + result = get_attesting_indices(state, attestations, stateCache) + for index in result: + if state.validators[index].slashed: + result.excl index