proc -> func in ncli/, research/, and test/ (#2818)

This commit is contained in:
tersec 2021-08-25 14:51:52 +00:00 committed by GitHub
parent 84ee4b2e9f
commit 43a976f89b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 30 additions and 30 deletions

View File

@ -67,7 +67,7 @@ proc open*(T: type E2Store, path: string, name: string, firstSlot: Slot): Result
ok(E2Store(data: data, index: index, slot: firstSlot)) ok(E2Store(data: data, index: index, slot: firstSlot))
proc close*(store: var E2Store) = func close*(store: var E2Store) =
store.data.close() store.data.close()
store.index.close() store.index.close()

View File

@ -128,7 +128,7 @@ type
name: "perfect" name: "perfect"
desc: "Include perfect records (full rewards)".}: bool desc: "Include perfect records (full rewards)".}: bool
proc getSlotRange(dag: ChainDAGRef, startSlot: int64, count: uint64): (Slot, Slot) = func getSlotRange(dag: ChainDAGRef, startSlot: int64, count: uint64): (Slot, Slot) =
let let
start = start =
if startSlot >= 0: Slot(startSlot) if startSlot >= 0: Slot(startSlot)
@ -139,7 +139,7 @@ proc getSlotRange(dag: ChainDAGRef, startSlot: int64, count: uint64): (Slot, Slo
else: start + count else: start + count
(start, ends) (start, ends)
proc getBlockRange(dag: ChainDAGRef, start, ends: Slot): seq[BlockRef] = func getBlockRange(dag: ChainDAGRef, start, ends: Slot): seq[BlockRef] =
# Range of block in reverse order # Range of block in reverse order
var var
blockRefs: seq[BlockRef] blockRefs: seq[BlockRef]
@ -372,7 +372,7 @@ proc cmdRewindState(conf: DbConf, cfg: RuntimeConfig) =
echo "Writing state..." echo "Writing state..."
dump("./", stateData.data.hbsPhase0, blck) dump("./", stateData.data.hbsPhase0, blck)
proc atCanonicalSlot(blck: BlockRef, slot: Slot): BlockSlot = func atCanonicalSlot(blck: BlockRef, slot: Slot): BlockSlot =
if slot == 0: if slot == 0:
blck.atSlot(slot) blck.atSlot(slot)
else: else:
@ -470,7 +470,7 @@ proc cmdValidatorPerf(conf: DbConf, cfg: RuntimeConfig) =
dag.updateStateData( dag.updateStateData(
state[], blockRefs[^1].atSlot(blockRefs[^1].slot - 1), false, cache) state[], blockRefs[^1].atSlot(blockRefs[^1].slot - 1), false, cache)
proc processEpoch() = func processEpoch() =
let let
prev_epoch_target_slot = prev_epoch_target_slot =
state[].data.get_previous_epoch().compute_start_slot_at_epoch() state[].data.get_previous_epoch().compute_start_slot_at_epoch()

View File

@ -121,7 +121,7 @@ proc printTimers*[Timers: enum](
validate: bool, validate: bool,
timers: array[Timers, RunningStat] timers: array[Timers, RunningStat]
) = ) =
proc fmtTime(t: float): string = &"{t * 1000 :>12.3f}, " func fmtTime(t: float): string = &"{t * 1000 :>12.3f}, "
echo "All time are ms" echo "All time are ms"
echo &"{\"Average\" :>12}, {\"StdDev\" :>12}, {\"Min\" :>12}, " & echo &"{\"Average\" :>12}, {\"StdDev\" :>12}, {\"Min\" :>12}, " &

View File

@ -24,7 +24,7 @@ type Timers = enum
tShuffle = "Retrieve committee once using get_beacon_committee" tShuffle = "Retrieve committee once using get_beacon_committee"
tAttest = "Combine committee attestations" tAttest = "Combine committee attestations"
proc jsonName(prefix, slot: auto): string = func jsonName(prefix, slot: auto): string =
fmt"{prefix:04}-{shortLog(slot):08}.json" fmt"{prefix:04}-{shortLog(slot):08}.json"
proc writeJson*(fn, v: auto) = proc writeJson*(fn, v: auto) =

