From 26234bec9ca3ca4084597939bc9c7bdf2db0edc0 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Tue, 29 Oct 2024 12:35:06 +0100 Subject: [PATCH] refuse proposals with a round number that is too high --- mysticeti/validator.nim | 2 ++ tests/mysticeti/validator/testMultiple.nim | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/mysticeti/validator.nim b/mysticeti/validator.nim index 85a5d8a..c9e6f84 100644 --- a/mysticeti/validator.nim +++ b/mysticeti/validator.nim @@ -89,6 +89,8 @@ func check*(validator: Validator, signed: SignedBlock): auto = return BlockCheck.invalid("block is not signed by a committee member") if member != signed.blck.author: return BlockCheck.invalid("block is not signed by its author") + if signed.blck.round > validator.round: + return BlockCheck.invalid("block has a round number that is too high") for parent in signed.blck.parents: if parent.round >= signed.blck.round: return BlockCheck.invalid("block has a parent from an invalid round") diff --git a/tests/mysticeti/validator/testMultiple.nim b/tests/mysticeti/validator/testMultiple.nim index 9ea8572..b186dcd 100644 --- a/tests/mysticeti/validator/testMultiple.nim +++ b/tests/mysticeti/validator/testMultiple.nim @@ -114,6 +114,7 @@ suite "Multiple Validators": test "refuses proposals without >2/3 parents from the previous round": let parents = exchangeProposals().mapIt(it.blck.id) + nextRound() let blck = Block.new( CommitteeMember(0), round = 1, @@ -142,6 +143,14 @@ suite "Multiple Validators": check checked.verdict == BlockVerdict.incomplete check checked.missing == @[parents[0].blck.id] + test "refuses proposals with a round number that is too high": + discard exchangeProposals() + validators[0].nextRound() + let proposal = validators[0].propose(seq[Transaction].example) + let checked = validators[1].check(proposal) + check checked.verdict == BlockVerdict.invalid + check checked.reason == "block has a round number that is too high" + test "skips blocks that are ignored by >2f validators": # first round: other validators do not receive proposal from first validator let proposals = exchangeProposals {