2022-08-04 08:04:30 +00:00
|
|
|
# Nimbus
|
2022-05-09 14:04:48 +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-08-04 08:04:30 +00:00
|
|
|
eth/[common/eth_types, p2p],
|
2022-05-09 14:04:48 +00:00
|
|
|
chronicles,
|
|
|
|
chronos,
|
2022-08-12 15:42:07 +00:00
|
|
|
../db/select_backend,
|
2022-08-04 08:04:30 +00:00
|
|
|
../p2p/chain,
|
|
|
|
./snap/[worker, worker_desc],
|
|
|
|
"."/[sync_desc, sync_sched, protocol]
|
2022-05-13 16:30:10 +00:00
|
|
|
|
|
|
|
{.push raises: [Defect].}
|
|
|
|
|
2022-05-23 16:53:19 +00:00
|
|
|
logScope:
|
2022-06-16 08:58:50 +00:00
|
|
|
topics = "snap-sync"
|
2022-05-23 16:53:19 +00:00
|
|
|
|
2022-05-13 16:30:10 +00:00
|
|
|
type
|
2022-08-04 08:04:30 +00:00
|
|
|
SnapSyncRef* = RunnerSyncRef[CtxData,BuddyData]
|
2022-05-23 16:53:19 +00:00
|
|
|
|
2022-05-17 11:09:49 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
2022-08-04 08:04:30 +00:00
|
|
|
# Virtual methods/interface, `mixin` functions
|
2022-05-17 11:09:49 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2022-08-04 08:04:30 +00:00
|
|
|
proc runSetup(ctx: SnapCtxRef; ticker: bool): bool =
|
|
|
|
worker.setup(ctx,ticker)
|
2022-05-17 11:09:49 +00:00
|
|
|
|
2022-08-04 08:04:30 +00:00
|
|
|
proc runRelease(ctx: SnapCtxRef) =
|
|
|
|
worker.release(ctx)
|
2022-05-23 16:53:19 +00:00
|
|
|
|
2022-08-04 08:04:30 +00:00
|
|
|
proc runStart(buddy: SnapBuddyRef): bool =
|
|
|
|
worker.start(buddy)
|
|
|
|
|
|
|
|
proc runStop(buddy: SnapBuddyRef) =
|
|
|
|
worker.stop(buddy)
|
|
|
|
|
2022-08-24 13:44:18 +00:00
|
|
|
proc runPool(buddy: SnapBuddyRef; last: bool) =
|
|
|
|
worker.runPool(buddy, last)
|
2022-08-04 08:04:30 +00:00
|
|
|
|
|
|
|
proc runSingle(buddy: SnapBuddyRef) {.async.} =
|
|
|
|
await worker.runSingle(buddy)
|
2022-05-23 16:53:19 +00:00
|
|
|
|
2022-08-04 08:04:30 +00:00
|
|
|
proc runMulti(buddy: SnapBuddyRef) {.async.} =
|
|
|
|
await worker.runMulti(buddy)
|
2022-05-09 14:04:48 +00:00
|
|
|
|
2022-05-13 16:30:10 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public functions
|
|
|
|
# ------------------------------------------------------------------------------
|
2022-05-09 14:04:48 +00:00
|
|
|
|
2022-08-04 08:04:30 +00:00
|
|
|
proc init*(
|
|
|
|
T: type SnapSyncRef;
|
|
|
|
ethNode: EthereumNode;
|
|
|
|
chain: Chain;
|
|
|
|
rng: ref HmacDrbgContext;
|
|
|
|
maxPeers: int;
|
2022-08-12 15:42:07 +00:00
|
|
|
dbBackend: ChainDb,
|
2022-08-04 08:04:30 +00:00
|
|
|
enableTicker = false): T =
|
2022-05-13 16:30:10 +00:00
|
|
|
new result
|
2022-10-10 02:31:28 +00:00
|
|
|
result.initSync(ethNode, chain, maxPeers, enableTicker)
|
2022-08-04 08:04:30 +00:00
|
|
|
result.ctx.chain = chain # explicitely override
|
|
|
|
result.ctx.data.rng = rng
|
2022-08-12 15:42:07 +00:00
|
|
|
result.ctx.data.dbBackend = dbBackend
|
2022-05-13 16:30:10 +00:00
|
|
|
|
2022-07-21 12:14:41 +00:00
|
|
|
proc start*(ctx: SnapSyncRef) =
|
2022-08-04 08:04:30 +00:00
|
|
|
doAssert ctx.startSync()
|
2022-05-13 16:30:10 +00:00
|
|
|
|
2022-07-21 12:14:41 +00:00
|
|
|
proc stop*(ctx: SnapSyncRef) =
|
2022-08-04 08:04:30 +00:00
|
|
|
ctx.stopSync()
|
2022-06-06 13:42:08 +00:00
|
|
|
|
2022-05-13 16:30:10 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|