Skip to content

Commit b56dd84

Browse files
committed
Return delegators for all nodes in getCurrentValidators if COMPLETE_GET_VALIDATORS env variable is set to true
1 parent 795c969 commit b56dd84

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

avalanchego/vms/platformvm/service.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"errors"
99
"fmt"
1010
"net/http"
11+
"os"
12+
"strings"
1113
"time"
1214

1315
stdmath "math"
@@ -78,8 +80,16 @@ var (
7880
errMissingPrivateKey = errors.New("argument 'privateKey' not given")
7981
errStartAfterEndTime = errors.New("start time must be before end time")
8082
errStartTimeInThePast = errors.New("start time in the past")
83+
84+
completeGetValidators = false
8185
)
8286

87+
func init() {
88+
// if COMPLETE_GET_VALIDATORS is set to true, the getCurrentValidators API will return delegators
89+
// for every node. Otherwise, it will only return delegators if a single nodeID is provided.
90+
completeGetValidators = strings.ToUpper(os.Getenv("COMPLETE_GET_VALIDATORS")) == "TRUE"
91+
}
92+
8393
// Service defines the API calls that can be made to the platform chain
8494
type Service struct {
8595
vm *VM
@@ -881,8 +891,8 @@ func (s *Service) GetCurrentValidators(_ *http.Request, args *GetCurrentValidato
881891
case txs.PrimaryNetworkDelegatorCurrentPriority, txs.SubnetPermissionlessDelegatorCurrentPriority:
882892
var rewardOwner *platformapi.Owner
883893
// If we are handling multiple nodeIDs, we don't return the
884-
// delegator information.
885-
if numNodeIDs == 1 {
894+
// delegator information unless completeGetValidators is true.
895+
if numNodeIDs == 1 || completeGetValidators {
886896
attr, err := s.loadStakerTxAttributes(currentStaker.TxID)
887897
if err != nil {
888898
return err
@@ -941,8 +951,8 @@ func (s *Service) GetCurrentValidators(_ *http.Request, args *GetCurrentValidato
941951
vdr.DelegatorCount = &delegatorCount
942952
vdr.DelegatorWeight = &delegatorWeight
943953

944-
if numNodeIDs == 1 {
945-
// queried a specific validator, load all of its delegators
954+
if numNodeIDs == 1 || completeGetValidators {
955+
// queried a specific validator or completeGetValidators is true, load all of its delegators
946956
vdr.Delegators = &delegators
947957
}
948958
reply.Validators[i] = vdr

0 commit comments

Comments
 (0)