diff --git a/beacon_chain/beacon_chain_db.nim b/beacon_chain/beacon_chain_db.nim index a869fa92f..2657289ce 100644 --- a/beacon_chain/beacon_chain_db.nim +++ b/beacon_chain/beacon_chain_db.nim @@ -634,8 +634,8 @@ template toBeaconStateNoImmutableValidators(state: altair.BeaconState): isomorphicCast[AltairBeaconStateNoImmutableValidators](state) template toBeaconStateNoImmutableValidators(state: bellatrix.BeaconState): - MergeBeaconStateNoImmutableValidators = - isomorphicCast[MergeBeaconStateNoImmutableValidators](state) + BellatrixBeaconStateNoImmutableValidators = + isomorphicCast[BellatrixBeaconStateNoImmutableValidators](state) proc putState*(db: BeaconChainDB, key: Eth2Digest, value: ForkyBeaconState) = db.updateImmutableValidators(value.validators.asSeq()) @@ -648,14 +648,9 @@ proc putState*(db: BeaconChainDB, state: ForkyHashedBeaconState) = db.putState(state.root, state.data) # For testing rollback -proc putCorruptPhase0State*(db: BeaconChainDB, key: Eth2Digest) = - db.statesNoVal[BeaconStateFork.Phase0].putSnappySSZ(key.data, Validator()) - -proc putCorruptAltairState*(db: BeaconChainDB, key: Eth2Digest) = - db.statesNoVal[BeaconStateFork.Altair].putSnappySSZ(key.data, Validator()) - -proc putCorruptMergeState*(db: BeaconChainDB, key: Eth2Digest) = - db.statesNoVal[BeaconStateFork.Bellatrix].putSnappySSZ(key.data, Validator()) +proc putCorruptState*( + db: BeaconChainDB, fork: static BeaconStateFork, key: Eth2Digest) = + db.statesNoVal[fork].putSnappySSZ(key.data, Validator()) func stateRootKey(root: Eth2Digest, slot: Slot): array[40, byte] = var ret: array[40, byte] diff --git a/beacon_chain/beacon_chain_db_immutable.nim b/beacon_chain/beacon_chain_db_immutable.nim index ce2fc8d13..53da0cd06 100644 --- a/beacon_chain/beacon_chain_db_immutable.nim +++ b/beacon_chain/beacon_chain_db_immutable.nim @@ -126,7 +126,7 @@ type # https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/bellatrix/beacon-chain.md#beaconstate # Memory-representation-equivalent to a Merge BeaconState for in-place SSZ # reading and writing - MergeBeaconStateNoImmutableValidators* = object + BellatrixBeaconStateNoImmutableValidators* = object # Versioning genesis_time*: uint64 genesis_validators_root*: Eth2Digest diff --git a/beacon_chain/consensus_object_pools/sync_committee_msg_pool.nim b/beacon_chain/consensus_object_pools/sync_committee_msg_pool.nim index 07e20352e..f09f95906 100644 --- a/beacon_chain/consensus_object_pools/sync_committee_msg_pool.nim +++ b/beacon_chain/consensus_object_pools/sync_committee_msg_pool.nim @@ -153,7 +153,7 @@ func computeAggregateSig(votes: seq[TrustedSyncCommitteeMsg], if initialized: contribution.signature = aggregateSig.finish.toValidatorSig - return initialized + initialized func produceContribution*( pool: SyncCommitteeMsgPool, diff --git a/beacon_chain/fork_choice/proto_array.nim b/beacon_chain/fork_choice/proto_array.nim index 8665effdf..fc0c4e4fb 100644 --- a/beacon_chain/fork_choice/proto_array.nim +++ b/beacon_chain/fork_choice/proto_array.nim @@ -62,7 +62,7 @@ func `[]`(nodes: ProtoNodes, idx: Index): Option[ProtoNode] = let i = idx - nodes.offset if i >= nodes.buf.len: return none(ProtoNode) - return some(nodes.buf[i]) + some(nodes.buf[i]) func len*(nodes: ProtoNodes): int = nodes.buf.len @@ -535,19 +535,19 @@ when isMainModule: echo "Sanity checks on fork choice tiebreaks" block: - let a = Eth2Digest.fromHex("0x0000000000000001000000000000000000000000000000000000000000000000") - let b = Eth2Digest.fromHex("0x0000000000000000000000000000000000000000000000000000000000000000") # sha256(1) + const a = Eth2Digest.fromHex("0x0000000000000001000000000000000000000000000000000000000000000000") + const b = Eth2Digest.fromHex("0x0000000000000000000000000000000000000000000000000000000000000000") # sha256(1) doAssert tiebreak(a, b) block: - let a = Eth2Digest.fromHex("0x0000000000000002000000000000000000000000000000000000000000000000") - let b = Eth2Digest.fromHex("0x0000000000000001000000000000000000000000000000000000000000000000") # sha256(1) + const a = Eth2Digest.fromHex("0x0000000000000002000000000000000000000000000000000000000000000000") + const b = Eth2Digest.fromHex("0x0000000000000001000000000000000000000000000000000000000000000000") # sha256(1) doAssert tiebreak(a, b) block: - let a = Eth2Digest.fromHex("0xD86E8112F3C4C4442126F8E9F44F16867DA487F29052BF91B810457DB34209A4") # sha256(2) - let b = Eth2Digest.fromHex("0x7C9FA136D4413FA6173637E883B6998D32E1D675F88CDDFF9DCBCF331820F4B8") # sha256(1) + const a = Eth2Digest.fromHex("0xD86E8112F3C4C4442126F8E9F44F16867DA487F29052BF91B810457DB34209A4") # sha256(2) + const b = Eth2Digest.fromHex("0x7C9FA136D4413FA6173637E883B6998D32E1D675F88CDDFF9DCBCF331820F4B8") # sha256(1) doAssert tiebreak(a, b) diff --git a/beacon_chain/networking/network_metadata.nim b/beacon_chain/networking/network_metadata.nim index af006b3cf..b1b22e5c6 100644 --- a/beacon_chain/networking/network_metadata.nim +++ b/beacon_chain/networking/network_metadata.nim @@ -1,5 +1,5 @@ # beacon_chain -# 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). @@ -191,13 +191,13 @@ proc getMetadataForNetwork*(networkName: string): Eth2NetworkMetadata {.raises: fatal "The selected network is not compatible with the current build", reason = metadata.incompatibilityDesc quit 1 - return metadata + metadata proc getRuntimeConfig*( eth2Network: Option[string]): RuntimeConfig {.raises: [Defect, IOError].} = if eth2Network.isSome: return getMetadataForNetwork(eth2Network.get).cfg - return defaultRuntimeConfig + defaultRuntimeConfig proc extractGenesisValidatorRootFromSnapshot*( snapshot: string): Eth2Digest {.raises: [Defect, IOError, SszError].} = diff --git a/beacon_chain/nimbus_beacon_node.nim b/beacon_chain/nimbus_beacon_node.nim index 0b6ee7591..6b197ac65 100644 --- a/beacon_chain/nimbus_beacon_node.nim +++ b/beacon_chain/nimbus_beacon_node.nim @@ -564,7 +564,7 @@ proc init*(T: type BeaconNode, node.updateValidatorMetrics() - return node + node func verifyFinalization(node: BeaconNode, slot: Slot) = # Epoch must be >= 4 to check finalization diff --git a/beacon_chain/spec/state_transition_block.nim b/beacon_chain/spec/state_transition_block.nim index a1af53f3a..0d47995eb 100644 --- a/beacon_chain/spec/state_transition_block.nim +++ b/beacon_chain/spec/state_transition_block.nim @@ -264,7 +264,7 @@ func findValidatorIndex*(state: ForkyBeaconState, pubkey: ValidatorPubKey): int for i in 0 ..< state.validators.len: if state.validators.asSeq[i].pubkey == pubkey: return i - return -1 + -1 proc process_deposit*(cfg: RuntimeConfig, state: var ForkyBeaconState, diff --git a/ncli/ncli_common.nim b/ncli/ncli_common.nim index 0c62c75ff..a6c344a4f 100644 --- a/ncli/ncli_common.nim +++ b/ncli/ncli_common.nim @@ -96,7 +96,7 @@ proc getAggregatedFilesLastEpoch*(dir: string): Epoch = fn[epochInfoFileNameDigitsCount + 1 .. 2 * epochInfoFileNameDigitsCount]) if fileLastEpoch > largestEpochInFileName: largestEpochInFileName = fileLastEpoch - return largestEpochInFileName.Epoch + largestEpochInFileName.Epoch func epochAsString*(epoch: Epoch): string = let strEpoch = $epoch @@ -194,7 +194,7 @@ func getFinalizedCheckpoint(state: ForkyBeaconState, old_current_justified_checkpoint.epoch + 1 == current_epoch: return old_current_justified_checkpoint - return state.finalized_checkpoint + state.finalized_checkpoint func getFinalizedCheckpoint(state: phase0.BeaconState, balances: TotalBalances): Checkpoint = diff --git a/tests/consensus_spec/test_fixture_fork_choice.nim b/tests/consensus_spec/test_fixture_fork_choice.nim index ad2bd0f35..f6313426c 100644 --- a/tests/consensus_spec/test_fixture_fork_choice.nim +++ b/tests/consensus_spec/test_fixture_fork_choice.nim @@ -196,7 +196,7 @@ proc stepOnBlock( ) doAssert status.isOk() - return blockAdded + blockAdded proc stepOnAttestation( dag: ChainDagRef, diff --git a/tests/test_beacon_chain_db.nim b/tests/test_beacon_chain_db.nim index d83d6783a..cc38422a3 100644 --- a/tests/test_beacon_chain_db.nim +++ b/tests/test_beacon_chain_db.nim @@ -35,7 +35,7 @@ proc getAltairStateRef(db: BeaconChainDB, root: Eth2Digest): if db.getState(root, res[], noRollback): return res -proc getMergeStateRef(db: BeaconChainDB, root: Eth2Digest): +proc getBellatrixStateRef(db: BeaconChainDB, root: Eth2Digest): bellatrix.NilableBeaconStateRef = # load beaconstate the way the block pool does it - into an existing instance let res = (bellatrix.BeaconStateRef)() @@ -76,7 +76,7 @@ proc getTestStates(stateFork: BeaconStateFork): auto = testStates -# Each of phase 0/altair/merge states gets used twice, so make them global to +# Each of phase 0/altair/bellatrix states gets used twice, so scope them to # module let testStatesPhase0 = getTestStates(BeaconStateFork.Phase0) @@ -253,12 +253,12 @@ suite "Beacon chain DB" & preset(): check: db.containsState(root) - hash_tree_root(db.getMergeStateRef(root)[]) == root + hash_tree_root(db.getBellatrixStateRef(root)[]) == root db.delState(root) check: not db.containsState(root) - db.getMergeStateRef(root).isNil + db.getBellatrixStateRef(root).isNil db.close() @@ -333,7 +333,7 @@ suite "Beacon chain DB" & preset(): slot: 10.Slot))) root = Eth2Digest() - db.putCorruptPhase0State(root) + db.putCorruptState(BeaconStateFork.Phase0, root) let restoreAddr = addr dag.headState @@ -356,7 +356,7 @@ suite "Beacon chain DB" & preset(): slot: 10.Slot))) root = Eth2Digest() - db.putCorruptAltairState(root) + db.putCorruptState(BeaconStateFork.Altair, root) let restoreAddr = addr dag.headState @@ -382,7 +382,7 @@ suite "Beacon chain DB" & preset(): slot: 10.Slot))) root = Eth2Digest() - db.putCorruptMergeState(root) + db.putCorruptState(BeaconStateFork.Bellatrix, root) let restoreAddr = addr dag.headState