From 09f7257bd38d059d7b99f2f7c371c30d1a6d33a2 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Tue, 29 Oct 2024 12:58:22 +0100 Subject: [PATCH] ignore parents that are too old to matter --- mysticeti/validator.nim | 5 +++-- tests/mysticeti/validator/testMultiple.nim | 25 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/mysticeti/validator.nim b/mysticeti/validator.nim index c9e6f84..a27d115 100644 --- a/mysticeti/validator.nim +++ b/mysticeti/validator.nim @@ -109,8 +109,9 @@ func check*(validator: Validator, signed: SignedBlock): auto = ) var missing: seq[BlockId] for parent in signed.blck.parents: - if validator.rounds.latest.find(parent).isNone: - missing.add(parent) + if parent.round >= validator.rounds.oldest.number: + if validator.rounds.latest.find(parent).isNone: + missing.add(parent) if missing.len > 0: return BlockCheck.incomplete(missing) BlockCheck.correct(signed) diff --git a/tests/mysticeti/validator/testMultiple.nim b/tests/mysticeti/validator/testMultiple.nim index b186dcd..c8b3d22 100644 --- a/tests/mysticeti/validator/testMultiple.nim +++ b/tests/mysticeti/validator/testMultiple.nim @@ -143,6 +143,31 @@ suite "Multiple Validators": check checked.verdict == BlockVerdict.incomplete check checked.missing == @[parents[0].blck.id] + test "does not refuse proposals with an unknown parent block that is too old": + # first round: nobody receives proposal from validator 0 + discard exchangeProposals { + 0: @[], + 1: @[0, 1, 2, 3], + 2: @[0, 1, 2, 3], + 3: @[0, 1, 2, 3] + } + # for the second to the sixth round, validator 0 is down + for _ in 2..6: + for validator in validators[1..3]: + validator.nextRound() + discard exchangeProposals { + 1: @[1, 2, 3], + 2: @[1, 2, 3], + 3: @[1, 2, 3] + } + # validator 1 cleans up old blocks + discard toSeq(validators[1].committed()) + # validator 0 comes back online and creates block for second round + validators[0].nextRound() + let proposal = validators[0].propose(seq[Transaction].example) + # validator 1 accepts block even though parent has already been cleaned up + check validators[1].check(proposal).verdict == BlockVerdict.correct + test "refuses proposals with a round number that is too high": discard exchangeProposals() validators[0].nextRound()