Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test only current validators api #3404

Draft
wants to merge 45 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
9c8835b
remove subnet IDs from uptime pkg
ceyonur Jul 24, 2024
733d5fd
remove subnet uptimes from platforvm
ceyonur Jul 25, 2024
10d8e86
remove subnet uptimes from p2p
ceyonur Jul 25, 2024
a2f69d0
remove subnet uptimes from api
ceyonur Jul 25, 2024
ee287c6
add tracked bool
ceyonur Jul 25, 2024
a42e48c
remove unnecessary err
ceyonur Jul 26, 2024
4c542af
remove connected subnet msg
ceyonur Jul 26, 2024
941f536
Merge branch 'master' into remove-subnetid-uptime-manager
ceyonur Jul 26, 2024
9161864
fix linter
ceyonur Jul 26, 2024
dfded5e
Merge branch 'master' into remove-subnetid-uptime-manager
ceyonur Jul 31, 2024
f275c15
rework on tests and reviews
ceyonur Jul 31, 2024
d9355cc
fix linter
ceyonur Jul 31, 2024
3998494
add GetCurrentValidators to state
ceyonur Aug 2, 2024
46501ad
Update proto/p2p/p2p.proto
ceyonur Aug 6, 2024
b7459bd
fix comment
ceyonur Aug 6, 2024
b81b737
Update vms/platformvm/service_test.go
ceyonur Aug 6, 2024
f6bb383
use disconnect in stop tracking
ceyonur Aug 6, 2024
7a6f7eb
remove todo comment
ceyonur Aug 6, 2024
64dec9c
Merge branch 'master' into remove-subnetid-uptime-manager
ceyonur Aug 6, 2024
75250de
small refactor
ceyonur Aug 29, 2024
33eb562
Merge branch 'master' into remove-subnetid-uptime-manager
ceyonur Sep 8, 2024
cba7a50
remove unused err
ceyonur Sep 8, 2024
b4955d6
remove subnet connector mock
ceyonur Sep 8, 2024
fb21285
add started tracking
ceyonur Sep 9, 2024
5412f16
Merge branch 'remove-subnetid-uptime-manager' into refactor-uptime-ma…
ceyonur Sep 9, 2024
477c3eb
do not return err
ceyonur Sep 9, 2024
84898f4
Merge branch 'refactor-uptime-manager' of github.com:ava-labs/avalanc…
ceyonur Sep 9, 2024
3c9096e
Merge branch 'master' into remove-subnetid-uptime-manager
ceyonur Sep 10, 2024
8c6a486
Merge branch 'remove-subnetid-uptime-manager' into refactor-uptime-ma…
ceyonur Sep 10, 2024
4ce1977
Merge branch 'master' into remove-subnetid-uptime-manager
ceyonur Sep 11, 2024
863c92e
Merge branch 'master' into remove-subnetid-uptime-manager
ceyonur Sep 16, 2024
1753950
Merge branch 'remove-subnetid-uptime-manager' into refactor-uptime-ma…
ceyonur Sep 16, 2024
a441d62
Merge branch 'master' into remove-subnetid-uptime-manager
ceyonur Sep 19, 2024
a4fd79d
Merge branch 'remove-subnetid-uptime-manager' into refactor-uptime-ma…
ceyonur Sep 19, 2024
9c2c211
add current validators api
ceyonur Sep 19, 2024
554a9e7
Merge branch 'master' into test-only-current-validators-api
ceyonur Sep 19, 2024
29e7797
regen mock
ceyonur Sep 19, 2024
7777ba6
Merge branch 'refactor-uptime-manager' into test-only-current-validat…
ceyonur Sep 19, 2024
a754e44
Merge branch 'refactor-uptime-manager' into test-only-current-validat…
ceyonur Sep 19, 2024
09d63ce
populate validationID
ceyonur Sep 20, 2024
3adf6d4
Merge branch 'test-only-current-validators-api' of github.com:ava-lab…
ceyonur Sep 20, 2024
07af6b2
add ctx
ceyonur Sep 20, 2024
5285749
Merge branch 'master' into test-only-current-validators-api
ceyonur Oct 4, 2024
f16a904
Merge branch 'master' into test-only-current-validators-api
ceyonur Oct 9, 2024
a2f59c8
Merge branch 'master' into test-only-current-validators-api
ceyonur Oct 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
411 changes: 343 additions & 68 deletions proto/pb/validatorstate/validator_state.pb.go

Large diffs are not rendered by default.

