Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
envestcc committed Jun 6, 2024
1 parent faa09df commit 2acc541
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
10 changes: 4 additions & 6 deletions action/protocol/staking/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,9 @@ func (p *Protocol) ActiveCandidates(ctx context.Context, sr protocol.StateReader
list := c.AllCandidates()
cand := make(CandidateList, 0, len(list))
for i := range list {
csVotes, err := p.contractStakingVotes(ctx, list[i].GetIdentifier(), srHeight)
// specifying the height param instead of query latest from indexer directly, aims to cause error when indexer falls behind.
// the reason of using srHeight-1 is contract indexer is not updated before the block is committed.
csVotes, err := p.contractStakingVotes(ctx, list[i].GetIdentifier(), srHeight-1)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -694,10 +696,7 @@ func (p *Protocol) contractStakingVotes(ctx context.Context, candidate address.A
featureCtx := protocol.MustGetFeatureCtx(ctx)
votes := big.NewInt(0)
if p.contractStakingIndexer != nil && featureCtx.AddContractStakingVotes {
// 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
btks, err := p.contractStakingIndexer.BucketsByCandidate(candidate, height-1)
btks, err := p.contractStakingIndexer.BucketsByCandidate(candidate, height)
if err != nil {
return nil, errors.Wrap(err, "failed to get BucketsByCandidate from contractStakingIndexer")
}
Expand All @@ -710,7 +709,6 @@ func (p *Protocol) contractStakingVotes(ctx context.Context, candidate address.A
} else {
votes.Add(votes, b.StakedAmount)
}

}
}
return votes, nil
Expand Down
4 changes: 2 additions & 2 deletions action/protocol/staking/staking_statereader.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,11 @@ func (c *compositeStakingStateReader) addContractStakingVotes(ctx context.Contex
if err != nil {
return err
}
btks, err := contractStakingSR.BucketsByCandidate(addr, height)
bkts, err := contractStakingSR.BucketsByCandidate(addr, height)
if err != nil {
return errors.Wrap(err, "failed to get BucketsByCandidate from contractStakingIndexerV2")
}
for _, b := range btks {
for _, b := range bkts {
if b.isUnstaked() {
continue
}
Expand Down

0 comments on commit 2acc541

Please sign in to comment.