Skip to content

Commit

Permalink
check from last file
Browse files Browse the repository at this point in the history
  • Loading branch information
advaita-saha committed Sep 17, 2024
1 parent f14c095 commit 8916087
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions nimbus/nimbus_import.nim
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,36 @@ proc importBlocks*(conf: NimbusConf, com: CommonRef) =
era: EraDB,
historical_roots: openArray[Eth2Digest],
historical_summaries: openArray[HistoricalSummary],
endSlot: Slot,
) =
# Checks if the Nimbus block number is ahead the era block number
# First we load the last era number, and get the fist slot number
# Since the slot emptiness cannot be predicted, we iterate over to find the block and check
# if the block number is greater than the current block number
var
lastEra = era(endSlot - 1)
startSlot = start_slot(lastEra) - 8192
debug "Finding slot number to resume import", startSlot, endSlot

while startSlot < endSlot:
let blk = getEthBlockFromEra(
era, historical_roots, historical_summaries, startSlot, clConfig.cfg
).valueOr:
startSlot += 1
if startSlot == endSlot - 1 :
error "No blocks found in the last era file"
quit QuitFailure
else:
continue

startSlot += 1
if blk.header.number < blockNumber:
notice "Avaiable Era Files are already imported",
stateBlockNumber = blockNumber, eraBlockNumber = blk.header.number
quit QuitSuccess
else:
break

if blockNumber > 1:
# Setting the initial lower bound
importedSlot = (blockNumber - lastEra1Block) + firstSlotAfterMerge
Expand All @@ -244,12 +273,6 @@ proc importBlocks*(conf: NimbusConf, com: CommonRef) =
importedSlot += 1
continue

# Checks if the Nimbus block number is ahead the era block number
if blockNumber < blk.header.number:
notice "Avaiable Era Files are already imported",
stateBlockNumber = blockNumber, eraBlockNumber = blk.header.number
quit QuitSuccess

clNum = blk.header.number
# decreasing the lower bound with each iteration
importedSlot += blockNumber - clNum
Expand Down Expand Up @@ -307,7 +330,7 @@ proc importBlocks*(conf: NimbusConf, com: CommonRef) =
# Load the last slot number
if blockNumber > lastEra1Block + 1:
updateLastImportedSlot(
eraDB, historical_roots.asSeq(), historical_summaries.asSeq()
eraDB, historical_roots.asSeq(), historical_summaries.asSeq(), endSlot
)

if importedSlot < firstSlotAfterMerge and firstSlotAfterMerge != 0:
Expand Down

0 comments on commit 8916087

Please sign in to comment.