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

[IBFT] Change quorum size calculation #513

Merged
merged 11 commits into from
Apr 27, 2022
Merged

Conversation

dbrajovic
Copy link
Contributor

@dbrajovic dbrajovic commented Apr 21, 2022

Description

This PR replaces the old calculation of finding the minimum number of validators reaching quorum.

N - number of validators in network
F = floor((N-1) / 3) - number of (allowed) faulty nodes in a given network

Previously :

quorum = 2 * F + 1

Now:

quorum = ceil(2/3 * N)

Changes include

  • Bugfix (non-breaking change that solves an issue)
  • Hotfix (change that solves an urgent issue, and requires immediate attention)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (change that is not backwards-compatible and/or changes current functionality)

Checklist

  • I have assigned this PR to myself
  • I have added at least 1 reviewer
  • I have added the relevant labels
  • I have updated the official documentation
  • I have added sufficient documentation in code

Testing

  • I have tested this code with the official test suite
  • I have tested this code manually

Manual tests

Please complete this section if you ran manual tests for this functionality, otherwise delete it

Additional comments

Fixes EDGE-514

The formula (previously used) for calculating the Quorum size, which is 2F + 1 did not scale well with the number of validators in a given network. Note the following differences:

2F + 1:

  • N = 1, F = 0 -> Q = 1
  • N = 2, F = 0 -> Q = 1
  • N = 3, F = 0 -> Q = 1
  • N = 4, F = 1 -> Q = 3
  • N = 5, F = 1 -> Q = 3
  • N = 6, F = 1 -> Q = 3
  • N = 7, F = 2 -> Q = 5
  • N = 8, F = 2 -> Q = 5
  • N = 9, F = 2 -> Q = 5

ceil(2/3 * N):
from table (for N=3 the formula does not apply, so a special if statement was used)

  • N = 1, F = 0 -> Q = 1
  • N = 2, F = 0 -> Q = 2
  • N = 3, F = 0 -> Q = 3
  • N = 4, F = 1 -> Q = 3
  • N = 5, F = 1 -> Q = 4
  • N = 6, F = 1 -> Q = 4
  • N = 7, F = 2 -> Q = 5
  • N = 8, F = 2 -> Q = 6
  • N = 9, F = 2 -> Q = 6

@dbrajovic dbrajovic added the feature New update to Polygon Edge label Apr 21, 2022
@dbrajovic dbrajovic self-assigned this Apr 21, 2022
@Kourin1996
Copy link
Contributor

@dbrajovic Can you write down the reason so that we can look back in the future?

consensus/ibft/state.go Outdated Show resolved Hide resolved
consensus/ibft/state.go Outdated Show resolved Hide resolved
Copy link
Contributor

@zivkovicmilos zivkovicmilos left a comment

Choose a reason for hiding this comment

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

Looks good 💯

I've went through the code and the spec, along with Saltini's paper, the logic seems to be sound.
I don't like that the formula differs for N < 4, but 🤷‍♂️ .

Copy link
Contributor

@Kourin1996 Kourin1996 left a comment

Choose a reason for hiding this comment

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

LGTM!

txpool/txpool.go Outdated Show resolved Hide resolved
@dbrajovic dbrajovic merged commit f91feef into develop Apr 27, 2022
@dbrajovic dbrajovic deleted the fix/ibft-quorum-optimal branch April 27, 2022 17:34
@github-actions github-actions bot locked and limited conversation to collaborators Apr 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New update to Polygon Edge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants