From 3c9fc494113ac840f0f409b08d3ba4b8c68781a3 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Thu, 10 Aug 2023 14:52:49 +0200 Subject: [PATCH] reduce ncli/research imports (#5275) * reduce ncli/research imports avoids ssl, most of chronos etc, speeds up compiles * copyright --- beacon_chain/beacon_clock.nim | 20 ++++++++------------ beacon_chain/nimbus_binary_common.nim | 4 ++++ ncli/ncli.nim | 8 ++++++++ research/simutils.nim | 6 +++--- vendor/nim-presto | 2 +- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/beacon_chain/beacon_clock.nim b/beacon_chain/beacon_clock.nim index 463838023..2aed9871f 100644 --- a/beacon_chain/beacon_clock.nim +++ b/beacon_chain/beacon_clock.nim @@ -9,12 +9,12 @@ import std/math, - chronos, chronicles, + chronos/timer, chronicles, ./spec/beacon_time from times import Time, getTime, fromUnix, `<`, `-`, inNanoseconds -export chronos.Duration, Moment, now +export timer.Duration, Moment, now type BeaconClock* = object @@ -62,9 +62,9 @@ func getBeaconTimeFn*(c: BeaconClock): GetBeaconTimeFn = proc fromNow*(c: BeaconClock, t: BeaconTime): tuple[inFuture: bool, offset: Duration] = let now = c.now() if t > now: - (true, chronos.nanoseconds((t - now).nanoseconds)) + (true, nanoseconds((t - now).nanoseconds)) else: - (false, chronos.nanoseconds((now - t).nanoseconds)) + (false, nanoseconds((now - t).nanoseconds)) proc fromNow*(c: BeaconClock, slot: Slot): tuple[inFuture: bool, offset: Duration] = c.fromNow(slot.start_beacon_time()) @@ -76,7 +76,7 @@ proc durationToNextSlot*(c: BeaconClock): Duration = if currentSlot.afterGenesis: let nextSlot = currentSlot.slot + 1 - chronos.nanoseconds( + nanoseconds( (nextSlot.start_beacon_time() - currentTime).nanoseconds) else: # absoluteTime = BeaconTime(-currentTime.ns_since_genesis). @@ -84,7 +84,7 @@ proc durationToNextSlot*(c: BeaconClock): Duration = absoluteTime = Slot(0).start_beacon_time() + (Slot(0).start_beacon_time() - currentTime) timeToNextSlot = absoluteTime - currentSlot.slot.start_beacon_time() - chronos.nanoseconds(timeToNextSlot.nanoseconds) + nanoseconds(timeToNextSlot.nanoseconds) proc durationToNextEpoch*(c: BeaconClock): Duration = let @@ -93,7 +93,7 @@ proc durationToNextEpoch*(c: BeaconClock): Duration = if currentSlot.afterGenesis: let nextEpochSlot = (currentSlot.slot.epoch() + 1).start_slot() - chronos.nanoseconds( + nanoseconds( (nextEpochSlot.start_beacon_time() - currentTime).nanoseconds) else: # absoluteTime = BeaconTime(-currentTime.ns_since_genesis). @@ -102,15 +102,11 @@ proc durationToNextEpoch*(c: BeaconClock): Duration = (Slot(0).start_beacon_time() - currentTime) timeToNextEpoch = absoluteTime - currentSlot.slot.epoch().start_slot().start_beacon_time() - chronos.nanoseconds(timeToNextEpoch.nanoseconds) + nanoseconds(timeToNextEpoch.nanoseconds) func saturate*(d: tuple[inFuture: bool, offset: Duration]): Duration = if d.inFuture: d.offset else: seconds(0) -proc sleepAsync*(t: TimeDiff): Future[void] = - sleepAsync(chronos.nanoseconds( - if t.nanoseconds < 0: 0'i64 else: t.nanoseconds)) - func shortLog*(d: Duration): string = $d diff --git a/beacon_chain/nimbus_binary_common.nim b/beacon_chain/nimbus_binary_common.nim index 275d655fd..edf8f4e68 100644 --- a/beacon_chain/nimbus_binary_common.nim +++ b/beacon_chain/nimbus_binary_common.nim @@ -262,6 +262,10 @@ proc runKeystoreCachePruningLoop*(cache: KeystoreCacheRef) {.async.} = if exitLoop: break cache.pruneExpiredKeys() +proc sleepAsync*(t: TimeDiff): Future[void] = + sleepAsync(nanoseconds( + if t.nanoseconds < 0: 0'i64 else: t.nanoseconds)) + proc runSlotLoop*[T](node: T, startTime: BeaconTime, slotProc: SlotStartProc[T]) {.async.} = var diff --git a/ncli/ncli.nim b/ncli/ncli.nim index aef3db416..97bd88064 100644 --- a/ncli/ncli.nim +++ b/ncli/ncli.nim @@ -1,4 +1,12 @@ +# beacon_chain +# Copyright (c) 2020-2023 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). +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import + std/strutils, confutils, json_serialization, snappy, ../beacon_chain/spec/eth2_apis/eth2_rest_serialization, diff --git a/research/simutils.nim b/research/simutils.nim index e03c117e1..7893362f8 100644 --- a/research/simutils.nim +++ b/research/simutils.nim @@ -7,11 +7,11 @@ import stats, strformat, times, + stew/io2, ../tests/testblockutil, ../tests/consensus_spec/os_ops, - ../beacon_chain/[beacon_chain_db, filepath], + ../beacon_chain/[filepath], ../beacon_chain/spec/datatypes/[phase0, altair], - ../beacon_chain/spec/[beaconstate, deposit_snapshots, forks, helpers], - ../beacon_chain/consensus_object_pools/[blockchain_dag, block_pools_types] + ../beacon_chain/spec/[beaconstate, deposit_snapshots, forks, helpers] template withTimer*(stats: var RunningStat, body: untyped) = # TODO unify timing somehow diff --git a/vendor/nim-presto b/vendor/nim-presto index 42552611c..8bb4a54f4 160000 --- a/vendor/nim-presto +++ b/vendor/nim-presto @@ -1 +1 @@ -Subproject commit 42552611cfe04ca7838243d0a0e88fb9a5e9701a +Subproject commit 8bb4a54f4751dc560efc24003be4b3b2b28316e7