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

ACP-77: Current validators API for SoV #3404

Merged
merged 267 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
267 commits
Select commit Hold shift + click to select a range
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
1b22842
WIP Add Expiry Replay Protection
StephenButtolph Sep 10, 2024
ad83805
rename
StephenButtolph Sep 10, 2024
7820c17
wip
StephenButtolph Sep 10, 2024
20ed013
Replace iterator equality helper
StephenButtolph Sep 10, 2024
fcb388c
merged
StephenButtolph Sep 10, 2024
a02b51c
Finish diff implementation
StephenButtolph Sep 11, 2024
daf45a3
Merge branch 'master' into implement-acp-77-add-validator-replay-prot…
StephenButtolph Sep 11, 2024
7bda9b1
Finish state implementation
StephenButtolph Sep 11, 2024
f24ca9f
lint
StephenButtolph Sep 11, 2024
463ce02
Implement iterator deduplicator
StephenButtolph Sep 11, 2024
4ce1977
Merge branch 'master' into remove-subnetid-uptime-manager
ceyonur Sep 11, 2024
3cc413a
Reuse Filter
StephenButtolph Sep 11, 2024
4de908e
Merge branch 'master' into implement-deduplication-iterator
StephenButtolph Sep 11, 2024
09f71e6
merged
StephenButtolph Sep 11, 2024
114beeb
nit
StephenButtolph Sep 11, 2024
0cd4f89
Merge branch 'master' into implement-acp-77-add-validator-replay-prot…
StephenButtolph Sep 11, 2024
57810a0
Add comments
StephenButtolph Sep 11, 2024
e89671a
otherExpiries -> unexpectedExpiries
StephenButtolph Sep 12, 2024
72f972c
restructure test
StephenButtolph Sep 12, 2024
e8eea6f
reduce diff
StephenButtolph Sep 12, 2024
d67408d
nit
StephenButtolph Sep 12, 2024
8571163
Merge branch 'master' into implement-acp-77-sov-validators-state
StephenButtolph Sep 13, 2024
6e457fa
Implement acp-77 state diff
StephenButtolph Sep 13, 2024
86754d0
Fix apply reordering
StephenButtolph Sep 13, 2024
c68afec
Implement acp-77 state diff without historical diffs
StephenButtolph Sep 14, 2024
09faa6b
nit
StephenButtolph Sep 14, 2024
51937f7
nit
StephenButtolph Sep 14, 2024
88a310e
Add num SoV validators on a subnet
StephenButtolph Sep 15, 2024
b11ff7e
fix tests
StephenButtolph Sep 15, 2024
6c9e0e0
Merge branch 'master' into implement-acp-77-sov-validators-state
StephenButtolph Sep 15, 2024
b028ada
write historical diffs
StephenButtolph Sep 15, 2024
42d61ef
Implement and test state diffs
StephenButtolph Sep 16, 2024
8ef4fcf
Store weights rather than counts
StephenButtolph Sep 16, 2024
e2045e2
load sov validators on startup
StephenButtolph Sep 16, 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
e0beab1
update in-memory validator sets
StephenButtolph Sep 17, 2024
410bcda
remove comment
StephenButtolph Sep 17, 2024
149e21e
Add SoV excess
StephenButtolph Sep 17, 2024
6c0945b
Merge branch 'master' into implement-acp-77-sov-validators-state
StephenButtolph Sep 18, 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
fbc5ce1
Merge branch 'master' into implement-acp-77-sov-validators-state
StephenButtolph Sep 20, 2024
cfc2790
Merge branch 'remove-subnetid-uptime-manager' into implement-acp-77-s…
StephenButtolph Sep 22, 2024
449994a
write subnet public key diffs
StephenButtolph Sep 23, 2024
744f4c7
merged
StephenButtolph Sep 23, 2024
d9108a7
mocks
StephenButtolph Sep 23, 2024
98020f1
Bound GetNextStakerTime
StephenButtolph Sep 24, 2024
cc9a086
fix test
StephenButtolph Sep 24, 2024
a3f0d94
add comment
StephenButtolph Sep 24, 2024
de81518
Add tests
StephenButtolph Sep 24, 2024
c062890
Merge branch 'bound-next-staker-time' into implement-acp-77-sov-valid…
StephenButtolph Sep 24, 2024
b68ed8a
merged
StephenButtolph Sep 25, 2024
8fe987c
ACP-77: Update warp messages to follow new specification
StephenButtolph Sep 30, 2024
30efc6d
ACP-77: Add warp message helpers to follow new specification
StephenButtolph Oct 1, 2024
903f7c3
migrate x/sync to p2p
joshua-kim Jun 11, 2024
34fe3a6
nit
joshua-kim Sep 10, 2024
b9d5507
add acp-118 implementation
joshua-kim Sep 10, 2024
99f0cde
undo diff
joshua-kim Oct 1, 2024
00fc8d1
nit
joshua-kim Oct 1, 2024
c08a1d7
undo
joshua-kim Oct 1, 2024
9d07a45
nit
joshua-kim Oct 1, 2024
f91e0a8
nit
joshua-kim Oct 1, 2024
a35b090
add context
joshua-kim Oct 1, 2024
dd7029c
fix
joshua-kim Oct 1, 2024
8978452
rename attestor -> verifier
joshua-kim Oct 1, 2024
a383209
nit
joshua-kim Oct 1, 2024
8b52ead
nit
joshua-kim Oct 1, 2024
3859d98
Merge branch 'master' into implement-acp-77-update-warp-messages
StephenButtolph Oct 1, 2024
0462fda
Merge branch 'acp-118-handler' into implement-acp-77-temp.0
StephenButtolph Oct 1, 2024
5a362bd
Merge branch 'implement-acp-77-temp.0' into implement-acp-77-sov-vali…
StephenButtolph Oct 1, 2024
a3cc8e8
merged
StephenButtolph Oct 1, 2024
ddb9ba6
Add deactivation owner
StephenButtolph Oct 1, 2024
556f1eb
fix tests
StephenButtolph Oct 1, 2024
891bca4
Store conversionID
StephenButtolph Oct 2, 2024
a33e0df
Include validationID
StephenButtolph Oct 2, 2024
8fee2b4
Merge branch 'master' into implement-acp-77-sov-validators-state
StephenButtolph Oct 2, 2024
0d3d3b9
Merge branch 'master' into implement-acp-77-sov-validators-state
StephenButtolph Oct 3, 2024
01c9072
remove unexpected file
StephenButtolph Oct 3, 2024
01de954
Merge branch 'master' into implement-acp-77-sov-validators-state
StephenButtolph Oct 3, 2024
5285749
Merge branch 'master' into test-only-current-validators-api
ceyonur Oct 4, 2024
1ca7524
Merge branch 'master' into implement-acp-77-sov-validators-state
StephenButtolph Oct 7, 2024
237f590
Allow xsvm to sign arbitrary warp messages
StephenButtolph Oct 7, 2024
bc53046
Merge branch 'implement-acp-77-allow-xsvm-signing' into implement-acp…
StephenButtolph Oct 7, 2024
127a3fa
nit
StephenButtolph Oct 7, 2024
1986804
nit cleanup
StephenButtolph Oct 9, 2024
f16a904
Merge branch 'master' into test-only-current-validators-api
ceyonur Oct 9, 2024
8279972
Remove unexpected block unwrapping
StephenButtolph Oct 9, 2024
3d5d6c1
Merge branch 'fix-block-passing' into implement-acp-77-sov-validators…
StephenButtolph Oct 10, 2024
d7ba4fb
Merge branch 'master' into implement-acp-77-sov-validators-state
StephenButtolph Oct 11, 2024
d550c97
Merge branch 'master' into implement-acp-77-sov-validators-state
StephenButtolph Oct 14, 2024
a2f59c8
Merge branch 'master' into test-only-current-validators-api
ceyonur Oct 14, 2024
9226649
Merge branch 'master' into implement-acp-77-sov-validators-state
StephenButtolph Oct 15, 2024
a94bfe3
Merge branch 'implement-acp-77-sov-validators-state' into test-only-c…
ceyonur Oct 16, 2024
83cc0dc
merged
StephenButtolph Oct 19, 2024
702639a
ACP-77: Add ConversionID to state
StephenButtolph Oct 19, 2024
4b562f0
nit
StephenButtolph Oct 19, 2024
7f3dd5e
nit
StephenButtolph Oct 19, 2024
f40c1b3
nit
StephenButtolph Oct 19, 2024
f69ec51
merged
StephenButtolph Oct 19, 2024
51f009b
nit
StephenButtolph Oct 19, 2024
36714ed
Merge branch 'implement-acp-77-add-conversion-id' into implement-acp-…
StephenButtolph Oct 19, 2024
05a7b13
nit
StephenButtolph Oct 19, 2024
09c5126
Merge branch 'implement-acp-77-add-conversion-id' into implement-acp-…
StephenButtolph Oct 19, 2024
a1db89e
nit
StephenButtolph Oct 19, 2024
2e7595c
Merge branch 'implement-acp-77-add-conversion-id' into implement-acp-…
StephenButtolph Oct 19, 2024
575b36a
remove unneeded assignment
StephenButtolph Oct 19, 2024
d2d0f69
update comment
StephenButtolph Oct 19, 2024
b6b6515
update comment
StephenButtolph Oct 19, 2024
6ffcd1b
update doc
StephenButtolph Oct 19, 2024
ad00180
Address comments
StephenButtolph Oct 20, 2024
f1b07d2
nit
StephenButtolph Oct 20, 2024
7fb99c0
fix unit tests
StephenButtolph Oct 20, 2024
65b5d50
Merge branch 'implement-acp-77-add-conversion-id' into implement-acp-…
StephenButtolph Oct 20, 2024
8791e78
merged
StephenButtolph Oct 20, 2024
f31cfc6
Add SoV Excess to P-chain state
StephenButtolph Oct 20, 2024
fe9a76d
merged
StephenButtolph Oct 20, 2024
58d5b8d
Populate BLS key diffs for subnet validators
StephenButtolph Oct 21, 2024
273fbbe
Populate BLS key diffs for subnet validators
StephenButtolph Oct 21, 2024
290ef97
Update mocks
StephenButtolph Oct 22, 2024
9155e1f
Fix tests
StephenButtolph Oct 22, 2024
cadf8f7
Merge branch 'master' into populate-subnet-public-key-diffs
StephenButtolph Oct 22, 2024
803d0c4
nit
StephenButtolph Oct 22, 2024
76f4eee
Merge branch 'populate-subnet-public-key-diffs' of github.com:ava-lab…
StephenButtolph Oct 22, 2024
a2c7773
Update test and populate public keys during startup
StephenButtolph Oct 22, 2024
95c42a1
comment
StephenButtolph Oct 23, 2024
3d7bd81
Merge branch 'master' into populate-subnet-public-key-diffs
StephenButtolph Oct 23, 2024
bbc395b
merged
StephenButtolph Oct 23, 2024
3a03597
merged
StephenButtolph Oct 23, 2024
21cdc32
Update P-chain state staker tests
StephenButtolph Oct 24, 2024
845f1d2
merged
StephenButtolph Oct 24, 2024
91a7cd7
fix test
StephenButtolph Oct 24, 2024
df02f3c
Merge branch 'update-state-staker-tests' into populate-subnet-public-…
StephenButtolph Oct 24, 2024
c848fee
fix test
StephenButtolph Oct 24, 2024
79c9b40
nit
StephenButtolph Oct 24, 2024
d8819fc
Merge branch 'master' into update-state-staker-tests
StephenButtolph Oct 24, 2024
667002e
Merge branch 'update-state-staker-tests' into populate-subnet-public-…
StephenButtolph Oct 24, 2024
31be1e2
merged
StephenButtolph Oct 24, 2024
8f0a080
merged
StephenButtolph Oct 24, 2024
d482de8
Merge branch 'populate-subnet-public-key-diffs' into implement-acp-77…
StephenButtolph Oct 24, 2024
e8b21ec
Verify no SoV + legacy overlap
StephenButtolph Oct 24, 2024
7f517c7
Fix legacy validator migration
StephenButtolph Oct 24, 2024
7d0d7e5
merged
StephenButtolph Oct 25, 2024
08bd9e3
ACP-77: Add subnetIDNodeID struct
StephenButtolph Oct 25, 2024
78c1c3d
nit
StephenButtolph Oct 26, 2024
6547c6d
Merge branch 'master' into implement-acp-77-add-subnetid-nodeid
StephenButtolph Oct 26, 2024
38ee164
Merge branch 'implement-acp-77-add-subnetid-nodeid' into implement-ac…
StephenButtolph Oct 26, 2024
d2137ef
fix merge
StephenButtolph Oct 26, 2024
5845d11
Split writeCurrentStakers into multiple functions
StephenButtolph Oct 26, 2024
6c3116a
merged
StephenButtolph Oct 27, 2024
d0d1602
reduce diff
StephenButtolph Oct 27, 2024
d397375
reduce diff
StephenButtolph Oct 27, 2024
5f8a09c
reduce diff
StephenButtolph Oct 27, 2024
3e9dc01
reduce diff
StephenButtolph Oct 27, 2024
da3a726
reduce diff
StephenButtolph Oct 27, 2024
8483ced
cleanup
StephenButtolph Oct 27, 2024
0507ce7
nit
StephenButtolph Oct 27, 2024
0022a65
Merge branch 'refactor-write-current-stakers' into implement-acp-77-s…
StephenButtolph Oct 27, 2024
8bbeee6
Add comment
StephenButtolph Oct 27, 2024
08dd776
comment
StephenButtolph Oct 27, 2024
255b0bf
nit
StephenButtolph Oct 27, 2024
3bc547d
reduce diff
StephenButtolph Oct 27, 2024
bff468d
Merge branch 'master' into refactor-write-current-stakers
StephenButtolph Oct 28, 2024
99f3c97
Merge branch 'refactor-write-current-stakers' into implement-acp-77-s…
StephenButtolph Oct 28, 2024
df4ca37
Merge branch 'master' into test-only-current-validators-api
ceyonur Oct 29, 2024
3dd5317
add L1 validators to GetCurrentValidatorSet
ceyonur Oct 29, 2024
50af053
Merge branch 'test-only-current-validators-api' of github.com:ava-lab…
ceyonur Oct 29, 2024
07ae8ed
Merge branch 'implement-acp-77-sov-validators-state' into test-only-c…
ceyonur Oct 29, 2024
e05aa37
cosmetic fix
ceyonur Oct 29, 2024
7cf1668
merged
StephenButtolph Oct 29, 2024
41f78f0
nit
StephenButtolph Oct 29, 2024
29cd6ba
nit
StephenButtolph Oct 29, 2024
8dfcbb1
Fix initValidatorSets
StephenButtolph Oct 29, 2024
ef29548
nit
StephenButtolph Oct 29, 2024
a77fb3c
test subnetIDNodeIDDB
StephenButtolph Oct 29, 2024
ce05dc8
fix comments
StephenButtolph Oct 29, 2024
3d04cef
nit
StephenButtolph Oct 29, 2024
dc35645
nit
StephenButtolph Oct 29, 2024
c299182
remove faulty test
ceyonur Oct 29, 2024
d472a9f
Reduce diff
StephenButtolph Oct 29, 2024
34ba29b
add comment
StephenButtolph Oct 29, 2024
f5d523d
remove IsL1 logic
ceyonur Oct 29, 2024
d0a947d
reviews
ceyonur Oct 30, 2024
61cace3
add new GetCurrentValidatorsSet test
ceyonur Oct 30, 2024
83a3fbf
Merge branch 'implement-acp-77-sov-validators-state' into test-only-c…
ceyonur Oct 30, 2024
97029aa
reduce diff
StephenButtolph Oct 30, 2024
dbeee70
Add NumSubnets to the validator manager interface
StephenButtolph Oct 30, 2024
729ded5
merged
StephenButtolph Oct 30, 2024
3621e53
add comment
StephenButtolph Oct 30, 2024
de2be9f
merged
StephenButtolph Oct 30, 2024
92a2277
Delete empty entries
StephenButtolph Oct 30, 2024
1bb8132
test IsSoV field
ceyonur Oct 30, 2024
11cc7e0
Merge branch 'test-only-current-validators-api' of github.com:ava-lab…
ceyonur Oct 30, 2024
6375aa2
simplify state futher
StephenButtolph Oct 30, 2024
aedff15
nit
StephenButtolph Oct 30, 2024
1ac030a
nit
StephenButtolph Oct 30, 2024
00a3ee6
remove notfound special handling
ceyonur Oct 31, 2024
9e0d7d5
Add caching
StephenButtolph Oct 31, 2024
9993b05
nit
StephenButtolph Oct 31, 2024
547d426
nit
StephenButtolph Oct 31, 2024
6bcc0ea
Add TODOs
StephenButtolph Oct 31, 2024
6065604
Merge branch 'master' into implement-acp-77-sov-validators-state
StephenButtolph Oct 31, 2024
a7792c7
Add config changes to readme
StephenButtolph Oct 31, 2024
39b961b
Merge branch 'implement-acp-77-sov-validators-state' of github.com:av…
StephenButtolph Oct 31, 2024
4723c46
Improve doc for PutSubnetOnlyValidator
StephenButtolph Oct 31, 2024
46c4889
Merge branch 'master' into implement-acp-77-sov-validators-state
StephenButtolph Oct 31, 2024
a576cd1
merged
StephenButtolph Oct 31, 2024
f1ca6e6
Add test that decreases weight
StephenButtolph Oct 31, 2024
71f88e8
Fix regression
StephenButtolph Oct 31, 2024
c2ffd17
nit
StephenButtolph Oct 31, 2024
5dd0fda
Merge branch 'implement-acp-77-sov-validators-state' into test-only-c…
ceyonur Nov 1, 2024
0b7a136
update releases md
ceyonur Nov 4, 2024
ea1fc78
Merge branch 'master' into test-only-current-validators-api
ceyonur Nov 5, 2024
b3848b9
remove TODO
ceyonur Nov 5, 2024
0ec15bf
Merge branch 'master' into test-only-current-validators-api
ceyonur Nov 5, 2024
26a8fea
reviews
ceyonur Nov 6, 2024
9a02db3
use inactive case
ceyonur Nov 6, 2024
292a744
Merge branch 'test-only-current-validators-api' of github.com:ava-lab…
ceyonur Nov 6, 2024
ac138ad
Merge branch 'master' into test-only-current-validators-api
ceyonur Nov 11, 2024
5ab910f
nits
ceyonur Nov 12, 2024
a2eba3f
merge proto definitions
ceyonur Nov 12, 2024
9a6d542
Merge branch 'master' into test-only-current-validators-api
ceyonur Nov 12, 2024
9e0c343
regen proto
ceyonur Nov 12, 2024
d7552ad
Merge branch 'test-only-current-validators-api' of github.com:ava-lab…
ceyonur Nov 12, 2024
79f77e6
add fill validationID field
ceyonur Nov 12, 2024
a47c606
revert irrelevant change
ceyonur Nov 12, 2024
7853e6b
Update proto/validatorstate/validator_state.proto
ceyonur Nov 13, 2024
c3a332e
Update vms/platformvm/validators/manager.go
ceyonur Nov 13, 2024
4792a9f
regen protobuf
ceyonur Nov 13, 2024
66739ff
remove comment
ceyonur Nov 13, 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
347 changes: 274 additions & 73 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.

