Skip to content

Commit

Permalink
Do not enable enclave when creating tempApp
Browse files Browse the repository at this point in the history
  • Loading branch information
iKapitonau committed Sep 26, 2024
1 parent be97d92 commit 1857d07
Show file tree
Hide file tree
Showing 128 changed files with 22,684 additions and 10 deletions.
4 changes: 3 additions & 1 deletion cmd/secretd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ func NewRootCmd() (*cobra.Command, app.EncodingConfig) {
return dir
}

tempApp := app.NewSecretNetworkApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, true, simtestutil.NewAppOptionsWithFlagHome(tempDir()), compute.DefaultWasmConfig())
wasmConfig := compute.DefaultWasmConfig()
wasmConfig.InitEnclave = false
tempApp := app.NewSecretNetworkApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, true, simtestutil.NewAppOptionsWithFlagHome(tempDir()), wasmConfig)

encodingConfig := app.EncodingConfig{
InterfaceRegistry: tempApp.GetInterfaceRegistry(),
Expand Down
66 changes: 66 additions & 0 deletions cosmos-sdk-store/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!--
Guiding Principles:
Changelogs are for humans, not machines.
There should be an entry for every single version.
The same types of changes should be grouped.
Versions and sections should be linkable.
The latest version comes first.
The release date of each version is displayed.
Mention whether you follow Semantic Versioning.
Usage:
Change log entries are to be added to the Unreleased section under the
appropriate stanza (see below). Each entry should ideally include a tag and
the Github issue reference in the following format:
* (<tag>) [#<issue-number>] Changelog message.
Types of changes (Stanzas):
"Features" for new features.
"Improvements" for changes in existing functionality.
"Deprecated" for soon-to-be removed features.
"Bug Fixes" for any bug fixes.
"API Breaking" for breaking exported APIs used by developers building on SDK.
Ref: https://keepachangelog.com/en/1.0.0/
-->

# Changelog

## v1.1.0 (March 20, 2024)

### Improvements

* [#19770](https://github.com/cosmos/cosmos-sdk/pull/19770) Upgrade IAVL to IAVL v1.1.1.

## v1.0.2 (January 10, 2024)

### Bug Fixes

* [#18897](https://github.com/cosmos/cosmos-sdk/pull/18897) Replace panic in pruning to avoid consensus halting.

## v1.0.1 (November 28, 2023)

### Bug Fixes

* [#18563](https://github.com/cosmos/cosmos-sdk/pull/18563) `LastCommitID().Hash` will always return `sha256([]byte{})` if the store is empty.

## v1.0.0 (October 31, 2023)

### Features

* [#17294](https://github.com/cosmos/cosmos-sdk/pull/17294) Add snapshot manager Close method.
* [#15568](https://github.com/cosmos/cosmos-sdk/pull/15568) Migrate the `iavl` to the new key format.
* Remove `DeleteVersion`, `DeleteVersions`, `LazyLoadVersionForOverwriting` from `iavl` tree API.
* Add `DeleteVersionsTo` and `SaveChangeSet`, since it will keep versions sequentially like `fromVersion` to `toVersion`.
* Refactor the pruning manager to use `DeleteVersionsTo`.
* [#15712](https://github.com/cosmos/cosmos-sdk/pull/15712) Add `WorkingHash` function to the store interface to get the current app hash before commit.
* [#14645](https://github.com/cosmos/cosmos-sdk/pull/14645) Add limit to the length of key and value.
* [#15683](https://github.com/cosmos/cosmos-sdk/pull/15683) `rootmulti.Store.CacheMultiStoreWithVersion` now can handle loading archival states that don't persist any of the module stores the current state has.
* [#16060](https://github.com/cosmos/cosmos-sdk/pull/16060) Support saving restoring snapshot locally.
* [#14746](https://github.com/cosmos/cosmos-sdk/pull/14746) The `store` module is extracted to have a separate go.mod file which allows it be a standalone module.
* [#14410](https://github.com/cosmos/cosmos-sdk/pull/14410) `rootmulti.Store.loadVersion` has validation to check if all the module stores' height is correct, it will error if any module store has incorrect height.

### Improvements

* [#17158](https://github.com/cosmos/cosmos-sdk/pull/17158) Start the goroutine after need to create a snapshot.

### API Breaking Changes

* [#16321](https://github.com/cosmos/cosmos-sdk/pull/16321) QueryInterface defines its own request and response types instead of relying on comet/abci & returns an error
24 changes: 24 additions & 0 deletions cosmos-sdk-store/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Cosmos-sdk -> cosmossdk.io/store@v1.0.2
## cosmossdk.io/store@v1.0.2
The version of cosmossdk.io/store@v1.0.2 has an issue we have come across during the upgrade to Cosmoms-sdk 0.50.x
This issue is based on the fact that during the store __Write__ operation not every store gets updated.
As a result when we call
```
func (rs *Store) CacheMultiStoreWithVersion(version int64) (types.CacheMultiStore, error)
```
a call to retrieve __cacheStore__ here:
```
cacheStore, err = store.(*iavl.Store).GetImmutable(version)
```
fails and we cannot process **multistore** queries because they fail with an error:
```
ERR [*] Cache for error="version does not exist" module=server module store=evidence
ERR [*] Cache for error="version does not exist" module=server module store=feegrant
ERR [*] Cache for error="version does not exist" module=server module store=hooks-for-ibc
ERR [*] Cache for error="version does not exist" module=server module store=feeibc
ERR [*] Cache for error="version does not exist" module=server module store=authz
ERR [*] Cache for error="version does not exist" module=server module store=emergencybutton
```
We introduced a fix for __CacheMultiStoreWithVersion__ where we bypass errors for certain modules.

49 changes: 49 additions & 0 deletions cosmos-sdk-store/cache/benchmark_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package cache

import (
"testing"

"cosmossdk.io/store/types"
)

func freshMgr() *CommitKVStoreCacheManager {
return &CommitKVStoreCacheManager{
caches: map[string]types.CommitKVStore{
"a1": nil,
"alalalalalal": nil,
},
}
}

func populate(mgr *CommitKVStoreCacheManager) {
mgr.caches["this one"] = (types.CommitKVStore)(nil)
mgr.caches["those ones are the ones"] = (types.CommitKVStore)(nil)
mgr.caches["very huge key right here and there are we going to ones are the ones"] = (types.CommitKVStore)(nil)
}

func BenchmarkReset(b *testing.B) {
b.ReportAllocs()
mgr := freshMgr()

b.ResetTimer()
b.ReportAllocs()

for i := 0; i < b.N; i++ {
mgr.Reset()
if len(mgr.caches) != 0 {
b.Fatal("Reset failed")
}
populate(mgr)
if len(mgr.caches) == 0 {
b.Fatal("populate failed")
}
mgr.Reset()
if len(mgr.caches) != 0 {
b.Fatal("Reset failed")
}
}

if mgr == nil {
b.Fatal("Impossible condition")
}
}
132 changes: 132 additions & 0 deletions cosmos-sdk-store/cache/cache.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package cache

import (
"fmt"

lru "github.com/hashicorp/golang-lru"

"cosmossdk.io/store/cachekv"
"cosmossdk.io/store/types"
)

var (
_ types.CommitKVStore = (*CommitKVStoreCache)(nil)
_ types.MultiStorePersistentCache = (*CommitKVStoreCacheManager)(nil)

// DefaultCommitKVStoreCacheSize defines the persistent ARC cache size for a
// CommitKVStoreCache.
DefaultCommitKVStoreCacheSize uint = 1000
)

type (
// CommitKVStoreCache implements an inter-block (persistent) cache that wraps a
// CommitKVStore. Reads first hit the internal ARC (Adaptive Replacement Cache).
// During a cache miss, the read is delegated to the underlying CommitKVStore
// and cached. Deletes and writes always happen to both the cache and the
// CommitKVStore in a write-through manner. Caching performed in the
// CommitKVStore and below is completely irrelevant to this layer.
CommitKVStoreCache struct {
types.CommitKVStore
cache *lru.ARCCache
}

// CommitKVStoreCacheManager maintains a mapping from a StoreKey to a
// CommitKVStoreCache. Each CommitKVStore, per StoreKey, is meant to be used
// in an inter-block (persistent) manner and typically provided by a
// CommitMultiStore.
CommitKVStoreCacheManager struct {
cacheSize uint
caches map[string]types.CommitKVStore
}
)

func NewCommitKVStoreCache(store types.CommitKVStore, size uint) *CommitKVStoreCache {
cache, err := lru.NewARC(int(size))
if err != nil {
panic(fmt.Errorf("failed to create KVStore cache: %s", err))
}

return &CommitKVStoreCache{
CommitKVStore: store,
cache: cache,
}
}

func NewCommitKVStoreCacheManager(size uint) *CommitKVStoreCacheManager {
return &CommitKVStoreCacheManager{
cacheSize: size,
caches: make(map[string]types.CommitKVStore),
}
}

// GetStoreCache returns a Cache from the CommitStoreCacheManager for a given
// StoreKey. If no Cache exists for the StoreKey, then one is created and set.
// The returned Cache is meant to be used in a persistent manner.
func (cmgr *CommitKVStoreCacheManager) GetStoreCache(key types.StoreKey, store types.CommitKVStore) types.CommitKVStore {
if cmgr.caches[key.Name()] == nil {
cmgr.caches[key.Name()] = NewCommitKVStoreCache(store, cmgr.cacheSize)
}

return cmgr.caches[key.Name()]
}

// Unwrap returns the underlying CommitKVStore for a given StoreKey.
func (cmgr *CommitKVStoreCacheManager) Unwrap(key types.StoreKey) types.CommitKVStore {
if ckv, ok := cmgr.caches[key.Name()]; ok {
return ckv.(*CommitKVStoreCache).CommitKVStore
}

return nil
}

// Reset resets in the internal caches.
func (cmgr *CommitKVStoreCacheManager) Reset() {
// Clear the map.
// Please note that we are purposefully using the map clearing idiom.
// See https://github.com/cosmos/cosmos-sdk/issues/6681.
for key := range cmgr.caches {
delete(cmgr.caches, key)
}
}

// CacheWrap implements the CacheWrapper interface
func (ckv *CommitKVStoreCache) CacheWrap() types.CacheWrap {
return cachekv.NewStore(ckv)
}

// Get retrieves a value by key. It will first look in the write-through cache.
// If the value doesn't exist in the write-through cache, the query is delegated
// to the underlying CommitKVStore.
func (ckv *CommitKVStoreCache) Get(key []byte) []byte {
types.AssertValidKey(key)

keyStr := string(key)
valueI, ok := ckv.cache.Get(keyStr)
if ok {
// cache hit
return valueI.([]byte)
}

// cache miss; write to cache
value := ckv.CommitKVStore.Get(key)
ckv.cache.Add(keyStr, value)

return value
}

// Set inserts a key/value pair into both the write-through cache and the
// underlying CommitKVStore.
func (ckv *CommitKVStoreCache) Set(key, value []byte) {
types.AssertValidKey(key)
types.AssertValidValue(value)

ckv.cache.Add(string(key), value)
ckv.CommitKVStore.Set(key, value)
}

// Delete removes a key/value pair from both the write-through cache and the
// underlying CommitKVStore.
func (ckv *CommitKVStoreCache) Delete(key []byte) {
ckv.cache.Remove(string(key))
ckv.CommitKVStore.Delete(key)
}
101 changes: 101 additions & 0 deletions cosmos-sdk-store/cache/cache_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package cache_test

import (
"fmt"
"testing"

dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/iavl"
"github.com/stretchr/testify/require"

"cosmossdk.io/log"
"cosmossdk.io/store/cache"
"cosmossdk.io/store/cachekv"
iavlstore "cosmossdk.io/store/iavl"
"cosmossdk.io/store/types"
"cosmossdk.io/store/wrapper"
)

func TestGetOrSetStoreCache(t *testing.T) {
db := wrapper.NewDBWrapper(dbm.NewMemDB())
mngr := cache.NewCommitKVStoreCacheManager(cache.DefaultCommitKVStoreCacheSize)

sKey := types.NewKVStoreKey("test")
tree := iavl.NewMutableTree(db, 100, false, log.NewNopLogger())
store := iavlstore.UnsafeNewStore(tree)
store2 := mngr.GetStoreCache(sKey, store)

require.NotNil(t, store2)
require.Equal(t, store2, mngr.GetStoreCache(sKey, store))
}

func TestUnwrap(t *testing.T) {
db := wrapper.NewDBWrapper(dbm.NewMemDB())
mngr := cache.NewCommitKVStoreCacheManager(cache.DefaultCommitKVStoreCacheSize)

sKey := types.NewKVStoreKey("test")
tree := iavl.NewMutableTree(db, 100, false, log.NewNopLogger())
store := iavlstore.UnsafeNewStore(tree)
_ = mngr.GetStoreCache(sKey, store)

require.Equal(t, store, mngr.Unwrap(sKey))
require.Nil(t, mngr.Unwrap(types.NewKVStoreKey("test2")))
}

func TestStoreCache(t *testing.T) {
db := wrapper.NewDBWrapper(dbm.NewMemDB())
mngr := cache.NewCommitKVStoreCacheManager(cache.DefaultCommitKVStoreCacheSize)

sKey := types.NewKVStoreKey("test")
tree := iavl.NewMutableTree(db, 100, false, log.NewNopLogger())
store := iavlstore.UnsafeNewStore(tree)
kvStore := mngr.GetStoreCache(sKey, store)

for i := uint(0); i < cache.DefaultCommitKVStoreCacheSize*2; i++ {
key := []byte(fmt.Sprintf("key_%d", i))
value := []byte(fmt.Sprintf("value_%d", i))

kvStore.Set(key, value)

res := kvStore.Get(key)
require.Equal(t, res, value)
require.Equal(t, res, store.Get(key))

kvStore.Delete(key)

require.Nil(t, kvStore.Get(key))
require.Nil(t, store.Get(key))
}
}

func TestReset(t *testing.T) {
db := wrapper.NewDBWrapper(dbm.NewMemDB())
mngr := cache.NewCommitKVStoreCacheManager(cache.DefaultCommitKVStoreCacheSize)

sKey := types.NewKVStoreKey("test")
tree := iavl.NewMutableTree(db, 100, false, log.NewNopLogger())
store := iavlstore.UnsafeNewStore(tree)
store2 := mngr.GetStoreCache(sKey, store)

require.NotNil(t, store2)
require.Equal(t, store2, mngr.GetStoreCache(sKey, store))

// reset and check if the cache is gone
mngr.Reset()
require.Nil(t, mngr.Unwrap(sKey))

// check if the cache is recreated
require.Equal(t, store2, mngr.GetStoreCache(sKey, store))
}

func TestCacheWrap(t *testing.T) {
db := wrapper.NewDBWrapper(dbm.NewMemDB())
mngr := cache.NewCommitKVStoreCacheManager(cache.DefaultCommitKVStoreCacheSize)

sKey := types.NewKVStoreKey("test")
tree := iavl.NewMutableTree(db, 100, false, log.NewNopLogger())
store := iavlstore.UnsafeNewStore(tree)

cacheWrapper := mngr.GetStoreCache(sKey, store).CacheWrap()
require.IsType(t, &cachekv.Store{}, cacheWrapper)
}
Loading

0 comments on commit 1857d07

Please sign in to comment.