Skip to content

Commit f2e77af

Browse files
dustinxieYutong Pei
authored andcommitted
filter candidate list as well before native staking (#1564)
1 parent d673834 commit f2e77af

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

action/protocol/poll/staking_committee.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (sc *stakingCommittee) DelegatesByHeight(height uint64) (state.CandidateLis
107107
// convert to epoch start height
108108
epochHeight := sc.getEpochHeight(sc.getEpochNum(height))
109109
if sc.hu.IsPre(config.Cook, epochHeight) {
110-
return cand, nil
110+
return sc.filterDelegates(cand), nil
111111
}
112112
// native staking starts from Cook
113113
if sc.nativeStaking == nil {
@@ -116,7 +116,7 @@ func (sc *stakingCommittee) DelegatesByHeight(height uint64) (state.CandidateLis
116116
nativeVotes, ts, err := sc.nativeStaking.Votes()
117117
if err == ErrNoData {
118118
// no native staking data
119-
return cand, nil
119+
return sc.filterDelegates(cand), nil
120120
}
121121
if err != nil {
122122
return nil, errors.Wrap(err, "failed to get native chain candidates")
@@ -134,6 +134,17 @@ func (sc *stakingCommittee) SetNativeStakingContract(contract string) {
134134
sc.nativeStaking.SetContract(contract)
135135
}
136136

137+
// return candidates whose votes are above threshold
138+
func (sc *stakingCommittee) filterDelegates(candidates state.CandidateList) state.CandidateList {
139+
var cand state.CandidateList
140+
for _, c := range candidates {
141+
if c.Votes.Cmp(sc.scoreThreshold) >= 0 {
142+
cand = append(cand, c)
143+
}
144+
}
145+
return cand
146+
}
147+
137148
func (sc *stakingCommittee) mergeDelegates(list state.CandidateList, votes *VoteTally, ts time.Time) state.CandidateList {
138149
// as of now, native staking does not have register contract, only voting/staking contract
139150
// it is assumed that all votes done on native staking target for delegates registered on Ethereum

0 commit comments

Comments
 (0)