find block by block id

This commit is contained in:
Mark Spanbroek 2024-10-17 16:06:28 +02:00
parent 6a400772cd
commit 96295461ae
2 changed files with 9 additions and 9 deletions

View File

@ -96,14 +96,6 @@ func status*(validator: Validator, blck: Block): ?SlotStatus =
func status*(validator: Validator, proposal: SignedBlock): ?SlotStatus =
validator.status(proposal.blck)
func searchBackwards(round: Round, blockId: BlockId): auto =
if found =? round.find(blockId.round):
let slot = found[blockId.author]
for proposal in slot.proposals:
let blck = proposal.blck
if blck.id == blockId:
return some blck
func updateIndirect(validator: Validator, slot: ProposerSlot, round: Round) =
without anchor =? round.findAnchor():
return
@ -118,7 +110,7 @@ func updateIndirect(validator: Validator, slot: ProposerSlot, round: Round) =
if parent in slotProposal.certificates:
slotProposal.certify(anchorProposal)
return
without parentBlock =? round.searchBackwards(parent):
without parentBlock =? round.find(parent):
discard
todo.add(parentBlock.parents)
slot.skip()

View File

@ -76,6 +76,14 @@ func find*(round: Round, number: uint64): ?Round =
return none Round
current = previous
func find*(round: Round, blockId: BlockId): auto =
if found =? round.find(blockId.round):
let slot = found[blockId.author]
for proposal in slot.proposals:
let blck = proposal.blck
if blck.id == blockId:
return some blck
func findAnchor*(round: Round): auto =
var next = round.find(round.number + 3)
while current =? next: