From f32c66ebc171123d18553d006e35386c4ef13f6e Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Fri, 14 Jul 2023 16:30:47 +0800 Subject: [PATCH] check slashed status in GetCandidateStatus --- internal/ethapi/api.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index a3138ca257..eedde75d18 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -819,7 +819,7 @@ func (s *PublicBlockChainAPI) GetCandidateStatus(ctx context.Context, coinbaseAd }) } - // Third, Get penalties list + // Get penalties list penalties = append(penalties, header.Penalties...) // check last 5 epochs to find penalize masternodes for i := 1; i <= common.LimitPenaltyEpoch; i++ { @@ -837,12 +837,22 @@ func (s *PublicBlockChainAPI) GetCandidateStatus(ctx context.Context, coinbaseAd penaltyList = common.ExtractAddressFromBytes(penalties) // map slashing status - for _, pen := range penaltyList { - if coinbaseAddress == pen { - result[fieldStatus] = statusSlashed - return result, nil + total := len(masternodes) + for _, candidate := range candidates { + for _, pen := range penaltyList { + if candidate.Address == pen { + if coinbaseAddress == pen { + result[fieldStatus] = statusSlashed + return result, nil + } + total++ + if total >= maxMasternodes { + return result, nil + } + } } } + return result, nil }