mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-05 08:45:27 +00:00
Provide global sync progress, supersedes activation indicator (#3039)
This commit is contained in:
parent
3e1f5e0b5f
commit
bc0620f6ca
@ -47,7 +47,7 @@ type
|
||||
ReqBeaconSyncerTargetCB* = proc(header: Header; finHash: Hash32) {.gcsafe, raises: [].}
|
||||
## Ditto (for beacon sync)
|
||||
|
||||
BeaconSyncerIsActiveCB* = proc(): bool {.gcsafe, raises: [].}
|
||||
BeaconSyncerProgressCB* = proc(): tuple[start, current, target: BlockNumber] {.gcsafe, raises: [].}
|
||||
## Query syncer status
|
||||
|
||||
NotifyBadBlockCB* = proc(invalid, origin: Header) {.gcsafe, raises: [].}
|
||||
@ -85,7 +85,7 @@ type
|
||||
## Call back function for a sync processor that returns the canonical
|
||||
## header.
|
||||
|
||||
beaconSyncerIsActiveCB: BeaconSyncerIsActiveCB
|
||||
beaconSyncerProgressCB: BeaconSyncerProgressCB
|
||||
## Call back function querying the status of the sync processor. The
|
||||
## function returns `true` if the syncer is running, downloading or
|
||||
## importing headers and blocks.
|
||||
@ -355,11 +355,11 @@ proc reqBeaconSyncerTarget*(com: CommonRef; header: Header; finHash: Hash32) =
|
||||
if not com.reqBeaconSyncerTargetCB.isNil:
|
||||
com.reqBeaconSyncerTargetCB(header, finHash)
|
||||
|
||||
proc beaconSyncerIsActive*(com: CommonRef): bool =
|
||||
proc beaconSyncerProgress*(com: CommonRef): tuple[start, current, target: BlockNumber] =
|
||||
## Query syncer status
|
||||
if not com.beaconSyncerIsActiveCB.isNil:
|
||||
return com.beaconSyncerIsActiveCB()
|
||||
# false
|
||||
if not com.beaconSyncerProgressCB.isNil:
|
||||
return com.beaconSyncerProgressCB()
|
||||
# (0,0,0)
|
||||
|
||||
proc notifyBadBlock*(com: CommonRef; invalid, origin: Header)
|
||||
{.gcsafe, raises: [].} =
|
||||
@ -481,9 +481,9 @@ func `reqBeaconSyncerTarget=`*(com: CommonRef; cb: ReqBeaconSyncerTargetCB) =
|
||||
## Activate or reset a call back handler for syncing.
|
||||
com.reqBeaconSyncerTargetCB = cb
|
||||
|
||||
func `beaconSyncerIsActive=`*(com: CommonRef; cb: BeaconSyncerIsActiveCB) =
|
||||
func `beaconSyncerProgress=`*(com: CommonRef; cb: BeaconSyncerProgressCB) =
|
||||
## Activate or reset a call back handler for querying syncer.
|
||||
com.beaconSyncerIsActiveCB = cb
|
||||
com.beaconSyncerProgressCB = cb
|
||||
|
||||
func `notifyBadBlock=`*(com: CommonRef; cb: NotifyBadBlockCB) =
|
||||
## Activate or reset a call back handler for bad block notification.
|
||||
|
@ -23,13 +23,18 @@ import
|
||||
# Private functions
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
proc querySyncStatusCB(
|
||||
proc queryProgressCB(
|
||||
ctx: BeaconCtxRef;
|
||||
info: static[string];
|
||||
): BeaconSyncerIsActiveCB =
|
||||
): BeaconSyncerProgressCB =
|
||||
## Syncer status query function/closure.
|
||||
return proc(): bool =
|
||||
not ctx.hibernate()
|
||||
return proc(): tuple[start, current, target: BlockNumber] =
|
||||
if not ctx.hibernate():
|
||||
return (ctx.layout.coupler,
|
||||
max(ctx.layout.coupler,
|
||||
min(ctx.chain.latestNumber(), ctx.layout.head)),
|
||||
ctx.layout.head)
|
||||
# (0,0,0)
|
||||
|
||||
proc updateBeaconHeaderCB(
|
||||
ctx: BeaconCtxRef;
|
||||
@ -102,13 +107,13 @@ proc setupServices*(ctx: BeaconCtxRef; info: static[string]) =
|
||||
## Helper for `setup()`: Enable external call-back based services
|
||||
# Activate target request. Will be called from RPC handler.
|
||||
ctx.pool.chain.com.reqBeaconSyncerTarget = ctx.updateBeaconHeaderCB info
|
||||
# Provide status info: running or hibernating
|
||||
ctx.pool.chain.com.beaconSyncerIsActive = ctx.querySyncStatusCB info
|
||||
# Provide progress info
|
||||
ctx.pool.chain.com.beaconSyncerProgress = ctx.queryProgressCB info
|
||||
|
||||
proc destroyServices*(ctx: BeaconCtxRef) =
|
||||
## Helper for `release()`
|
||||
ctx.pool.chain.com.reqBeaconSyncerTarget = ReqBeaconSyncerTargetCB(nil)
|
||||
ctx.pool.chain.com.beaconSyncerIsActive = BeaconSyncerIsActiveCB(nil)
|
||||
ctx.pool.chain.com.beaconSyncerProgress = BeaconSyncerProgressCB(nil)
|
||||
|
||||
# ---------
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user