Skip to content

Commit 86961df

Browse files
Merge branch 'dev' into platformvm-iter-syntax
2 parents 222b900 + 551eae5 commit 86961df

File tree

5 files changed

+110
-20
lines changed

5 files changed

+110
-20
lines changed

.ci/run_e2e_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ echo "Using Avalanche Image: $AVALANCHE_IMAGE"
1717

1818
DOCKER_REPO="avaplatform"
1919
BYZANTINE_IMAGE="$DOCKER_REPO/avalanche-byzantine:v0.1.5-rc.1"
20-
TEST_SUITE_IMAGE="$DOCKER_REPO/avalanche-testing:v0.10.5-rc.1"
20+
TEST_SUITE_IMAGE="$DOCKER_REPO/avalanche-testing:v0.10.5-rc.2"
2121

2222
# If Docker Credentials are not available skip the Byzantine Tests
2323
if [[ -z ${DOCKER_USERNAME} ]]; then

api/info/service.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ func (service *Info) GetBlockchainID(_ *http.Request, args *GetBlockchainIDArgs,
132132
return err
133133
}
134134

135+
// PeersArgs are the arguments for calling Peers
136+
type PeersArgs struct {
137+
NodeIDs []string `json:"nodeIDs"`
138+
}
139+
135140
// PeersReply are the results from calling Peers
136141
type PeersReply struct {
137142
// Number of elements in [Peers]
@@ -141,10 +146,19 @@ type PeersReply struct {
141146
}
142147

143148
// Peers returns the list of current validators
144-
func (service *Info) Peers(_ *http.Request, _ *struct{}, reply *PeersReply) error {
149+
func (service *Info) Peers(_ *http.Request, args *PeersArgs, reply *PeersReply) error {
145150
service.log.Info("Info: Peers called")
146151

147-
reply.Peers = service.networking.Peers()
152+
nodeIDs := make([]ids.ShortID, 0, len(args.NodeIDs))
153+
for _, nodeID := range args.NodeIDs {
154+
nID, err := ids.ShortFromPrefixedString(nodeID, constants.NodeIDPrefix)
155+
if err != nil {
156+
return err
157+
}
158+
nodeIDs = append(nodeIDs, nID)
159+
}
160+
161+
reply.Peers = service.networking.Peers(nodeIDs)
148162
reply.NumPeers = json.Uint64(len(reply.Peers))
149163
return nil
150164
}

network/network.go

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ type Network interface {
8383
// IP.
8484
Track(ip utils.IPDesc)
8585

86-
// Returns the description of the nodes this network is currently connected
87-
// to externally. Thread safety must be managed internally to the network.
88-
Peers() []PeerID
86+
// Returns the description of the specified [nodeIDs] this network is currently
87+
// connected to externally or all nodes this network is connected to if [nodeIDs]
88+
// is empty. Thread safety must be managed internally to the network.
89+
Peers(nodeIDs []ids.ShortID) []PeerID
8990

9091
// Close this network and all existing connections it has. Thread safety
9192
// must be managed internally to the network. Calling close multiple times
@@ -746,21 +747,40 @@ func (n *network) Dispatch() error {
746747

747748
// IPs implements the Network interface
748749
// assumes the stateLock is not held.
749-
func (n *network) Peers() []PeerID {
750+
func (n *network) Peers(nodeIDs []ids.ShortID) []PeerID {
750751
n.stateLock.RLock()
751752
defer n.stateLock.RUnlock()
752753

753-
peers := make([]PeerID, 0, len(n.peers))
754-
for _, peer := range n.peers {
755-
if peer.connected.GetValue() {
756-
peers = append(peers, PeerID{
757-
IP: peer.conn.RemoteAddr().String(),
758-
PublicIP: peer.getIP().String(),
759-
ID: peer.id.PrefixedString(constants.NodeIDPrefix),
760-
Version: peer.versionStr.GetValue().(string),
761-
LastSent: time.Unix(atomic.LoadInt64(&peer.lastSent), 0),
762-
LastReceived: time.Unix(atomic.LoadInt64(&peer.lastReceived), 0),
763-
})
754+
var peers []PeerID
755+
756+
if len(nodeIDs) == 0 {
757+
peers = make([]PeerID, 0, len(n.peers))
758+
for _, peer := range n.peers {
759+
if peer.connected.GetValue() {
760+
peers = append(peers, PeerID{
761+
IP: peer.conn.RemoteAddr().String(),
762+
PublicIP: peer.getIP().String(),
763+
ID: peer.id.PrefixedString(constants.NodeIDPrefix),
764+
Version: peer.versionStr.GetValue().(string),
765+
LastSent: time.Unix(atomic.LoadInt64(&peer.lastSent), 0),
766+
LastReceived: time.Unix(atomic.LoadInt64(&peer.lastReceived), 0),
767+
})
768+
}
769+
}
770+
} else {
771+
peers = make([]PeerID, 0, len(nodeIDs))
772+
for _, nodeID := range nodeIDs {
773+
peer, ok := n.peers[nodeID]
774+
if ok && peer.connected.GetValue() {
775+
peers = append(peers, PeerID{
776+
IP: peer.conn.RemoteAddr().String(),
777+
PublicIP: peer.getIP().String(),
778+
ID: peer.id.PrefixedString(constants.NodeIDPrefix),
779+
Version: peer.versionStr.GetValue().(string),
780+
LastSent: time.Unix(atomic.LoadInt64(&peer.lastSent), 0),
781+
LastReceived: time.Unix(atomic.LoadInt64(&peer.lastReceived), 0),
782+
})
783+
}
764784
}
765785
}
766786
return peers

node/node.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ func (n *Node) initDatabase() error {
403403
func (n *Node) initNodeID() error {
404404
if !n.Config.EnableP2PTLS {
405405
n.ID = ids.ShortID(hashing.ComputeHash160Array([]byte(n.Config.StakingIP.IP().String())))
406-
n.Log.Info("Set the node's ID to %s", n.ID)
406+
n.Log.Info("Set the node's ID to %s", n.ID.PrefixedString(constants.NodeIDPrefix))
407407
return nil
408408
}
409409

@@ -421,7 +421,7 @@ func (n *Node) initNodeID() error {
421421
if err != nil {
422422
return fmt.Errorf("problem deriving staker ID from certificate: %w", err)
423423
}
424-
n.Log.Info("Set node's ID to %s", n.ID)
424+
n.Log.Info("Set node's ID to %s", n.ID.PrefixedString(constants.NodeIDPrefix))
425425
return nil
426426
}
427427

vms/platformvm/service.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,11 @@ type GetCurrentValidatorsArgs struct {
603603
// Subnet we're listing the validators of
604604
// If omitted, defaults to primary network
605605
SubnetID ids.ID `json:"subnetID"`
606+
// NodeIDs of validators to request. If [NodeIDs]
607+
// is empty, it fetches all current validators. If
608+
// some nodeIDs are not currently validators, they
609+
// will be omitted from the response.
610+
NodeIDs []string `json:"nodeIDs"`
606611
}
607612

608613
// GetCurrentValidatorsReply are the results from calling GetCurrentValidators.
@@ -620,6 +625,17 @@ func (service *Service) GetCurrentValidators(_ *http.Request, args *GetCurrentVa
620625
// Validator's node ID as string --> Delegators to them
621626
vdrTodelegators := map[string][]APIPrimaryDelegator{}
622627

628+
// Create set of nodeIDs
629+
nodeIDs := ids.ShortSet{}
630+
for _, nodeID := range args.NodeIDs {
631+
nID, err := ids.ShortFromPrefixedString(nodeID, constants.NodeIDPrefix)
632+
if err != nil {
633+
return err
634+
}
635+
nodeIDs.Add(nID)
636+
}
637+
includeAllNodes := nodeIDs.Len() == 0
638+
623639
stopPrefix := []byte(fmt.Sprintf("%s%s", args.SubnetID, stopDBPrefix))
624640
stopDB := prefixdb.NewNested(stopPrefix, service.vm.DB)
625641
defer stopDB.Close()
@@ -640,6 +656,10 @@ func (service *Service) GetCurrentValidators(_ *http.Request, args *GetCurrentVa
640656

641657
switch staker := tx.Tx.UnsignedTx.(type) {
642658
case *UnsignedAddDelegatorTx:
659+
if !includeAllNodes && !nodeIDs.Contains(staker.Validator.ID()) {
660+
continue
661+
}
662+
643663
weight := json.Uint64(staker.Validator.Weight())
644664

645665
var rewardOwner *APIOwner
@@ -672,6 +692,10 @@ func (service *Service) GetCurrentValidators(_ *http.Request, args *GetCurrentVa
672692
}
673693
vdrTodelegators[delegator.NodeID] = append(vdrTodelegators[delegator.NodeID], delegator)
674694
case *UnsignedAddValidatorTx:
695+
if !includeAllNodes && !nodeIDs.Contains(staker.Validator.ID()) {
696+
continue
697+
}
698+
675699
nodeID := staker.Validator.ID()
676700
startTime := staker.StartTime()
677701
weight := json.Uint64(staker.Validator.Weight())
@@ -716,6 +740,10 @@ func (service *Service) GetCurrentValidators(_ *http.Request, args *GetCurrentVa
716740
DelegationFee: delegationFee,
717741
})
718742
case *UnsignedAddSubnetValidatorTx:
743+
if !includeAllNodes && !nodeIDs.Contains(staker.Validator.ID()) {
744+
continue
745+
}
746+
719747
weight := json.Uint64(staker.Validator.Weight())
720748
reply.Validators = append(reply.Validators, APIStaker{
721749
TxID: tx.Tx.ID(),
@@ -751,6 +779,11 @@ type GetPendingValidatorsArgs struct {
751779
// Subnet we're getting the pending validators of
752780
// If omitted, defaults to primary network
753781
SubnetID ids.ID `json:"subnetID"`
782+
// NodeIDs of validators to request. If [NodeIDs]
783+
// is empty, it fetches all pending validators. If
784+
// some requested nodeIDs are not pending validators,
785+
// they are omitted from the response.
786+
NodeIDs []string `json:"nodeIDs"`
754787
}
755788

756789
// GetPendingValidatorsReply are the results from calling GetPendingValidators.
@@ -767,6 +800,17 @@ func (service *Service) GetPendingValidators(_ *http.Request, args *GetPendingVa
767800
reply.Validators = []interface{}{}
768801
reply.Delegators = []interface{}{}
769802

803+
// Create set of nodeIDs
804+
nodeIDs := ids.ShortSet{}
805+
for _, nodeID := range args.NodeIDs {
806+
nID, err := ids.ShortFromPrefixedString(nodeID, constants.NodeIDPrefix)
807+
if err != nil {
808+
return err
809+
}
810+
nodeIDs.Add(nID)
811+
}
812+
includeAllNodes := nodeIDs.Len() == 0
813+
770814
startPrefix := []byte(fmt.Sprintf("%s%s", args.SubnetID, startDBPrefix))
771815
startDB := prefixdb.NewNested(startPrefix, service.vm.DB)
772816
defer startDB.Close()
@@ -787,6 +831,10 @@ func (service *Service) GetPendingValidators(_ *http.Request, args *GetPendingVa
787831

788832
switch staker := tx.UnsignedTx.(type) {
789833
case *UnsignedAddDelegatorTx:
834+
if !includeAllNodes && !nodeIDs.Contains(staker.Validator.ID()) {
835+
continue
836+
}
837+
790838
weight := json.Uint64(staker.Validator.Weight())
791839
reply.Delegators = append(reply.Delegators, APIStaker{
792840
TxID: tx.ID(),
@@ -796,6 +844,10 @@ func (service *Service) GetPendingValidators(_ *http.Request, args *GetPendingVa
796844
StakeAmount: &weight,
797845
})
798846
case *UnsignedAddValidatorTx:
847+
if !includeAllNodes && !nodeIDs.Contains(staker.Validator.ID()) {
848+
continue
849+
}
850+
799851
nodeID := staker.Validator.ID()
800852
weight := json.Uint64(staker.Validator.Weight())
801853
delegationFee := json.Float32(100 * float32(staker.Shares) / float32(PercentDenominator))
@@ -813,6 +865,10 @@ func (service *Service) GetPendingValidators(_ *http.Request, args *GetPendingVa
813865
Connected: &connected,
814866
})
815867
case *UnsignedAddSubnetValidatorTx:
868+
if !includeAllNodes && !nodeIDs.Contains(staker.Validator.ID()) {
869+
continue
870+
}
871+
816872
weight := json.Uint64(staker.Validator.Weight())
817873
reply.Validators = append(reply.Validators, APIStaker{
818874
TxID: tx.ID(),

0 commit comments

Comments
 (0)