mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-17 15:50:57 +00:00
c5e895aaab
* Rename `playXXX` => `passXXX` why: Better purpose match * Code massage, log message updates * Moved `ticker.nim` to `misc` folder to be used the same by full and snap sync why: Simplifies maintenance * Move `worker/pivot*` => `worker/pass/pass_snap/*` why: better for maintenance * Moved helper source file => `pass/pass_snap/helper` * Renamed ComError => GetError, `worker/com/` => `worker/get/` * Keep ticker enable flag in worker descriptor why: This allows to pass this flag with the descriptor and not an extra function argument when calling the setup function. * Extracted setup/release code from `worker.nim` => `pass/pass_init.nim`
97 lines
2.9 KiB
Nim
97 lines
2.9 KiB
Nim
# Nimbus
|
|
# 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.
|
|
|
|
## Sync mode pass multiplexer
|
|
## ==========================
|
|
##
|
|
## Pass state diagram:
|
|
## ::
|
|
## <init> -> <snap-sync> -> <full-sync> ---+
|
|
## ^ |
|
|
## | |
|
|
## +----------+
|
|
##
|
|
{.push raises: [].}
|
|
|
|
import
|
|
chronicles,
|
|
chronos,
|
|
./range_desc,
|
|
./worker/pass,
|
|
./worker_desc
|
|
|
|
logScope:
|
|
topics = "snap-worker"
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Private helpers
|
|
# ------------------------------------------------------------------------------
|
|
|
|
template ignoreException(info: static[string]; code: untyped) =
|
|
try:
|
|
code
|
|
except CatchableError as e:
|
|
error "Exception at " & info & ":", name=($e.name), msg=(e.msg)
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Public start/stop and admin functions
|
|
# ------------------------------------------------------------------------------
|
|
|
|
proc setup*(ctx: SnapCtxRef): bool =
|
|
## Global set up
|
|
ctx.passInitSetup()
|
|
ignoreException("setup"):
|
|
ctx.passActor.setup(ctx)
|
|
true
|
|
|
|
proc release*(ctx: SnapCtxRef) =
|
|
## Global clean up
|
|
ignoreException("release"):
|
|
ctx.passActor.release(ctx)
|
|
ctx.passInitRelease()
|
|
|
|
proc start*(buddy: SnapBuddyRef): bool =
|
|
## Initialise worker peer
|
|
ignoreException("start"):
|
|
result = buddy.ctx.passActor.start(buddy)
|
|
|
|
proc stop*(buddy: SnapBuddyRef) =
|
|
## Clean up this peer
|
|
ignoreException("stop"):
|
|
buddy.ctx.passActor.stop(buddy)
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Public functions, sync handler multiplexers
|
|
# ------------------------------------------------------------------------------
|
|
|
|
proc runDaemon*(ctx: SnapCtxRef) {.async.} =
|
|
## Sync processsing multiplexer
|
|
ignoreException("runDaemon"):
|
|
await ctx.passActor.daemon(ctx)
|
|
|
|
proc runSingle*(buddy: SnapBuddyRef) {.async.} =
|
|
## Sync processsing multiplexer
|
|
ignoreException("runSingle"):
|
|
await buddy.ctx.passActor.single(buddy)
|
|
|
|
proc runPool*(buddy: SnapBuddyRef, last: bool; laps: int): bool =
|
|
## Sync processsing multiplexer
|
|
ignoreException("runPool"):
|
|
result = buddy.ctx.passActor.pool(buddy,last,laps)
|
|
|
|
proc runMulti*(buddy: SnapBuddyRef) {.async.} =
|
|
## Sync processsing multiplexer
|
|
ignoreException("runMulti"):
|
|
await buddy.ctx.passActor.multi(buddy)
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# End
|
|
# ------------------------------------------------------------------------------
|