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
Changes from 11 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
34 changes: 18 additions & 16 deletions vms/platformvm/state/state.go
Original file line number Diff line number Diff line change
@@ -61,8 +61,9 @@ const (
var (
_ State = (*state)(nil)

errValidatorSetAlreadyPopulated = errors.New("validator set already populated")
errIsNotSubnet = errors.New("is not a subnet")
errValidatorSetAlreadyPopulated = errors.New("validator set already populated")
errIsNotSubnet = errors.New("is not a subnet")
errMissingPrimaryNetworkValidator = errors.New("missing primary network validator")

BlockIDPrefix = []byte("blockID")
BlockPrefix = []byte("block")
@@ -1906,9 +1907,11 @@ func (s *state) initValidatorSets() error {
}

for nodeID, subnetValidator := range subnetValidators {
// The subnet validator's Public Key is inherited from the
// corresponding primary network validator.
primaryValidator, ok := primaryNetworkValidators[nodeID]
if !ok {
return errors.New("subnet validator without corresponding primary network validator")
return fmt.Errorf("%w: %s", errMissingPrimaryNetworkValidator, nodeID)
}

var (
@@ -2507,7 +2510,9 @@ func (s *state) makeSubnetOnlyValidatorHistoricalDiffs() (map[subnetIDNodeID]*va

func (s *state) writeCurrentStakers(updateValidators bool, height uint64, codecVersion uint16) error {
for subnetID, validatorDiffs := range s.currentStakers.validatorDiffs {
// Write the primary network diff last
// We must write the primary network stakers last because writing subnet
// validator diffs may depend on the primary network validator diffs to
// inherit the public keys.
if subnetID == constants.PrimaryNetworkID {
continue
}
@@ -2575,9 +2580,6 @@ func (s *state) writeCurrentStakersSubnetDiff(

// Record the change in weight and/or public key for each validator.
for nodeID, validatorDiff := range validatorDiffs {
// Copy [nodeID] so it doesn't get overwritten next iteration.
nodeID := nodeID

var (
staker *Staker
pk *bls.PublicKey
@@ -2601,8 +2603,10 @@ func (s *state) writeCurrentStakersSubnetDiff(
// writing.
pk = vdr.validator.PublicKey
} else {
// This should never happen.
return errors.New("missing primary network validator")
// This should never happen as the primary network diffs are
// written last and subnet validator times must be a subset
// of the primary network validator times.
return fmt.Errorf("%w: %s", errMissingPrimaryNetworkValidator, nodeID)
}
}

@@ -2612,9 +2616,8 @@ func (s *state) writeCurrentStakersSubnetDiff(
switch validatorDiff.validatorStatus {
case added:
if pk != nil {
// Record that the public key for the validator is being
// added. This means the prior value for the public key was
// nil.
// Record that the public key for the validator is being added.
// This means the prior value for the public key was nil.
err := s.validatorPublicKeyDiffsDB.Put(
marshalDiffKey(subnetID, height, nodeID),
nil,
@@ -2626,8 +2629,8 @@ func (s *state) writeCurrentStakersSubnetDiff(

// The validator is being added.
//
// Invariant: It's impossible for a delegator to have been
// rewarded in the same block that the validator was added.
// Invariant: It's impossible for a delegator to have been rewarded
// in the same block that the validator was added.
startTime := uint64(staker.StartTime.Unix())
metadata := &validatorMetadata{
txID: staker.TxID,
@@ -2657,8 +2660,7 @@ func (s *state) writeCurrentStakersSubnetDiff(
// public key.
//
// Note: We store the uncompressed public key here as it is
// significantly more efficient to parse when applying
// diffs.
// significantly more efficient to parse when applying diffs.
err := s.validatorPublicKeyDiffsDB.Put(
marshalDiffKey(subnetID, height, nodeID),
bls.PublicKeyToUncompressedBytes(pk),
189 changes: 139 additions & 50 deletions vms/platformvm/state/state_test.go
Original file line number Diff line number Diff line change
@@ -119,10 +119,10 @@ func TestPersistStakers(t *testing.T) {
primaryValidatorDuration = 28 * 24 * time.Hour
primaryDelegatorDuration = 14 * 24 * time.Hour
subnetValidatorDuration = 21 * 24 * time.Hour
subnetDelegatorDuration = 14 * 24 * time.Hour

primaryValidatorReward = iota
primaryDelegatorReward
subnetValidatorReward
)
var (
primaryValidatorStartTime = time.Now().Truncate(time.Second)
@@ -133,6 +133,10 @@ func TestPersistStakers(t *testing.T) {
primaryDelegatorEndTime = primaryDelegatorStartTime.Add(primaryDelegatorDuration)
primaryDelegatorEndTimeUnix = uint64(primaryDelegatorEndTime.Unix())

subnetValidatorStartTime = primaryValidatorStartTime
subnetValidatorEndTime = subnetValidatorStartTime.Add(subnetValidatorDuration)
subnetValidatorEndTimeUnix = uint64(subnetValidatorEndTime.Unix())

primaryValidatorData = txs.Validator{
NodeID: ids.GenerateTestNodeID(),
End: primaryValidatorEndTimeUnix,
@@ -143,6 +147,13 @@ func TestPersistStakers(t *testing.T) {
End: primaryDelegatorEndTimeUnix,
Wght: 6789,
}
subnetValidatorData = txs.Validator{
NodeID: primaryValidatorData.NodeID,
End: subnetValidatorEndTimeUnix,
Wght: 9876,
}

subnetID = ids.GenerateTestID()
)

unsignedAddPrimaryNetworkValidator := createPermissionlessValidatorTx(t, constants.PrimaryNetworkID, primaryValidatorData)
@@ -181,6 +192,18 @@ func TestPersistStakers(t *testing.T) {
)
require.NoError(t, err)

unsignedAddSubnetValidator := createPermissionlessValidatorTx(t, subnetID, subnetValidatorData)
addSubnetValidator := &txs.Tx{Unsigned: unsignedAddSubnetValidator}
require.NoError(t, addSubnetValidator.Initialize(txs.Codec))

subnetCurrentValidatorStaker, err := NewCurrentStaker(
addSubnetValidator.ID(),
unsignedAddSubnetValidator,
subnetValidatorStartTime,
subnetValidatorReward,
)
require.NoError(t, err)

tests := map[string]struct {
initialStakers []*Staker
initialTxs []*txs.Tx
@@ -248,6 +271,23 @@ func TestPersistStakers(t *testing.T) {
expectedPendingValidator: primaryNetworkPendingValidatorStaker,
expectedPendingDelegators: []*Staker{primaryNetworkPendingDelegatorStaker},
},
"add current subnet validator": {
initialStakers: []*Staker{primaryNetworkCurrentValidatorStaker},
initialTxs: []*txs.Tx{addPrimaryNetworkValidator},
staker: subnetCurrentValidatorStaker,
tx: addSubnetValidator,
expectedCurrentValidator: subnetCurrentValidatorStaker,
expectedValidatorSetOutput: &validators.GetValidatorOutput{
NodeID: subnetCurrentValidatorStaker.NodeID,
PublicKey: primaryNetworkCurrentValidatorStaker.PublicKey,
Weight: subnetCurrentValidatorStaker.Weight,
},
expectedWeightDiff: &ValidatorWeightDiff{
Decrease: false,
Amount: subnetCurrentValidatorStaker.Weight,
},
expectedPublicKeyDiff: maybe.Some[*bls.PublicKey](nil),
},
"delete current primary network validator": {
initialStakers: []*Staker{primaryNetworkCurrentValidatorStaker},
initialTxs: []*txs.Tx{addPrimaryNetworkValidator},
@@ -296,6 +336,16 @@ func TestPersistStakers(t *testing.T) {
staker: primaryNetworkPendingDelegatorStaker,
expectedPendingValidator: primaryNetworkPendingValidatorStaker,
},
"delete current subnet validator": {
initialStakers: []*Staker{primaryNetworkCurrentValidatorStaker, subnetCurrentValidatorStaker},
initialTxs: []*txs.Tx{addPrimaryNetworkValidator, addSubnetValidator},
staker: subnetCurrentValidatorStaker,
expectedWeightDiff: &ValidatorWeightDiff{
Decrease: true,
Amount: subnetCurrentValidatorStaker.Weight,
},
expectedPublicKeyDiff: maybe.Some[*bls.PublicKey](primaryNetworkCurrentValidatorStaker.PublicKey),
},
}

for name, test := range tests {
@@ -366,18 +416,22 @@ func TestPersistStakers(t *testing.T) {
if test.expectedCurrentValidator == nil {
require.ErrorIs(err, database.ErrNotFound)

// Only current validators should have uptimes
_, _, err := state.GetUptime(test.staker.NodeID)
require.ErrorIs(err, database.ErrNotFound)
if test.staker.SubnetID == constants.PrimaryNetworkID {
// Uptimes are only considered for primary network validators
_, _, err := state.GetUptime(test.staker.NodeID)
require.ErrorIs(err, database.ErrNotFound)
}
} else {
require.NoError(err)
require.Equal(test.expectedCurrentValidator, currentValidator)

// Current validators should also have uptimes
upDuration, lastUpdated, err := state.GetUptime(currentValidator.NodeID)
require.NoError(err)
require.Zero(upDuration)
require.Equal(currentValidator.StartTime, lastUpdated)
if test.staker.SubnetID == constants.PrimaryNetworkID {
// Uptimes are only considered for primary network validators
upDuration, lastUpdated, err := state.GetUptime(currentValidator.NodeID)
require.NoError(err)
require.Zero(upDuration)
require.Equal(currentValidator.StartTime, lastUpdated)
}
}

pendingValidator, err := state.GetPendingValidator(test.staker.SubnetID, test.staker.NodeID)
@@ -430,18 +484,14 @@ func TestPersistStakers(t *testing.T) {
require.Equal(expectedPublicKeyDiff, bls.PublicKeyFromValidUncompressedBytes(publicKeyDiffBytes))
}

// re-load the state from disk
// re-load the state from disk for the second iteration
state = newTestState(t, db)
}
})
}
}

func createPermissionlessValidatorTx(
t testing.TB,
subnetID ids.ID,
validatorsData txs.Validator,
) *txs.AddPermissionlessValidatorTx {
func createPermissionlessValidatorTx(t testing.TB, subnetID ids.ID, validatorsData txs.Validator) *txs.AddPermissionlessValidatorTx {
var sig signer.Signer = &signer.Empty{}
if subnetID == constants.PrimaryNetworkID {
sk, err := bls.NewSecretKey()
@@ -902,7 +952,6 @@ func TestStateAddRemoveValidator(t *testing.T) {

var expectedValidators set.Set[subnetIDNodeID]
for _, added := range diff.addedValidators {
added := added
require.NoError(d.PutCurrentValidator(&added))

expectedValidators.Add(subnetIDNodeID{
@@ -911,7 +960,6 @@ func TestStateAddRemoveValidator(t *testing.T) {
})
}
for _, removed := range diff.removedValidators {
removed := removed
d.DeleteCurrentValidator(&removed)

expectedValidators.Remove(subnetIDNodeID{
@@ -946,43 +994,84 @@ func TestStateAddRemoveValidator(t *testing.T) {
require.ErrorIs(err, database.ErrNotFound)
}

primaryValidatorSet := state.validators.GetMap(constants.PrimaryNetworkID)
delete(primaryValidatorSet, defaultValidatorNodeID) // Ignore the genesis validator
require.Equal(diff.expectedPrimaryValidatorSet, primaryValidatorSet)

require.Equal(diff.expectedSubnetValidatorSet, state.validators.GetMap(subnetID))

for i := 0; i < currentIndex; i++ {
prevDiff := diffs[i]
prevHeight := uint64(i + 1)

primaryValidatorSet := copyValidatorSet(diff.expectedPrimaryValidatorSet)
require.NoError(state.ApplyValidatorWeightDiffs(
context.Background(),
primaryValidatorSet,
currentHeight,
prevHeight+1,
constants.PrimaryNetworkID,
))
require.NoError(state.ApplyValidatorPublicKeyDiffs(
context.Background(),
primaryValidatorSet,
currentHeight,
prevHeight+1,
constants.PrimaryNetworkID,
))
require.Equal(prevDiff.expectedPrimaryValidatorSet, primaryValidatorSet)

subnetValidatorSet := copyValidatorSet(diff.expectedSubnetValidatorSet)
require.NoError(state.ApplyValidatorWeightDiffs(
context.Background(),
subnetValidatorSet,
currentHeight,
prevHeight+1,
subnetID,
))
require.NoError(state.ApplyValidatorPublicKeyDiffs(
context.Background(),
subnetValidatorSet,
currentHeight,
prevHeight+1,
subnetID,
))
require.Equal(prevDiff.expectedSubnetValidatorSet, subnetValidatorSet)
{
primaryValidatorSet := copyValidatorSet(diff.expectedPrimaryValidatorSet)
require.NoError(state.ApplyValidatorWeightDiffs(
context.Background(),
primaryValidatorSet,
currentHeight,
prevHeight+1,
constants.PrimaryNetworkID,
))
require.NoError(state.ApplyValidatorPublicKeyDiffs(
context.Background(),
primaryValidatorSet,
currentHeight,
prevHeight+1,
constants.PrimaryNetworkID,
))
require.Equal(prevDiff.expectedPrimaryValidatorSet, primaryValidatorSet)
}

{
legacySubnetValidatorSet := copyValidatorSet(diff.expectedSubnetValidatorSet)
require.NoError(state.ApplyValidatorWeightDiffs(
context.Background(),
legacySubnetValidatorSet,
currentHeight,
prevHeight+1,
subnetID,
))

// Update the public keys of the subnet validators with the current
// primary network validator public keys
for nodeID, vdr := range legacySubnetValidatorSet {
if primaryVdr, ok := diff.expectedPrimaryValidatorSet[nodeID]; ok {
vdr.PublicKey = primaryVdr.PublicKey
} else {
vdr.PublicKey = nil
}
}

require.NoError(state.ApplyValidatorPublicKeyDiffs(
context.Background(),
legacySubnetValidatorSet,
currentHeight,
prevHeight+1,
constants.PrimaryNetworkID,
))
require.Equal(prevDiff.expectedSubnetValidatorSet, legacySubnetValidatorSet)
}

{
subnetValidatorSet := copyValidatorSet(diff.expectedSubnetValidatorSet)
require.NoError(state.ApplyValidatorWeightDiffs(
context.Background(),
subnetValidatorSet,
currentHeight,
prevHeight+1,
subnetID,
))

require.NoError(state.ApplyValidatorPublicKeyDiffs(
context.Background(),
subnetValidatorSet,
currentHeight,
prevHeight+1,
subnetID,
))
require.Equal(prevDiff.expectedSubnetValidatorSet, subnetValidatorSet)
}
}
}
}