-
Notifications
You must be signed in to change notification settings - Fork 101
consensus/istanbul: Deduplicate ValSet logic in consensus #722
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
Open
tnasu
wants to merge
6
commits into
kaiachain:dev
Choose a base branch
from
tnasu:dev-consensus-refactor
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b273293
consensus/istanbul: Remove Backend.GetPropser
tnasu d9c3d53
consensus/istanbul: Remove Backend.GetCommitteeState and change to pr…
tnasu a6de335
consensus/istanbul: Remove Backend.GetValidatorSet|GetCommitteeStateB…
tnasu 098c23b
consensus/istanbul: Extract committeeStateProvider feature
tnasu ba9eaea
consensus/istanbul: Set the provider to the core
tnasu a955240
(fixup) formatted goimports
tnasu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ import ( | |
| "github.com/kaiachain/kaia/blockchain/types" | ||
| "github.com/kaiachain/kaia/common" | ||
| "github.com/kaiachain/kaia/common/prque" | ||
| "github.com/kaiachain/kaia/consensus" | ||
| "github.com/kaiachain/kaia/consensus/istanbul" | ||
| "github.com/kaiachain/kaia/event" | ||
| "github.com/kaiachain/kaia/log" | ||
|
|
@@ -111,6 +112,9 @@ type core struct { | |
|
|
||
| councilSizeGauge metrics.Gauge | ||
| committeeSizeGauge metrics.Gauge | ||
|
|
||
| // Committee state provider | ||
| committeeStateProvider consensus.CommitteeStateProviderInterface | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On second thought, i think it would be better to inject the valset and the govModule. What do you think? |
||
| } | ||
|
|
||
| func (c *core) finalizeMessage(msg *message) ([]byte, error) { | ||
|
|
@@ -266,7 +270,12 @@ func (c *core) startNewRound(round *big.Int) { | |
| } | ||
| } | ||
|
|
||
| c.currentCommittee, err = c.backend.GetCommitteeStateByRound(newView.Sequence.Uint64(), round.Uint64()) | ||
| // Get committee state using committee state provider | ||
| if c.committeeStateProvider == nil { | ||
| logger.Error("Committee state provider is not set") | ||
| return | ||
| } | ||
| c.currentCommittee, err = c.committeeStateProvider.GetCommitteeStateByRound(newView.Sequence.Uint64(), round.Uint64()) | ||
| if err != nil { | ||
| logger.Error("Failed to get current round's committee state", "err", err) | ||
| return | ||
|
|
@@ -321,11 +330,16 @@ func (c *core) catchUpRound(view *istanbul.View) { | |
| c.updateRoundState(view, c.currentCommittee, true) | ||
| c.roundChangeSet.Clear(view.Round) | ||
|
|
||
| newProposer, err := c.backend.GetProposerByRound(view.Sequence.Uint64(), view.Round.Uint64()) | ||
| if err != nil { | ||
| logger.Warn("Failed to get proposer by round", "err", err) | ||
| // The newProposer is only for logging purpose, so we don't need to return here. | ||
| // If there's error, it'll be handled in the `startNewRound` anyway. | ||
| // Get proposer using committee state provider | ||
| var newProposer common.Address | ||
| var err error | ||
| if c.committeeStateProvider != nil { | ||
| newProposer, err = c.committeeStateProvider.GetProposerByRound(view.Sequence.Uint64(), view.Round.Uint64()) | ||
| if err != nil { | ||
| logger.Warn("Failed to get proposer by round", "err", err) | ||
| // The newProposer is only for logging purpose, so we don't need to return here. | ||
| // If there's error, it'll be handled in the `startNewRound` anyway. | ||
| } | ||
| } | ||
|
|
||
| c.newRoundChangeTimer() | ||
|
|
@@ -437,6 +451,11 @@ func (c *core) checkValidatorSignature(data []byte, sig []byte) (common.Address, | |
| return c.currentCommittee.CheckValidatorSignature(data, sig) | ||
| } | ||
|
|
||
| // SetCommitteeStateProvider sets the committee state provider for the core | ||
| func (c *core) SetCommitteeStateProvider(provider consensus.CommitteeStateProviderInterface) { | ||
| c.committeeStateProvider = provider | ||
| } | ||
|
|
||
| // PrepareCommittedSeal returns a committed seal for the given hash | ||
| func PrepareCommittedSeal(hash common.Hash) []byte { | ||
| var buf bytes.Buffer | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How's about adding
getQualifiedValidatorsat kaiax/valset module interface?