49 changes: 45 additions & 4 deletions proto/pb/validatorstate/validator_state_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions proto/validatorstate/validator_state.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ service ValidatorState {
// GetValidatorSet returns the weights of the nodeIDs for the provided
// subnet at the requested P-chain height.
rpc GetValidatorSet(GetValidatorSetRequest) returns (GetValidatorSetResponse);
// GetCurrentValidatorSet returns the weights of the nodeIDs for the provided
// subnet at the current P-chain height.
rpc GetCurrentValidatorSet(GetCurrentValidatorSetRequest) returns (GetCurrentValidatorSetResponse);
}

message GetMinimumHeightResponse {
Expand All @@ -40,12 +43,31 @@ message GetValidatorSetRequest {
bytes subnet_id = 2;
}

message GetCurrentValidatorSetRequest {
bytes subnet_id = 1;
}

message Validator {
bytes node_id = 1;
uint64 weight = 2;
bytes public_key = 3;
}

message CurrentValidator {
bytes node_id = 1;
uint64 weight = 2;
bytes public_key = 3;
uint64 start_time = 4;
uint64 set_weight_nonce = 5;
bool is_active = 6;
bytes validation_id = 7;
}

message GetValidatorSetResponse {
repeated Validator validators = 1;
}

message GetCurrentValidatorSetResponse {
repeated CurrentValidator validators = 1;
uint64 current_height = 2;
}
46 changes: 46 additions & 0 deletions snow/validators/gvalidators/validator_state_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,49 @@ func (c *Client) GetValidatorSet(
}
return vdrs, nil
}

func (c *Client) GetCurrentValidatorSet(
ctx context.Context,
subnetID ids.ID,
) (map[ids.ID]*validators.GetCurrentValidatorOutput, uint64, error) {
resp, err := c.client.GetCurrentValidatorSet(ctx, &pb.GetCurrentValidatorSetRequest{
SubnetId: subnetID[:],
})
if err != nil {
return nil, 0, err
}

vdrs := make(map[ids.ID]*validators.GetCurrentValidatorOutput, len(resp.Validators))
for _, validator := range resp.Validators {
nodeID, err := ids.ToNodeID(validator.NodeId)
if err != nil {
return nil, 0, err
}
var publicKey *bls.PublicKey
if len(validator.PublicKey) > 0 {
// This is a performance optimization to avoid the cost of
// compression and key re-verification with
// PublicKeyFromCompressedBytes. We can safely assume that the BLS
// Public Keys are verified before being added to the P-Chain and
// served by the gRPC server.
publicKey = bls.PublicKeyFromValidUncompressedBytes(validator.PublicKey)
if publicKey == nil {
return nil, 0, errFailedPublicKeyDeserialize
}
}
validationID, err := ids.ToID(validator.ValidationId)
if err != nil {
return nil, 0, err
}

vdrs[validationID] = &validators.GetCurrentValidatorOutput{
NodeID: nodeID,
PublicKey: publicKey,
Weight: validator.Weight,
StartTime: validator.StartTime,
SetWeightNonce: validator.SetWeightNonce,
IsActive: validator.IsActive,
}
}
return vdrs, resp.GetCurrentHeight(), nil
}
37 changes: 37 additions & 0 deletions snow/validators/gvalidators/validator_state_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,40 @@ func (s *Server) GetValidatorSet(ctx context.Context, req *pb.GetValidatorSetReq
}
return resp, nil
}

func (s *Server) GetCurrentValidatorSet(ctx context.Context, req *pb.GetCurrentValidatorSetRequest) (*pb.GetCurrentValidatorSetResponse, error) {
subnetID, err := ids.ToID(req.SubnetId)
if err != nil {
return nil, err
}

vdrs, currentHeight, err := s.state.GetCurrentValidatorSet(ctx, subnetID)
if err != nil {
return nil, err
}

resp := &pb.GetCurrentValidatorSetResponse{
Validators: make([]*pb.CurrentValidator, len(vdrs)),
CurrentHeight: currentHeight,
}

i := 0
for _, vdr := range vdrs {
vdrPB := &pb.CurrentValidator{
NodeId: vdr.NodeID.Bytes(),
StartTime: vdr.StartTime,
IsActive: vdr.IsActive,
ValidationId: vdr.ValidationID[:],
Weight: vdr.Weight,
SetWeightNonce: vdr.SetWeightNonce,
}
if vdr.PublicKey != nil {
// This is a performance optimization to avoid the cost of compression
// from PublicKeyToCompressedBytes.
vdrPB.PublicKey = bls.PublicKeyToUncompressedBytes(vdr.PublicKey)
}
resp.Validators[i] = vdrPB
i++
}
return resp, nil
}
24 changes: 24 additions & 0 deletions snow/validators/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ type State interface {
height uint64,
subnetID ids.ID,
) (map[ids.NodeID]*GetValidatorOutput, error)

