mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-05 16:54:00 +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: [].}
|
ReqBeaconSyncerTargetCB* = proc(header: Header; finHash: Hash32) {.gcsafe, raises: [].}
|
||||||
## Ditto (for beacon sync)
|
## Ditto (for beacon sync)
|
||||||
|
|
||||||
BeaconSyncerIsActiveCB* = proc(): bool {.gcsafe, raises: [].}
|
BeaconSyncerProgressCB* = proc(): tuple[start, current, target: BlockNumber] {.gcsafe, raises: [].}
|
||||||
## Query syncer status
|
## Query syncer status
|
||||||
|
|
||||||
NotifyBadBlockCB* = proc(invalid, origin: Header) {.gcsafe, raises: [].}
|
NotifyBadBlockCB* = proc(invalid, origin: Header) {.gcsafe, raises: [].}
|
||||||
@ -85,7 +85,7 @@ type
|
|||||||
## Call back function for a sync processor that returns the canonical
|
## Call back function for a sync processor that returns the canonical
|
||||||
## header.
|
## header.
|
||||||
|
|
||||||
beaconSyncerIsActiveCB: BeaconSyncerIsActiveCB
|
beaconSyncerProgressCB: BeaconSyncerProgressCB
|
||||||
## Call back function querying the status of the sync processor. The
|
## Call back function querying the status of the sync processor. The
|
||||||
## function returns `true` if the syncer is running, downloading or
|
## function returns `true` if the syncer is running, downloading or
|
||||||
## importing headers and blocks.
|
## importing headers and blocks.
|
||||||
@ -355,11 +355,11 @@ proc reqBeaconSyncerTarget*(com: CommonRef; header: Header; finHash: Hash32) =
|
|||||||
if not com.reqBeaconSyncerTargetCB.isNil:
|
if not com.reqBeaconSyncerTargetCB.isNil:
|
||||||
com.reqBeaconSyncerTargetCB(header, finHash)
|
com.reqBeaconSyncerTargetCB(header, finHash)
|
||||||
|
|
||||||
proc beaconSyncerIsActive*(com: CommonRef): bool =
|
proc beaconSyncerProgress*(com: CommonRef): tuple[start, current, target: BlockNumber] =
|
||||||
## Query syncer status
|
## Query syncer status
|
||||||
if not com.beaconSyncerIsActiveCB.isNil:
|
if not com.beaconSyncerProgressCB.isNil:
|
||||||
return com.beaconSyncerIsActiveCB()
|
return com.beaconSyncerProgressCB()
|
||||||
# false
|
# (0,0,0)
|
||||||
|
|
||||||
proc notifyBadBlock*(com: CommonRef; invalid, origin: Header)
|
proc notifyBadBlock*(com: CommonRef; invalid, origin: Header)
|
||||||
{.gcsafe, raises: [].} =
|
{.gcsafe, raises: [].} =
|
||||||
@ -481,9 +481,9 @@ func `reqBeaconSyncerTarget=`*(com: CommonRef; cb: ReqBeaconSyncerTargetCB) =
|
|||||||
## Activate or reset a call back handler for syncing.
|
## Activate or reset a call back handler for syncing.
|
||||||
com.reqBeaconSyncerTargetCB = cb
|
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.
|
## Activate or reset a call back handler for querying syncer.
|
||||||
com.beaconSyncerIsActiveCB = cb
|
com.beaconSyncerProgressCB = cb
|
||||||
|
|
||||||
func `notifyBadBlock=`*(com: CommonRef; cb: NotifyBadBlockCB) =
|
func `notifyBadBlock=`*(com: CommonRef; cb: NotifyBadBlockCB) =
|
||||||
## Activate or reset a call back handler for bad block notification.
|
## Activate or reset a call back handler for bad block notification.
|
||||||
|
@ -23,13 +23,18 @@ import
|
|||||||
# Private functions
|
# Private functions
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
proc querySyncStatusCB(
|
proc queryProgressCB(
|
||||||
ctx: BeaconCtxRef;
|
ctx: BeaconCtxRef;
|
||||||
info: static[string];
|
info: static[string];
|
||||||
): BeaconSyncerIsActiveCB =
|
): BeaconSyncerProgressCB =
|
||||||
## Syncer status query function/closure.
|
## Syncer status query function/closure.
|
||||||
return proc(): bool =
|
return proc(): tuple[start, current, target: BlockNumber] =
|
||||||
not ctx.hibernate()
|
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(
|
proc updateBeaconHeaderCB(
|
||||||
ctx: BeaconCtxRef;
|
ctx: BeaconCtxRef;
|
||||||
@ -102,13 +107,13 @@ proc setupServices*(ctx: BeaconCtxRef; info: static[string]) =
|
|||||||
## Helper for `setup()`: Enable external call-back based services
|
## Helper for `setup()`: Enable external call-back based services
|
||||||
# Activate target request. Will be called from RPC handler.
|
# Activate target request. Will be called from RPC handler.
|
||||||
ctx.pool.chain.com.reqBeaconSyncerTarget = ctx.updateBeaconHeaderCB info
|
ctx.pool.chain.com.reqBeaconSyncerTarget = ctx.updateBeaconHeaderCB info
|
||||||
# Provide status info: running or hibernating
|
# Provide progress info
|
||||||
ctx.pool.chain.com.beaconSyncerIsActive = ctx.querySyncStatusCB info
|
ctx.pool.chain.com.beaconSyncerProgress = ctx.queryProgressCB info
|
||||||
|
|
||||||
proc destroyServices*(ctx: BeaconCtxRef) =
|
proc destroyServices*(ctx: BeaconCtxRef) =
|
||||||
## Helper for `release()`
|
## Helper for `release()`
|
||||||
ctx.pool.chain.com.reqBeaconSyncerTarget = ReqBeaconSyncerTargetCB(nil)
|
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