Removed obsolete `finalHash` and `final` block number maintenance
why: Not needed anymore, `forkChoice()` as has been integrated into `importBlock()`.
This commit is contained in:
parent
0ea1a959d8
commit
c3810253fc
|
@ -110,7 +110,7 @@ proc forkchoiceUpdated*(ben: BeaconEngineRef,
|
|||
|
||||
# Update sync header (if any)
|
||||
com.syncReqNewHead(header)
|
||||
com.reqBeaconSyncTargetCB(header, update.finalizedBlockHash)
|
||||
com.reqBeaconSyncTargetCB(header)
|
||||
|
||||
return simpleFCU(PayloadExecutionStatus.syncing)
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ type
|
|||
SyncReqNewHeadCB* = proc(header: Header) {.gcsafe, raises: [].}
|
||||
## Update head for syncing
|
||||
|
||||
ReqBeaconSyncTargetCB* = proc(header: Header; finHash: Hash32) {.gcsafe, raises: [].}
|
||||
ReqBeaconSyncTargetCB* = proc(header: Header) {.gcsafe, raises: [].}
|
||||
## Ditto (for beacon sync)
|
||||
|
||||
NotifyBadBlockCB* = proc(invalid, origin: Header) {.gcsafe, raises: [].}
|
||||
|
@ -350,10 +350,10 @@ proc syncReqNewHead*(com: CommonRef; header: Header)
|
|||
if not com.syncReqNewHead.isNil:
|
||||
com.syncReqNewHead(header)
|
||||
|
||||
proc reqBeaconSyncTargetCB*(com: CommonRef; header: Header; finHash: Hash32) =
|
||||
proc reqBeaconSyncTargetCB*(com: CommonRef; header: Header) =
|
||||
## Used by RPC updater
|
||||
if not com.reqBeaconSyncTargetCB.isNil:
|
||||
com.reqBeaconSyncTargetCB(header, finHash)
|
||||
com.reqBeaconSyncTargetCB(header)
|
||||
|
||||
proc notifyBadBlock*(com: CommonRef; invalid, origin: Header)
|
||||
{.gcsafe, raises: [].} =
|
||||
|
|
|
@ -219,7 +219,7 @@ Running the sync process for *MainNet*
|
|||
--------------------------------------
|
||||
|
||||
For syncing, a beacon node is needed that regularly informs via *RPC* of a
|
||||
recently finalised block header.
|
||||
recent target block header.
|
||||
|
||||
The beacon node program used here is the *nimbus_beacon_node* binary from the
|
||||
*nimbus-eth2* project (any other, e.g.the *light client* will do.)
|
||||
|
@ -230,7 +230,7 @@ The beacon node program used here is the *nimbus_beacon_node* binary from the
|
|||
--jwt-secret=/tmp/jwtsecret
|
||||
|
||||
where *http://127.0.0.1:8551* is the URL of the sync process that receives the
|
||||
finalised block header (here on the same physical machine) and `/tmp/jwtsecret`
|
||||
target block headers (here on the same physical machine) and `/tmp/jwtsecret`
|
||||
is the shared secret file needed for mutual communication authentication.
|
||||
|
||||
It will take a while for *nimbus_beacon_node* to catch up (see the
|
||||
|
|
|
@ -170,10 +170,6 @@ proc runPeer*(
|
|||
buddy.only.multiRunIdle = Moment.now() - buddy.only.stoppedMultiRun
|
||||
buddy.only.nMultiLoop.inc # statistics/debugging
|
||||
|
||||
# Update consensus header target when needed. It comes with a finalised
|
||||
# header hash where we need to complete the block number.
|
||||
await buddy.headerStagedUpdateTarget info
|
||||
|
||||
if not await buddy.napUnlessSomethingToFetch():
|
||||
#
|
||||
# Layout of a triple of linked header chains (see `README.md`)
|
||||
|
|
|
@ -342,7 +342,7 @@ proc blocksStagedImport*(
|
|||
ctx.updateMetrics()
|
||||
|
||||
debug info & ": import done", iv, nBlocks, B=ctx.chain.baseNumber.bnStr,
|
||||
L=ctx.chain.latestNumber.bnStr, F=ctx.layout.final.bnStr
|
||||
L=ctx.chain.latestNumber.bnStr
|
||||
return true
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
|
@ -92,10 +92,6 @@ proc dbLoadSyncStateLayout*(ctx: BeaconCtxRef; info: static[string]): bool =
|
|||
# If there was a manual import after a previous sync, then saved state
|
||||
# might be outdated.
|
||||
if rc.isOk and
|
||||
# The base number is the least record of the FCU chains/tree. So the
|
||||
# finalised entry must not be smaller.
|
||||
ctx.chain.baseNumber() <= rc.value.final and
|
||||
|
||||
# If the latest FCU number is not larger than the head, there is nothing
|
||||
# to do (might also happen after a manual import.)
|
||||
latest < rc.value.head and
|
||||
|
|
|
@ -19,7 +19,7 @@ import
|
|||
../worker_desc,
|
||||
./update/metrics,
|
||||
./headers_staged/[headers, linked_hchain],
|
||||
"."/[headers_unproc, update]
|
||||
./headers_unproc
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Private functions
|
||||
|
@ -53,35 +53,6 @@ proc fetchAndCheck(
|
|||
# Public functions
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
proc headerStagedUpdateTarget*(
|
||||
buddy: BeaconBuddyRef;
|
||||
info: static[string];
|
||||
) {.async: (raises: []).} =
|
||||
## Fetch finalised beacon header if there is an update available
|
||||
let
|
||||
ctx = buddy.ctx
|
||||
peer = buddy.peer
|
||||
if ctx.layout.lastState == idleSyncState and
|
||||
ctx.target.final == 0 and
|
||||
ctx.target.finalHash != zeroHash32 and
|
||||
not ctx.target.locked:
|
||||
const iv = BnRange.new(1u,1u) # dummy interval
|
||||
|
||||
ctx.target.locked = true
|
||||
let rc = await buddy.headersFetchReversed(iv, ctx.target.finalHash, info)
|
||||
ctx.target.locked = false
|
||||
|
||||
if rc.isOk:
|
||||
let hash = rlp.encode(rc.value[0]).keccak256
|
||||
if hash != ctx.target.finalHash:
|
||||
# Oops
|
||||
buddy.ctrl.zombie = true
|
||||
trace info & ": finalised header hash mismatch", peer, hash,
|
||||
expected=ctx.target.finalHash
|
||||
else:
|
||||
ctx.updateFinalBlockHeader(rc.value[0], ctx.target.finalHash, info)
|
||||
|
||||
|
||||
proc headersStagedCollect*(
|
||||
buddy: BeaconBuddyRef;
|
||||
info: static[string];
|
||||
|
|
|
@ -38,7 +38,7 @@ when enableTicker:
|
|||
head: ctx.layout.head,
|
||||
headOk: ctx.layout.lastState != idleSyncState,
|
||||
target: ctx.target.consHead.number,
|
||||
targetOk: ctx.target.final != 0,
|
||||
targetOk: ctx.target.changed,
|
||||
|
||||
nHdrStaged: ctx.headersStagedQueueLen(),
|
||||
hdrStagedTop: ctx.headersStagedQueueTopKey(),
|
||||
|
@ -62,31 +62,13 @@ proc updateBeaconHeaderCB(
|
|||
): ReqBeaconSyncTargetCB =
|
||||
## Update beacon header. This function is intended as a call back function
|
||||
## for the RPC module.
|
||||
return proc(h: Header; f: Hash32) {.gcsafe, raises: [].} =
|
||||
|
||||
# Check whether there is an update running (otherwise take next upate)
|
||||
if not ctx.target.locked and # ignore if currently updating
|
||||
ctx.target.final == 0 and # ignore if complete already
|
||||
f != zeroHash32 and # finalised hash is set
|
||||
return proc(h: Header) {.gcsafe, raises: [].} =
|
||||
if ctx.chain.baseNumber() < h.number and # sanity check
|
||||
ctx.layout.head < h.number and # update is advancing
|
||||
ctx.target.consHead.number < h.number: # .. ditto
|
||||
|
||||
ctx.target.consHead = h
|
||||
ctx.target.finalHash = f
|
||||
ctx.target.changed = true
|
||||
|
||||
# Check whether `FC` knows about the finalised block already.
|
||||
#
|
||||
# On a full node, all blocks before the current state are stored on the
|
||||
# database which is also accessed by `FC`. So one can already decude here
|
||||
# whether `FC` id capable of handling that finalised block (the number of
|
||||
# must be at least the `base` from `FC`.)
|
||||
#
|
||||
# Otherwise the block header will need to be fetched from a peer when
|
||||
# available and checked there (see `headerStagedUpdateTarget()`.)
|
||||
#
|
||||
let finHdr = ctx.chain.headerByHash(f).valueOr: return
|
||||
ctx.updateFinalBlockHeader(finHdr, f, info)
|
||||
ctx.target.changed = true # enable this dataset
|
||||
ctx.updateFromHibernating info # wake up if sleeping
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Public functions
|
||||
|
|
|
@ -156,8 +156,6 @@ proc setupCollectingHeaders(ctx: BeaconCtxRef; info: static[string]) =
|
|||
ctx.sst.layout = SyncStateLayout(
|
||||
coupler: c,
|
||||
dangling: h,
|
||||
final: ctx.target.final,
|
||||
finalHash: ctx.target.finalHash,
|
||||
head: h,
|
||||
lastState: collectingHeaders) # state transition
|
||||
|
||||
|
@ -282,8 +280,7 @@ proc updateSyncState*(ctx: BeaconCtxRef; info: static[string]) =
|
|||
# Check whether the system has been idle and a new header download
|
||||
# session can be set up
|
||||
if prevState == idleSyncState and
|
||||
ctx.target.changed and # and there is a new target from CL
|
||||
ctx.target.final != 0: # .. ditto
|
||||
ctx.target.changed: # and there is a new target from CL
|
||||
ctx.setupCollectingHeaders info # set up new header sync
|
||||
return
|
||||
# Notreached
|
||||
|
@ -313,33 +310,14 @@ proc updateSyncState*(ctx: BeaconCtxRef; info: static[string]) =
|
|||
ctx.startHibernating info
|
||||
|
||||
|
||||
proc updateFinalBlockHeader*(
|
||||
ctx: BeaconCtxRef;
|
||||
finHdr: Header;
|
||||
finHash: Hash32;
|
||||
info: static[string];
|
||||
) =
|
||||
## Update the finalised header cache. If the finalised header is acceptable,
|
||||
## the syncer will be activated from hibernation if necessary.
|
||||
##
|
||||
let
|
||||
b = ctx.chain.baseNumber()
|
||||
f = finHdr.number
|
||||
if f < b:
|
||||
trace info & ": finalised block # too low",
|
||||
B=b.bnStr, finalised=f.bnStr, delta=(b - f)
|
||||
proc updateFromHibernating*(ctx: BeaconCtxRef; info: static[string]) =
|
||||
## Activate syncer if hibernating.
|
||||
if ctx.hibernate:
|
||||
ctx.hibernate = false # activates syncer
|
||||
debug info & ": activating syncer", T=ctx.target.consHead.bnStr
|
||||
|
||||
ctx.target.reset
|
||||
|
||||
else:
|
||||
ctx.target.final = f
|
||||
ctx.target.finalHash = finHash
|
||||
|
||||
# Activate running (unless done yet)
|
||||
if ctx.hibernate:
|
||||
ctx.hibernate = false
|
||||
debug info & ": activating syncer", B=b.bnStr,
|
||||
finalised=f.bnStr, head=ctx.target.consHead.bnStr
|
||||
# Re-calculate sync state
|
||||
ctx.updateSyncState info
|
||||
|
||||
# Update, so it can be followed nicely
|
||||
ctx.updateMetrics()
|
||||
|
|
|
@ -128,10 +128,6 @@ const
|
|||
## entry block number is too high and so leaves a gap to the ledger state
|
||||
## block number.)
|
||||
|
||||
finaliserChainLengthMax* = 32
|
||||
## When importing with `importBlock()`, finalise after at most this many
|
||||
## invocations of `importBlock()`.
|
||||
|
||||
# ----------------------
|
||||
|
||||
static:
|
||||
|
|
|
@ -72,11 +72,8 @@ type
|
|||
|
||||
SyncStateTarget* = object
|
||||
## Beacon state to be implicitely updated by RPC method
|
||||
locked*: bool ## Don't update while fetching header
|
||||
changed*: bool ## Tell that something has changed
|
||||
consHead*: Header ## Consensus head
|
||||
final*: BlockNumber ## Finalised block number
|
||||
finalHash*: Hash32 ## Finalised hash
|
||||
|
||||
SyncStateLayout* = object
|
||||
## Layout of a linked header chains defined by the triple `(C,D,H)` as
|
||||
|
@ -95,14 +92,9 @@ type
|
|||
##
|
||||
coupler*: BlockNumber ## Bottom end `C` of full chain `(C,H]`
|
||||
dangling*: BlockNumber ## Left end `D` of linked chain `[D,H]`
|
||||
head*: BlockNumber ## `H`, block num of some finalised block
|
||||
head*: BlockNumber ## `H`, block number of some target block
|
||||
lastState*: SyncLayoutState ## Last known layout state
|
||||
|
||||
# Legacy entries, will be removed some time. This is currently needed
|
||||
# for importing blocks into `FC` the support of which will be deprecated.
|
||||
final*: BlockNumber ## Finalised block number `F`
|
||||
finalHash*: Hash32 ## Hash of `F`
|
||||
|
||||
SyncState* = object
|
||||
## Sync state for header and block chains
|
||||
target*: SyncStateTarget ## Consensus head, see `T` in `README.md`
|
||||
|
|
Loading…
Reference in New Issue