Skip to content

Commit 3d2946e

Browse files
committed
Stub out GetAllValidatorSets
1 parent e8ef3ad commit 3d2946e

File tree

8 files changed

+95
-2
lines changed

8 files changed

+95
-2
lines changed

proto/validatorstate/validator_state.proto

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ service ValidatorState {
1414
rpc GetCurrentHeight(google.protobuf.Empty) returns (GetCurrentHeightResponse);
1515
// GetSubnetID returns the subnetID of the provided chain.
1616
rpc GetSubnetID(GetSubnetIDRequest) returns (GetSubnetIDResponse);
17+
// GetAllValidatorSets returns the weights of the nodeIDs for all
18+
// subnets at the requested P-chain height.
19+
rpc GetAllValidatorSets(GetAllValidatorSetsRequest) returns (GetAllValidatorSetsResponse);
1720
// GetValidatorSet returns the weights of the nodeIDs for the provided
1821
// subnet at the requested P-chain height.
1922
rpc GetValidatorSet(GetValidatorSetRequest) returns (GetValidatorSetResponse);
@@ -38,6 +41,10 @@ message GetSubnetIDResponse {
3841
bytes subnet_id = 1;
3942
}
4043

44+
message GetAllValidatorSetsRequest {
45+
uint64 height = 1;
46+
}
47+
4148
message GetValidatorSetRequest {
4249
uint64 height = 1;
4350
bytes subnet_id = 2;

snow/validators/gvalidators/validator_state_client.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ func (c *Client) GetSubnetID(ctx context.Context, chainID ids.ID) (ids.ID, error
6969
return ids.ToID(resp.SubnetId)
7070
}
7171

72+
func (c *Client) GetAllValidatorSets(
73+
ctx context.Context,
74+
height uint64,
75+
) (map[ids.ID]map[ids.NodeID]*validators.GetValidatorOutput, error) {
76+
// TODO
77+
return nil, nil
78+
}
79+
7280
func (c *Client) GetValidatorSet(
7381
ctx context.Context,
7482
height uint64,

snow/validators/state.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ type State interface {
2424
// GetSubnetID returns the subnetID of the provided chain.
2525
GetSubnetID(ctx context.Context, chainID ids.ID) (ids.ID, error)
2626

27+
// GetAllValidatorSets returns the validators of all subnets at the
28+
// requested P-chain height.
29+
// The returned map should not be modified.
30+
GetAllValidatorSets(
31+
ctx context.Context,
32+
height uint64,
33+
) (map[ids.ID]map[ids.NodeID]*GetValidatorOutput, error)
34+
2735
// GetValidatorSet returns the validators of the provided subnet at the
2836
// requested P-chain height.
2937
// The returned map should not be modified.
@@ -86,6 +94,16 @@ func (s *lockedState) GetValidatorSet(
8694
return s.s.GetValidatorSet(ctx, height, subnetID)
8795
}
8896

97+
func (s *lockedState) GetAllValidatorSets(
98+
ctx context.Context,
99+
height uint64,
100+
) (map[ids.ID]map[ids.NodeID]*GetValidatorOutput, error) {
101+
s.lock.Lock()
102+
defer s.lock.Unlock()
103+
104+
return s.s.GetAllValidatorSets(ctx, height)
105+
}
106+
89107
func (s *lockedState) GetCurrentValidatorSet(
90108
ctx context.Context,
91109
subnetID ids.ID,
@@ -106,6 +124,10 @@ func NewNoValidatorsState(state State) State {
106124
}
107125
}
108126

127+
func (*noValidators) GetAllValidatorSets(context.Context, uint64) (map[ids.ID]map[ids.NodeID]*GetValidatorOutput, error) {
128+
return nil, nil
129+
}
130+
109131
func (*noValidators) GetValidatorSet(context.Context, uint64, ids.ID) (map[ids.NodeID]*GetValidatorOutput, error) {
110132
return nil, nil
111133
}

snow/validators/traced_state.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type tracedState struct {
2121
getMinimumHeightTag string
2222
getCurrentHeightTag string
2323
getSubnetIDTag string
24+
getAllValidatorSetsTag string
2425
getValidatorSetTag string
2526
getCurrentValidatorSetTag string
2627
tracer trace.Tracer
@@ -61,6 +62,18 @@ func (s *tracedState) GetSubnetID(ctx context.Context, chainID ids.ID) (ids.ID,
6162
return s.s.GetSubnetID(ctx, chainID)
6263
}
6364

65+
func (s *tracedState) GetAllValidatorSets(
66+
ctx context.Context,
67+
height uint64,
68+
) (map[ids.ID]map[ids.NodeID]*GetValidatorOutput, error) {
69+
ctx, span := s.tracer.Start(ctx, s.getAllValidatorSetsTag, oteltrace.WithAttributes(
70+
attribute.Int64("height", int64(height)),
71+
))
72+
defer span.End()
73+
74+
return s.s.GetAllValidatorSets(ctx, height)
75+
}
76+
6477
func (s *tracedState) GetValidatorSet(
6578
ctx context.Context,
6679
height uint64,

snow/validators/validatorsmock/state.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

snow/validators/validatorstest/state.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var (
1818
errMinimumHeight = errors.New("unexpectedly called GetMinimumHeight")
1919
errCurrentHeight = errors.New("unexpectedly called GetCurrentHeight")
2020
errSubnetID = errors.New("unexpectedly called GetSubnetID")
21+
errGetAllValidatorSets = errors.New("unexpectedly called GetAllValidatorSets")
2122
errGetValidatorSet = errors.New("unexpectedly called GetValidatorSet")
2223
errGetCurrentValidatorSet = errors.New("unexpectedly called GetCurrentValidatorSet")
2324
)
@@ -30,12 +31,14 @@ type State struct {
3031
CantGetMinimumHeight,
3132
CantGetCurrentHeight,
3233
CantGetSubnetID,
33-
CantGetValidatorSet bool
34+
CantGetAllValidatorSets bool
35+
CantGetValidatorSet bool
3436
CantGetCurrentValidatorSet bool
3537

3638
GetMinimumHeightF func(ctx context.Context) (uint64, error)
3739
GetCurrentHeightF func(ctx context.Context) (uint64, error)
3840
GetSubnetIDF func(ctx context.Context, chainID ids.ID) (ids.ID, error)
41+
GetAllValidatorSetsF func(ctx context.Context, height uint64) (map[ids.ID]map[ids.NodeID]*validators.GetValidatorOutput, error)
3942
GetValidatorSetF func(ctx context.Context, height uint64, subnetID ids.ID) (map[ids.NodeID]*validators.GetValidatorOutput, error)
4043
GetCurrentValidatorSetF func(ctx context.Context, subnetID ids.ID) (map[ids.ID]*validators.GetCurrentValidatorOutput, uint64, error)
4144
}
@@ -70,6 +73,19 @@ func (vm *State) GetSubnetID(ctx context.Context, chainID ids.ID) (ids.ID, error
7073
return ids.Empty, errSubnetID
7174
}
7275

76+
func (vm *State) GetAllValidatorSets(
77+
ctx context.Context,
78+
height uint64,
79+
) (map[ids.ID]map[ids.NodeID]*validators.GetValidatorOutput, error) {
80+
if vm.GetAllValidatorSetsF != nil {
81+
return vm.GetAllValidatorSetsF(ctx, height)
82+
}
83+
if vm.CantGetAllValidatorSets && vm.T != nil {
84+
require.FailNow(vm.T, errGetAllValidatorSets.Error())
85+
}
86+
return nil, errGetAllValidatorSets
87+
}
88+
7389
func (vm *State) GetValidatorSet(
7490
ctx context.Context,
7591
height uint64,
@@ -78,7 +94,7 @@ func (vm *State) GetValidatorSet(
7894
if vm.GetValidatorSetF != nil {
7995
return vm.GetValidatorSetF(ctx, height, subnetID)
8096
}
81-
if vm.CantGetValidatorSet && vm.T != nil {
97+
if vm.CantGetAllValidatorSets && vm.T != nil {
8298
require.FailNow(vm.T, errGetValidatorSet.Error())
8399
}
84100
return nil, errGetValidatorSet

vms/platformvm/validators/manager.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ func (m *manager) getCurrentHeight(context.Context) (uint64, error) {
196196
return lastAccepted.Height(), nil
197197
}
198198

199+
func (m *manager) GetAllValidatorSets(
200+
ctx context.Context,
201+
targetHeight uint64,
202+
) (map[ids.ID]map[ids.NodeID]*validators.GetValidatorOutput, error) {
203+
// TODO
204+
return nil, nil
205+
}
206+
199207
func (m *manager) GetValidatorSet(
200208
ctx context.Context,
201209
targetHeight uint64,

vms/platformvm/validators/validatorstest/manager.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ func (manager) GetSubnetID(context.Context, ids.ID) (ids.ID, error) {
2828
return ids.Empty, nil
2929
}
3030

31+
func (manager) GetAllValidatorSets(context.Context, uint64) (map[ids.ID]map[ids.NodeID]*snowvalidators.GetValidatorOutput, error) {
32+
return nil, nil
33+
}
34+
3135
func (manager) GetValidatorSet(context.Context, uint64, ids.ID) (map[ids.NodeID]*snowvalidators.GetValidatorOutput, error) {
3236
return nil, nil
3337
}

0 commit comments

Comments
 (0)