treat `persistBlocks()` exception as failure return code, unless `Defect` (#1155)
This commit is contained in:
parent
f29cbebb9d
commit
1a5e2e53dd
|
@ -57,17 +57,6 @@ type
|
||||||
trustedPeers: HashSet[Peer]
|
trustedPeers: HashSet[Peer]
|
||||||
hasOutOfOrderBlocks: bool
|
hasOutOfOrderBlocks: bool
|
||||||
|
|
||||||
template catchException(info: string; code: untyped) =
|
|
||||||
try:
|
|
||||||
code
|
|
||||||
except CatchableError as e:
|
|
||||||
raise (ref CatchableError)(msg: e.msg)
|
|
||||||
except Defect as e:
|
|
||||||
raise (ref Defect)(msg: e.msg)
|
|
||||||
except Exception as e:
|
|
||||||
raise newException(
|
|
||||||
BlockchainSyncDefect, info & "(): " & $e.name & " -- " & e.msg)
|
|
||||||
|
|
||||||
proc hash*(p: Peer): Hash = hash(cast[pointer](p))
|
proc hash*(p: Peer): Hash = hash(cast[pointer](p))
|
||||||
|
|
||||||
proc endIndex(b: WantedBlocks): BlockNumber =
|
proc endIndex(b: WantedBlocks): BlockNumber =
|
||||||
|
@ -120,8 +109,19 @@ proc availableWorkItem(ctx: FastSyncCtx): int =
|
||||||
|
|
||||||
proc persistWorkItem(ctx: FastSyncCtx, wi: var WantedBlocks): ValidationResult
|
proc persistWorkItem(ctx: FastSyncCtx, wi: var WantedBlocks): ValidationResult
|
||||||
{.gcsafe, raises:[Defect,CatchableError].} =
|
{.gcsafe, raises:[Defect,CatchableError].} =
|
||||||
catchException("persistBlocks"):
|
try:
|
||||||
result = ctx.chain.persistBlocks(wi.headers, wi.bodies)
|
result = ctx.chain.persistBlocks(wi.headers, wi.bodies)
|
||||||
|
except CatchableError as e:
|
||||||
|
error "storing persistent blocks failed",
|
||||||
|
error = $e.name, msg = e.msg
|
||||||
|
result = ValidationResult.Error
|
||||||
|
except Defect as e:
|
||||||
|
# Pass through
|
||||||
|
raise (ref Defect)(msg: e.msg)
|
||||||
|
except Exception as e:
|
||||||
|
error "exception while storing persistent blocks",
|
||||||
|
error = $e.name, msg = e.msg
|
||||||
|
result = ValidationResult.Error
|
||||||
case result
|
case result
|
||||||
of ValidationResult.OK:
|
of ValidationResult.OK:
|
||||||
ctx.finalizedBlock = wi.endIndex
|
ctx.finalizedBlock = wi.endIndex
|
||||||
|
|
Loading…
Reference in New Issue