// GetCurrentValidatorSet returns the current validators of the provided subnet
// and the current P-Chain height.
// Map is keyed by ValidationID.
// The returned map should not be modified.
GetCurrentValidatorSet(
ctx context.Context,
subnetID ids.ID,
) (map[ids.ID]*GetCurrentValidatorOutput, uint64, error)
}

type lockedState struct {
Expand Down Expand Up @@ -78,6 +87,16 @@ func (s *lockedState) GetValidatorSet(
return s.s.GetValidatorSet(ctx, height, subnetID)
}

func (s *lockedState) GetCurrentValidatorSet(
ctx context.Context,
subnetID ids.ID,
) (map[ids.ID]*GetCurrentValidatorOutput, uint64, error) {
s.lock.Lock()
defer s.lock.Unlock()

return s.s.GetCurrentValidatorSet(ctx, subnetID)
}

type noValidators struct {
State
}
Expand All @@ -91,3 +110,8 @@ func NewNoValidatorsState(state State) State {
func (*noValidators) GetValidatorSet(context.Context, uint64, ids.ID) (map[ids.NodeID]*GetValidatorOutput, error) {
return nil, nil
}

func (*noValidators) GetCurrentValidatorSet(context.Context, ids.ID) (map[ids.ID]*GetCurrentValidatorOutput, uint64, error) {
// TODO: should we return the actual height?
return nil, 0, nil
}
12 changes: 12 additions & 0 deletions snow/validators/traced_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,15 @@ func (s *tracedState) GetValidatorSet(

return s.s.GetValidatorSet(ctx, height, subnetID)
}

func (s *tracedState) GetCurrentValidatorSet(
ctx context.Context,
subnetID ids.ID,
) (map[ids.ID]*GetCurrentValidatorOutput, uint64, error) {
ctx, span := s.tracer.Start(ctx, s.getValidatorSetTag, oteltrace.WithAttributes(
attribute.Stringer("subnetID", subnetID),
))
defer span.End()

return s.s.GetCurrentValidatorSet(ctx, subnetID)
}
10 changes: 10 additions & 0 deletions snow/validators/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,13 @@ type GetValidatorOutput struct {
PublicKey *bls.PublicKey
Weight uint64
}

type GetCurrentValidatorOutput struct {
ValidationID ids.ID
NodeID ids.NodeID
PublicKey *bls.PublicKey
Weight uint64
StartTime uint64
SetWeightNonce uint64
IsActive bool
}
16 changes: 16 additions & 0 deletions snow/validators/validatorsmock/state.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 19 additions & 4 deletions snow/validators/validatorstest/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ type State struct {
CantGetCurrentHeight,
CantGetSubnetID,
CantGetValidatorSet bool
CantGetCurrentValidatorSet bool

GetMinimumHeightF func(ctx context.Context) (uint64, error)
GetCurrentHeightF func(ctx context.Context) (uint64, error)
GetSubnetIDF func(ctx context.Context, chainID ids.ID) (ids.ID, error)
GetValidatorSetF func(ctx context.Context, height uint64, subnetID ids.ID) (map[ids.NodeID]*validators.GetValidatorOutput, error)
GetMinimumHeightF func(ctx context.Context) (uint64, error)
GetCurrentHeightF func(ctx context.Context) (uint64, error)
GetSubnetIDF func(ctx context.Context, chainID ids.ID) (ids.ID, error)
GetValidatorSetF func(ctx context.Context, height uint64, subnetID ids.ID) (map[ids.NodeID]*validators.GetValidatorOutput, error)
GetCurrentValidatorSetF func(ctx context.Context, subnetID ids.ID) (map[ids.ID]*validators.GetCurrentValidatorOutput, uint64, error)
}

func (vm *State) GetMinimumHeight(ctx context.Context) (uint64, error) {
Expand Down Expand Up @@ -80,3 +82,16 @@ func (vm *State) GetValidatorSet(
}
return nil, errGetValidatorSet
}

func (vm *State) GetCurrentValidatorSet(
ctx context.Context,
subnetID ids.ID,
) (map[ids.ID]*validators.GetCurrentValidatorOutput, uint64, error) {
if vm.GetCurrentValidatorSetF != nil {
return vm.GetCurrentValidatorSetF(ctx, subnetID)
}
if vm.CantGetCurrentValidatorSet && vm.T != nil {
require.FailNow(vm.T, "unexpectedly called GetCurrentValidatorSet")
}
return nil, 0, nil
}
16 changes: 16 additions & 0 deletions vms/platformvm/state/mock_state.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading