-
Notifications
You must be signed in to change notification settings - Fork 807
Add SoV state struct #3370
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
Merged
Merged
Add SoV state struct #3370
Changes from all commits
Commits
Show all changes
175 commits
Select commit
Hold shift + click to select a range
1857cb9
[vms/platformvm] Add tracking of a Subnet manager
dhrubabasu 4d11a29
Merge branch 'master' into store-warp-addressed-call-pair
dhrubabasu 90a38ff
Update vms/platformvm/state/diff.go
dhrubabasu f60e4ea
nit
dhrubabasu 1ca0caf
nit
dhrubabasu 1cd2428
nit
dhrubabasu 3587c32
nit
dhrubabasu ec16c11
[vms/platformvm] Cleanup execution config tests
dhrubabasu f52cbbe
Merge branch 'master' into cleanup-execution-config-test
dhrubabasu 076b1f0
nit
dhrubabasu df5ca64
nit
dhrubabasu dcc056b
Merge branch 'master' into cleanup-execution-config-test
dhrubabasu 3279764
nit
dhrubabasu 911a167
mark as helper
dhrubabasu ddf3392
Merge branch 'master' into cleanup-execution-config-test
dhrubabasu 25802a8
merged
dhrubabasu 01b854a
reduce diff
dhrubabasu f79e0c7
add write
dhrubabasu 1eda29c
merged
dhrubabasu 3fa1306
nits
dhrubabasu 16ffe7b
nit
dhrubabasu 3035064
nits
dhrubabasu 62ece94
Merge branch 'master' into store-warp-addressed-call-pair
dhrubabasu 333a41e
fix UT
dhrubabasu 520ac91
add UTs
dhrubabasu db5f197
lint
dhrubabasu 574a120
nit
dhrubabasu 501beb1
nit
dhrubabasu ab5c23b
add test for cache
dhrubabasu e0d0a00
Merge branch 'master' into store-warp-addressed-call-pair
dhrubabasu 12a1969
wip
dhrubabasu cda1001
table tests
dhrubabasu 2ff46f4
Merge branch 'master' into store-warp-addressed-call-pair
dhrubabasu e05a514
Merge branch 'store-warp-addressed-call-pair' into ConvertSubnetTx
dhrubabasu 7ab0094
wip
dhrubabasu 79e84b1
wip
dhrubabasu 264a73f
merged
dhrubabasu 1340a51
nits
dhrubabasu 62f6d78
nits
dhrubabasu 6e54ba7
nits
dhrubabasu 68e621d
passing
dhrubabasu 8e9f406
add tests
dhrubabasu dd08695
reduce scope
dhrubabasu 3042de2
nit
dhrubabasu 9b8aa4a
merged
dhrubabasu 1d72e1b
nits
dhrubabasu 5126df9
merged
dhrubabasu 909a24c
Etna
dhrubabasu c1299c8
nit
dhrubabasu a2d0968
nit
dhrubabasu aa6b6f6
Implement SoV data struct
dhrubabasu be79d4c
Merge branch 'master' into disable-permissioned-subnet-txs-post-manager
dhrubabasu 367cf42
disable CreateChainTx
dhrubabasu a14f140
pass CI
dhrubabasu eed7d1a
wire in validatorWeightDiffsDB and validatorPublicKeyDiffsDB
dhrubabasu 30240fc
wip
dhrubabasu 9fe5414
passing for now
dhrubabasu 413a7a9
Merge branch 'master' into disable-permissioned-subnet-txs-post-manager
dhrubabasu c988391
nit
dhrubabasu 3f49097
move write
dhrubabasu 447e326
reduce footpring
dhrubabasu b23b654
nit
dhrubabasu 952fd7f
nit
dhrubabasu db18027
nit
dhrubabasu e019360
Merge branch 'master' into disable-permissioned-subnet-txs-post-manager
dhrubabasu 43b2b53
merged
dhrubabasu fe4f3d6
Merge branch 'disable-permissioned-subnet-txs-post-manager' into Conv…
dhrubabasu ddf94a4
RemoveSubnet
dhrubabasu 4a5fecb
Merge branch 'disable-permissioned-subnet-txs-post-manager' into Conv…
dhrubabasu 643ddbd
fix test
dhrubabasu 215821f
Merge branch 'disable-permissioned-subnet-txs-post-manager' into Conv…
dhrubabasu bdc015d
wip e2e
dhrubabasu d1652c0
fix build
dhrubabasu 4fb9e17
wip
dhrubabasu 2555a6a
nit
dhrubabasu 751bdea
nit
dhrubabasu 1c91b02
nit
dhrubabasu 82ce5d0
finish e2e
dhrubabasu 4c2205e
nit
dhrubabasu 0ba141d
nit
dhrubabasu e537d23
nit
dhrubabasu f18163b
Merge branch 'ConvertSubnetTx' into sov-data-struct
dhrubabasu 35e0580
wip
dhrubabasu a61fb06
Merge branch 'ConvertSubnetTx' into sov-data-struct
dhrubabasu b42de99
merged
dhrubabasu 4a1ca5c
minimize
dhrubabasu 0b15984
nit
dhrubabasu 99378b4
reduce diff
dhrubabasu 1684fdb
cleanup e2e
dhrubabasu 22ac121
Merge branch 'master' into ConvertSubnetTx
dhrubabasu a8524ba
cleanup
dhrubabasu b5df28b
cap address size to 4096
dhrubabasu bed839d
skip correctly
dhrubabasu 4adc17e
nit
dhrubabasu ffeb3d3
nits
dhrubabasu 37cbc52
linear scan... for now
dhrubabasu 4edc421
Merge branch 'master' into ConvertSubnetTx
dhrubabasu 67e2bef
Merge branch 'ConvertSubnetTx' into sov-data-struct
dhrubabasu 63d5ac7
int
dhrubabasu ece7c2b
wip
dhrubabasu 92a7187
cleanup complexity
dhrubabasu 144dad2
fix
dhrubabasu 6cc89e1
Merge branch 'ConvertSubnetTx' into sov-data-struct
dhrubabasu 1503bd4
merged
dhrubabasu 7dd74b5
Merge branch 'ConvertSubnetTx' into sov-data-struct
dhrubabasu 6a0db3f
nit
dhrubabasu 4afac28
merged
dhrubabasu 5545958
Merge branch 'ConvertSubnetTx' into sov-data-struct
dhrubabasu 41127c9
nit
dhrubabasu 8b54f2f
Merge branch 'ConvertSubnetTx' into sov-data-struct
dhrubabasu 13238f1
nit
dhrubabasu fdc1069
nit
dhrubabasu 57dc1be
Merge branch 'ConvertSubnetTx' into sov-data-struct
dhrubabasu 85ce497
nit
dhrubabasu 33e7126
nit
dhrubabasu 15473d5
Merge branch 'ConvertSubnetTx' into sov-data-struct
dhrubabasu 58eebf4
nit
dhrubabasu f7a5558
wip
dhrubabasu f33f9a7
nit
dhrubabasu 499f19c
Separate codec registries by upgrade
StephenButtolph dfaff2e
merged
StephenButtolph 6b26b49
nit
StephenButtolph aeddd28
Merge branch 'separate-codec-by-upgrade' into ConvertSubnetTx
StephenButtolph 3dcdcda
Update naming
StephenButtolph 64a6c53
Use hex output
StephenButtolph ad664a0
Reduce diff
StephenButtolph 186cf8d
Improve json format
StephenButtolph de97114
Improve tests
StephenButtolph 40a2cae
Fix error
StephenButtolph b0ce060
cleanup test
StephenButtolph 0ecfc50
remove static fee support
StephenButtolph 06534fc
reduce diff
StephenButtolph a44b68a
nit
StephenButtolph 68a6e24
fix comment
StephenButtolph 61640da
Add builder test
StephenButtolph 1619e79
nit
StephenButtolph f536353
Remove usage of mocks
StephenButtolph f6339b5
nit
StephenButtolph 91338cb
fix test
StephenButtolph f602280
Support unmarshalling of json byte slices
StephenButtolph c3b076b
standardize json and add tests
StephenButtolph 4328bac
fix marshal tests
StephenButtolph 805ae43
fix marshal more tests
StephenButtolph 518cf19
fix even marshal more tests
StephenButtolph 26b3702
merged
StephenButtolph e1f55a5
Nit use var
StephenButtolph 8895f27
Cleanup serialization tests
StephenButtolph aa7f222
Add comment
StephenButtolph 91c8619
var block
StephenButtolph b5638e0
reorder
StephenButtolph 4831205
Merge branch 'master' into ConvertSubnetTx
StephenButtolph df3fb4c
embed json
StephenButtolph 8f8ebc9
Merge branch 'ConvertSubnetTx' of github.com:ava-labs/avalanchego int…
StephenButtolph d87a472
huh tabs are os dependent?
StephenButtolph ff95e5b
I misread the error, it was returns
StephenButtolph 7aee249
Merge branch 'ConvertSubnetTx' into sov-data-struct
StephenButtolph 1ca22eb
Merge branch 'master' into sov-data-struct
StephenButtolph bd52982
Implement acp-77 fee calculations
StephenButtolph a0af420
fix comment
StephenButtolph 2bc3f86
fix test
StephenButtolph 1a8e5f2
fix comment
StephenButtolph 29af8da
comment grammer
StephenButtolph 77a9820
Implement function
StephenButtolph 471871f
Merge branch 'implement-acp-77-fees' into sov-data-struct
StephenButtolph a490641
merge fee implementation
StephenButtolph 62a2ae1
Add CalculateExcess tests
StephenButtolph c780c34
Merge branch 'implement-acp-77-fees' into sov-data-struct
StephenButtolph 5af7744
Remove validator state struct
StephenButtolph c43629d
Add SoV state struct
StephenButtolph d7f3f01
Comment nits
StephenButtolph 0d6d40b
Add less type assertion
StephenButtolph 21d9229
Add StartTime
StephenButtolph 233af70
Merge branch 'sov-data-struct' into add-sov-struct
StephenButtolph 16b35e0
Reduce diff
StephenButtolph 4c0e0f8
Merge branch 'master' into add-sov-struct
StephenButtolph File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package state | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/google/btree" | ||
|
||
"github.com/ava-labs/avalanchego/database" | ||
"github.com/ava-labs/avalanchego/ids" | ||
"github.com/ava-labs/avalanchego/vms/platformvm/block" | ||
) | ||
|
||
var _ btree.LessFunc[*SubnetOnlyValidator] = (*SubnetOnlyValidator).Less | ||
|
||
type SubnetOnlyValidator struct { | ||
// ValidationID is not serialized because it is used as the key in the | ||
// database, so it doesn't need to be stored in the value. | ||
ValidationID ids.ID | ||
|
||
SubnetID ids.ID `serialize:"true"` | ||
NodeID ids.NodeID `serialize:"true"` | ||
|
||
// PublicKey is the uncompressed BLS public key of the validator. It is | ||
// guaranteed to be populated. | ||
PublicKey []byte `serialize:"true"` | ||
|
||
// StartTime is the unix timestamp, in seconds, when this validator was | ||
// added to the set. | ||
StartTime uint64 `serialize:"true"` | ||
|
||
// Weight of this validator. It can be updated when the MinNonce is | ||
// increased. If the weight is being set to 0, the validator is being | ||
// removed. | ||
Weight uint64 `serialize:"true"` | ||
ceyonur marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// MinNonce is the smallest nonce that can be used to modify this | ||
// validator's weight. It is initially set to 0 and is set to one higher | ||
// than the last nonce used. It is not valid to use nonce MaxUint64 unless | ||
// the weight is being set to 0, which removes the validator from the set. | ||
MinNonce uint64 `serialize:"true"` | ||
|
||
// EndAccumulatedFee is the amount of globally accumulated fees that can | ||
// accrue before this validator must be deactivated. It is equal to the | ||
// amount of fees this validator is willing to pay plus the amount of | ||
// globally accumulated fees when this validator started validating. | ||
EndAccumulatedFee uint64 `serialize:"true"` | ||
} | ||
|
||
// Less determines a canonical ordering of *SubnetOnlyValidators based on their | ||
// EndAccumulatedFees and ValidationIDs. | ||
// | ||
// Returns true if: | ||
// | ||
// 1. This validator has a lower EndAccumulatedFee than the other. | ||
// 2. This validator has an equal EndAccumulatedFee to the other and has a | ||
// lexicographically lower ValidationID. | ||
func (v *SubnetOnlyValidator) Less(o *SubnetOnlyValidator) bool { | ||
switch { | ||
case v.EndAccumulatedFee < o.EndAccumulatedFee: | ||
return true | ||
case o.EndAccumulatedFee < v.EndAccumulatedFee: | ||
return false | ||
default: | ||
return v.ValidationID.Compare(o.ValidationID) == -1 | ||
} | ||
} | ||
|
||
func getSubnetOnlyValidator(db database.KeyValueReader, validationID ids.ID) (*SubnetOnlyValidator, error) { | ||
bytes, err := db.Get(validationID[:]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
vdr := &SubnetOnlyValidator{ | ||
ValidationID: validationID, | ||
} | ||
if _, err = block.GenesisCodec.Unmarshal(bytes, vdr); err != nil { | ||
return nil, fmt.Errorf("failed to unmarshal SubnetOnlyValidator: %w", err) | ||
} | ||
return vdr, err | ||
} | ||
|
||
func putSubnetOnlyValidator(db database.KeyValueWriter, vdr *SubnetOnlyValidator) error { | ||
bytes, err := block.GenesisCodec.Marshal(block.CodecVersion, vdr) | ||
if err != nil { | ||
return fmt.Errorf("failed to marshal SubnetOnlyValidator: %w", err) | ||
} | ||
return db.Put(vdr.ValidationID[:], bytes) | ||
} | ||
|
||
func deleteSubnetOnlyValidator(db database.KeyValueDeleter, validationID ids.ID) error { | ||
return db.Delete(validationID[:]) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package state | ||
|
||
import ( | ||
"math/rand" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/ava-labs/avalanchego/database" | ||
"github.com/ava-labs/avalanchego/database/memdb" | ||
"github.com/ava-labs/avalanchego/ids" | ||
"github.com/ava-labs/avalanchego/utils/crypto/bls" | ||
) | ||
|
||
func TestSubnetOnlyValidator_Less(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
v *SubnetOnlyValidator | ||
o *SubnetOnlyValidator | ||
equal bool | ||
}{ | ||
{ | ||
name: "v.EndAccumulatedFee < o.EndAccumulatedFee", | ||
v: &SubnetOnlyValidator{ | ||
ValidationID: ids.GenerateTestID(), | ||
EndAccumulatedFee: 1, | ||
}, | ||
o: &SubnetOnlyValidator{ | ||
ValidationID: ids.GenerateTestID(), | ||
EndAccumulatedFee: 2, | ||
}, | ||
equal: false, | ||
}, | ||
{ | ||
name: "v.EndAccumulatedFee = o.EndAccumulatedFee, v.ValidationID < o.ValidationID", | ||
v: &SubnetOnlyValidator{ | ||
ValidationID: ids.ID{0}, | ||
EndAccumulatedFee: 1, | ||
}, | ||
o: &SubnetOnlyValidator{ | ||
ValidationID: ids.ID{1}, | ||
EndAccumulatedFee: 1, | ||
}, | ||
equal: false, | ||
}, | ||
{ | ||
name: "v.EndAccumulatedFee = o.EndAccumulatedFee, v.ValidationID = o.ValidationID", | ||
v: &SubnetOnlyValidator{ | ||
ValidationID: ids.ID{0}, | ||
EndAccumulatedFee: 1, | ||
}, | ||
o: &SubnetOnlyValidator{ | ||
ValidationID: ids.ID{0}, | ||
EndAccumulatedFee: 1, | ||
}, | ||
equal: true, | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
require := require.New(t) | ||
|
||
less := test.v.Less(test.o) | ||
require.Equal(!test.equal, less) | ||
|
||
greater := test.o.Less(test.v) | ||
require.False(greater) | ||
}) | ||
} | ||
} | ||
|
||
func TestSubnetOnlyValidator_DatabaseHelpers(t *testing.T) { | ||
require := require.New(t) | ||
db := memdb.New() | ||
|
||
sk, err := bls.NewSecretKey() | ||
require.NoError(err) | ||
|
||
vdr := &SubnetOnlyValidator{ | ||
ValidationID: ids.GenerateTestID(), | ||
SubnetID: ids.GenerateTestID(), | ||
NodeID: ids.GenerateTestNodeID(), | ||
PublicKey: bls.PublicKeyToUncompressedBytes(bls.PublicFromSecretKey(sk)), | ||
StartTime: rand.Uint64(), // #nosec G404 | ||
Weight: rand.Uint64(), // #nosec G404 | ||
MinNonce: rand.Uint64(), // #nosec G404 | ||
EndAccumulatedFee: rand.Uint64(), // #nosec G404 | ||
} | ||
|
||
// Validator hasn't been put on disk yet | ||
gotVdr, err := getSubnetOnlyValidator(db, vdr.ValidationID) | ||
require.ErrorIs(err, database.ErrNotFound) | ||
require.Nil(gotVdr) | ||
|
||
// Place the validator on disk | ||
require.NoError(putSubnetOnlyValidator(db, vdr)) | ||
|
||
// Verify that the validator can be fetched from disk | ||
gotVdr, err = getSubnetOnlyValidator(db, vdr.ValidationID) | ||
require.NoError(err) | ||
require.Equal(vdr, gotVdr) | ||
|
||
// Remove the validator from disk | ||
require.NoError(deleteSubnetOnlyValidator(db, vdr.ValidationID)) | ||
|
||
// Verify that the validator has been removed from disk | ||
gotVdr, err = getSubnetOnlyValidator(db, vdr.ValidationID) | ||
require.ErrorIs(err, database.ErrNotFound) | ||
require.Nil(gotVdr) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.