From d3a3670c2f3b91796fe220fdae2f021e20e56fdd Mon Sep 17 00:00:00 2001 From: envestcc Date: Wed, 7 Jun 2023 22:31:34 +0800 Subject: [PATCH 1/6] make contractstakingindexer nullable --- action/protocol/staking/handlers_test.go | 4 +- action/protocol/staking/protocol.go | 2 +- action/protocol/staking/protocol_test.go | 8 +-- .../protocol/staking/staking_statereader.go | 51 +++++++++++++++++-- action/protocol/staking/validations_test.go | 2 +- action/protocol/staking/vote_reviser_test.go | 2 +- chainservice/builder.go | 2 +- 7 files changed, 56 insertions(+), 15 deletions(-) diff --git a/action/protocol/staking/handlers_test.go b/action/protocol/staking/handlers_test.go index 272a8bc3cd..40b194b1ee 100644 --- a/action/protocol/staking/handlers_test.go +++ b/action/protocol/staking/handlers_test.go @@ -84,7 +84,7 @@ func TestProtocol_HandleCreateStake(t *testing.T) { p, err := NewProtocol(depositGas, &BuilderConfig{ Staking: genesis.Default.Staking, PersistStakingPatchBlock: math.MaxUint64, - }, nil, &emptyContractStakingIndexer{}, genesis.Default.GreenlandBlockHeight) + }, nil, nil, genesis.Default.GreenlandBlockHeight) require.NoError(err) // set up candidate @@ -2680,7 +2680,7 @@ func initAll(t *testing.T, ctrl *gomock.Controller) (protocol.StateManager, *Pro p, err := NewProtocol(depositGas, &BuilderConfig{ Staking: genesis.Default.Staking, PersistStakingPatchBlock: math.MaxUint64, - }, nil, &emptyContractStakingIndexer{}, genesis.Default.GreenlandBlockHeight) + }, nil, nil, genesis.Default.GreenlandBlockHeight) require.NoError(err) // set up candidate diff --git a/action/protocol/staking/protocol.go b/action/protocol/staking/protocol.go index 772fdf8857..df7b112513 100644 --- a/action/protocol/staking/protocol.go +++ b/action/protocol/staking/protocol.go @@ -475,7 +475,7 @@ func (p *Protocol) ActiveCandidates(ctx context.Context, sr protocol.StateReader list := c.AllCandidates() cand := make(CandidateList, 0, len(list)) for i := range list { - if ok && featureCtx.AddContractStakingVotes { + if p.contractStakingIndexer != nil && ok && featureCtx.AddContractStakingVotes { list[i].Votes.Add(list[i].Votes, p.contractStakingIndexer.CandidateVotes(list[i].Owner)) } if list[i].SelfStake.Cmp(p.config.RegistrationConsts.MinSelfStake) >= 0 { diff --git a/action/protocol/staking/protocol_test.go b/action/protocol/staking/protocol_test.go index 43cf1ed5f8..1167bce3a3 100644 --- a/action/protocol/staking/protocol_test.go +++ b/action/protocol/staking/protocol_test.go @@ -89,7 +89,7 @@ func TestProtocol(t *testing.T) { stk, err := NewProtocol(nil, &BuilderConfig{ Staking: genesis.Default.Staking, PersistStakingPatchBlock: math.MaxUint64, - }, nil, &emptyContractStakingIndexer{}, genesis.Default.GreenlandBlockHeight) + }, nil, nil, genesis.Default.GreenlandBlockHeight) r.NotNil(stk) r.NoError(err) buckets, _, err := csr.getAllBuckets() @@ -199,7 +199,7 @@ func TestCreatePreStates(t *testing.T) { p, err := NewProtocol(nil, &BuilderConfig{ Staking: genesis.Default.Staking, PersistStakingPatchBlock: math.MaxUint64, - }, nil, &emptyContractStakingIndexer{}, genesis.Default.GreenlandBlockHeight, genesis.Default.GreenlandBlockHeight) + }, nil, nil, genesis.Default.GreenlandBlockHeight, genesis.Default.GreenlandBlockHeight) require.NoError(err) ctx := protocol.WithBlockCtx( genesis.WithGenesisContext(context.Background(), genesis.Default), @@ -262,7 +262,7 @@ func Test_CreatePreStatesWithRegisterProtocol(t *testing.T) { p, err := NewProtocol(nil, &BuilderConfig{ Staking: genesis.Default.Staking, PersistStakingPatchBlock: math.MaxUint64, - }, cbi, &emptyContractStakingIndexer{}, genesis.Default.GreenlandBlockHeight, genesis.Default.GreenlandBlockHeight) + }, cbi, nil, genesis.Default.GreenlandBlockHeight, genesis.Default.GreenlandBlockHeight) require.NoError(err) rol := rolldpos.NewProtocol(23, 4, 3) @@ -378,7 +378,7 @@ func Test_CreateGenesisStates(t *testing.T) { p, err := NewProtocol(nil, &BuilderConfig{ Staking: cfg, PersistStakingPatchBlock: math.MaxUint64, - }, nil, &emptyContractStakingIndexer{}, genesis.Default.GreenlandBlockHeight) + }, nil, nil, genesis.Default.GreenlandBlockHeight) require.NoError(err) v, err := p.Start(ctx, sm) diff --git a/action/protocol/staking/staking_statereader.go b/action/protocol/staking/staking_statereader.go index e60dbcd003..37a604bfdc 100644 --- a/action/protocol/staking/staking_statereader.go +++ b/action/protocol/staking/staking_statereader.go @@ -66,6 +66,12 @@ func (c *compositeStakingStateReader) readStateBuckets(ctx context.Context, req return nil, 0, err } } + + if !c.isContractStakingEnabled() { + buckets.Buckets = getPageOfArray(buckets.Buckets, int(req.GetPagination().GetOffset()), int(req.GetPagination().GetLimit())) + return buckets, height, nil + } + // read LSD buckets lsdBuckets, err := c.contractIndexer.Buckets() if err != nil { @@ -75,9 +81,9 @@ func (c *compositeStakingStateReader) readStateBuckets(ctx context.Context, req if err != nil { return nil, 0, err } - // 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 } @@ -88,6 +94,10 @@ func (c *compositeStakingStateReader) readStateBucketsByVoter(ctx context.Contex if err != nil { return nil, 0, err } + if !c.isContractStakingEnabled() { + buckets.Buckets = getPageOfArray(buckets.Buckets, int(req.GetPagination().GetOffset()), int(req.GetPagination().GetLimit())) + return buckets, height, err + } // read LSD buckets lsdBuckets, err := c.contractIndexer.Buckets() @@ -99,9 +109,9 @@ func (c *compositeStakingStateReader) readStateBucketsByVoter(ctx context.Contex if err != nil { return nil, 0, err } - // 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 } @@ -112,6 +122,12 @@ func (c *compositeStakingStateReader) readStateBucketsByCandidate(ctx context.Co if err != nil { return nil, 0, err } + + if !c.isContractStakingEnabled() { + buckets.Buckets = getPageOfArray(buckets.Buckets, int(req.GetPagination().GetOffset()), int(req.GetPagination().GetLimit())) + return buckets, height, err + } + // read LSD buckets candidate := c.nativeSR.GetCandidateByName(req.GetCandName()) if candidate == nil { @@ -127,6 +143,7 @@ func (c *compositeStakingStateReader) readStateBucketsByCandidate(ctx context.Co } // 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 } @@ -137,6 +154,10 @@ func (c *compositeStakingStateReader) readStateBucketByIndices(ctx context.Conte if err != nil { return nil, 0, err } + if !c.isContractStakingEnabled() { + return buckets, height, nil + } + // read LSD buckets lsdBuckets, err := c.contractIndexer.BucketsByIndices(req.GetIndex()) if err != nil { @@ -148,6 +169,7 @@ func (c *compositeStakingStateReader) readStateBucketByIndices(ctx context.Conte } // merge native and LSD buckets buckets.Buckets = append(buckets.Buckets, lsbIoTeXBuckets.Buckets...) + return buckets, height, nil } @@ -156,6 +178,9 @@ func (c *compositeStakingStateReader) readStateBucketCount(ctx context.Context, if err != nil { return nil, 0, err } + if !c.isContractStakingEnabled() { + return bucketCnt, height, nil + } buckets, err := c.contractIndexer.Buckets() if err != nil { return nil, 0, err @@ -192,11 +217,12 @@ func (c *compositeStakingStateReader) readStateCandidates(ctx context.Context, r return nil, 0, err } } - if !protocol.MustGetFeatureCtx(ctx).AddContractStakingVotes { return candidates, height, nil } - + if !c.isContractStakingEnabled() { + return candidates, height, nil + } for _, candidate := range candidates.Candidates { if err = addContractStakingVotes(candidate, c.contractIndexer); err != nil { return nil, 0, err @@ -210,6 +236,9 @@ func (c *compositeStakingStateReader) readStateCandidateByName(ctx context.Conte if err != nil { return nil, 0, err } + if !c.isContractStakingEnabled() { + return candidate, height, nil + } if !protocol.MustGetFeatureCtx(ctx).AddContractStakingVotes { return candidate, height, nil } @@ -224,6 +253,9 @@ func (c *compositeStakingStateReader) readStateCandidateByAddress(ctx context.Co if err != nil { return nil, 0, err } + if !c.isContractStakingEnabled() { + return candidate, height, nil + } if !protocol.MustGetFeatureCtx(ctx).AddContractStakingVotes { return candidate, height, nil } @@ -243,7 +275,9 @@ func (c *compositeStakingStateReader) readStateTotalStakingAmount(ctx context.Co if !ok { return nil, 0, errors.Errorf("invalid balance %s", accountMeta.Balance) } - + if !c.isContractStakingEnabled() { + return accountMeta, height, nil + } // add contract staking amount buckets, err := c.contractIndexer.Buckets() if err != nil { @@ -258,6 +292,9 @@ func (c *compositeStakingStateReader) readStateTotalStakingAmount(ctx context.Co } func (c *compositeStakingStateReader) readStateContractStakingBucketTypes(ctx context.Context, _ *iotexapi.ReadStakingDataRequest_ContractStakingBucketTypes) (*iotextypes.ContractStakingBucketTypeList, uint64, error) { + if !c.isContractStakingEnabled() { + return &iotextypes.ContractStakingBucketTypeList{}, c.nativeSR.Height(), nil + } bts, err := c.contractIndexer.BucketTypes() if err != nil { return nil, 0, err @@ -272,6 +309,10 @@ func (c *compositeStakingStateReader) readStateContractStakingBucketTypes(ctx co return &iotextypes.ContractStakingBucketTypeList{BucketTypes: pbBts}, c.nativeSR.Height(), nil } +func (c *compositeStakingStateReader) isContractStakingEnabled() bool { + return c.contractIndexer != nil +} + func addContractStakingVotes(candidate *iotextypes.CandidateV2, contractStakingSR ContractStakingIndexer) error { votes, ok := big.NewInt(0).SetString(candidate.TotalWeightedVotes, 10) if !ok { diff --git a/action/protocol/staking/validations_test.go b/action/protocol/staking/validations_test.go index 32c2660966..4dfef6498e 100644 --- a/action/protocol/staking/validations_test.go +++ b/action/protocol/staking/validations_test.go @@ -21,7 +21,7 @@ func initTestProtocol(t *testing.T) (*Protocol, []*Candidate) { p, err := NewProtocol(nil, &BuilderConfig{ Staking: genesis.Default.Staking, PersistStakingPatchBlock: math.MaxUint64, - }, nil, &emptyContractStakingIndexer{}, genesis.Default.GreenlandBlockHeight) + }, nil, nil, genesis.Default.GreenlandBlockHeight) require.NoError(err) var cans []*Candidate diff --git a/action/protocol/staking/vote_reviser_test.go b/action/protocol/staking/vote_reviser_test.go index 7931e47249..b6691c8bec 100644 --- a/action/protocol/staking/vote_reviser_test.go +++ b/action/protocol/staking/vote_reviser_test.go @@ -121,7 +121,7 @@ func TestVoteReviser(t *testing.T) { PersistStakingPatchBlock: math.MaxUint64, }, nil, - &emptyContractStakingIndexer{}, + nil, genesis.Default.OkhotskBlockHeight, genesis.Default.HawaiiBlockHeight, genesis.Default.GreenlandBlockHeight, diff --git a/chainservice/builder.go b/chainservice/builder.go index a07d645728..0ace5953f6 100644 --- a/chainservice/builder.go +++ b/chainservice/builder.go @@ -302,7 +302,7 @@ func (builder *Builder) buildContractStakingIndexer(forTest bool) error { return nil } if forTest || builder.cfg.Genesis.SystemStakingContractAddress == "" { - builder.cs.contractStakingIndexer = contractstaking.NewDummyContractStakingIndexer() + builder.cs.contractStakingIndexer = nil return nil } dbConfig := builder.cfg.DB From 54fc8713d2062f6598c7e9ccf8a49edd0c7544dc Mon Sep 17 00:00:00 2001 From: envestcc Date: Wed, 7 Jun 2023 22:44:10 +0800 Subject: [PATCH 2/6] remove unused code --- .../protocol/staking/contractstake_indexer.go | 34 -------- blockindex/contractstaking/dummy_indexer.go | 86 ------------------- 2 files changed, 120 deletions(-) delete mode 100644 blockindex/contractstaking/dummy_indexer.go diff --git a/action/protocol/staking/contractstake_indexer.go b/action/protocol/staking/contractstake_indexer.go index a1cb639d23..6278e5dd0a 100644 --- a/action/protocol/staking/contractstake_indexer.go +++ b/action/protocol/staking/contractstake_indexer.go @@ -29,38 +29,4 @@ type ( // BucketTypes returns the active bucket types BucketTypes() ([]*ContractStakingBucketType, error) } - - // TODO (iip-13): remove this empty contract staking indexer - emptyContractStakingIndexer struct{} ) - -var _ ContractStakingIndexer = (*emptyContractStakingIndexer)(nil) - -// NewEmptyContractStakingIndexer creates an empty contract staking indexer -func NewEmptyContractStakingIndexer() ContractStakingIndexer { - return &emptyContractStakingIndexer{} -} - -func (f *emptyContractStakingIndexer) CandidateVotes(ownerAddr address.Address) *big.Int { - return big.NewInt(0) -} - -func (f *emptyContractStakingIndexer) Buckets() ([]*VoteBucket, error) { - return nil, nil -} - -func (f *emptyContractStakingIndexer) BucketsByIndices([]uint64) ([]*VoteBucket, error) { - return nil, nil -} - -func (f *emptyContractStakingIndexer) TotalBucketCount() uint64 { - return 0 -} - -func (f *emptyContractStakingIndexer) BucketTypes() ([]*ContractStakingBucketType, error) { - return nil, nil -} - -func (f *emptyContractStakingIndexer) BucketsByCandidate(ownerAddr address.Address) ([]*VoteBucket, error) { - return nil, nil -} diff --git a/blockindex/contractstaking/dummy_indexer.go b/blockindex/contractstaking/dummy_indexer.go deleted file mode 100644 index 79a26c1dd7..0000000000 --- a/blockindex/contractstaking/dummy_indexer.go +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (c) 2023 IoTeX Foundation -// This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability -// or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed. -// This source code is governed by Apache License 2.0 that can be found in the LICENSE file. - -package contractstaking - -import ( - "context" - "math/big" - - "github.com/iotexproject/iotex-address/address" - - "github.com/iotexproject/iotex-core/action/protocol/staking" - "github.com/iotexproject/iotex-core/blockchain/block" -) - -type ( - // dummyContractStakingIndexer is a empty contract staking indexer - dummyContractStakingIndexer struct{} -) - -// NewDummyContractStakingIndexer creates an empty contract staking indexer -func NewDummyContractStakingIndexer() ContractIndexer { - return &dummyContractStakingIndexer{} -} - -// Start starts the indexer -func (d *dummyContractStakingIndexer) Start(ctx context.Context) error { - return nil -} - -// Stop stops the indexer -func (d *dummyContractStakingIndexer) Stop(ctx context.Context) error { - return nil -} - -// StartHeight returns the start height of the indexer -func (d *dummyContractStakingIndexer) StartHeight() uint64 { - return 0 -} - -// Height returns the height of the indexer -func (d *dummyContractStakingIndexer) Height() (uint64, error) { - return 0, nil -} - -// PutBlock puts a block into the indexer -func (d *dummyContractStakingIndexer) PutBlock(ctx context.Context, blk *block.Block) error { - return nil -} - -// DeleteTipBlock deletes the tip block from the indexer -func (d *dummyContractStakingIndexer) DeleteTipBlock(context.Context, *block.Block) error { - return nil -} - -// CandidateVotes returns the total staked votes of a candidate -func (d *dummyContractStakingIndexer) CandidateVotes(ownerAddr address.Address) *big.Int { - return big.NewInt(0) -} - -// Buckets returns active buckets -func (d *dummyContractStakingIndexer) Buckets() ([]*staking.VoteBucket, error) { - return nil, nil -} - -// BucketsByIndices returns active buckets by indices -func (d *dummyContractStakingIndexer) BucketsByIndices([]uint64) ([]*staking.VoteBucket, error) { - return nil, nil -} - -// TotalBucketCount returns the total number of buckets including burned buckets -func (d *dummyContractStakingIndexer) TotalBucketCount() uint64 { - return 0 -} - -// BucketTypes returns the active bucket types -func (d *dummyContractStakingIndexer) BucketTypes() ([]*staking.ContractStakingBucketType, error) { - return nil, nil -} - -// BucketsByCandidate returns active buckets by candidate -func (d *dummyContractStakingIndexer) BucketsByCandidate(ownerAddr address.Address) ([]*staking.VoteBucket, error) { - return nil, nil -} From d31803926d5a254c19efc7addfc2273bec8d03b0 Mon Sep 17 00:00:00 2001 From: envestcc Date: Wed, 7 Jun 2023 22:49:40 +0800 Subject: [PATCH 3/6] remove unnecessary interface --- blockindex/contractstaking/indexer.go | 20 -------------------- chainservice/chainservice.go | 2 +- 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/blockindex/contractstaking/indexer.go b/blockindex/contractstaking/indexer.go index 82e9255824..5adcf8a386 100644 --- a/blockindex/contractstaking/indexer.go +++ b/blockindex/contractstaking/indexer.go @@ -15,7 +15,6 @@ import ( "github.com/pkg/errors" "github.com/iotexproject/iotex-core/blockchain/block" - "github.com/iotexproject/iotex-core/blockchain/blockdao" "github.com/iotexproject/iotex-core/db" "github.com/iotexproject/iotex-core/pkg/util/byteutil" ) @@ -25,25 +24,6 @@ const ( ) type ( - // ContractIndexer defines the interface of contract staking reader - ContractIndexer interface { - blockdao.BlockIndexerWithStart - - // CandidateVotes returns the total staked votes of a candidate - // candidate identified by owner address - CandidateVotes(ownerAddr address.Address) *big.Int - // Buckets returns active buckets - Buckets() ([]*Bucket, error) - // BucketsByIndices returns active buckets by indices - BucketsByIndices([]uint64) ([]*Bucket, error) - // BucketsByCandidate returns active buckets by candidate - BucketsByCandidate(ownerAddr address.Address) ([]*Bucket, error) - // TotalBucketCount returns the total number of buckets including burned buckets - TotalBucketCount() uint64 - // BucketTypes returns the active bucket types - BucketTypes() ([]*BucketType, error) - } - // Indexer is the contract staking indexer // Main functions: // 1. handle contract staking contract events when new block comes to generate index data diff --git a/chainservice/chainservice.go b/chainservice/chainservice.go index 2231943a8f..941ea043c2 100644 --- a/chainservice/chainservice.go +++ b/chainservice/chainservice.go @@ -87,7 +87,7 @@ type ChainService struct { candidateIndexer *poll.CandidateIndexer candBucketsIndexer *staking.CandidatesBucketsIndexer sgdIndexer blockindex.SGDRegistry - contractStakingIndexer contractstaking.ContractIndexer + contractStakingIndexer *contractstaking.Indexer registry *protocol.Registry nodeInfoManager *nodeinfo.InfoManager apiStats *nodestats.APILocalStats From 7129fcb953c12c73dbfe73e57a2070388c59e0ab Mon Sep 17 00:00:00 2001 From: envestcc Date: Mon, 12 Jun 2023 11:25:07 +0800 Subject: [PATCH 4/6] address comments --- action/protocol/staking/protocol.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action/protocol/staking/protocol.go b/action/protocol/staking/protocol.go index df7b112513..bdba7a9dfb 100644 --- a/action/protocol/staking/protocol.go +++ b/action/protocol/staking/protocol.go @@ -475,7 +475,7 @@ func (p *Protocol) ActiveCandidates(ctx context.Context, sr protocol.StateReader list := c.AllCandidates() cand := make(CandidateList, 0, len(list)) for i := range list { - if p.contractStakingIndexer != nil && ok && featureCtx.AddContractStakingVotes { + if ok && p.contractStakingIndexer != nil && featureCtx.AddContractStakingVotes { list[i].Votes.Add(list[i].Votes, p.contractStakingIndexer.CandidateVotes(list[i].Owner)) } if list[i].SelfStake.Cmp(p.config.RegistrationConsts.MinSelfStake) >= 0 { From a1c471f7a23afd6514ac0fede2c7718834979762 Mon Sep 17 00:00:00 2001 From: envestcc Date: Wed, 5 Jul 2023 16:14:26 +0800 Subject: [PATCH 5/6] add featureCtx for ActiveCandidates --- action/protocol/staking/protocol.go | 3 +-- action/protocol/staking/staking_statereader.go | 1 - chainservice/builder.go | 11 +++++++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/action/protocol/staking/protocol.go b/action/protocol/staking/protocol.go index bdba7a9dfb..1eed03150a 100644 --- a/action/protocol/staking/protocol.go +++ b/action/protocol/staking/protocol.go @@ -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 { diff --git a/action/protocol/staking/staking_statereader.go b/action/protocol/staking/staking_statereader.go index 37a604bfdc..4b0dcef39b 100644 --- a/action/protocol/staking/staking_statereader.go +++ b/action/protocol/staking/staking_statereader.go @@ -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 } diff --git a/chainservice/builder.go b/chainservice/builder.go index 0ace5953f6..b7bac80dbb 100644 --- a/chainservice/builder.go +++ b/chainservice/builder.go @@ -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" @@ -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 From bf485f5f08d16cbbbb50a6f868d0d366814de317 Mon Sep 17 00:00:00 2001 From: envestcc Date: Thu, 6 Jul 2023 10:19:41 +0800 Subject: [PATCH 6/6] remove empty line --- action/protocol/staking/staking_statereader.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/action/protocol/staking/staking_statereader.go b/action/protocol/staking/staking_statereader.go index 4b0dcef39b..683aeafc07 100644 --- a/action/protocol/staking/staking_statereader.go +++ b/action/protocol/staking/staking_statereader.go @@ -110,7 +110,6 @@ func (c *compositeStakingStateReader) readStateBucketsByVoter(ctx context.Contex } // 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 } @@ -142,7 +141,6 @@ func (c *compositeStakingStateReader) readStateBucketsByCandidate(ctx context.Co } // 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 } @@ -168,7 +166,6 @@ func (c *compositeStakingStateReader) readStateBucketByIndices(ctx context.Conte } // merge native and LSD buckets buckets.Buckets = append(buckets.Buckets, lsbIoTeXBuckets.Buckets...) - return buckets, height, nil }