19 changes: 18 additions & 1 deletion 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 validator set for the provided subnet at
// the current P-chain height.
rpc GetCurrentValidatorSet(GetCurrentValidatorSetRequest) returns (GetCurrentValidatorSetResponse);
}

message GetMinimumHeightResponse {
Expand All @@ -40,12 +43,26 @@ 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;
bytes public_key = 3; // Uncompressed public key, can be empty
uint64 start_time = 4; // can be empty
uint64 min_nonce = 5; // can be empty
bool is_active = 6; // can be empty
bytes validation_id = 7; // can be empty
bool is_sov = 8; // can be empty
}

message GetValidatorSetResponse {
repeated Validator validators = 1;
}

message GetCurrentValidatorSetResponse {
repeated Validator validators = 1;
uint64 current_height = 2;
}
48 changes: 48 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,51 @@ 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 {
// PublicKeyFromValidUncompressedBytes is used rather than
// PublicKeyFromCompressedBytes because it is significantly faster
// due to the avoidance of decompression and key re-verification. 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{
ValidationID: validationID,
NodeID: nodeID,
PublicKey: publicKey,
Weight: validator.Weight,
StartTime: validator.StartTime,
MinNonce: validator.MinNonce,
IsActive: validator.IsActive,
IsSoV: validator.IsSov,
}
}
return vdrs, resp.GetCurrentHeight(), nil
}
39 changes: 39 additions & 0 deletions snow/validators/gvalidators/validator_state_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,42 @@ 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.Validator, len(vdrs)),
CurrentHeight: currentHeight,
}

