[clock] Avoid crash when getBlock fails

This commit is contained in:
Mark Spanbroek 2022-05-17 19:49:39 +02:00 committed by markspanbroek
parent 3a8ce485e4
commit 83522e459c
1 changed files with 2 additions and 1 deletions

View File

@ -26,7 +26,8 @@ proc start*(clock: OnChainClock) {.async.} =
let computerTime = getTime().toUnix
clock.offset = blockTime - computerTime
onBlock(!await clock.provider.getBlock(BlockTag.latest))
if latestBlock =? (await clock.provider.getBlock(BlockTag.latest)):
onBlock(latestBlock)
clock.subscription = await clock.provider.subscribe(onBlock)