update certificates for older blocks

This commit is contained in:
Mark Spanbroek 2024-10-30 11:25:24 +01:00
parent 432692f472
commit 923f09976e
4 changed files with 32 additions and 24 deletions

View File

@ -53,7 +53,9 @@ func updateSkipped(validator: Validator, supporter: Block) =
slot.skipBy(stake)
func updateCertified(validator: Validator, certificate: Block) =
without (proposing, voting, _) =? validator.rounds.wave:
without certifying =? validator.rounds.latest.find(certificate.round) and
voting =? certifying.previous and
proposing =? voting.previous:
return
for proposal in proposing.proposals:
var support: Stake

View File

@ -16,13 +16,6 @@ func oldest*(rounds: Rounds): auto =
func latest*(rounds: Rounds): auto =
rounds.latest
func wave*(rounds: Rounds): auto =
# A wave consists of 3 rounds: proposing -> voting -> certifying
let certifying = rounds.latest
if voting =? certifying.previous:
if proposing =? voting.previous:
return some (proposing, voting, certifying)
func addNewRound*(rounds: var Rounds) =
rounds.latest = Round[Rounds.Signing, Rounds.Hashing].new(rounds.latest)

View File

@ -258,6 +258,35 @@ suite "Multiple Validators":
validators[0].receive(validators[0].check(certificates[2]).blck)
check validators[0].status(round, author) == some SlotStatus.commit
test "commits blocks that are certified by blocks that are received later":
# first round: proposing
let proposals = exchangeProposals()
# second round: first validator does not receive votes
nextRound()
discard exchangeProposals {
1: @[1, 2, 3],
2: @[1, 2, 3],
3: @[1, 2, 3]
}
# third round: first validator does not receive certificates
nextRound()
discard exchangeProposals {
1: @[1, 2, 3],
2: @[1, 2, 3],
3: @[1, 2, 3]
}
# fourth round: first validator receives votes and certificates, because
# they are the parents of the blocks from this round
nextRound()
discard exchangeProposals {
1: @[0, 1, 2, 3],
2: @[0, 1, 2, 3],
3: @[0, 1, 2, 3]
}
let round = proposals[0].blck.round
let author = proposals[0].blck.author
check validators[0].status(round, author) == some SlotStatus.commit
test "can iterate over the list of committed blocks":
# blocks proposed in first round, in order of committee members
let first = exchangeProposals().mapIt(it.blck)

View File

@ -51,19 +51,3 @@ suite "List of Validator Rounds":
rounds.removeOldestRound()
expect Defect:
rounds.removeOldestRound()
test "a wave consists of the last three rounds":
var rounds = Rounds.init(slots = 4)
rounds.addNewRound()
check rounds.wave.isNone
rounds.addNewRound()
var wave: (Round, Round, Round)
wave = !rounds.wave()
check wave[0].number == 0
check wave[1].number == 1
check wave[2].number == 2
rounds.addNewRound()
wave = !rounds.wave()
check wave[0].number == 1
check wave[1].number == 2
check wave[2].number == 3