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

core/qbft: only trigger each upon rule once per round #536

Merged
merged 2 commits into from
May 15, 2022

Conversation

leolara
Copy link
Contributor

@leolara leolara commented May 14, 2022

The QBFT paper states that each upon rules should only be triggered once per round (with the exception of uponJustifiedDecided.

The current implementation allows for rules to be triggered multiple times.

Note this isn't such a big problem, since the algorithm is idempotent, the only affect is that more messages are sent over the wire then necessary.

category: refactor
ticket: #523

@CLAassistant
Copy link

CLAassistant commented May 14, 2022

CLA assistant check
All committers have signed the CLA.

@leolara leolara force-pushed the leolara/I523/qbft-only-trigger-upon-rule-once branch 2 times, most recently from 5646511 to 9de3b65 Compare May 14, 2022 18:13
@codecov
Copy link

codecov bot commented May 14, 2022

Codecov Report

Merging #536 (a2a4e47) into main (c793c5c) will decrease coverage by 0.37%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #536      +/-   ##
==========================================
- Coverage   54.90%   54.52%   -0.38%     
==========================================
  Files          91       91              
  Lines        8468     8482      +14     
==========================================
- Hits         4649     4625      -24     
- Misses       3210     3247      +37     
- Partials      609      610       +1     
Impacted Files Coverage Δ
core/qbft/qbft.go 78.16% <100.00%> (-8.55%) ⬇️
app/app.go 64.20% <0.00%> (+0.88%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c793c5c...a2a4e47. Read the comment docs.

@@ -202,6 +203,29 @@ func Run[I any, V comparable](ctx context.Context, d Definition[I, V], t Transpo
dedupIn = dedup
}

isDuplicatedRule := func(rule uponRule) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

please add comments to the functions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}

changeRound := func(newRound int64) {
resetDedupRules()
Copy link
Contributor

Choose a reason for hiding this comment

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

can probably inline resetDedupRules since it is just a single line function, and I would also move trimBuffer here:

// changeRound updates the round and clears state of the previous round
changeRound := func(newRound int64) {
    round = newRound
    dedupRules = make(map[uponRule]bool)
    trimBuffer()
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

return true
}

// first time for this rule
Copy link
Contributor

Choose a reason for hiding this comment

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

nit (also please capitalise comment sentences): // First time for this rule in current round

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -202,6 +203,29 @@ func Run[I any, V comparable](ctx context.Context, d Definition[I, V], t Transpo
dedupIn = dedup
}

isDuplicatedRule := func(rule uponRule) bool {
if rule == uponJustifiedDecided {
Copy link
Contributor

Choose a reason for hiding this comment

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

On second thought, I think it is sending of qCommit that may be triggered multiple times per round, not the receiving of qCommit. Receiving it once is sufficient, since then we have decided and we are done. So I think we must remove this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -155,6 +155,7 @@ func Run[I any, V comparable](ctx context.Context, d Definition[I, V], t Transpo
dedupIn = make(map[dedupKey]bool)
timerChan <-chan time.Time
stopTimer func()
dedupRules = make(map[uponRule]bool)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I would put the two dedup maps next to each other. We could also rename dedupIn to dedupMsgs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@leolara leolara changed the title core/qbft: Only trigger each upon rule once per round core/qbft: only trigger each upon rule once per round May 15, 2022
@leolara leolara force-pushed the leolara/I523/qbft-only-trigger-upon-rule-once branch from 9de3b65 to e62962b Compare May 15, 2022 13:37
@leolara leolara added the merge when ready Indicates bulldozer bot may merge when all checks pass label May 15, 2022
@obol-bulldozer obol-bulldozer bot merged commit 4b27eb2 into main May 15, 2022
@obol-bulldozer obol-bulldozer bot deleted the leolara/I523/qbft-only-trigger-upon-rule-once branch May 15, 2022 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge when ready Indicates bulldozer bot may merge when all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants