mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-23 21:12:52 +00:00
reduce ncli/research imports (#5275)
* reduce ncli/research imports avoids ssl, most of chronos etc, speeds up compiles * copyright
This commit is contained in:
parent
a154a42205
commit
3c9fc49411
@ -9,12 +9,12 @@
|
|||||||
|
|
||||||
import
|
import
|
||||||
std/math,
|
std/math,
|
||||||
chronos, chronicles,
|
chronos/timer, chronicles,
|
||||||
./spec/beacon_time
|
./spec/beacon_time
|
||||||
|
|
||||||
from times import Time, getTime, fromUnix, `<`, `-`, inNanoseconds
|
from times import Time, getTime, fromUnix, `<`, `-`, inNanoseconds
|
||||||
|
|
||||||
export chronos.Duration, Moment, now
|
export timer.Duration, Moment, now
|
||||||
|
|
||||||
type
|
type
|
||||||
BeaconClock* = object
|
BeaconClock* = object
|
||||||
@ -62,9 +62,9 @@ func getBeaconTimeFn*(c: BeaconClock): GetBeaconTimeFn =
|
|||||||
proc fromNow*(c: BeaconClock, t: BeaconTime): tuple[inFuture: bool, offset: Duration] =
|
proc fromNow*(c: BeaconClock, t: BeaconTime): tuple[inFuture: bool, offset: Duration] =
|
||||||
let now = c.now()
|
let now = c.now()
|
||||||
if t > now:
|
if t > now:
|
||||||
(true, chronos.nanoseconds((t - now).nanoseconds))
|
(true, nanoseconds((t - now).nanoseconds))
|
||||||
else:
|
else:
|
||||||
(false, chronos.nanoseconds((now - t).nanoseconds))
|
(false, nanoseconds((now - t).nanoseconds))
|
||||||
|
|
||||||
proc fromNow*(c: BeaconClock, slot: Slot): tuple[inFuture: bool, offset: Duration] =
|
proc fromNow*(c: BeaconClock, slot: Slot): tuple[inFuture: bool, offset: Duration] =
|
||||||
c.fromNow(slot.start_beacon_time())
|
c.fromNow(slot.start_beacon_time())
|
||||||
@ -76,7 +76,7 @@ proc durationToNextSlot*(c: BeaconClock): Duration =
|
|||||||
|
|
||||||
if currentSlot.afterGenesis:
|
if currentSlot.afterGenesis:
|
||||||
let nextSlot = currentSlot.slot + 1
|
let nextSlot = currentSlot.slot + 1
|
||||||
chronos.nanoseconds(
|
nanoseconds(
|
||||||
(nextSlot.start_beacon_time() - currentTime).nanoseconds)
|
(nextSlot.start_beacon_time() - currentTime).nanoseconds)
|
||||||
else:
|
else:
|
||||||
# absoluteTime = BeaconTime(-currentTime.ns_since_genesis).
|
# absoluteTime = BeaconTime(-currentTime.ns_since_genesis).
|
||||||
@ -84,7 +84,7 @@ proc durationToNextSlot*(c: BeaconClock): Duration =
|
|||||||
absoluteTime = Slot(0).start_beacon_time() +
|
absoluteTime = Slot(0).start_beacon_time() +
|
||||||
(Slot(0).start_beacon_time() - currentTime)
|
(Slot(0).start_beacon_time() - currentTime)
|
||||||
timeToNextSlot = absoluteTime - currentSlot.slot.start_beacon_time()
|
timeToNextSlot = absoluteTime - currentSlot.slot.start_beacon_time()
|
||||||
chronos.nanoseconds(timeToNextSlot.nanoseconds)
|
nanoseconds(timeToNextSlot.nanoseconds)
|
||||||
|
|
||||||
proc durationToNextEpoch*(c: BeaconClock): Duration =
|
proc durationToNextEpoch*(c: BeaconClock): Duration =
|
||||||
let
|
let
|
||||||
@ -93,7 +93,7 @@ proc durationToNextEpoch*(c: BeaconClock): Duration =
|
|||||||
|
|
||||||
if currentSlot.afterGenesis:
|
if currentSlot.afterGenesis:
|
||||||
let nextEpochSlot = (currentSlot.slot.epoch() + 1).start_slot()
|
let nextEpochSlot = (currentSlot.slot.epoch() + 1).start_slot()
|
||||||
chronos.nanoseconds(
|
nanoseconds(
|
||||||
(nextEpochSlot.start_beacon_time() - currentTime).nanoseconds)
|
(nextEpochSlot.start_beacon_time() - currentTime).nanoseconds)
|
||||||
else:
|
else:
|
||||||
# absoluteTime = BeaconTime(-currentTime.ns_since_genesis).
|
# absoluteTime = BeaconTime(-currentTime.ns_since_genesis).
|
||||||
@ -102,15 +102,11 @@ proc durationToNextEpoch*(c: BeaconClock): Duration =
|
|||||||
(Slot(0).start_beacon_time() - currentTime)
|
(Slot(0).start_beacon_time() - currentTime)
|
||||||
timeToNextEpoch = absoluteTime -
|
timeToNextEpoch = absoluteTime -
|
||||||
currentSlot.slot.epoch().start_slot().start_beacon_time()
|
currentSlot.slot.epoch().start_slot().start_beacon_time()
|
||||||
chronos.nanoseconds(timeToNextEpoch.nanoseconds)
|
nanoseconds(timeToNextEpoch.nanoseconds)
|
||||||
|
|
||||||
func saturate*(d: tuple[inFuture: bool, offset: Duration]): Duration =
|
func saturate*(d: tuple[inFuture: bool, offset: Duration]): Duration =
|
||||||
if d.inFuture: d.offset else: seconds(0)
|
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 =
|
func shortLog*(d: Duration): string =
|
||||||
$d
|
$d
|
||||||
|
|
||||||
|
@ -262,6 +262,10 @@ proc runKeystoreCachePruningLoop*(cache: KeystoreCacheRef) {.async.} =
|
|||||||
if exitLoop: break
|
if exitLoop: break
|
||||||
cache.pruneExpiredKeys()
|
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,
|
proc runSlotLoop*[T](node: T, startTime: BeaconTime,
|
||||||
slotProc: SlotStartProc[T]) {.async.} =
|
slotProc: SlotStartProc[T]) {.async.} =
|
||||||
var
|
var
|
||||||
|
@ -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
|
import
|
||||||
|
std/strutils,
|
||||||
confutils, json_serialization,
|
confutils, json_serialization,
|
||||||
snappy,
|
snappy,
|
||||||
../beacon_chain/spec/eth2_apis/eth2_rest_serialization,
|
../beacon_chain/spec/eth2_apis/eth2_rest_serialization,
|
||||||
|
@ -7,11 +7,11 @@
|
|||||||
|
|
||||||
import
|
import
|
||||||
stats, strformat, times,
|
stats, strformat, times,
|
||||||
|
stew/io2,
|
||||||
../tests/testblockutil, ../tests/consensus_spec/os_ops,
|
../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/datatypes/[phase0, altair],
|
||||||
../beacon_chain/spec/[beaconstate, deposit_snapshots, forks, helpers],
|
../beacon_chain/spec/[beaconstate, deposit_snapshots, forks, helpers]
|
||||||
../beacon_chain/consensus_object_pools/[blockchain_dag, block_pools_types]
|
|
||||||
|
|
||||||
template withTimer*(stats: var RunningStat, body: untyped) =
|
template withTimer*(stats: var RunningStat, body: untyped) =
|
||||||
# TODO unify timing somehow
|
# TODO unify timing somehow
|
||||||
|
2
vendor/nim-presto
vendored
2
vendor/nim-presto
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 42552611cfe04ca7838243d0a0e88fb9a5e9701a
|
Subproject commit 8bb4a54f4751dc560efc24003be4b3b2b28316e7
|
Loading…
x
Reference in New Issue
Block a user