Skip to content

Commit

Permalink
filter candidate list as well before native staking (#1564)
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinxie authored and Yutong Pei committed Oct 23, 2019
1 parent d673834 commit f2e77af
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions action/protocol/poll/staking_committee.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (sc *stakingCommittee) DelegatesByHeight(height uint64) (state.CandidateLis
// convert to epoch start height
epochHeight := sc.getEpochHeight(sc.getEpochNum(height))
if sc.hu.IsPre(config.Cook, epochHeight) {
return cand, nil
return sc.filterDelegates(cand), nil
}
// native staking starts from Cook
if sc.nativeStaking == nil {
Expand All @@ -116,7 +116,7 @@ func (sc *stakingCommittee) DelegatesByHeight(height uint64) (state.CandidateLis
nativeVotes, ts, err := sc.nativeStaking.Votes()
if err == ErrNoData {
// no native staking data
return cand, nil
return sc.filterDelegates(cand), nil
}
if err != nil {
return nil, errors.Wrap(err, "failed to get native chain candidates")
Expand All @@ -134,6 +134,17 @@ func (sc *stakingCommittee) SetNativeStakingContract(contract string) {
sc.nativeStaking.SetContract(contract)
}

// return candidates whose votes are above threshold
func (sc *stakingCommittee) filterDelegates(candidates state.CandidateList) state.CandidateList {
var cand state.CandidateList
for _, c := range candidates {
if c.Votes.Cmp(sc.scoreThreshold) >= 0 {
cand = append(cand, c)
}
}
return cand
}

func (sc *stakingCommittee) mergeDelegates(list state.CandidateList, votes *VoteTally, ts time.Time) state.CandidateList {
// as of now, native staking does not have register contract, only voting/staking contract
// it is assumed that all votes done on native staking target for delegates registered on Ethereum
Expand Down

0 comments on commit f2e77af

Please sign in to comment.