Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Consensus logic for Multi-BLS Validators with quorum #4799

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

GheisMohammadi
Copy link
Contributor

@GheisMohammadi GheisMohammadi commented Nov 12, 2024

Issue

This PR improves the consensus logic to handle cases where validators with multiple BLS keys achieve quorum on their initial signatures or commits. Currently, such scenarios can block phase transitions because the condition if !quorumWasMet && quorumIsMet doesn't account for quorum being achieved immediately.

To fix this, a new function, checkFirstReceivedSignature, is introduced. It checks whether quorum is reached on the first batch of signatures or commits. The PR also updates the logic for Prepare and Commit phases to properly handle these edge cases. The PR helps to better handling of multi-BLS key validators while maintaining compatibility with single-key setups.

@GheisMohammadi GheisMohammadi self-assigned this Nov 12, 2024
@GheisMohammadi GheisMohammadi marked this pull request as draft November 12, 2024 15:12
@GheisMohammadi GheisMohammadi changed the title Fix Consensus Quorum Calculation Fix Consensus Quorum Calculation for Multi-BLS Key Validators Nov 12, 2024
@sophoah
Copy link
Contributor

sophoah commented Nov 20, 2024

@GheisMohammadi i am good with that PR. Can you do run the same logic with isFirstReceivedSignature for onPrepare ? and use it here

if consensus.decider.IsQuorumAchieved(quorum.Prepare) {
? It prevent doing the return when the leader node already has quorum on the first onPrepare. Goal is to run didReachPrepareQuorum
if err := consensus.didReachPrepareQuorum(); err != nil {

@GheisMohammadi
Copy link
Contributor Author

@GheisMohammadi i am good with that PR. Can you do run the same logic with isFirstReceivedSignature for onPrepare ? and use it here

if consensus.decider.IsQuorumAchieved(quorum.Prepare) {

? It prevent doing the return when the leader node already has quorum on the first onPrepare. Goal is to run didReachPrepareQuorum

if err := consensus.didReachPrepareQuorum(); err != nil {

done

quorumPreExisting := consensus.decider.IsQuorumAchieved(quorum.Prepare)
//// Read - End

if quorumPreExisting {
// already have enough signatures
consensus.getLogger().Debug().
Interface("validatorPubKeys", recvMsg.SenderPubkeys).
Msg("[OnPrepare] Received Additional Prepare Message")
return
Copy link
Contributor

@sophoah sophoah Nov 20, 2024

Choose a reason for hiding this comment

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

when leader node with multi bls key has quorum, we hit that return code and will never hit consensus.didReachPrepareQuorum()

Copy link
Contributor

Choose a reason for hiding this comment

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

if !isFirstReceivedSignature && quorumPreExisting

first time with quorum we don't return so we can hit consensus.didReachPrepareQuorum(); then subsequently we return

Comment on lines +207 to +211
quorumFromInitialSignature := hasMultiBlsKeys && isFirstReceivedSignature && quorumPreExisting
quorumPostNewSignatures := consensus.decider.IsQuorumAchieved(quorum.Prepare)
quorumFromNewSignatures := !quorumPreExisting && quorumPostNewSignatures

if quorumFromInitialSignature || quorumFromNewSignatures {
Copy link
Contributor

Choose a reason for hiding this comment

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

old code was fine, as we just need consensus.didReachPrepareQuorum() to hit once

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed return. So, it allows adding new signatures in Prepare Phase despite existing quorum. I think this would fix the issue

@sophoah sophoah changed the title Fix Consensus Quorum Calculation for Multi-BLS Key Validators Improve Consensus logic for Multi-BLS Validators with quorum Nov 20, 2024
@sophoah
Copy link
Contributor

sophoah commented Nov 21, 2024

could you add PR description, and is this something we can write unit test (for onPrepare and onCommit) here as well ?

@sophoah
Copy link
Contributor

sophoah commented Nov 22, 2024

@Frozen please review/approve

@sophoah sophoah requested a review from Frozen November 22, 2024 06:51
@sophoah
Copy link
Contributor

sophoah commented Nov 22, 2024

@GheisMohammadi please update PR description

@sophoah sophoah mentioned this pull request Nov 22, 2024
@GheisMohammadi
Copy link
Contributor Author

@GheisMohammadi please update PR description

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants