add workaround for stack overflow on block add

This commit is contained in:
Jacek Sieka 2019-11-27 16:19:41 +01:00 committed by zah
parent d5f20846ad
commit c98a0d28ae
2 changed files with 17 additions and 4 deletions

View File

@ -135,6 +135,8 @@ type
heads*: seq[Head]
inAdd*: bool
MissingBlock* = object
slots*: uint64 # number of slots that are suspected missing
tries*: int

View File

@ -214,10 +214,21 @@ proc addResolvedBlock(
# unresolved blocks magically become resolved
# TODO there are more efficient ways of doing this that don't risk
# running out of stack etc
let retries = pool.pending
for k, v in retries:
discard pool.add(state, k, v)
# TODO This code is convoluted because when there are more than ~1.5k
# blocks being synced, there's a stack overflow as `add` gets called
# for the whole chain of blocks. Instead we use this ugly field in `pool`
# which could be avoided by refactoring the code
if not pool.inAdd:
pool.inAdd = true
defer: pool.inAdd = false
var keepGoing = true
while keepGoing:
let retries = pool.pending
for k, v in retries:
discard pool.add(state, k, v)
# Keep going for as long as the pending pool is shrinking
# TODO inefficient! so what?
keepGoing = pool.pending.len < retries.len
blockRef
proc add*(