View File

@ -1,5 +1,5 @@
# beacon_chain # beacon_chain
# Copyright (c) 2018 Status Research & Development GmbH # Copyright (c) 2018-2021 Status Research & Development GmbH
# Licensed and distributed under either of # Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * 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). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@ -7,7 +7,7 @@
# import ../interpreter # included to be able to use "suite" # import ../interpreter # included to be able to use "suite"
proc setup_finality_01(): tuple[fork_choice: ForkChoiceBackend, ops: seq[Operation]] = func setup_finality_01(): tuple[fork_choice: ForkChoiceBackend, ops: seq[Operation]] =
var balances = @[Gwei(1), Gwei(1)] var balances = @[Gwei(1), Gwei(1)]
let GenesisRoot = fakeHash(0) let GenesisRoot = fakeHash(0)

View File

@ -1,5 +1,5 @@
# beacon_chain # beacon_chain
# Copyright (c) 2018 Status Research & Development GmbH # Copyright (c) 2018-2021 Status Research & Development GmbH
# Licensed and distributed under either of # Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * 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). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@ -7,7 +7,7 @@
# import ../interpreter # included to be able to use "suite" # import ../interpreter # included to be able to use "suite"
proc setup_finality_02(): tuple[fork_choice: ForkChoiceBackend, ops: seq[Operation]] = func setup_finality_02(): tuple[fork_choice: ForkChoiceBackend, ops: seq[Operation]] =
var balances = @[Gwei(1), Gwei(1)] var balances = @[Gwei(1), Gwei(1)]
let GenesisRoot = fakeHash(0) let GenesisRoot = fakeHash(0)

View File

@ -1,5 +1,5 @@
# beacon_chain # beacon_chain
# Copyright (c) 2018 Status Research & Development GmbH # Copyright (c) 2018-2021 Status Research & Development GmbH
# Licensed and distributed under either of # Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * 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). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@ -7,7 +7,7 @@
# import ../interpreter # included to be able to use "suite" # import ../interpreter # included to be able to use "suite"
proc setup_no_votes(): tuple[fork_choice: ForkChoiceBackend, ops: seq[Operation]] = func setup_no_votes(): tuple[fork_choice: ForkChoiceBackend, ops: seq[Operation]] =
let balances = newSeq[Gwei](16) let balances = newSeq[Gwei](16)
let GenesisRoot = fakeHash(0) let GenesisRoot = fakeHash(0)

View File

@ -1,5 +1,5 @@
# beacon_chain # beacon_chain
# Copyright (c) 2018 Status Research & Development GmbH # Copyright (c) 2018-2021 Status Research & Development GmbH
# Licensed and distributed under either of # Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * 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). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@ -7,7 +7,7 @@
# import ../interpreter # included to be able to use "suite" # import ../interpreter # included to be able to use "suite"
proc setup_votes(): tuple[fork_choice: ForkChoiceBackend, ops: seq[Operation]] = func setup_votes(): tuple[fork_choice: ForkChoiceBackend, ops: seq[Operation]] =
var balances = @[Gwei(1), Gwei(1)] var balances = @[Gwei(1), Gwei(1)]
let GenesisRoot = fakeHash(0) let GenesisRoot = fakeHash(0)

View File

@ -1,5 +1,5 @@
# beacon_chain # beacon_chain
# Copyright (c) 2018-2019 Status Research & Development GmbH # Copyright (c) 2018-2021 Status Research & Development GmbH
# Licensed and distributed under either of # Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * 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). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@ -56,7 +56,7 @@ proc compareContainerStmt(xSubField, ySubField: NimNode, stmts: var NimNode) =
"and " & `yStr` & "[" & $idx & "] = " & $`ySubField`[idx] & "\n" "and " & `yStr` & "[" & $idx & "] = " & $`ySubField`[idx] & "\n"
) )
proc inspectType(tImpl, xSubField, ySubField: NimNode, stmts: var NimNode) = func inspectType(tImpl, xSubField, ySubField: NimNode, stmts: var NimNode) =
# echo "kind: " & $tImpl.kind # echo "kind: " & $tImpl.kind
# echo " -- field: " & $xSubField.toStrLit # echo " -- field: " & $xSubField.toStrLit
case tImpl.kind case tImpl.kind

