diff --git a/core/state/statedb_utils.go b/core/state/statedb_utils.go index 4a0c9d45e6..a9c210b569 100644 --- a/core/state/statedb_utils.go +++ b/core/state/statedb_utils.go @@ -93,16 +93,17 @@ func GetCandidates(statedb *StateDB) []common.Address { slot := slotValidatorMapping["candidates"] slotHash := common.BigToHash(new(big.Int).SetUint64(slot)) arrLength := statedb.GetState(common.HexToAddress(common.MasternodeVotingSMC), slotHash) - keys := []common.Hash{} - for i := uint64(0); i < arrLength.Big().Uint64(); i++ { + count := arrLength.Big().Uint64() + rets := make([]common.Address, 0, count) + + for i := uint64(0); i < count; i++ { key := GetLocDynamicArrAtElement(slotHash, i, 1) - keys = append(keys, key) - } - rets := []common.Address{} - for _, key := range keys { ret := statedb.GetState(common.HexToAddress(common.MasternodeVotingSMC), key) - rets = append(rets, common.HexToAddress(ret.Hex())) + if !ret.IsZero() { + rets = append(rets, common.HexToAddress(ret.Hex())) + } } + return rets } diff --git a/eth/hooks/engine_v1_hooks.go b/eth/hooks/engine_v1_hooks.go index 9d14e7a3a4..78ec7a1e19 100644 --- a/eth/hooks/engine_v1_hooks.go +++ b/eth/hooks/engine_v1_hooks.go @@ -238,9 +238,7 @@ func AttachConsensusV1Hooks(adaptor *XDPoS.XDPoS, bc *core.BlockChain, chainConf if err != nil { return nil, err } - if address.String() != "xdc0000000000000000000000000000000000000000" { - candidates = append(candidates, utils.Masternode{Address: address, Stake: v}) - } + candidates = append(candidates, utils.Masternode{Address: address, Stake: v}) } // sort candidates by stake descending sort.Slice(candidates, func(i, j int) bool { diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 1a0ec61881..1ca90b7e40 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -756,9 +756,7 @@ func (s *PublicBlockChainAPI) GetCandidateStatus(ctx context.Context, coinbaseAd candidatesAddresses := state.GetCandidates(statedb) for _, address := range candidatesAddresses { v := state.GetCandidateCap(statedb, address) - if address.String() != "xdc0000000000000000000000000000000000000000" { - candidates = append(candidates, utils.Masternode{Address: address, Stake: v}) - } + candidates = append(candidates, utils.Masternode{Address: address, Stake: v}) } } if err != nil || len(candidates) == 0 { @@ -882,9 +880,7 @@ func (s *PublicBlockChainAPI) GetCandidates(ctx context.Context, epoch rpc.Epoch candidatesAddresses := state.GetCandidates(statedb) for _, address := range candidatesAddresses { v := state.GetCandidateCap(statedb, address) - if address.String() != "xdc0000000000000000000000000000000000000000" { - candidates = append(candidates, utils.Masternode{Address: address, Stake: v}) - } + candidates = append(candidates, utils.Masternode{Address: address, Stake: v}) } }