@@ -638,6 +638,64 @@ func (s *server) AddPermissionlessValidator(
638
638
return & rpcpb.AddPermissionlessValidatorResponse {ClusterInfo : clusterInfo }, nil
639
639
}
640
640
641
+ func (s * server ) AddSubnetValidators (
642
+ _ context.Context ,
643
+ req * rpcpb.AddSubnetValidatorsRequest ,
644
+ ) (* rpcpb.AddSubnetValidatorsResponse , error ) {
645
+ s .mu .Lock ()
646
+ defer s .mu .Unlock ()
647
+
648
+ if s .network == nil {
649
+ return nil , ErrNotBootstrapped
650
+ }
651
+
652
+ s .log .Debug ("AddSubnetValidators" )
653
+
654
+ if len (req .GetValidatorsSpec ()) == 0 {
655
+ return nil , ErrNoValidatorSpec
656
+ }
657
+
658
+ validatorSpecList := []network.SubnetValidatorsSpec {}
659
+ for _ , spec := range req .GetValidatorsSpec () {
660
+ validatorSpec := getSubnetValidatorSpec (spec )
661
+ validatorSpecList = append (validatorSpecList , validatorSpec )
662
+ }
663
+
664
+ // check that the given subnets exist
665
+ subnetsSet := set.Set [string ]{}
666
+ subnetsSet .Add (maps .Keys (s .clusterInfo .Subnets )... )
667
+
668
+ for _ , validatorSpec := range validatorSpecList {
669
+ if validatorSpec .SubnetID == "" {
670
+ return nil , ErrNoSubnetID
671
+ } else if ! subnetsSet .Contains (validatorSpec .SubnetID ) {
672
+ return nil , fmt .Errorf ("subnet id %q does not exist" , validatorSpec .SubnetID )
673
+ }
674
+ }
675
+
676
+ s .clusterInfo .Healthy = false
677
+ s .clusterInfo .CustomChainsHealthy = false
678
+
679
+ ctx , cancel := context .WithTimeout (context .Background (), waitForHealthyTimeout )
680
+ defer cancel ()
681
+ err := s .network .AddSubnetValidators (ctx , validatorSpecList )
682
+
683
+ s .updateClusterInfo ()
684
+
685
+ if err != nil {
686
+ s .log .Error ("failed to add subnet validators" , zap .Error (err ))
687
+ return nil , err
688
+ }
689
+
690
+ s .log .Info ("successfully added subnet validators" )
691
+
692
+ clusterInfo , err := deepCopy (s .clusterInfo )
693
+ if err != nil {
694
+ return nil , err
695
+ }
696
+ return & rpcpb.AddSubnetValidatorsResponse {ClusterInfo : clusterInfo }, nil
697
+ }
698
+
641
699
func (s * server ) RemoveSubnetValidator (
642
700
_ context.Context ,
643
701
req * rpcpb.RemoveSubnetValidatorRequest ,
@@ -1550,6 +1608,15 @@ func getPermissionlessValidatorSpec(
1550
1608
return validatorSpec , nil
1551
1609
}
1552
1610
1611
+ func getSubnetValidatorSpec (
1612
+ spec * rpcpb.SubnetValidatorsSpec ,
1613
+ ) network.SubnetValidatorsSpec {
1614
+ return network.SubnetValidatorsSpec {
1615
+ SubnetID : spec .SubnetId ,
1616
+ NodeNames : spec .GetNodeNames (),
1617
+ }
1618
+ }
1619
+
1553
1620
func getRemoveSubnetValidatorSpec (
1554
1621
spec * rpcpb.RemoveSubnetValidatorSpec ,
1555
1622
) network.SubnetValidatorsSpec {
0 commit comments