i := 0
for _, vdr := range vdrs {
vdrPB := &pb.Validator{
NodeId: vdr.NodeID.Bytes(),
StartTime: vdr.StartTime,
IsActive: vdr.IsActive,
ValidationId: vdr.ValidationID[:],
Weight: vdr.Weight,
MinNonce: vdr.MinNonce,
IsSov: vdr.IsSoV,
}
if vdr.PublicKey != nil {
// Passing in the uncompressed bytes is a performance optimization
// to avoid the cost of calling PublicKeyFromCompressedBytes on the
// client side.
vdrPB.PublicKey = bls.PublicKeyToUncompressedBytes(vdr.PublicKey)
}
resp.Validators[i] = vdrPB
i++
}
return resp, nil
}
23 changes: 23 additions & 0 deletions snow/validators/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ 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.
GetCurrentValidatorSet(
ctx context.Context,
subnetID ids.ID,
) (map[ids.ID]*GetCurrentValidatorOutput, uint64, error)
}

type lockedState struct {
Expand Down Expand Up @@ -78,6 +86,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 +109,8 @@ func NewNoValidatorsState(state State) State {
func (*noValidators) GetValidatorSet(context.Context, uint64, ids.ID) (map[ids.NodeID]*GetValidatorOutput, error) {
return nil, nil
}

func (n *noValidators) GetCurrentValidatorSet(ctx context.Context, _ ids.ID) (map[ids.ID]*GetCurrentValidatorOutput, uint64, error) {
height, err := n.GetCurrentHeight(ctx)
return nil, height, err
}
38 changes: 26 additions & 12 deletions snow/validators/traced_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,24 @@ import (
var _ State = (*tracedState)(nil)

type tracedState struct {
s State
getMinimumHeightTag string
getCurrentHeightTag string
getSubnetIDTag string
getValidatorSetTag string
tracer trace.Tracer
s State
getMinimumHeightTag string
getCurrentHeightTag string
getSubnetIDTag string
getValidatorSetTag string
getCurrentValidatorSetTag string
tracer trace.Tracer
}

func Trace(s State, name string, tracer trace.Tracer) State {
return &tracedState{
s: s,
getMinimumHeightTag: name + ".GetMinimumHeight",
getCurrentHeightTag: name + ".GetCurrentHeight",
getSubnetIDTag: name + ".GetSubnetID",
getValidatorSetTag: name + ".GetValidatorSet",
tracer: tracer,
s: s,
getMinimumHeightTag: name + ".GetMinimumHeight",
getCurrentHeightTag: name + ".GetCurrentHeight",
getSubnetIDTag: name + ".GetSubnetID",
getValidatorSetTag: name + ".GetValidatorSet",
getCurrentValidatorSetTag: name + ".GetCurrentValidatorSet",
tracer: tracer,
}
}

Expand Down Expand Up @@ -72,3 +74,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.getCurrentValidatorSetTag, oteltrace.WithAttributes(
attribute.Stringer("subnetID", subnetID),
))
defer span.End()

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

type GetCurrentValidatorOutput struct {
ValidationID ids.ID
NodeID ids.NodeID
PublicKey *bls.PublicKey
Weight uint64
StartTime uint64
MinNonce uint64
IsActive bool
IsSoV 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.

Loading
Loading