From e17a0869e5f4b8c19917263ef891054a0a4e588d Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Fri, 14 Jul 2023 16:04:44 +0800 Subject: [PATCH] check masternode before candidate in GetCandidateStatus --- internal/ethapi/api.go | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 2e61139e7d..a3138ca257 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -773,24 +773,19 @@ func (s *PublicBlockChainAPI) GetCandidateStatus(ctx context.Context, coinbaseAd maxMasternodes = common.MaxMasternodes } - isTopCandidate := false - // check penalties from checkpoint headers and modify status of a node to SLASHED if it's in top 150 candidates - // if it's SLASHED but it's out of top 150, the status should be still PROPOSED + // check penalties from checkpoint headers and modify status of a node to SLASHED if it's in top maxMasternodes candidates. + // if it's SLASHED but it's out of top maxMasternodes, the status should be still PROPOSED. + isCandidate := false for i := 0; i < len(candidates); i++ { if coinbaseAddress == candidates[i].Address { - if i < maxMasternodes { - isTopCandidate = true - } + isCandidate = true result[fieldStatus] = statusProposed result[fieldCapacity] = candidates[i].Stake break } } - if !isTopCandidate { - return result, nil - } - // Second, Find candidates that have masternode status + // Get masternode list if engine, ok := s.b.GetEngine().(*XDPoS.XDPoS); ok { masternodes = engine.GetMasternodesFromCheckpointHeader(header) if len(masternodes) == 0 { @@ -801,14 +796,23 @@ func (s *PublicBlockChainAPI) GetCandidateStatus(ctx context.Context, coinbaseAd } else { log.Error("Undefined XDPoS consensus engine") } - // Set masternode status + + // Set to statusMasternode if it is masternode for _, masternode := range masternodes { if coinbaseAddress == masternode { result[fieldStatus] = statusMasternode + if !isCandidate { + result[fieldCapacity] = -1 + log.Warn("Find non-candidate masternode", "masternode", masternode.String(), "checkpointNumber", checkpointNumber, "epoch", epoch, "epochNumber", epochNumber) + } return result, nil } } + if !isCandidate || len(masternodes) >= maxMasternodes { + return result, nil + } + if len(candidates) > maxMasternodes { sort.Slice(candidates, func(i, j int) bool { return candidates[i].Stake.Cmp(candidates[j].Stake) > 0