From 923f09976e51a502b4ec567ce43276e0210b4e0f Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Wed, 30 Oct 2024 11:25:24 +0100 Subject: [PATCH] update certificates for older blocks --- mysticeti/validator.nim | 4 ++- mysticeti/validator/rounds.nim | 7 ------ tests/mysticeti/validator/testMultiple.nim | 29 ++++++++++++++++++++++ tests/mysticeti/validator/testRounds.nim | 16 ------------ 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/mysticeti/validator.nim b/mysticeti/validator.nim index 89a75e0..d4d3b66 100644 --- a/mysticeti/validator.nim +++ b/mysticeti/validator.nim @@ -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 diff --git a/mysticeti/validator/rounds.nim b/mysticeti/validator/rounds.nim index d2675a3..5990b38 100644 --- a/mysticeti/validator/rounds.nim +++ b/mysticeti/validator/rounds.nim @@ -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) diff --git a/tests/mysticeti/validator/testMultiple.nim b/tests/mysticeti/validator/testMultiple.nim index 4395baa..14b7860 100644 --- a/tests/mysticeti/validator/testMultiple.nim +++ b/tests/mysticeti/validator/testMultiple.nim @@ -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) diff --git a/tests/mysticeti/validator/testRounds.nim b/tests/mysticeti/validator/testRounds.nim index 0c3d500..a3696fb 100644 --- a/tests/mysticeti/validator/testRounds.nim +++ b/tests/mysticeti/validator/testRounds.nim @@ -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