Skip to content

Commit

Permalink
add featureCtx for ActiveCandidates
Browse files Browse the repository at this point in the history
  • Loading branch information
envestcc committed Jul 5, 2023
1 parent 715fa61 commit 193d323
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 1 addition & 2 deletions action/protocol/staking/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,10 @@ func (p *Protocol) ActiveCandidates(ctx context.Context, sr protocol.StateReader
if err != nil {
return nil, errors.Wrap(err, "failed to get ActiveCandidates")
}
featureCtx, ok := protocol.GetFeatureCtx(ctx)
list := c.AllCandidates()
cand := make(CandidateList, 0, len(list))
for i := range list {
if ok && p.contractStakingIndexer != nil && featureCtx.AddContractStakingVotes {
if p.contractStakingIndexer != nil && protocol.MustGetFeatureCtx(ctx).AddContractStakingVotes {
list[i].Votes.Add(list[i].Votes, p.contractStakingIndexer.CandidateVotes(list[i].Owner))
}
if list[i].SelfStake.Cmp(p.config.RegistrationConsts.MinSelfStake) >= 0 {
Expand Down
1 change: 0 additions & 1 deletion action/protocol/staking/staking_statereader.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func (c *compositeStakingStateReader) readStateBuckets(ctx context.Context, req
}
// merge native and LSD buckets
buckets.Buckets = append(buckets.Buckets, lsdIoTeXBuckets.Buckets...)

buckets.Buckets = getPageOfArray(buckets.Buckets, int(req.GetPagination().GetOffset()), int(req.GetPagination().GetLimit()))
return buckets, height, err
}
Expand Down
11 changes: 9 additions & 2 deletions chainservice/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/iotexproject/iotex-core/blockchain"
"github.com/iotexproject/iotex-core/blockchain/block"
"github.com/iotexproject/iotex-core/blockchain/blockdao"
"github.com/iotexproject/iotex-core/blockchain/genesis"
"github.com/iotexproject/iotex-core/blockindex"
"github.com/iotexproject/iotex-core/blockindex/contractstaking"
"github.com/iotexproject/iotex-core/blocksync"
Expand Down Expand Up @@ -434,9 +435,15 @@ func (builder *Builder) buildNodeInfoManager() error {
if stk == nil {
return errors.New("cannot find staking protocol")
}

chain := builder.cs.chain
dm := nodeinfo.NewInfoManager(&builder.cfg.NodeInfo, cs.p2pAgent, cs.chain, builder.cfg.Chain.ProducerPrivateKey(), func() []string {
candidates, err := stk.ActiveCandidates(context.Background(), cs.factory, 0)
ctx := protocol.WithFeatureCtx(
protocol.WithBlockCtx(
genesis.WithGenesisContext(context.Background(), chain.Genesis()),
protocol.BlockCtx{BlockHeight: chain.TipHeight()},
),
)
candidates, err := stk.ActiveCandidates(ctx, cs.factory, 0)
if err != nil {
log.L().Error("failed to get active candidates", zap.Error(errors.WithStack(err)))
return nil
Expand Down

0 comments on commit 193d323

Please sign in to comment.