Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

NewRoundMessageValidator creates RoundChangeValidator with correct value #518

Merged
merged 4 commits into from
Jan 7, 2019

Conversation

rain-on
Copy link
Contributor

@rain-on rain-on commented Jan 7, 2019

A RoundChangeValidator accepts number of prepare Messages (which is 1 less than quorum).

Previously, NewRoundMessageValidator created a RoundChangeValidator with expected prepare messages set to quorum (which is 1 too large).

@@ -56,7 +56,7 @@ public RoundChangeMessageValidator createRoundChangeMessageValidator(
return new RoundChangeMessageValidator(
roundIdentifier -> createMessageValidator(roundIdentifier, parentHeader),
validators,
IbftHelpers.calculateRequiredValidatorQuorum(validators.size()),
IbftHelpers.calculateRequiredValidatorQuorum(validators.size()) - 1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you want one less than the required quorum of validators? [magic number]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like above, comment would hep explain why this is being done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This calc has been broken out to a helper function which is now used in many places (which is good).
Throughout IBFT, the number of prepare messages is 1 less than the actual 2/3 quorum as the Proposal is deemed to act as a prepare message (thus, there is also a rule that none of the prepare messages may come from the Proposer).

@@ -121,9 +123,11 @@ private boolean validateRoundChangeMessagesAndEnsureTargetRoundMatchesRoot(

for (final SignedData<RoundChangePayload> roundChangeMsg :
roundChangeCert.getRoundChangePayloads()) {
// RoundChangeValidator requires the "requisite Prepare Msg Count" (which is 1 less than
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this comment could be incorporated into a method or constant, negating the need for its existence.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has been moved out to IbftHelpers.prepareMessageCountFromQuorum()

@@ -56,7 +56,7 @@ public RoundChangeMessageValidator createRoundChangeMessageValidator(
return new RoundChangeMessageValidator(
roundIdentifier -> createMessageValidator(roundIdentifier, parentHeader),
validators,
IbftHelpers.calculateRequiredValidatorQuorum(validators.size()),
IbftHelpers.calculateRequiredValidatorQuorum(validators.size()) - 1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like above, comment would hep explain why this is being done

Copy link
Contributor

@CjHare CjHare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some good refactoring there!

@rain-on rain-on merged commit 35f2dfb into PegaSysEng:master Jan 7, 2019
@rain-on rain-on deleted the prepare_quorum branch January 16, 2019 21:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants