split function into multiple parts
This commit is contained in:
parent
c01fb9f0da
commit
f3e3c0de8f
|
@ -209,32 +209,42 @@ proc tryForceUpdate(
|
|||
finalizedSlot = forkyStore.finalized_header.beacon.slot,
|
||||
optimisticSlot = forkyStore.optimistic_header.beacon.slot
|
||||
|
||||
proc processObject(
|
||||
proc doProcessObject(
|
||||
self: var LightClientProcessor,
|
||||
obj: SomeForkedLightClientObject,
|
||||
bootstrap: ForkedLightClientBootstrap,
|
||||
wallTime: BeaconTime): Result[void, VerifierError] =
|
||||
let
|
||||
res = withForkyObject(obj):
|
||||
when lcDataFork > LightClientDataFork.None:
|
||||
when forkyObject is ForkyLightClientBootstrap:
|
||||
if self.store[].kind > LightClientDataFork.None:
|
||||
if bootstrap.kind == LightClientDataFork.None:
|
||||
err(VerifierError.Invalid)
|
||||
elif self.store[].kind > LightClientDataFork.None:
|
||||
err(VerifierError.Duplicate)
|
||||
else:
|
||||
let trustedBlockRoot = self.getTrustedBlockRoot()
|
||||
if trustedBlockRoot.isNone:
|
||||
err(VerifierError.MissingParent)
|
||||
else:
|
||||
withForkyBootstrap(bootstrap):
|
||||
when lcDataFork > LightClientDataFork.None:
|
||||
let initRes = initialize_light_client_store(
|
||||
trustedBlockRoot.get, forkyObject, self.cfg)
|
||||
trustedBlockRoot.get, forkyBootstrap, self.cfg)
|
||||
if initRes.isErr:
|
||||
err(initRes.error)
|
||||
else:
|
||||
self.store[] = ForkedLightClientStore.init(initRes.get)
|
||||
ok()
|
||||
elif forkyObject is SomeForkyLightClientUpdate:
|
||||
if self.store[].kind == LightClientDataFork.None:
|
||||
else:
|
||||
raiseAssert "Unreachable; bootstrap.kind was checked"
|
||||
|
||||
proc doProcessObject(
|
||||
self: var LightClientProcessor,
|
||||
update: SomeForkedLightClientUpdate,
|
||||
wallTime: BeaconTime): Result[void, VerifierError] =
|
||||
if update.kind == LightClientDataFork.None:
|
||||
err(VerifierError.Invalid)
|
||||
elif self.store[].kind == LightClientDataFork.None:
|
||||
err(VerifierError.MissingParent)
|
||||
else:
|
||||
withForkyObject(update):
|
||||
when lcDataFork > LightClientDataFork.None:
|
||||
if lcDataFork > self.store[].kind:
|
||||
info "Upgrading light client",
|
||||
oldFork = self.store[].kind, newFork = lcDataFork
|
||||
|
@ -243,13 +253,18 @@ proc processObject(
|
|||
when lcDataFork > LightClientDataFork.None:
|
||||
let
|
||||
wallSlot = wallTime.slotOrZero()
|
||||
upgradedObject = obj.migratingToDataFork(lcDataFork)
|
||||
upgraded = update.migratingToDataFork(lcDataFork)
|
||||
process_light_client_update(
|
||||
forkyStore, upgradedObject.forky(lcDataFork), wallSlot,
|
||||
forkyStore, upgraded.forky(lcDataFork), wallSlot,
|
||||
self.cfg, self.genesis_validators_root)
|
||||
else: raiseAssert "Unreachable"
|
||||
else:
|
||||
err(VerifierError.Invalid)
|
||||
raiseAssert "Unreachable; self.store[].kind was checked"
|
||||
|
||||
proc processObject(
|
||||
self: var LightClientProcessor,
|
||||
obj: SomeForkedLightClientObject,
|
||||
wallTime: BeaconTime): Result[void, VerifierError] =
|
||||
let res = self.doProcessObject(obj, wallTime)
|
||||
|
||||
withForkyObject(obj):
|
||||
when lcDataFork > LightClientDataFork.None:
|
||||
|
@ -270,10 +285,9 @@ proc processObject(
|
|||
of VerifierError.Duplicate:
|
||||
if wallTime >= self.lastDuplicateTick + duplicateRateLimit:
|
||||
if self.numDupsSinceProgress < minForceUpdateDuplicates:
|
||||
let best = forkyStore.best_valid_update.get
|
||||
if (proc(): bool = # Reduce stack size
|
||||
let upgradedObj = obj.migratingToDataFork(lcDataFork)
|
||||
upgradedObj.forky(lcDataFork).matches(best))():
|
||||
if upgradedObj.forky(lcDataFork).matches(
|
||||
forkyStore.best_valid_update.get):
|
||||
self.lastDuplicateTick = wallTime
|
||||
inc self.numDupsSinceProgress
|
||||
if self.numDupsSinceProgress >= minForceUpdateDuplicates and
|
||||
|
|
Loading…
Reference in New Issue