From 806de111593f820afcdf1a85e90c975edab28612 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 16 Sep 2022 16:33:17 +0200 Subject: [PATCH 1/7] configurable fastnode --- baseapp/options.go | 4 +++ go.mod | 2 +- go.sum | 4 +-- server/mock/store.go | 4 +++ server/start.go | 1 + simapp/go.mod | 2 +- simapp/go.sum | 4 +-- simapp/simd/cmd/root.go | 1 + store/cache/cache_test.go | 6 ++-- store/iavl/store.go | 8 +++--- store/iavl/store_test.go | 24 ++++++++-------- store/iavl/tree_test.go | 2 +- store/prefix/store_test.go | 2 +- store/rootmulti/proof_test.go | 2 +- store/rootmulti/store.go | 52 ++++++++++++++++++++--------------- store/types/iterator_test.go | 2 +- store/types/store.go | 3 ++ 17 files changed, 72 insertions(+), 51 deletions(-) diff --git a/baseapp/options.go b/baseapp/options.go index a9377f223f84..00017184c821 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -64,6 +64,10 @@ func SetIAVLCacheSize(size int) func(*BaseApp) { return func(bapp *BaseApp) { bapp.cms.SetIAVLCacheSize(size) } } +func SetIAVLDisableFastNode(disable bool) func(*BaseApp) { + return func(bapp *BaseApp) { bapp.cms.SetIAVLDisableFastNode(disable) } +} + // SetInterBlockCache provides a BaseApp option function that sets the // inter-block cache. func SetInterBlockCache(cache sdk.MultiStorePersistentCache) func(*BaseApp) { diff --git a/go.mod b/go.mod index 75fdfcc44645..26c24c398120 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/cosmos/cosmos-sdk/store/tools/ics23 v0.0.0-20220820010601-dc361be9e3ff github.com/cosmos/go-bip39 v1.0.0 github.com/cosmos/gogoproto v1.4.2 - github.com/cosmos/iavl v0.19.1 + github.com/cosmos/iavl v0.19.2-0.20220916140702-9b6be3095313 github.com/cosmos/ledger-cosmos-go v0.11.1 github.com/gogo/gateway v1.1.0 github.com/golang/mock v1.6.0 diff --git a/go.sum b/go.sum index df52e83ad8b5..c09c6c1e0498 100644 --- a/go.sum +++ b/go.sum @@ -194,8 +194,8 @@ github.com/cosmos/gogoproto v1.4.2 h1:UeGRcmFW41l0G0MiefWhkPEVEwvu78SZsHBvI78dAY github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU= github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4Y= github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw= -github.com/cosmos/iavl v0.19.1 h1:3gaq9b6SjiB0KBTygRnAvEGml2pQlu1TH8uma5g63Ys= -github.com/cosmos/iavl v0.19.1/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= +github.com/cosmos/iavl v0.19.2-0.20220916140702-9b6be3095313 h1:R7CnaI/0OLwOusy7n9750n8fqQ3yCQ8OJQI2L3ws9RA= +github.com/cosmos/iavl v0.19.2-0.20220916140702-9b6be3095313/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= github.com/cosmos/keyring v1.2.0 h1:8C1lBP9xhImmIabyXW4c3vFjjLiBdGCmfLUfeZlV1Yo= github.com/cosmos/keyring v1.2.0/go.mod h1:fc+wB5KTk9wQ9sDx0kFXB3A0MaeGHM9AwRStKOQ5vOA= github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4= diff --git a/server/mock/store.go b/server/mock/store.go index ce5f8409a71d..51d44ed9d215 100644 --- a/server/mock/store.go +++ b/server/mock/store.go @@ -130,6 +130,10 @@ func (ms multiStore) SetIAVLCacheSize(size int) { panic("not implemented") } +func (ms multiStore) SetIAVLDisableFastNode(disable bool) { + panic("not implemented") +} + func (ms multiStore) SetInitialVersion(version int64) error { panic("not implemented") } diff --git a/server/start.go b/server/start.go index 4165b8a618c8..a026d54d6e08 100644 --- a/server/start.go +++ b/server/start.go @@ -56,6 +56,7 @@ const ( FlagIndexEvents = "index-events" FlagMinRetainBlocks = "min-retain-blocks" FlagIAVLCacheSize = "iavl-cache-size" + FlagIAVLFastnode = "iavl-fast-node" // state sync-related flags FlagStateSyncSnapshotInterval = "state-sync.snapshot-interval" diff --git a/simapp/go.mod b/simapp/go.mod index 8468a82199d4..e4b9c60e3d5f 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -45,7 +45,7 @@ require ( github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/gogoproto v1.4.2 // indirect github.com/cosmos/gorocksdb v1.2.0 // indirect - github.com/cosmos/iavl v0.19.1 // indirect + github.com/cosmos/iavl v0.19.2-0.20220916140702-9b6be3095313 // indirect github.com/cosmos/ledger-cosmos-go v0.11.1 // indirect github.com/cosmos/ledger-go v0.9.2 // indirect github.com/creachadair/taskgroup v0.3.2 // indirect diff --git a/simapp/go.sum b/simapp/go.sum index c6bbc67733be..8b2058e8fa98 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -190,8 +190,8 @@ github.com/cosmos/gogoproto v1.4.2 h1:UeGRcmFW41l0G0MiefWhkPEVEwvu78SZsHBvI78dAY github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU= github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4Y= github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw= -github.com/cosmos/iavl v0.19.1 h1:3gaq9b6SjiB0KBTygRnAvEGml2pQlu1TH8uma5g63Ys= -github.com/cosmos/iavl v0.19.1/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= +github.com/cosmos/iavl v0.19.2-0.20220916140702-9b6be3095313 h1:R7CnaI/0OLwOusy7n9750n8fqQ3yCQ8OJQI2L3ws9RA= +github.com/cosmos/iavl v0.19.2-0.20220916140702-9b6be3095313/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= github.com/cosmos/keyring v1.2.0 h1:8C1lBP9xhImmIabyXW4c3vFjjLiBdGCmfLUfeZlV1Yo= github.com/cosmos/keyring v1.2.0/go.mod h1:fc+wB5KTk9wQ9sDx0kFXB3A0MaeGHM9AwRStKOQ5vOA= github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4= diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index e64a62b1e796..3d6d827793ed 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -304,6 +304,7 @@ func newApp( baseapp.SetIndexEvents(cast.ToStringSlice(appOpts.Get(server.FlagIndexEvents))), baseapp.SetSnapshot(snapshotStore, snapshotOptions), baseapp.SetIAVLCacheSize(cast.ToInt(appOpts.Get(server.FlagIAVLCacheSize))), + baseapp.SetIAVLDisableFastNode(cast.ToBool(appOpts.Get(server.FlagIAVLFastnode))), ) } diff --git a/store/cache/cache_test.go b/store/cache/cache_test.go index 45c5d147a4ca..1a38981adbe5 100644 --- a/store/cache/cache_test.go +++ b/store/cache/cache_test.go @@ -18,7 +18,7 @@ func TestGetOrSetStoreCache(t *testing.T) { mngr := cache.NewCommitKVStoreCacheManager(cache.DefaultCommitKVStoreCacheSize) sKey := types.NewKVStoreKey("test") - tree, err := iavl.NewMutableTree(db, 100) + tree, err := iavl.NewMutableTree(db, 100, false) require.NoError(t, err) store := iavlstore.UnsafeNewStore(tree) store2 := mngr.GetStoreCache(sKey, store) @@ -32,7 +32,7 @@ func TestUnwrap(t *testing.T) { mngr := cache.NewCommitKVStoreCacheManager(cache.DefaultCommitKVStoreCacheSize) sKey := types.NewKVStoreKey("test") - tree, err := iavl.NewMutableTree(db, 100) + tree, err := iavl.NewMutableTree(db, 100, false) require.NoError(t, err) store := iavlstore.UnsafeNewStore(tree) _ = mngr.GetStoreCache(sKey, store) @@ -46,7 +46,7 @@ func TestStoreCache(t *testing.T) { mngr := cache.NewCommitKVStoreCacheManager(cache.DefaultCommitKVStoreCacheSize) sKey := types.NewKVStoreKey("test") - tree, err := iavl.NewMutableTree(db, 100) + tree, err := iavl.NewMutableTree(db, 100, false) require.NoError(t, err) store := iavlstore.UnsafeNewStore(tree) kvStore := mngr.GetStoreCache(sKey, store) diff --git a/store/iavl/store.go b/store/iavl/store.go index 6437971f923b..b9482ba5462f 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -43,16 +43,16 @@ type Store struct { // LoadStore returns an IAVL Store as a CommitKVStore. Internally, it will load the // store's version (id) from the provided DB. An error is returned if the version // fails to load, or if called with a positive version on an empty tree. -func LoadStore(db dbm.DB, logger log.Logger, key types.StoreKey, id types.CommitID, lazyLoading bool, cacheSize int) (types.CommitKVStore, error) { - return LoadStoreWithInitialVersion(db, logger, key, id, lazyLoading, 0, cacheSize) +func LoadStore(db dbm.DB, logger log.Logger, key types.StoreKey, id types.CommitID, lazyLoading bool, cacheSize int, disableFastnode bool) (types.CommitKVStore, error) { + return LoadStoreWithInitialVersion(db, logger, key, id, lazyLoading, 0, cacheSize, disableFastnode) } // LoadStoreWithInitialVersion returns an IAVL Store as a CommitKVStore setting its initialVersion // to the one given. Internally, it will load the store's version (id) from the // provided DB. An error is returned if the version fails to load, or if called with a positive // version on an empty tree. -func LoadStoreWithInitialVersion(db dbm.DB, logger log.Logger, key types.StoreKey, id types.CommitID, lazyLoading bool, initialVersion uint64, cacheSize int) (types.CommitKVStore, error) { - tree, err := iavl.NewMutableTreeWithOpts(db, cacheSize, &iavl.Options{InitialVersion: initialVersion}) +func LoadStoreWithInitialVersion(db dbm.DB, logger log.Logger, key types.StoreKey, id types.CommitID, lazyLoading bool, initialVersion uint64, cacheSize int, disableFastnode bool) (types.CommitKVStore, error) { + tree, err := iavl.NewMutableTreeWithOpts(db, cacheSize, &iavl.Options{InitialVersion: initialVersion}, disableFastnode) if err != nil { return nil, err } diff --git a/store/iavl/store_test.go b/store/iavl/store_test.go index c70bedfd7e6e..f1cd586e36a0 100644 --- a/store/iavl/store_test.go +++ b/store/iavl/store_test.go @@ -34,7 +34,7 @@ func randBytes(numBytes int) []byte { // make a tree with data from above and save it func newAlohaTree(t *testing.T, db dbm.DB) (*iavl.MutableTree, types.CommitID) { - tree, err := iavl.NewMutableTree(db, cacheSize) + tree, err := iavl.NewMutableTree(db, cacheSize, false) require.NoError(t, err) for k, v := range treeData { @@ -100,17 +100,17 @@ func TestLoadStore(t *testing.T) { require.Equal(t, string(hcStore.Get([]byte("hello"))), "ciao") // Querying a new store at some previous non-pruned height H - newHStore, err := LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), cIDH, false, DefaultIAVLCacheSize) + newHStore, err := LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), cIDH, false, DefaultIAVLCacheSize, false) require.NoError(t, err) require.Equal(t, string(newHStore.Get([]byte("hello"))), "hallo") // Querying a new store at some previous pruned height Hp - newHpStore, err := LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), cIDHp, false, DefaultIAVLCacheSize) + newHpStore, err := LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), cIDHp, false, DefaultIAVLCacheSize, false) require.NoError(t, err) require.Equal(t, string(newHpStore.Get([]byte("hello"))), "hola") // Querying a new store at current height H - newHcStore, err := LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), cIDHc, false, DefaultIAVLCacheSize) + newHcStore, err := LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), cIDHc, false, DefaultIAVLCacheSize, false) require.NoError(t, err) require.Equal(t, string(newHcStore.Get([]byte("hello"))), "ciao") } @@ -281,7 +281,7 @@ func TestIAVLIterator(t *testing.T) { func TestIAVLReverseIterator(t *testing.T) { db := dbm.NewMemDB() - tree, err := iavl.NewMutableTree(db, cacheSize) + tree, err := iavl.NewMutableTree(db, cacheSize, false) require.NoError(t, err) iavlStore := UnsafeNewStore(tree) @@ -314,7 +314,7 @@ func TestIAVLReverseIterator(t *testing.T) { func TestIAVLPrefixIterator(t *testing.T) { db := dbm.NewMemDB() - tree, err := iavl.NewMutableTree(db, cacheSize) + tree, err := iavl.NewMutableTree(db, cacheSize, false) require.NoError(t, err) iavlStore := UnsafeNewStore(tree) @@ -378,7 +378,7 @@ func TestIAVLPrefixIterator(t *testing.T) { func TestIAVLReversePrefixIterator(t *testing.T) { db := dbm.NewMemDB() - tree, err := iavl.NewMutableTree(db, cacheSize) + tree, err := iavl.NewMutableTree(db, cacheSize, false) require.NoError(t, err) iavlStore := UnsafeNewStore(tree) @@ -446,7 +446,7 @@ func nextVersion(iavl *Store) { func TestIAVLNoPrune(t *testing.T) { db := dbm.NewMemDB() - tree, err := iavl.NewMutableTree(db, cacheSize) + tree, err := iavl.NewMutableTree(db, cacheSize, false) require.NoError(t, err) iavlStore := UnsafeNewStore(tree) @@ -465,7 +465,7 @@ func TestIAVLNoPrune(t *testing.T) { func TestIAVLStoreQuery(t *testing.T) { db := dbm.NewMemDB() - tree, err := iavl.NewMutableTree(db, cacheSize) + tree, err := iavl.NewMutableTree(db, cacheSize, false) require.NoError(t, err) iavlStore := UnsafeNewStore(tree) @@ -569,7 +569,7 @@ func BenchmarkIAVLIteratorNext(b *testing.B) { b.ReportAllocs() db := dbm.NewMemDB() treeSize := 1000 - tree, err := iavl.NewMutableTree(db, cacheSize) + tree, err := iavl.NewMutableTree(db, cacheSize, false) require.NoError(b, err) for i := 0; i < treeSize; i++ { @@ -603,7 +603,7 @@ func TestSetInitialVersion(t *testing.T) { { "works with a mutable tree", func(db *dbm.MemDB) *Store { - tree, err := iavl.NewMutableTree(db, cacheSize) + tree, err := iavl.NewMutableTree(db, cacheSize, false) require.NoError(t, err) store := UnsafeNewStore(tree) @@ -613,7 +613,7 @@ func TestSetInitialVersion(t *testing.T) { { "throws error on immutable tree", func(db *dbm.MemDB) *Store { - tree, err := iavl.NewMutableTree(db, cacheSize) + tree, err := iavl.NewMutableTree(db, cacheSize, false) require.NoError(t, err) store := UnsafeNewStore(tree) _, version, err := store.tree.SaveVersion() diff --git a/store/iavl/tree_test.go b/store/iavl/tree_test.go index 44ba844473f2..02d19a97bf59 100644 --- a/store/iavl/tree_test.go +++ b/store/iavl/tree_test.go @@ -10,7 +10,7 @@ import ( func TestImmutableTreePanics(t *testing.T) { t.Parallel() - immTree := iavl.NewImmutableTree(dbm.NewMemDB(), 100) + immTree := iavl.NewImmutableTree(dbm.NewMemDB(), 100, false) it := &immutableTree{immTree} require.Panics(t, func() { it.Set([]byte{}, []byte{}) }) require.Panics(t, func() { it.Remove([]byte{}) }) diff --git a/store/prefix/store_test.go b/store/prefix/store_test.go index bf49e9cfe528..25e07cbb1ae3 100644 --- a/store/prefix/store_test.go +++ b/store/prefix/store_test.go @@ -90,7 +90,7 @@ func testPrefixStore(t *testing.T, baseStore types.KVStore, prefix []byte) { func TestIAVLStorePrefix(t *testing.T) { db := dbm.NewMemDB() - tree, err := tiavl.NewMutableTree(db, cacheSize) + tree, err := tiavl.NewMutableTree(db, cacheSize, false) require.NoError(t, err) iavlStore := iavl.UnsafeNewStore(tree) diff --git a/store/rootmulti/proof_test.go b/store/rootmulti/proof_test.go index 3e5d42067d9e..3769d884eb8c 100644 --- a/store/rootmulti/proof_test.go +++ b/store/rootmulti/proof_test.go @@ -15,7 +15,7 @@ import ( func TestVerifyIAVLStoreQueryProof(t *testing.T) { // Create main tree for testing. db := dbm.NewMemDB() - iStore, err := iavl.LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), types.CommitID{}, false, iavl.DefaultIAVLCacheSize) + iStore, err := iavl.LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), types.CommitID{}, false, iavl.DefaultIAVLCacheSize, false) store := iStore.(*iavl.Store) require.Nil(t, err) store.Set([]byte("MYKEY"), []byte("MYVALUE")) diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index b1d3294448e9..de6c453bf9a3 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -35,21 +35,24 @@ const ( commitInfoKeyFmt = "s/%d" // s/ ) +const iavlDisablefastNodeDefault = false + // Store is composed of many CommitStores. Name contrasts with // cacheMultiStore which is used for branching other MultiStores. It implements // the CommitMultiStore interface. type Store struct { - db dbm.DB - logger log.Logger - lastCommitInfo *types.CommitInfo - pruningManager *pruning.Manager - iavlCacheSize int - storesParams map[types.StoreKey]storeParams - stores map[types.StoreKey]types.CommitKVStore - keysByName map[string]types.StoreKey - lazyLoading bool - initialVersion int64 - removalMap map[types.StoreKey]bool + db dbm.DB + logger log.Logger + lastCommitInfo *types.CommitInfo + pruningManager *pruning.Manager + iavlCacheSize int + iavlDisableFastNode bool + storesParams map[types.StoreKey]storeParams + stores map[types.StoreKey]types.CommitKVStore + keysByName map[string]types.StoreKey + lazyLoading bool + initialVersion int64 + removalMap map[types.StoreKey]bool traceWriter io.Writer traceContext types.TraceContext @@ -71,15 +74,16 @@ var ( // LoadVersion must be called. func NewStore(db dbm.DB, logger log.Logger) *Store { return &Store{ - db: db, - logger: logger, - iavlCacheSize: iavl.DefaultIAVLCacheSize, - storesParams: make(map[types.StoreKey]storeParams), - stores: make(map[types.StoreKey]types.CommitKVStore), - keysByName: make(map[string]types.StoreKey), - listeners: make(map[types.StoreKey][]types.WriteListener), - removalMap: make(map[types.StoreKey]bool), - pruningManager: pruning.NewManager(db, logger), + db: db, + logger: logger, + iavlCacheSize: iavl.DefaultIAVLCacheSize, + iavlDisableFastNode: iavlDisablefastNodeDefault, + storesParams: make(map[types.StoreKey]storeParams), + stores: make(map[types.StoreKey]types.CommitKVStore), + keysByName: make(map[string]types.StoreKey), + listeners: make(map[types.StoreKey][]types.WriteListener), + removalMap: make(map[types.StoreKey]bool), + pruningManager: pruning.NewManager(db, logger), } } @@ -105,6 +109,10 @@ func (rs *Store) SetIAVLCacheSize(cacheSize int) { rs.iavlCacheSize = cacheSize } +func (rs *Store) SetIAVLDisableFastNode(disableFastNode bool) { + rs.iavlDisableFastNode = disableFastNode +} + // SetLazyLoading sets if the iavl store should be loaded lazily or not func (rs *Store) SetLazyLoading(lazyLoading bool) { rs.lazyLoading = lazyLoading @@ -876,9 +884,9 @@ func (rs *Store) loadCommitStoreFromParams(key types.StoreKey, id types.CommitID var err error if params.initialVersion == 0 { - store, err = iavl.LoadStore(db, rs.logger, key, id, rs.lazyLoading, rs.iavlCacheSize) + store, err = iavl.LoadStore(db, rs.logger, key, id, rs.lazyLoading, rs.iavlCacheSize, rs.iavlDisableFastNode) } else { - store, err = iavl.LoadStoreWithInitialVersion(db, rs.logger, key, id, rs.lazyLoading, params.initialVersion, rs.iavlCacheSize) + store, err = iavl.LoadStoreWithInitialVersion(db, rs.logger, key, id, rs.lazyLoading, params.initialVersion, rs.iavlCacheSize, rs.iavlDisableFastNode) } if err != nil { diff --git a/store/types/iterator_test.go b/store/types/iterator_test.go index 57b072475eaf..7f0ef7234ee9 100644 --- a/store/types/iterator_test.go +++ b/store/types/iterator_test.go @@ -13,7 +13,7 @@ import ( func newMemTestKVStore(t *testing.T) types.KVStore { db := dbm.NewMemDB() - store, err := iavl.LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), types.CommitID{}, false, iavl.DefaultIAVLCacheSize) + store, err := iavl.LoadStore(db, log.NewNopLogger(), types.NewKVStoreKey("test"), types.CommitID{}, false, iavl.DefaultIAVLCacheSize, false) require.NoError(t, err) return store } diff --git a/store/types/store.go b/store/types/store.go index 0ef43576d426..e3c0f0822ad2 100644 --- a/store/types/store.go +++ b/store/types/store.go @@ -189,6 +189,9 @@ type CommitMultiStore interface { // SetIAVLCacheSize sets the cache size of the IAVL tree. SetIAVLCacheSize(size int) + // SetIAVLDisableFastNode enables/disables fastnode feature on iavl. + SetIAVLDisableFastNode(disable bool) + // RollbackToVersion rollback the db to specific version(height). RollbackToVersion(version int64) error } From e08766c3ad0d6ff9a0c99d9970701117b665d782 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 16 Sep 2022 16:43:59 +0200 Subject: [PATCH 2/7] add it to toml --- server/config/config.go | 46 +++++++++++++++++++++++------------------ server/config/toml.go | 4 ++++ 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/server/config/config.go b/server/config/config.go index d77aab06f934..21b9ff4490db 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -81,9 +81,13 @@ type BaseConfig struct { // IndexEvents defines the set of events in the form {eventType}.{attributeKey}, // which informs Tendermint what to index. If empty, all events will be indexed. IndexEvents []string `mapstructure:"index-events"` + // IavlCacheSize set the size of the iavl tree cache. IAVLCacheSize uint64 `mapstructure:"iavl-cache-size"` + // IAVLDisableFastnNode enables or disables the fast sync node. + IAVLDisableFastnNode bool `mapstructure:"iavl-disable-fastnode"` + // AppDBBackend defines the type of Database to use for the application and snapshots databases. // An empty string indicates that the Tendermint config's DBBackend value should be used. AppDBBackend string `mapstructure:"app-db-backend"` @@ -236,15 +240,16 @@ func (c *Config) GetMinGasPrices() sdk.DecCoins { func DefaultConfig() *Config { return &Config{ BaseConfig: BaseConfig{ - MinGasPrices: defaultMinGasPrices, - InterBlockCache: true, - Pruning: pruningtypes.PruningOptionDefault, - PruningKeepRecent: "0", - PruningInterval: "0", - MinRetainBlocks: 0, - IndexEvents: make([]string, 0), - IAVLCacheSize: 781250, // 50 MB - AppDBBackend: "", + MinGasPrices: defaultMinGasPrices, + InterBlockCache: true, + Pruning: pruningtypes.PruningOptionDefault, + PruningKeepRecent: "0", + PruningInterval: "0", + MinRetainBlocks: 0, + IndexEvents: make([]string, 0), + IAVLCacheSize: 781250, // 50 MB + IAVLDisableFastnNode: false, + AppDBBackend: "", }, Telemetry: telemetry.Config{ Enabled: false, @@ -306,17 +311,18 @@ func GetConfig(v *viper.Viper) (Config, error) { return Config{ BaseConfig: BaseConfig{ - MinGasPrices: v.GetString("minimum-gas-prices"), - InterBlockCache: v.GetBool("inter-block-cache"), - Pruning: v.GetString("pruning"), - PruningKeepRecent: v.GetString("pruning-keep-recent"), - PruningInterval: v.GetString("pruning-interval"), - HaltHeight: v.GetUint64("halt-height"), - HaltTime: v.GetUint64("halt-time"), - IndexEvents: v.GetStringSlice("index-events"), - MinRetainBlocks: v.GetUint64("min-retain-blocks"), - IAVLCacheSize: v.GetUint64("iavl-cache-size"), - AppDBBackend: v.GetString("app-db-backend"), + MinGasPrices: v.GetString("minimum-gas-prices"), + InterBlockCache: v.GetBool("inter-block-cache"), + Pruning: v.GetString("pruning"), + PruningKeepRecent: v.GetString("pruning-keep-recent"), + PruningInterval: v.GetString("pruning-interval"), + HaltHeight: v.GetUint64("halt-height"), + HaltTime: v.GetUint64("halt-time"), + IndexEvents: v.GetStringSlice("index-events"), + MinRetainBlocks: v.GetUint64("min-retain-blocks"), + IAVLCacheSize: v.GetUint64("iavl-cache-size"), + IAVLDisableFastnNode: v.GetBool("iavl-disable-fastnode"), + AppDBBackend: v.GetString("app-db-backend"), }, Telemetry: telemetry.Config{ ServiceName: v.GetString("telemetry.service-name"), diff --git a/server/config/toml.go b/server/config/toml.go index 65dceec60efd..69cc7df5bd04 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -74,6 +74,10 @@ index-events = [{{ range .BaseConfig.IndexEvents }}{{ printf "%q, " . }}{{end}}] # Default cache size is 50mb. iavl-cache-size = {{ .BaseConfig.IAVLCacheSize }} +# IavlDisableFastnNode enables or disables the fast node feature of IAVL. +# Default is false. +iavl-cache-size = {{ .BaseConfig.IAVLDisableFastnNode }} + # AppDBBackend defines the database backend type to use for the application and snapshots DBs. # An empty string indicates that a fallback will be used. # First fallback is the deprecated compile-time types.DBBackend value. From d915f07fc50163f605ce0c8dad7b9f3ede753cd6 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 16 Sep 2022 17:22:51 +0200 Subject: [PATCH 3/7] fix++ --- .../store_internal_proofs_createnonmembershipproof_test.go | 2 +- server/config/toml.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fuzz/tests/store_internal_proofs_createnonmembershipproof_test.go b/fuzz/tests/store_internal_proofs_createnonmembershipproof_test.go index acd47a1fa4dd..74210b576c36 100644 --- a/fuzz/tests/store_internal_proofs_createnonmembershipproof_test.go +++ b/fuzz/tests/store_internal_proofs_createnonmembershipproof_test.go @@ -25,7 +25,7 @@ func FuzzStoreInternalProofsCreateNonmembershipProof(f *testing.F) { if len(sz.Data) == 0 || len(sz.Key) == 0 { return } - tree, err := iavl.NewMutableTree(db.NewMemDB(), 0) + tree, err := iavl.NewMutableTree(db.NewMemDB(), 0, false) if err != nil { t.Fatal(err) } diff --git a/server/config/toml.go b/server/config/toml.go index 69cc7df5bd04..3e6e6cbe0732 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -76,7 +76,7 @@ iavl-cache-size = {{ .BaseConfig.IAVLCacheSize }} # IavlDisableFastnNode enables or disables the fast node feature of IAVL. # Default is false. -iavl-cache-size = {{ .BaseConfig.IAVLDisableFastnNode }} +iavl-disable-fastnode = {{ .BaseConfig.IAVLDisableFastnNode }} # AppDBBackend defines the database backend type to use for the application and snapshots DBs. # An empty string indicates that a fallback will be used. From 8d9eb4d40290254d27e30e45fbd1e4d40f67d520 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 16 Sep 2022 17:34:49 +0200 Subject: [PATCH 4/7] go mod tidy --- tests/go.mod | 2 +- tests/go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/go.mod b/tests/go.mod index aa044c5887fa..d963643823b2 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -43,7 +43,7 @@ require ( github.com/cosmos/cosmos-proto v1.0.0-alpha7 // indirect github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/gorocksdb v1.2.0 // indirect - github.com/cosmos/iavl v0.19.1 // indirect + github.com/cosmos/iavl v0.19.2-0.20220916140702-9b6be3095313 // indirect github.com/cosmos/ledger-cosmos-go v0.11.1 // indirect github.com/cosmos/ledger-go v0.9.2 // indirect github.com/creachadair/taskgroup v0.3.2 // indirect diff --git a/tests/go.sum b/tests/go.sum index beac75ee56c8..8441d5e85ce4 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -190,8 +190,8 @@ github.com/cosmos/gogoproto v1.4.2 h1:UeGRcmFW41l0G0MiefWhkPEVEwvu78SZsHBvI78dAY github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU= github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4Y= github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw= -github.com/cosmos/iavl v0.19.1 h1:3gaq9b6SjiB0KBTygRnAvEGml2pQlu1TH8uma5g63Ys= -github.com/cosmos/iavl v0.19.1/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= +github.com/cosmos/iavl v0.19.2-0.20220916140702-9b6be3095313 h1:R7CnaI/0OLwOusy7n9750n8fqQ3yCQ8OJQI2L3ws9RA= +github.com/cosmos/iavl v0.19.2-0.20220916140702-9b6be3095313/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= github.com/cosmos/keyring v1.2.0 h1:8C1lBP9xhImmIabyXW4c3vFjjLiBdGCmfLUfeZlV1Yo= github.com/cosmos/keyring v1.2.0/go.mod h1:fc+wB5KTk9wQ9sDx0kFXB3A0MaeGHM9AwRStKOQ5vOA= github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4= From d3dc87ffeceb36499901a854742eda67271d1bc9 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Sat, 17 Sep 2022 18:16:25 +0200 Subject: [PATCH 5/7] comments --- server/start.go | 2 +- simapp/simd/cmd/root.go | 2 +- store/iavl/store.go | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/server/start.go b/server/start.go index a026d54d6e08..beb51729b686 100644 --- a/server/start.go +++ b/server/start.go @@ -56,7 +56,7 @@ const ( FlagIndexEvents = "index-events" FlagMinRetainBlocks = "min-retain-blocks" FlagIAVLCacheSize = "iavl-cache-size" - FlagIAVLFastnode = "iavl-fast-node" + FlagIAVLFastNode = "iavl-disable-fastnode" // state sync-related flags FlagStateSyncSnapshotInterval = "state-sync.snapshot-interval" diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 3d6d827793ed..41d01e302af3 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -304,7 +304,7 @@ func newApp( baseapp.SetIndexEvents(cast.ToStringSlice(appOpts.Get(server.FlagIndexEvents))), baseapp.SetSnapshot(snapshotStore, snapshotOptions), baseapp.SetIAVLCacheSize(cast.ToInt(appOpts.Get(server.FlagIAVLCacheSize))), - baseapp.SetIAVLDisableFastNode(cast.ToBool(appOpts.Get(server.FlagIAVLFastnode))), + baseapp.SetIAVLDisableFastNode(cast.ToBool(appOpts.Get(server.FlagIAVLFastNode))), ) } diff --git a/store/iavl/store.go b/store/iavl/store.go index b9482ba5462f..c0a48c925e5d 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -43,16 +43,16 @@ type Store struct { // LoadStore returns an IAVL Store as a CommitKVStore. Internally, it will load the // store's version (id) from the provided DB. An error is returned if the version // fails to load, or if called with a positive version on an empty tree. -func LoadStore(db dbm.DB, logger log.Logger, key types.StoreKey, id types.CommitID, lazyLoading bool, cacheSize int, disableFastnode bool) (types.CommitKVStore, error) { - return LoadStoreWithInitialVersion(db, logger, key, id, lazyLoading, 0, cacheSize, disableFastnode) +func LoadStore(db dbm.DB, logger log.Logger, key types.StoreKey, id types.CommitID, lazyLoading bool, cacheSize int, disableFastNode bool) (types.CommitKVStore, error) { + return LoadStoreWithInitialVersion(db, logger, key, id, lazyLoading, 0, cacheSize, disableFastNode) } // LoadStoreWithInitialVersion returns an IAVL Store as a CommitKVStore setting its initialVersion // to the one given. Internally, it will load the store's version (id) from the // provided DB. An error is returned if the version fails to load, or if called with a positive // version on an empty tree. -func LoadStoreWithInitialVersion(db dbm.DB, logger log.Logger, key types.StoreKey, id types.CommitID, lazyLoading bool, initialVersion uint64, cacheSize int, disableFastnode bool) (types.CommitKVStore, error) { - tree, err := iavl.NewMutableTreeWithOpts(db, cacheSize, &iavl.Options{InitialVersion: initialVersion}, disableFastnode) +func LoadStoreWithInitialVersion(db dbm.DB, logger log.Logger, key types.StoreKey, id types.CommitID, lazyLoading bool, initialVersion uint64, cacheSize int, disableFastNode bool) (types.CommitKVStore, error) { + tree, err := iavl.NewMutableTreeWithOpts(db, cacheSize, &iavl.Options{InitialVersion: initialVersion}, disableFastNode) if err != nil { return nil, err } From e375fab98b23533379384fc6ab2330708b919f99 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Sat, 17 Sep 2022 18:18:41 +0200 Subject: [PATCH 6/7] godoc --- baseapp/options.go | 1 + 1 file changed, 1 insertion(+) diff --git a/baseapp/options.go b/baseapp/options.go index 00017184c821..f9a67f186d7c 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -64,6 +64,7 @@ func SetIAVLCacheSize(size int) func(*BaseApp) { return func(bapp *BaseApp) { bapp.cms.SetIAVLCacheSize(size) } } +// SetIAVLDisableFastNode enables(false)/disables(true) fast node usage from the IAVL store. func SetIAVLDisableFastNode(disable bool) func(*BaseApp) { return func(bapp *BaseApp) { bapp.cms.SetIAVLDisableFastNode(disable) } } From ff083a43498851fa720130ba8eb920417efc1c49 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Sat, 17 Sep 2022 22:43:15 +0200 Subject: [PATCH 7/7] add exmaple and changelog --- CHANGELOG.md | 1 + simapp/simd/cmd/root.go | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3e737a3d307..83e85f363931 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -87,6 +87,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [#13233](https://github.com/cosmos/cosmos-sdk/pull/13233) Add `--append` to `add-genesis-account` sub-command to append new tokens after an account is already created. * [#13236](https://github.com/cosmos/cosmos-sdk/pull/13236) Integrate Filter Logging * [#13301](https://github.com/cosmos/cosmos-sdk/pull/13301) Keep the balance query endpoint compatible with legacy blocks +* [#13321](https://github.com/cosmos/cosmos-sdk/pull/13321) Add flag to disable fast node migration and usage. ### State Machine Breaking diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 41d01e302af3..bcfaa1bd3619 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -145,6 +145,7 @@ func initAppConfig() (string, interface{}) { // // In simapp, we set the min gas prices to 0. srvCfg.MinGasPrices = "0stake" + // srvCfg.BaseConfig.IAVLDisableFastnNode = true // disable fastnode by default customAppConfig := CustomAppConfig{ Config: *srvCfg,