View File

@ -1,5 +1,5 @@
# beacon_chain # beacon_chain
# Copyright (c) 2018-2019 Status Research & Development GmbH # Copyright (c) 2018-2021 Status Research & Development GmbH
# Licensed and distributed under either of # Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * 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). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@ -8,7 +8,7 @@
import import
../../beacon_chain/spec/digest ../../beacon_chain/spec/digest
proc `*`*(a: static array[1, byte], n: static int): static Eth2Digest = func `*`*(a: static array[1, byte], n: static int): static Eth2Digest =
doAssert n == 32 doAssert n == 32
for mbyte in result.data.mitems: for mbyte in result.data.mitems:
mbyte = a[0] mbyte = a[0]

View File

@ -13,7 +13,7 @@ import
blscurve, blscurve,
../../beacon_chain/spec/datatypes/base ../../beacon_chain/spec/datatypes/base
proc newKeyPair(rng: var BrHmacDrbgContext): BlsResult[tuple[pub: ValidatorPubKey, priv: ValidatorPrivKey]] = func newKeyPair(rng: var BrHmacDrbgContext): BlsResult[tuple[pub: ValidatorPubKey, priv: ValidatorPrivKey]] =
## Generates a new public-private keypair ## Generates a new public-private keypair
## This requires entropy on the system ## This requires entropy on the system
# The input-keying-material requires 32 bytes at least for security # The input-keying-material requires 32 bytes at least for security

View File

@ -40,7 +40,7 @@ type
input: seq[ValidatorPubKey] input: seq[ValidatorPubKey]
output: ValidatorPubKey output: ValidatorPubKey
proc readValue(r: var JsonReader, a: var Eth2Domain) = func readValue(r: var JsonReader, a: var Eth2Domain) =
## Custom deserializer for Eth2Domain ## Custom deserializer for Eth2Domain
# Furthermore Nim parseHex doesn't support uint # Furthermore Nim parseHex doesn't support uint
# until https://github.com/nim-lang/Nim/pull/11067 # until https://github.com/nim-lang/Nim/pull/11067

View File

@ -26,7 +26,7 @@ import
../testutil ../testutil
func hexToDigest(hex: string): Eth2Digest = func hexToDigest(hex: string): Eth2Digest =
result = Eth2Digest.fromHex(hex) Eth2Digest.fromHex(hex)
proc sqlite3db_delete(basepath, dbname: string) = proc sqlite3db_delete(basepath, dbname: string) =
removeFile(basepath / dbname&".sqlite3-shm") removeFile(basepath / dbname&".sqlite3-shm")

View File

@ -27,7 +27,7 @@ func fakeRoot(index: SomeInteger): Eth2Digest =
result.data[0 ..< 8] = (1'u64 shl 32 + index.uint64).toBytesBE() result.data[0 ..< 8] = (1'u64 shl 32 + index.uint64).toBytesBE()
func hexToDigest(hex: string): Eth2Digest = func hexToDigest(hex: string): Eth2Digest =
result = Eth2Digest.fromHex(hex) Eth2Digest.fromHex(hex)
proc sqlite3db_delete(basepath, dbname: string) = proc sqlite3db_delete(basepath, dbname: string) =
removeFile(basepath / dbname&".sqlite3-shm") removeFile(basepath / dbname&".sqlite3-shm")

View File

