-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
(cherry picked from commit 0b43fcc) # Conflicts: # server/v2/testdata/app.toml # server/v2/types.go # store/v2/commitment/metadata.go # store/v2/root/factory.go # store/v2/root/migrate_test.go # store/v2/root/store.go # store/v2/root/store_test.go # store/v2/root/upgrade_test.go
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
[grpc] | ||
# Enable defines if the gRPC server should be enabled. | ||
enable = false | ||
# Address defines the gRPC server address to bind to. | ||
address = 'localhost:9090' | ||
# MaxRecvMsgSize defines the max message size in bytes the server can receive. | ||
# The default value is 10MB. | ||
max-recv-msg-size = 10485760 | ||
# MaxSendMsgSize defines the max message size in bytes the server can send. | ||
# The default value is math.MaxInt32. | ||
max-send-msg-size = 2147483647 | ||
|
||
[mock-server-1] | ||
# Mock field | ||
mock_field = 'default' | ||
# Mock field two | ||
mock_field_two = 1 | ||
|
||
[server] | ||
# minimum-gas-prices defines the price which a validator is willing to accept for processing a transaction. A transaction's fees must meet the minimum of any denomination specified in this config (e.g. 0.25token1;0.0001token2). | ||
minimum-gas-prices = '0stake' | ||
|
||
[store] | ||
# The type of database for application and snapshots databases. | ||
app-db-backend = 'goleveldb' | ||
|
||
[store.options] | ||
# State storage database type. Currently we support: "sqlite", "pebble" and "rocksdb" | ||
ss-type = 'sqlite' | ||
# State commitment database type. Currently we support: "iavl" and "iavl-v2" | ||
sc-type = 'iavl' | ||
|
||
# Pruning options for state storage | ||
[store.options.ss-pruning-option] | ||
# Number of recent heights to keep on disk. | ||
keep-recent = 2 | ||
# Height interval at which pruned heights are removed from disk. | ||
interval = 100 | ||
|
||
# Pruning options for state commitment | ||
[store.options.sc-pruning-option] | ||
# Number of recent heights to keep on disk. | ||
keep-recent = 2 | ||
# Height interval at which pruned heights are removed from disk. | ||
interval = 100 | ||
|
||
[store.options.iavl-config] | ||
# CacheSize set the size of the iavl tree cache. | ||
cache-size = 100000 | ||
# If true, the tree will work like no fast storage and always not upgrade fast storage. | ||
skip-fast-storage-upgrade = true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package serverv2 | ||
|
||
import ( | ||
"github.com/spf13/viper" | ||
|
||
appmodulev2 "cosmossdk.io/core/appmodule/v2" | ||
"cosmossdk.io/core/server" | ||
"cosmossdk.io/core/transaction" | ||
"cosmossdk.io/log" | ||
"cosmossdk.io/schema/decoding" | ||
"cosmossdk.io/server/v2/appmanager" | ||
Check failure on line 11 in server/v2/types.go GitHub Actions / split-test-files
Check failure on line 11 in server/v2/types.go GitHub Actions / dependency-review
|
||
"cosmossdk.io/store/v2" | ||
Check failure on line 12 in server/v2/types.go GitHub Actions / split-test-files
Check failure on line 12 in server/v2/types.go GitHub Actions / dependency-review
|
||
) | ||
|
||
type AppCreator[T transaction.Tx] func(log.Logger, *viper.Viper) AppI[T] | ||
|
||
type AppI[T transaction.Tx] interface { | ||
Name() string | ||
InterfaceRegistry() server.InterfaceRegistry | ||
GetAppManager() *appmanager.AppManager[T] | ||
GetQueryHandlers() map[string]appmodulev2.Handler | ||
GetStore() store.RootStore | ||
GetSchemaDecoderResolver() decoding.DecoderResolver | ||
Close() error | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
package commitment | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"fmt" | ||
|
||
corestore "cosmossdk.io/core/store" | ||
"cosmossdk.io/store/v2/internal/encoding" | ||
Check failure on line 9 in store/v2/commitment/metadata.go GitHub Actions / split-test-files
Check failure on line 9 in store/v2/commitment/metadata.go GitHub Actions / dependency-review
|
||
"cosmossdk.io/store/v2/proof" | ||
Check failure on line 10 in store/v2/commitment/metadata.go GitHub Actions / split-test-files
Check failure on line 10 in store/v2/commitment/metadata.go GitHub Actions / dependency-review
|
||
) | ||
|
||
const ( | ||
commitInfoKeyFmt = "c/%d" // c/<version> | ||
latestVersionKey = "c/latest" | ||
removedStoreKeyPrefix = "c/removed/" // c/removed/<version>/<store-name> | ||
) | ||
|
||
// MetadataStore is a store for metadata related to the commitment store. | ||
// It isn't metadata store role to close the underlying KVStore. | ||
type MetadataStore struct { | ||
kv corestore.KVStoreWithBatch | ||
} | ||
|
||
// NewMetadataStore creates a new MetadataStore. | ||
func NewMetadataStore(kv corestore.KVStoreWithBatch) *MetadataStore { | ||
return &MetadataStore{ | ||
kv: kv, | ||
} | ||
} | ||
|
||
// GetLatestVersion returns the latest committed version. | ||
func (m *MetadataStore) GetLatestVersion() (uint64, error) { | ||
value, err := m.kv.Get([]byte(latestVersionKey)) | ||
if err != nil { | ||
return 0, err | ||
} | ||
if value == nil { | ||
return 0, nil | ||
} | ||
|
||
version, _, err := encoding.DecodeUvarint(value) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
return version, nil | ||
} | ||
|
||
func (m *MetadataStore) setLatestVersion(version uint64) error { | ||
var buf bytes.Buffer | ||
buf.Grow(encoding.EncodeUvarintSize(version)) | ||
if err := encoding.EncodeUvarint(&buf, version); err != nil { | ||
return err | ||
} | ||
return m.kv.Set([]byte(latestVersionKey), buf.Bytes()) | ||
} | ||
|
||
// GetCommitInfo returns the commit info for the given version. | ||
func (m *MetadataStore) GetCommitInfo(version uint64) (*proof.CommitInfo, error) { | ||
key := []byte(fmt.Sprintf(commitInfoKeyFmt, version)) | ||
value, err := m.kv.Get(key) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if value == nil { | ||
return nil, nil | ||
} | ||
|
||
cInfo := &proof.CommitInfo{} | ||
if err := cInfo.Unmarshal(value); err != nil { | ||
return nil, err | ||
} | ||
|
||
return cInfo, nil | ||
} | ||
|
||
func (m *MetadataStore) flushCommitInfo(version uint64, cInfo *proof.CommitInfo) (err error) { | ||
// do nothing if commit info is nil, as will be the case for an empty, initializing store | ||
if cInfo == nil { | ||
return nil | ||
} | ||
|
||
batch := m.kv.NewBatch() | ||
defer func() { | ||
err = errors.Join(err, batch.Close()) | ||
}() | ||
cInfoKey := []byte(fmt.Sprintf(commitInfoKeyFmt, version)) | ||
value, err := cInfo.Marshal() | ||
if err != nil { | ||
return err | ||
} | ||
if err := batch.Set(cInfoKey, value); err != nil { | ||
return err | ||
} | ||
|
||
var buf bytes.Buffer | ||
buf.Grow(encoding.EncodeUvarintSize(version)) | ||
if err := encoding.EncodeUvarint(&buf, version); err != nil { | ||
return err | ||
} | ||
if err := batch.Set([]byte(latestVersionKey), buf.Bytes()); err != nil { | ||
return err | ||
} | ||
|
||
if err := batch.Write(); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (m *MetadataStore) flushRemovedStoreKeys(version uint64, storeKeys []string) (err error) { | ||
batch := m.kv.NewBatch() | ||
defer func() { | ||
err = errors.Join(err, batch.Close()) | ||
}() | ||
|
||
for _, storeKey := range storeKeys { | ||
key := []byte(fmt.Sprintf("%s%s", encoding.BuildPrefixWithVersion(removedStoreKeyPrefix, version), storeKey)) | ||
if err := batch.Set(key, []byte{}); err != nil { | ||
return err | ||
} | ||
} | ||
return batch.Write() | ||
} | ||
|
||
func (m *MetadataStore) GetRemovedStoreKeys(version uint64) (storeKeys [][]byte, err error) { | ||
end := encoding.BuildPrefixWithVersion(removedStoreKeyPrefix, version+1) | ||
iter, err := m.kv.Iterator([]byte(removedStoreKeyPrefix), end) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer func() { | ||
if ierr := iter.Close(); ierr != nil { | ||
err = ierr | ||
} | ||
}() | ||
|
||
for ; iter.Valid(); iter.Next() { | ||
storeKey := iter.Key()[len(end):] | ||
storeKeys = append(storeKeys, storeKey) | ||
} | ||
return storeKeys, nil | ||
} | ||
|
||
func (m *MetadataStore) deleteRemovedStoreKeys(version uint64, removeStore func(storeKey []byte, version uint64) error) (err error) { | ||
removedStoreKeys, err := m.GetRemovedStoreKeys(version) | ||
if err != nil { | ||
return err | ||
} | ||
if len(removedStoreKeys) == 0 { | ||
return nil | ||
} | ||
|
||
batch := m.kv.NewBatch() | ||
defer func() { | ||
err = errors.Join(err, batch.Close()) | ||
}() | ||
for _, storeKey := range removedStoreKeys { | ||
if err := removeStore(storeKey, version); err != nil { | ||
return err | ||
} | ||
if err := batch.Delete(storeKey); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return batch.Write() | ||
} | ||
|
||
func (m *MetadataStore) deleteCommitInfo(version uint64) error { | ||
cInfoKey := []byte(fmt.Sprintf(commitInfoKeyFmt, version)) | ||
return m.kv.Delete(cInfoKey) | ||
} |