2022-08-04 08:04:30 +00:00
|
|
|
# Nimbus
|
2022-07-21 12:14:41 +00:00
|
|
|
# Copyright (c) 2021 Status Research & Development GmbH
|
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
|
|
# http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed
|
|
|
|
# except according to those terms.
|
|
|
|
|
|
|
|
import
|
2022-10-20 16:59:54 +00:00
|
|
|
eth/[common, p2p],
|
2022-07-21 12:14:41 +00:00
|
|
|
chronicles,
|
|
|
|
chronos,
|
2022-08-04 08:04:30 +00:00
|
|
|
stew/[interval_set, sorted_set],
|
|
|
|
"."/[full/worker, sync_desc, sync_sched, protocol]
|
2022-07-21 12:14:41 +00:00
|
|
|
|
|
|
|
{.push raises: [Defect].}
|
|
|
|
|
|
|
|
logScope:
|
|
|
|
topics = "full-sync"
|
|
|
|
|
|
|
|
type
|
2022-08-04 08:04:30 +00:00
|
|
|
FullSyncRef* = RunnerSyncRef[CtxData,BuddyData]
|
2022-07-21 12:14:41 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2022-08-04 08:04:30 +00:00
|
|
|
# Virtual methods/interface, `mixin` functions
|
2022-07-21 12:14:41 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2022-08-04 08:04:30 +00:00
|
|
|
proc runSetup(ctx: FullCtxRef; ticker: bool): bool =
|
|
|
|
worker.setup(ctx,ticker)
|
2022-07-21 12:14:41 +00:00
|
|
|
|
2022-08-04 08:04:30 +00:00
|
|
|
proc runRelease(ctx: FullCtxRef) =
|
|
|
|
worker.release(ctx)
|
2022-07-21 12:14:41 +00:00
|
|
|
|
2022-11-14 14:13:00 +00:00
|
|
|
proc runDaemon(ctx: FullCtxRef) {.async.} =
|
|
|
|
discard
|
|
|
|
|
2022-08-04 08:04:30 +00:00
|
|
|
proc runStart(buddy: FullBuddyRef): bool =
|
|
|
|
worker.start(buddy)
|
|
|
|
|
|
|
|
proc runStop(buddy: FullBuddyRef) =
|
|
|
|
worker.stop(buddy)
|
|
|
|
|
2022-08-24 13:44:18 +00:00
|
|
|
proc runPool(buddy: FullBuddyRef; last: bool) =
|
|
|
|
worker.runPool(buddy, last)
|
2022-08-04 08:04:30 +00:00
|
|
|
|
|
|
|
proc runSingle(buddy: FullBuddyRef) {.async.} =
|
|
|
|
await worker.runSingle(buddy)
|
2022-07-21 12:14:41 +00:00
|
|
|
|
2022-08-04 08:04:30 +00:00
|
|
|
proc runMulti(buddy: FullBuddyRef) {.async.} =
|
|
|
|
await worker.runMulti(buddy)
|
2022-07-21 12:14:41 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public functions
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
proc init*(
|
|
|
|
T: type FullSyncRef;
|
|
|
|
ethNode: EthereumNode;
|
2022-10-10 02:31:28 +00:00
|
|
|
chain: Chain;
|
2022-09-30 08:22:14 +00:00
|
|
|
rng: ref HmacDrbgContext;
|
2022-07-21 12:14:41 +00:00
|
|
|
maxPeers: int;
|
2022-08-04 08:04:30 +00:00
|
|
|
enableTicker = false): T =
|
|
|
|
new result
|
2022-10-10 02:31:28 +00:00
|
|
|
result.initSync(ethNode, chain, maxPeers, enableTicker)
|
2022-09-30 08:22:14 +00:00
|
|
|
result.ctx.data.rng = rng
|
2022-07-21 12:14:41 +00:00
|
|
|
|
|
|
|
proc start*(ctx: FullSyncRef) =
|
2022-08-04 08:04:30 +00:00
|
|
|
doAssert ctx.startSync()
|
2022-07-21 12:14:41 +00:00
|
|
|
|
|
|
|
proc stop*(ctx: FullSyncRef) =
|
2022-08-04 08:04:30 +00:00
|
|
|
ctx.stopSync()
|
2022-07-21 12:14:41 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|