-
Notifications
You must be signed in to change notification settings - Fork 671
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
[vms/platformvm] Replace GetSubnets
with GetSubnetIDs
in State
#3055
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
870067a
[vms/platformvm] Return correct owner in `GetSubnets` after transfer
dhrubabasu 6b51777
save
dhrubabasu fdb5b96
lint
dhrubabasu 1e30022
nit
dhrubabasu ce51fc5
Merge branch 'master' into getSubnetIDs
dhrubabasu fb7eddf
nits
dhrubabasu fea3ad5
nit
dhrubabasu ceef49f
nit
dhrubabasu 988de1b
nit
dhrubabasu 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 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
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 |
---|---|---|
|
@@ -104,7 +104,7 @@ type Chain interface { | |
|
||
AddRewardUTXO(txID ids.ID, utxo *avax.UTXO) | ||
|
||
AddSubnet(createSubnetTx *txs.Tx) | ||
AddSubnet(subnetID ids.ID) | ||
|
||
GetSubnetOwner(subnetID ids.ID) (fx.Owner, error) | ||
SetSubnetOwner(subnetID ids.ID, owner fx.Owner) | ||
|
@@ -134,7 +134,7 @@ type State interface { | |
GetBlockIDAtHeight(height uint64) (ids.ID, error) | ||
|
||
GetRewardUTXOs(txID ids.ID) ([]*avax.UTXO, error) | ||
GetSubnets() ([]*txs.Tx, error) | ||
GetSubnetIDs() ([]ids.ID, error) | ||
GetChains(subnetID ids.ID) ([]*txs.Tx, error) | ||
|
||
// ApplyValidatorWeightDiffs iterates from [startHeight] towards the genesis | ||
|
@@ -330,10 +330,10 @@ type state struct { | |
utxoDB database.Database | ||
utxoState avax.UTXOState | ||
|
||
cachedSubnets []*txs.Tx // nil if the subnets haven't been loaded | ||
addedSubnets []*txs.Tx | ||
subnetBaseDB database.Database | ||
subnetDB linkeddb.LinkedDB | ||
cachedSubnetIDs []ids.ID // nil if the subnets haven't been loaded | ||
addedSubnetIDs []ids.ID | ||
subnetBaseDB database.Database | ||
subnetDB linkeddb.LinkedDB | ||
|
||
// Subnet ID --> Owner of the subnet | ||
subnetOwners map[ids.ID]fx.Owner | ||
|
@@ -728,39 +728,35 @@ func (s *state) doneInit() error { | |
return s.singletonDB.Put(InitializedKey, nil) | ||
} | ||
|
||
func (s *state) GetSubnets() ([]*txs.Tx, error) { | ||
if s.cachedSubnets != nil { | ||
return s.cachedSubnets, nil | ||
func (s *state) GetSubnetIDs() ([]ids.ID, error) { | ||
if s.cachedSubnetIDs != nil { | ||
return s.cachedSubnetIDs, nil | ||
} | ||
|
||
subnetDBIt := s.subnetDB.NewIterator() | ||
defer subnetDBIt.Release() | ||
|
||
txs := []*txs.Tx(nil) | ||
subnetIDs := []ids.ID{} | ||
for subnetDBIt.Next() { | ||
subnetIDBytes := subnetDBIt.Key() | ||
subnetID, err := ids.ToID(subnetIDBytes) | ||
if err != nil { | ||
return nil, err | ||
} | ||
subnetTx, _, err := s.GetTx(subnetID) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing this |
||
if err != nil { | ||
return nil, err | ||
} | ||
txs = append(txs, subnetTx) | ||
subnetIDs = append(subnetIDs, subnetID) | ||
} | ||
if err := subnetDBIt.Error(); err != nil { | ||
return nil, err | ||
} | ||
txs = append(txs, s.addedSubnets...) | ||
s.cachedSubnets = txs | ||
return txs, nil | ||
subnetIDs = append(subnetIDs, s.addedSubnetIDs...) | ||
s.cachedSubnetIDs = subnetIDs | ||
return subnetIDs, nil | ||
} | ||
|
||
func (s *state) AddSubnet(createSubnetTx *txs.Tx) { | ||
s.addedSubnets = append(s.addedSubnets, createSubnetTx) | ||
if s.cachedSubnets != nil { | ||
s.cachedSubnets = append(s.cachedSubnets, createSubnetTx) | ||
func (s *state) AddSubnet(subnetID ids.ID) { | ||
s.addedSubnetIDs = append(s.addedSubnetIDs, subnetID) | ||
if s.cachedSubnetIDs != nil { | ||
s.cachedSubnetIDs = append(s.cachedSubnetIDs, subnetID) | ||
} | ||
} | ||
|
||
|
@@ -2185,14 +2181,12 @@ func (s *state) writeUTXOs() error { | |
} | ||
|
||
func (s *state) writeSubnets() error { | ||
for _, subnet := range s.addedSubnets { | ||
subnetID := subnet.ID() | ||
|
||
for _, subnetID := range s.addedSubnetIDs { | ||
if err := s.subnetDB.Put(subnetID[:], nil); err != nil { | ||
return fmt.Errorf("failed to write subnet: %w", err) | ||
} | ||
} | ||
s.addedSubnets = nil | ||
s.addedSubnetIDs = nil | ||
return nil | ||
} | ||
|
||
|
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a super small change in behavior, but I think it's a good change. In the case that there are no subnets (which isn't realistic in most cases outside of testing), previously we wouldn't cache the lookup. Now we will cache the lookup as there being no subnets.