Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b72da16

Browse files
committedJul 17, 2024·
correct candidate selfstake in api
1 parent 351a54e commit b72da16

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed
 

‎action/protocol/staking/candidate_statereader.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ func (c *candSR) readStateCandidates(ctx context.Context, req *iotexapi.ReadStak
466466
limit := int(req.GetPagination().GetLimit())
467467
candidates := getPageOfCandidates(c.AllCandidates(), offset, limit)
468468

469-
list, err := toIoTeXTypesCandidateListV2(c, candidates, !protocol.MustGetFeatureCtx(ctx).EnforceLegacyEndorsement)
469+
list, err := toIoTeXTypesCandidateListV2(c, candidates, protocol.MustGetFeatureCtx(ctx))
470470
return list, c.Height(), err
471471
}
472472

@@ -475,7 +475,7 @@ func (c *candSR) readStateCandidateByName(ctx context.Context, req *iotexapi.Rea
475475
if cand == nil {
476476
return &iotextypes.CandidateV2{}, c.Height(), nil
477477
}
478-
list, err := toIoTeXTypesCandidateV2(c, cand, !protocol.MustGetFeatureCtx(ctx).EnforceLegacyEndorsement)
478+
list, err := toIoTeXTypesCandidateV2(c, cand, protocol.MustGetFeatureCtx(ctx))
479479
return list, c.Height(), err
480480
}
481481

@@ -505,7 +505,7 @@ func (c *candSR) readStateCandidateByAddress(ctx context.Context, req *iotexapi.
505505
if cand == nil {
506506
return &iotextypes.CandidateV2{}, c.Height(), nil
507507
}
508-
candV2, err := toIoTeXTypesCandidateV2(c, cand, !protocol.MustGetFeatureCtx(ctx).EnforceLegacyEndorsement)
508+
candV2, err := toIoTeXTypesCandidateV2(c, cand, protocol.MustGetFeatureCtx(ctx))
509509
return candV2, c.Height(), err
510510
}
511511

‎action/protocol/staking/protocol.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ func (p *Protocol) handleStakingIndexer(ctx context.Context, epochStartHeight ui
340340
if err != nil && errors.Cause(err) != state.ErrStateNotExist {
341341
return err
342342
}
343-
candidateList, err := toIoTeXTypesCandidateListV2(csr, all, !protocol.MustGetFeatureCtx(ctx).EnforceLegacyEndorsement)
343+
candidateList, err := toIoTeXTypesCandidateListV2(csr, all, protocol.MustGetFeatureCtx(ctx))
344344
if err != nil {
345345
return err
346346
}

‎action/protocol/staking/read_state.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,10 @@ func getPageOfBuckets(buckets []*VoteBucket, offset, limit int) []*VoteBucket {
6262
return getPageOfArray(buckets, offset, limit)
6363
}
6464

65-
func toIoTeXTypesCandidateV2(csr CandidateStateReader, cand *Candidate, isClean bool) (*iotextypes.CandidateV2, error) {
65+
func toIoTeXTypesCandidateV2(csr CandidateStateReader, cand *Candidate, featureCtx protocol.FeatureCtx) (*iotextypes.CandidateV2, error) {
6666
esr := NewEndorsementStateReader(csr.SR())
6767
height, _ := csr.SR().Height()
6868
needClear := func(c *Candidate) (bool, error) {
69-
if isClean {
70-
return false, nil
71-
}
7269
if !c.isSelfStakeBucketSettled() {
7370
return false, nil
7471
}
@@ -80,16 +77,13 @@ func toIoTeXTypesCandidateV2(csr CandidateStateReader, cand *Candidate, isClean
8077
return false, err
8178
}
8279
if isSelfOwnedBucket(csr, vb) {
83-
return false, nil
80+
return vb.isUnstaked(), nil
8481
}
85-
endorse, err := esr.Get(c.SelfStakeBucketIdx)
82+
status, err := esr.Status(featureCtx, c.SelfStakeBucketIdx, height)
8683
if err != nil {
87-
if errors.Is(err, state.ErrStateNotExist) {
88-
return true, nil
89-
}
9084
return false, err
9185
}
92-
return endorse.LegacyStatus(height) == EndorseExpired, nil
86+
return status == EndorseExpired, nil
9387
}
9488
c := cand.toIoTeXTypes()
9589
// clear self-stake bucket if endorsement is expired but not updated yet
@@ -104,12 +98,12 @@ func toIoTeXTypesCandidateV2(csr CandidateStateReader, cand *Candidate, isClean
10498
return c, nil
10599
}
106100

107-
func toIoTeXTypesCandidateListV2(csr CandidateStateReader, candidates CandidateList, isClean bool) (*iotextypes.CandidateListV2, error) {
101+
func toIoTeXTypesCandidateListV2(csr CandidateStateReader, candidates CandidateList, featureCtx protocol.FeatureCtx) (*iotextypes.CandidateListV2, error) {
108102
res := iotextypes.CandidateListV2{
109103
Candidates: make([]*iotextypes.CandidateV2, 0, len(candidates)),
110104
}
111105
for _, c := range candidates {
112-
cand, err := toIoTeXTypesCandidateV2(csr, c, isClean)
106+
cand, err := toIoTeXTypesCandidateV2(csr, c, featureCtx)
113107
if err != nil {
114108
return nil, err
115109
}

0 commit comments

Comments
 (0)
Please sign in to comment.