-
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
Clean up candidates #3696
Clean up candidates #3696
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3696 +/- ##
==========================================
- Coverage 74.47% 73.73% -0.74%
==========================================
Files 269 276 +7
Lines 23925 24187 +262
==========================================
+ Hits 17818 17835 +17
- Misses 5174 5444 +270
+ Partials 933 908 -25
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
@@ -56,7 +56,7 @@ type ( | |||
Upsert(*Candidate) error | |||
CreditBucketPool(*big.Int) error | |||
DebitBucketPool(*big.Int, bool) error | |||
Commit() error | |||
Commit(bool) error |
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.
this fix should only happen one-time at the HF height, why need to add it as an extra input
func (vr *VoteReviser) storeToCache(height uint64, cands CandidateList) { | ||
vr.cache[height] = cands | ||
func (vr *VoteReviser) storeToCache(height uint64, dirty, cands CandidateList) { | ||
vr.cache[height] = [2]CandidateList{dirty, cands} |
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.
cache should only contain the correct candidates after revise, we should be able to do the fix w/o modifying these low-level implementations
return err | ||
} | ||
log.L().Info("committed revise action", | ||
zap.String("name", cand.Name), zap.String("votes", cand.Votes.String())) |
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.
we should be able to do the fix w/o modifying these low-level implementations
@@ -440,14 +444,20 @@ func (cb *candBase) all() CandidateList { | |||
return list | |||
} | |||
|
|||
func (cb *candBase) commit(change *candChange) (int, error) { | |||
func (cb *candBase) commit(change *candChange, keepAliasBug bool) (int, error) { |
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.
if we could have the flag in the candBase
, then I think it's inefficient to pass it down every time
@@ -17,7 +17,8 @@ import ( | |||
type ( | |||
// candChange captures the change to candidates | |||
candChange struct { | |||
dirty map[string]*Candidate | |||
candidates []*Candidate | |||
dirty map[string]*Candidate |
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.
we should be able to do the fix w/o modifying these low-level implementations
dirty = append(dirty, c) | ||
} | ||
for _, c := range csm.DirtyView().candCenter.base.operatorMap { | ||
dirty = append(dirty, c) |
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.
reviser should not bother/deal with candCenter.base.operatorMap
return nil | ||
} | ||
|
||
// LegacyCommit writes the change into base with legacy logic |
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.
It is cleaner than the bool argument.
ownerMap[addr] = owner | ||
} | ||
for _, c := range cands { | ||
if owner, ok := ownerMap[c.Owner.String()]; ok { |
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.
if owner, ok := csm.DirtyView().candCenter.base.ownerMap[c.Owner.String()]; ok {}
Discussed offline. The idea of this pr is easier to understand |
} | ||
for _, c := range csm.DirtyView().candCenter.base.operatorMap { | ||
retval = append(retval, c) | ||
} |
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.
we should not use name/operatorMap
here? don't quite understand the code.
here's my understanding of the intended logic per our discussion during v1.8.4 fix:
input cands
is the list of candidates (with vote correctly revised) in the statedb, as done in v1.8.4 fix, we saved the list of candidates that have been called CandidateRegister/Update
actions during the affected period, these are candidates that can potentially have an alias in the candidate center
_, _, owners := readCandCenterStateFromStateDB()
so on top of cands
, update the name/operator/reward of owners
, that is what we need to do
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.
another comment is that VoteReviser
logic is clean, it just reads candidates/buckets from statedb, and tally votes again.
now it needs to deal with csm.DirtyView().candCenter.xxx
, this adds unnecessary code dependency/coupling
in other words, VoteReviser
is designed to work w/o knowing the existence of candCenter
, then it should be kept that way
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.
name, operator, owners, err := readCandCenterStateFromStateDB(sr, height) |
csm.DirtyView().candCenter.base.recordOwner(c) |
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, ideally we should not use csm.DirtyView().candCenter.xxx
in protocol.go
and handlers.go
so we should not expand it into vote_reviser.go
if possible
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.
name, operator, owners, err := readCandCenterStateFromStateDB(sr, height)
, will NOT be called at next HF height
even if it's read, seems owners
is not used in this PR
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Fixes #(issue)
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Test Configuration:
Checklist: