-
Notifications
You must be signed in to change notification settings - Fork 324
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
[blockindex] restrict height for contract_staking_indexer during read operation #3927
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6f3b8fd
add height limit for contract staking indexer
envestcc a5fcd3a
update tests
envestcc 0f88d0e
address comments
envestcc 07e537b
address comments
envestcc f10a948
address comments
envestcc 4ab8f36
address comments
envestcc 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
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 |
---|---|---|
|
@@ -467,6 +467,10 @@ func (p *Protocol) Validate(ctx context.Context, act action.Action, sr protocol. | |
|
||
// ActiveCandidates returns all active candidates in candidate center | ||
func (p *Protocol) ActiveCandidates(ctx context.Context, sr protocol.StateReader, height uint64) (state.CandidateList, error) { | ||
height, err := sr.Height() | ||
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.
|
||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to get StateReader height") | ||
} | ||
c, err := ConstructBaseView(sr) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to get ActiveCandidates") | ||
|
@@ -476,7 +480,14 @@ func (p *Protocol) ActiveCandidates(ctx context.Context, sr protocol.StateReader | |
featureCtx := protocol.MustGetFeatureCtx(ctx) | ||
for i := range list { | ||
if p.contractStakingIndexer != nil && featureCtx.AddContractStakingVotes { | ||
list[i].Votes.Add(list[i].Votes, p.contractStakingIndexer.CandidateVotes(list[i].Owner)) | ||
// specifying the height param instead of query latest from indexer directly, aims to cause error when indexer falls behind | ||
// currently there are two possible sr (i.e. factory or workingSet), it means the height could be chain height or current block height | ||
// using height-1 will cover the two scenario while detect whether the indexer is lagging behind | ||
contractVotes, err := p.contractStakingIndexer.CandidateVotes(list[i].Owner, height-1) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to get CandidateVotes from contractStakingIndexer") | ||
} | ||
list[i].Votes.Add(list[i].Votes, contractVotes) | ||
} | ||
if list[i].SelfStake.Cmp(p.config.RegistrationConsts.MinSelfStake) >= 0 { | ||
cand = append(cand, list[i]) | ||
|
This file contains 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 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
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.
not needed?
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.
yes, forget to revert