chore(docs): fix comments that do not start with the name of the exported element (#20999)

This commit is contained in:
Tuan Tran 2024-07-19 23:21:01 +07:00 committed by GitHub
parent c2a1268f59
commit 023ed3558d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 85 additions and 73 deletions

View File

@ -10,7 +10,7 @@ import (
"cosmossdk.io/store/types"
)
// Wrapper type for dbm.Db with implementation of KVStore
// Store is wrapper type for dbm.Db with implementation of KVStore
type Store struct {
dbm.DB
}

View File

@ -26,12 +26,12 @@ func NewStore(parent types.KVStore, gasMeter types.GasMeter, gasConfig types.Gas
return kvs
}
// Implements Store.
// GetStoreType implements Store.
func (gs *Store) GetStoreType() types.StoreType {
return gs.parent.GetStoreType()
}
// Implements KVStore.
// Get implements KVStore.
func (gs *Store) Get(key []byte) (value []byte) {
gs.gasMeter.ConsumeGas(gs.gasConfig.ReadCostFlat, types.GasReadCostFlatDesc)
value = gs.parent.Get(key)
@ -43,7 +43,7 @@ func (gs *Store) Get(key []byte) (value []byte) {
return value
}
// Implements KVStore.
// Set implements KVStore.
func (gs *Store) Set(key, value []byte) {
types.AssertValidKey(key)
types.AssertValidValue(value)
@ -54,13 +54,13 @@ func (gs *Store) Set(key, value []byte) {
gs.parent.Set(key, value)
}
// Implements KVStore.
// Has implements KVStore.
func (gs *Store) Has(key []byte) bool {
gs.gasMeter.ConsumeGas(gs.gasConfig.HasCost, types.GasHasDesc)
return gs.parent.Has(key)
}
// Implements KVStore.
// Delete implements KVStore.
func (gs *Store) Delete(key []byte) {
// charge gas to prevent certain attack vectors even though space is being freed
gs.gasMeter.ConsumeGas(gs.gasConfig.DeleteCost, types.GasDeleteDesc)
@ -82,7 +82,7 @@ func (gs *Store) ReverseIterator(start, end []byte) types.Iterator {
return gs.iterator(start, end, false)
}
// Implements KVStore.
// CacheWrap implements KVStore.
func (gs *Store) CacheWrap() types.CacheWrap {
panic("cannot CacheWrap a GasKVStore")
}
@ -120,12 +120,12 @@ func newGasIterator(gasMeter types.GasMeter, gasConfig types.GasConfig, parent t
}
}
// Implements Iterator.
// Domain implements Iterator.
func (gi *gasIterator) Domain() (start, end []byte) {
return gi.parent.Domain()
}
// Implements Iterator.
// Valid implements Iterator.
func (gi *gasIterator) Valid() bool {
return gi.parent.Valid()
}
@ -152,7 +152,7 @@ func (gi *gasIterator) Value() (value []byte) {
return value
}
// Implements Iterator.
// Close implements Iterator.
func (gi *gasIterator) Close() error {
return gi.parent.Close()
}

View File

@ -179,12 +179,12 @@ func (st *Store) GetAllVersions() []int {
return st.tree.AvailableVersions()
}
// Implements Store.
// GetStoreType implements Store.
func (st *Store) GetStoreType() types.StoreType {
return types.StoreTypeIAVL
}
// Implements Store.
// CacheWrap implements Store.
func (st *Store) CacheWrap() types.CacheWrap {
return cachekv.NewStore(st)
}
@ -194,7 +194,7 @@ func (st *Store) CacheWrapWithTrace(w io.Writer, tc types.TraceContext) types.Ca
return cachekv.NewStore(tracekv.NewStore(st, w, tc))
}
// Implements types.KVStore.
// Set implements types.KVStore.
func (st *Store) Set(key, value []byte) {
types.AssertValidKey(key)
types.AssertValidValue(value)
@ -204,7 +204,7 @@ func (st *Store) Set(key, value []byte) {
}
}
// Implements types.KVStore.
// Get implements types.KVStore.
func (st *Store) Get(key []byte) []byte {
defer st.metrics.MeasureSince("store", "iavl", "get")
value, err := st.tree.Get(key)
@ -214,7 +214,7 @@ func (st *Store) Get(key []byte) []byte {
return value
}
// Implements types.KVStore.
// Has implements types.KVStore.
func (st *Store) Has(key []byte) (exists bool) {
defer st.metrics.MeasureSince("store", "iavl", "has")
has, err := st.tree.Has(key)
@ -224,7 +224,7 @@ func (st *Store) Has(key []byte) (exists bool) {
return has
}
// Implements types.KVStore.
// Delete implements types.KVStore.
func (st *Store) Delete(key []byte) {
defer st.metrics.MeasureSince("store", "iavl", "delete")
_, _, err := st.tree.Remove(key)
@ -246,7 +246,7 @@ func (st *Store) LoadVersionForOverwriting(targetVersion int64) error {
return st.tree.LoadVersionForOverwriting(targetVersion)
}
// Implements types.KVStore.
// Iterator implements types.KVStore.
func (st *Store) Iterator(start, end []byte) types.Iterator {
iterator, err := st.tree.Iterator(start, end, true)
if err != nil {
@ -255,7 +255,7 @@ func (st *Store) Iterator(start, end []byte) types.Iterator {
return iterator
}
// Implements types.KVStore.
// ReverseIterator implements types.KVStore.
func (st *Store) ReverseIterator(start, end []byte) types.Iterator {
iterator, err := st.tree.Iterator(start, end, false)
if err != nil {
@ -270,7 +270,7 @@ func (st *Store) SetInitialVersion(version int64) {
st.tree.SetInitialVersion(uint64(version))
}
// Exports the IAVL store at the given version, returning an iavl.Exporter for the tree.
// Export exports the IAVL store at the given version, returning an iavl.Exporter for the tree.
func (st *Store) Export(version int64) (*iavl.Exporter, error) {
istore, err := st.GetImmutable(version)
if err != nil {

View File

@ -120,7 +120,7 @@ func (sm *simpleMap) Sort() {
sm.sorted = true
}
// Returns a copy of sorted KVPairs.
// KVPairs returns a copy of sorted KVPairs.
// NOTE these contain the hashed key and value.
func (sm *simpleMap) KVPairs() kv.Pairs {
sm.Sort()
@ -134,7 +134,7 @@ func (sm *simpleMap) KVPairs() kv.Pairs {
//----------------------------------------
// A local extension to KVPair that can be hashed.
// KVPair is a local extension to KVPair that can be hashed.
// Key and value are length prefixed and concatenated,
// then hashed.
type KVPair kv.Pair

View File

@ -42,12 +42,12 @@ func (s Store) key(key []byte) (res []byte) {
return
}
// Implements Store
// GetStoreType implements Store
func (s Store) GetStoreType() types.StoreType {
return s.parent.GetStoreType()
}
// Implements CacheWrap
// CacheWrap implements CacheWrap
func (s Store) CacheWrap() types.CacheWrap {
return cachekv.NewStore(s)
}
@ -57,30 +57,30 @@ func (s Store) CacheWrapWithTrace(w io.Writer, tc types.TraceContext) types.Cach
return cachekv.NewStore(tracekv.NewStore(s, w, tc))
}
// Implements KVStore
// Get implements KVStore
func (s Store) Get(key []byte) []byte {
res := s.parent.Get(s.key(key))
return res
}
// Implements KVStore
// Has implements KVStore
func (s Store) Has(key []byte) bool {
return s.parent.Has(s.key(key))
}
// Implements KVStore
// Set implements KVStore
func (s Store) Set(key, value []byte) {
types.AssertValidKey(key)
types.AssertValidValue(value)
s.parent.Set(s.key(key), value)
}
// Implements KVStore
// Delete implements KVStore
func (s Store) Delete(key []byte) {
s.parent.Delete(s.key(key))
}
// Implements KVStore
// Iterator implements KVStore
// Check https://github.com/cometbft/cometbft/blob/master/libs/db/prefix_db.go#L106
func (s Store) Iterator(start, end []byte) types.Iterator {
newstart := cloneAppend(s.prefix, start)
@ -134,17 +134,17 @@ func newPrefixIterator(prefix, start, end []byte, parent types.Iterator) *prefix
}
}
// Implements Iterator
// Domain implements Iterator
func (pi *prefixIterator) Domain() ([]byte, []byte) {
return pi.start, pi.end
}
// Implements Iterator
// Valid implements Iterator
func (pi *prefixIterator) Valid() bool {
return pi.valid && pi.iter.Valid()
}
// Implements Iterator
// Next implements Iterator
func (pi *prefixIterator) Next() {
if !pi.valid {
panic("prefixIterator invalid, cannot call Next()")
@ -156,7 +156,7 @@ func (pi *prefixIterator) Next() {
}
}
// Implements Iterator
// Key implements Iterator
func (pi *prefixIterator) Key() (key []byte) {
if !pi.valid {
panic("prefixIterator invalid, cannot call Key()")
@ -168,7 +168,7 @@ func (pi *prefixIterator) Key() (key []byte) {
return
}
// Implements Iterator
// Value implements Iterator
func (pi *prefixIterator) Value() []byte {
if !pi.valid {
panic("prefixIterator invalid, cannot call Value()")
@ -177,7 +177,7 @@ func (pi *prefixIterator) Value() []byte {
return pi.iter.Value()
}
// Implements Iterator
// Close implements Iterator
func (pi *prefixIterator) Close() error {
return pi.iter.Close()
}

View File

@ -17,6 +17,8 @@ func RequireProof(subpath string) bool {
//-----------------------------------------------------------------------------
// DefaultProofRuntime returns a new ProofRuntime with default op decoders registered.
// It registers decoders for IAVL commitment and Simple Merkle commitment proof operations.
// XXX: This should be managed by the rootMultiStore which may want to register
// more proof ops?
func DefaultProofRuntime() (prt *merkle.ProofRuntime) {

View File

@ -725,7 +725,7 @@ func (rs *Store) PruneStores(pruningHeight int64) (err error) {
return nil
}
// getStoreByName performs a lookup of a StoreKey given a store name typically
// GetStoreByName performs a lookup of a StoreKey given a store name typically
// provided in a path. The StoreKey is then used to perform a lookup and return
// a Store. If the Store is wrapped in an inter-block cache, it will be unwrapped
// prior to being returned. If the StoreKey does not exist, nil is returned.

View File

@ -92,7 +92,7 @@ func (s *Store) Get(height uint64, format uint32) (*types.Snapshot, error) {
return snapshot, nil
}
// Get fetches the latest snapshot from the database, if any.
// GetLatest fetches the latest snapshot from the database, if any.
func (s *Store) GetLatest() (*types.Snapshot, error) {
iter, err := s.db.ReverseIterator(encodeKey(0, 0), encodeKey(uint64(math.MaxUint64), math.MaxUint32))
if err != nil {

View File

@ -7,7 +7,7 @@ import (
"cosmossdk.io/errors"
)
// Converts an ABCI snapshot to a snapshot. Mainly to decode the SDK metadata.
// SnapshotFromABCI converts an ABCI snapshot to a snapshot. Mainly to decode the SDK metadata.
func SnapshotFromABCI(in *abci.Snapshot) (Snapshot, error) {
snapshot := Snapshot{
Height: in.Height,
@ -22,7 +22,7 @@ func SnapshotFromABCI(in *abci.Snapshot) (Snapshot, error) {
return snapshot, nil
}
// Converts a Snapshot to its ABCI representation. Mainly to encode the SDK metadata.
// ToABCI converts a Snapshot to its ABCI representation. Mainly to encode the SDK metadata.
func (s Snapshot) ToABCI() (abci.Snapshot, error) {
out := abci.Snapshot{
Height: s.Height,

View File

@ -17,7 +17,7 @@ type GRPCClient struct {
client ABCIListenerServiceClient
}
// ListenEndBlock listens to end block request and responses.
// ListenFinalizeBlock listens to end block request and responses.
// In addition, it retrieves a types.Context from a context.Context instance.
// It panics if a types.Context was not properly attached.
// When the node is configured to stop on listening errors,

View File

@ -18,13 +18,13 @@ type Store struct {
dbadapter.Store
}
// Constructs new MemDB adapter
// NewStore constructs new MemDB adapter
func NewStore() *Store {
return &Store{Store: dbadapter.Store{DB: dbm.NewMemDB()}}
}
// Implements CommitStore
// Commit cleans up Store.
// Implements CommitStore
func (ts *Store) Commit() (id types.CommitID) {
ts.Store = dbadapter.Store{DB: dbm.NewMemDB()}
return
@ -38,7 +38,7 @@ func (ts *Store) GetPruning() pruningtypes.PruningOptions {
return pruningtypes.NewPruningOptions(pruningtypes.PruningUndefined)
}
// Implements CommitStore
// LastCommitID implements CommitStore
func (ts *Store) LastCommitID() types.CommitID {
return types.CommitID{}
}
@ -47,7 +47,7 @@ func (ts *Store) WorkingHash() []byte {
return []byte{}
}
// Implements Store.
// GetStoreType implements Store.
func (ts *Store) GetStoreType() types.StoreType {
return types.StoreTypeTransient
}

View File

@ -19,12 +19,13 @@ type Codec interface {
// in the value pointed to by v.
Unmarshal(bz []byte, ptr proto.Message) error
// Unmarshal parses the data encoded with UnmarshalLengthPrefixed method and stores
// UnmarshalLengthPrefixed parses the data encoded with UnmarshalLengthPrefixed method and stores
// the result in the value pointed to by v.
UnmarshalLengthPrefixed(bz []byte, ptr proto.Message) error
}
// ============= TestCodec =============
// TestCodec defines a codec that utilizes Protobuf for both binary and JSON
// encoding.
type TestCodec struct{}

View File

@ -17,7 +17,7 @@ type Store interface {
CacheWrapper
}
// something that can persist to disk
// Committer is something that can persist to disk
type Committer interface {
Commit() CommitID
LastCommitID() CommitID
@ -37,6 +37,8 @@ type PausablePruner interface {
PausePruning(bool)
}
// CommitStore represents a store that can be committed and provides basic store operations.
// It combines the functionality of Committer and Store interfaces.
// Stores of MultiStore must implement CommitStore.
type CommitStore interface {
Committer
@ -131,7 +133,7 @@ func (s *StoreUpgrades) RenamedFrom(key string) string {
type MultiStore interface {
Store
// Branches MultiStore into a cached storage object.
// CacheMultiStore branches MultiStore into a cached storage object.
// NOTE: Caller should probably not call .Write() on each, but
// call CacheMultiStore.Write().
CacheMultiStore() CacheMultiStore
@ -140,7 +142,7 @@ type MultiStore interface {
// each stored is loaded at a specific version (height).
CacheMultiStoreWithVersion(version int64) (CacheMultiStore, error)
// Convenience for fetching substores.
// GetStore is convenience for fetching substores.
// If the store does not exist, panics.
GetStore(StoreKey) Store
GetKVStore(StoreKey) KVStore
@ -162,7 +164,7 @@ type MultiStore interface {
LatestVersion() int64
}
// From MultiStore.CacheMultiStore()....
// CacheMultiStore is from MultiStore.CacheMultiStore()....
type CacheMultiStore interface {
MultiStore
Write() // Writes operations to underlying KVStore
@ -174,17 +176,17 @@ type CommitMultiStore interface {
MultiStore
snapshottypes.Snapshotter
// Mount a store of type using the given db.
// MountStoreWithDB mount a store of type using the given db.
// If db == nil, the new store will use the CommitMultiStore db.
MountStoreWithDB(key StoreKey, typ StoreType, db dbm.DB)
// Panics on a nil key.
// GetCommitStore panics on a nil key.
GetCommitStore(key StoreKey) CommitStore
// Panics on a nil key.
// GetCommitKVStore panics on a nil key.
GetCommitKVStore(key StoreKey) CommitKVStore
// Load the latest persisted version. Called once after all calls to
// LoadLatestVersion load the latest persisted version. Called once after all calls to
// Mount*Store() are complete.
LoadLatestVersion() error
@ -198,13 +200,13 @@ type CommitMultiStore interface {
// in order to handle breaking formats in migrations
LoadVersionAndUpgrade(ver int64, upgrades *StoreUpgrades) error
// Load a specific persisted version. When you load an old version, or when
// LoadVersion load a specific persisted version. When you load an old version, or when
// the last commit attempt didn't complete, the next commit after loading
// must be idempotent (return the same commit id). Otherwise the behavior is
// undefined.
LoadVersion(ver int64) error
// Set an inter-block (persistent) cache that maintains a mapping from
// SetInterBlockCache set an inter-block (persistent) cache that maintains a mapping from
// StoreKeys to CommitKVStores.
SetInterBlockCache(MultiStorePersistentCache)
@ -265,7 +267,7 @@ type KVStore interface {
// Exceptionally allowed for cachekv.Store, safe to write in the modules.
Iterator(start, end []byte) Iterator
// Iterator over a domain of keys in descending order. End is exclusive.
// ReverseIterator iterates over a domain of keys in descending order. End is exclusive.
// Start must be less than end, or the Iterator is invalid.
// Iterator must be closed by caller.
// CONTRACT: No writes may happen within a domain while an iterator exists over it.
@ -282,7 +284,7 @@ type Iterator = dbm.Iterator
type CacheKVStore interface {
KVStore
// Writes operations to underlying KVStore
// Write writes operations to underlying KVStore
Write()
}
@ -329,7 +331,7 @@ func (cid CommitID) String() string {
//----------------------------------------
// Store types
// kind of store
// StoreType is kind of store
type StoreType int
const (
@ -425,7 +427,7 @@ type TransientStoreKey struct {
name string
}
// Constructs new TransientStoreKey
// NewTransientStoreKey constructs new TransientStoreKey
// Must return a pointer according to the ocap principle
func NewTransientStoreKey(name string) *TransientStoreKey {
return &TransientStoreKey{
@ -433,12 +435,12 @@ func NewTransientStoreKey(name string) *TransientStoreKey {
}
}
// Implements StoreKey
// Name implements StoreKey
func (key *TransientStoreKey) Name() string {
return key.name
}
// Implements StoreKey
// String implements StoreKey
func (key *TransientStoreKey) String() string {
return fmt.Sprintf("TransientStoreKey{%p, %s}", key, key.name)
}
@ -494,11 +496,11 @@ func (tc TraceContext) Merge(newTc TraceContext) TraceContext {
// MultiStorePersistentCache defines an interface which provides inter-block
// (persistent) caching capabilities for multiple CommitKVStores based on StoreKeys.
type MultiStorePersistentCache interface {
// Wrap and return the provided CommitKVStore with an inter-block (persistent)
// GetStoreCache wrap and return the provided CommitKVStore with an inter-block (persistent)
// cache.
GetStoreCache(key StoreKey, store CommitKVStore) CommitKVStore
// Return the underlying CommitKVStore for a StoreKey.
// Unwrap return the underlying CommitKVStore for a StoreKey.
Unwrap(key StoreKey) CommitKVStore
// Reset the entire set of internal caches.

View File

@ -1,9 +1,12 @@
package types
var (
// 128K - 1
// MaxKeyLength is the maximum allowed length for a key in bytes.
// It is set to 128K - 1 (131,071 bytes).
MaxKeyLength = (1 << 17) - 1
// 2G - 1
// MaxValueLength is the maximum allowed length for a value in bytes.
// It is set to 2G - 1 (2,147,483,647 bytes).
MaxValueLength = (1 << 31) - 1
)

View File

@ -247,7 +247,7 @@ func (itr *prefixDBIterator) Next() {
}
}
// Next implements Iterator.
// Key implements Iterator.
func (itr *prefixDBIterator) Key() []byte {
itr.assertIsValid()
key := itr.source.Key()

View File

@ -28,7 +28,7 @@ var uvarintPool = &sync.Pool{
},
}
// decodeBytes decodes a varint length-prefixed byte slice, returning it along with the number
// DecodeBytes decodes a varint length-prefixed byte slice, returning it along with the number
// of input bytes read.
// Assumes bz will not be mutated.
func DecodeBytes(bz []byte) ([]byte, int, error) {
@ -55,7 +55,7 @@ func DecodeBytes(bz []byte) ([]byte, int, error) {
return bz[n:end], end, nil
}
// decodeUvarint decodes a varint-encoded unsigned integer from a byte slice, returning it and the
// DecodeUvarint decodes a varint-encoded unsigned integer from a byte slice, returning it and the
// number of bytes decoded.
func DecodeUvarint(bz []byte) (uint64, int, error) {
u, n := binary.Uvarint(bz)
@ -71,7 +71,7 @@ func DecodeUvarint(bz []byte) (uint64, int, error) {
return u, n, nil
}
// decodeVarint decodes a varint-encoded integer from a byte slice, returning it and the number of
// DecodeVarint decodes a varint-encoded integer from a byte slice, returning it and the number of
// bytes decoded.
func DecodeVarint(bz []byte) (int64, int, error) {
i, n := binary.Varint(bz)
@ -96,7 +96,7 @@ func EncodeBytes(w io.Writer, bz []byte) error {
return err
}
// encodeBytesSlice length-prefixes the byte slice and returns it.
// EncodeBytesSlice length-prefixes the byte slice and returns it.
func EncodeBytesSlice(bz []byte) ([]byte, error) {
buf := bufPool.Get().(*bytes.Buffer)
buf.Reset()
@ -110,7 +110,7 @@ func EncodeBytesSlice(bz []byte) ([]byte, error) {
return bytesCopy, err
}
// encodeBytesSize returns the byte size of the given slice including length-prefixing.
// EncodeBytesSize returns the byte size of the given slice including length-prefixing.
func EncodeBytesSize(bz []byte) int {
return EncodeUvarintSize(uint64(len(bz))) + len(bz)
}

View File

@ -202,7 +202,9 @@ func MVCCKeyCompare(a, b []byte) int {
return bytes.Compare(aTS, bTS)
}
// <key>\x00[<version>]<#version-bytes>
// MVCCEncode encodes a key and version into an MVCC format.
// The format is: <key>\x00[<version>]<#version-bytes>
// If the version is 0, only the key and a null byte are encoded.
func MVCCEncode(key []byte, version uint64) (dst []byte) {
dst = append(dst, key...)
dst = append(dst, 0)

View File

@ -1,10 +1,12 @@
package store
var (
// 128K - 1
// MaxKeyLength is the maximum allowed length for a key in bytes.
// It is set to 128K - 1 (131,071 bytes).
MaxKeyLength = (1 << 17) - 1
// 2G - 1
// MaxValueLength is the maximum allowed length for a value in bytes.
// It is set to 2G - 1 (2,147,483,647 bytes).
MaxValueLength = (1 << 31) - 1
)