@ -17,7 +17,7 @@ import
# Justification and finalization utils # Justification and finalization utils
# --------------------------------------------------------------- # ---------------------------------------------------------------
proc addMockAttestations*( func addMockAttestations*(
state: var phase0.BeaconState, epoch: Epoch, state: var phase0.BeaconState, epoch: Epoch,
source, target: Checkpoint, source, target: Checkpoint,
sufficient_support = false sufficient_support = false
@ -78,14 +78,14 @@ proc addMockAttestations*(
inclusion_delay: 1 inclusion_delay: 1
) )
proc getCheckpoints*(epoch: Epoch): tuple[c1, c2, c3, c4, c5: Checkpoint] = func getCheckpoints*(epoch: Epoch): tuple[c1, c2, c3, c4, c5: Checkpoint] =
if epoch >= 1: result.c1 = Checkpoint(epoch: epoch - 1, root: [byte 0xAA] * 32) if epoch >= 1: result.c1 = Checkpoint(epoch: epoch - 1, root: [byte 0xAA] * 32)
if epoch >= 2: result.c2 = Checkpoint(epoch: epoch - 2, root: [byte 0xBB] * 32) if epoch >= 2: result.c2 = Checkpoint(epoch: epoch - 2, root: [byte 0xBB] * 32)
if epoch >= 3: result.c3 = Checkpoint(epoch: epoch - 3, root: [byte 0xCC] * 32) if epoch >= 3: result.c3 = Checkpoint(epoch: epoch - 3, root: [byte 0xCC] * 32)
if epoch >= 4: result.c4 = Checkpoint(epoch: epoch - 4, root: [byte 0xDD] * 32) if epoch >= 4: result.c4 = Checkpoint(epoch: epoch - 4, root: [byte 0xDD] * 32)
if epoch >= 5: result.c5 = Checkpoint(epoch: epoch - 5, root: [byte 0xEE] * 32) if epoch >= 5: result.c5 = Checkpoint(epoch: epoch - 5, root: [byte 0xEE] * 32)
proc putCheckpointsInBlockRoots*( func putCheckpointsInBlockRoots*(
state: var phase0.BeaconState, state: var phase0.BeaconState,
checkpoints: openArray[Checkpoint]) = checkpoints: openArray[Checkpoint]) =
for c in checkpoints: for c in checkpoints:

View File

@ -68,7 +68,7 @@ type
Baz = object Baz = object
i: uint64 i: uint64
proc toDigest[N: static int](x: array[N, byte]): Eth2Digest = func toDigest[N: static int](x: array[N, byte]): Eth2Digest =
result.data[0 .. N-1] = x result.data[0 .. N-1] = x
suite "SSZ navigator": suite "SSZ navigator":

View File

@ -21,7 +21,7 @@ import
blockchain_dag, block_quarantine, block_clearance], blockchain_dag, block_quarantine, block_clearance],
./testutil, ./testdbutil, ./testblockutil ./testutil, ./testdbutil, ./testblockutil
proc `$`(x: BlockRef): string = func `$`(x: BlockRef): string =
$x.root $x.root
proc pruneAtFinalization(dag: ChainDAGRef) = proc pruneAtFinalization(dag: ChainDAGRef) =

View File

@ -589,7 +589,7 @@ suite "PeerPool testing suite":
test "Score check test": test "Score check test":
var pool = newPeerPool[PeerTest, PeerTestID]() var pool = newPeerPool[PeerTest, PeerTestID]()
proc scoreCheck(peer: PeerTest): bool = func scoreCheck(peer: PeerTest): bool =
if peer.weight >= 0: if peer.weight >= 0:
result = true result = true
else: else:
@ -651,7 +651,7 @@ suite "PeerPool testing suite":
test "Delete peer on release text": test "Delete peer on release text":
proc testDeleteOnRelease(): Future[bool] {.async.} = proc testDeleteOnRelease(): Future[bool] {.async.} =
proc scoreCheck(peer: PeerTest): bool = func scoreCheck(peer: PeerTest): bool =
if peer.weight >= 0: if peer.weight >= 0:
result = true result = true
else: else: