Fixed crash caused by findAncestorBySlot (#196)

closes #193
This commit is contained in:
Yuriy Glukhov 2019-03-22 12:57:19 +02:00 committed by Mamy Ratsimbazafy
parent 94c3b005fa
commit 894816fa0c
1 changed files with 4 additions and 1 deletions

View File

@ -23,11 +23,14 @@ proc init*(T: type BlockRef, root: Eth2Digest, blck: BeaconBlock): BlockRef =
proc findAncestorBySlot*(blck: BlockRef, slot: Slot): BlockRef =
## Find the first ancestor that has a slot number less than or equal to `slot`
assert(not blck.isNil)
result = blck
while result != nil and result.slot > slot:
while result.parent != nil and result.slot > slot:
result = result.parent
assert(not result.isNil)
proc init*(T: type BlockPool, db: BeaconChainDB): BlockPool =
# TODO we require that the db contains both a head and a tail block -
# asserting here doesn't seem like the right way to go about it however..