-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
feat(store/v2): add version exists #22235
Changes from all commits
59b785b
a3168cc
dffb45d
64ae24d
cbd465c
72feb12
fd3909c
74de046
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,19 +7,29 @@ import ( | |
"cosmossdk.io/store/v2/proof" | ||
) | ||
|
||
// VersionedDatabase defines an API for a versioned database that allows reads, | ||
// VersionedWriter defines an API for a versioned database that allows reads, | ||
// writes, iteration and commitment over a series of versions. | ||
type VersionedDatabase interface { | ||
type VersionedWriter interface { | ||
VersionedReader | ||
|
||
SetLatestVersion(version uint64) error | ||
ApplyChangeset(version uint64, cs *corestore.Changeset) error | ||
Comment on lines
+15
to
+16
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. Add missing documentation for exported methods The methods |
||
|
||
// Close releases associated resources. It should NOT be idempotent. It must | ||
// only be called once and any call after may panic. | ||
io.Closer | ||
} | ||
|
||
type VersionedReader interface { | ||
Has(storeKey []byte, version uint64, key []byte) (bool, error) | ||
Get(storeKey []byte, version uint64, key []byte) ([]byte, error) | ||
|
||
GetLatestVersion() (uint64, error) | ||
SetLatestVersion(version uint64) error | ||
VersionExists(v uint64) (bool, error) | ||
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. Use descriptive parameter name and add documentation for The parameter |
||
|
||
Iterator(storeKey []byte, version uint64, start, end []byte) (corestore.Iterator, error) | ||
ReverseIterator(storeKey []byte, version uint64, start, end []byte) (corestore.Iterator, error) | ||
|
||
ApplyChangeset(version uint64, cs *corestore.Changeset) error | ||
|
||
// Close releases associated resources. It should NOT be idempotent. It must | ||
// only be called once and any call after may panic. | ||
io.Closer | ||
|
@@ -53,18 +63,14 @@ type Committer interface { | |
// GetProof returns the proof of existence or non-existence for the given key. | ||
GetProof(storeKey []byte, version uint64, key []byte) ([]proof.CommitmentOp, error) | ||
|
||
// Get returns the value for the given key at the given version. | ||
// | ||
// NOTE: This method only exists to support migration from IAVL v0/v1 to v2. | ||
// Once migration is complete, this method should be removed and/or not used. | ||
Get(storeKey []byte, version uint64, key []byte) ([]byte, error) | ||
|
||
// SetInitialVersion sets the initial version of the committer. | ||
SetInitialVersion(version uint64) error | ||
|
||
// GetCommitInfo returns the CommitInfo for the given version. | ||
GetCommitInfo(version uint64) (*proof.CommitInfo, error) | ||
|
||
Get(storeKey []byte, version uint64, key []byte) ([]byte, error) | ||
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. Add missing documentation for exported method The method |
||
|
||
// Close releases associated resources. It should NOT be idempotent. It must | ||
// only be called once and any call after may panic. | ||
io.Closer | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ type Store struct { | |
dbCloser io.Closer | ||
|
||
// stateStorage reflects the state storage backend | ||
stateStorage store.VersionedDatabase | ||
stateStorage store.VersionedWriter | ||
|
||
// stateCommitment reflects the state commitment (SC) backend | ||
stateCommitment store.Committer | ||
|
@@ -74,7 +74,7 @@ type Store struct { | |
func New( | ||
dbCloser io.Closer, | ||
logger corelog.Logger, | ||
ss store.VersionedDatabase, | ||
ss store.VersionedWriter, | ||
sc store.Committer, | ||
pm *pruning.Manager, | ||
mm *migration.Manager, | ||
|
@@ -127,19 +127,21 @@ func (s *Store) StateLatest() (uint64, corestore.ReaderMap, error) { | |
return v, NewReaderMap(v, s), nil | ||
} | ||
|
||
// StateAt checks if the requested version is present in ss. | ||
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. 🛠️ Refactor suggestion Consider renaming 'StateAt' method for clarity The method name |
||
func (s *Store) StateAt(v uint64) (corestore.ReaderMap, error) { | ||
// TODO(bez): We may want to avoid relying on the SC metadata here. Instead, | ||
// we should add a VersionExists() method to the VersionedDatabase interface. | ||
// | ||
// Ref: https://github.com/cosmos/cosmos-sdk/issues/19091 | ||
if cInfo, err := s.stateCommitment.GetCommitInfo(v); err != nil || cInfo == nil { | ||
return nil, fmt.Errorf("failed to get commit info for version %d: %w", v, err) | ||
// check if version is present in state storage | ||
isExist, err := s.stateStorage.VersionExists(v) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !isExist { | ||
return nil, fmt.Errorf("version %d does not exist", v) | ||
} | ||
|
||
return NewReaderMap(v, s), nil | ||
} | ||
|
||
func (s *Store) GetStateStorage() store.VersionedDatabase { | ||
func (s *Store) GetStateStorage() store.VersionedWriter { | ||
return s.stateStorage | ||
} | ||
|
||
|
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.
💡 Codebase verification
Issues Found: Update Remaining
VersionedDatabase
ReferencesThe
VersionedDatabase
type is still referenced in multiple files:store/v2/storage/store.go
store/v2/mock/types.go
server/v2/cometbft/internal/mock/mock_store.go
Please update these references to
VersionedWriter
to ensure consistency across the codebase.🔗 Analysis chain
LGTM. Verify impact and update documentation if needed.
The change from
storev2.VersionedDatabase
tostorev2.VersionedWriter
for theGetStateStorage
method return type looks good. This modification aligns with the PR objectives of enhancing the state machine functionality.To ensure this change doesn't introduce any inconsistencies, please run the following script to check for any other occurrences of
VersionedDatabase
that might need updating:Consider updating any relevant documentation or comments related to the
GetStateStorage
method to reflect this change in return type, if necessary.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 897