From d1c006d07511a359782c1935fbbf9da4e026767b Mon Sep 17 00:00:00 2001 From: yutianwu Date: Mon, 17 Jun 2019 11:12:28 +0800 Subject: [PATCH 1/2] set version --- Gopkg.lock | 15 ++++++++------- Gopkg.toml | 2 +- server/mock/store.go | 4 ++++ store/iavlstore.go | 5 +++++ store/rootmultistore.go | 9 +++++++++ store/transientstore.go | 6 +++++- types/store.go | 1 + types/upgrade.go | 9 +++++++++ 8 files changed, 42 insertions(+), 9 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index b7ade8b8f..0d40ab598 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -445,17 +445,17 @@ version = "v0.14.1" [[projects]] - branch = "release/v0.12.0-binance.1" - digest = "1:3d89342599bf89417ae3c6197abf7f5b5a05dd6b2337df950aaa1d5d627bc47b" + branch = "add_set_version" + digest = "1:1d88f1320e234cdf1627b9025a5b565bceb597795e76db163af5e298cc715cae" name = "github.com/tendermint/iavl" packages = ["."] pruneopts = "UT" - revision = "" + revision = "df2579cea9dde3c1b79dec98893e38766576f386" source = "github.com/binance-chain/bnc-tendermint-iavl" [[projects]] branch = "release/v0.31.5-binance.0" - digest = "1:dbb6f4dbcde22f21c7c021ec2141a1a9339ed9b578a54201b07a0d6ad40e265d" + digest = "1:dc2205db501620ad7c2be28dec030e1c953ecb05b0010c26271e4f832c171a2e" name = "github.com/tendermint/tendermint" packages = [ "abci/client", @@ -552,9 +552,8 @@ name = "github.com/zondax/ledger-go" packages = ["."] pruneopts = "UT" - revision = "6d4c92579518a79bb50589cc1c35995f610832f5" - source = "https://github.com/binance-chain/ledger-go" - version = "v0.9.1" + revision = "94455688b6fac63ee05a4a61f44d5a4095317f74" + version = "v0.9.0" [[projects]] digest = "1:6f6dc6060c4e9ba73cf28aa88f12a69a030d3d19d518ef8e931879eaa099628d" @@ -737,6 +736,8 @@ "github.com/tendermint/tendermint/rpc/core/types", "github.com/tendermint/tendermint/rpc/lib/client", "github.com/tendermint/tendermint/rpc/lib/server", + "github.com/tendermint/tendermint/snapshot", + "github.com/tendermint/tendermint/state", "github.com/tendermint/tendermint/types", "github.com/tendermint/tendermint/version", "github.com/zondax/ledger-cosmos-go", diff --git a/Gopkg.toml b/Gopkg.toml index 4bef229ec..bab9f00c5 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -50,7 +50,7 @@ [[override]] name = "github.com/tendermint/iavl" source = "github.com/binance-chain/bnc-tendermint-iavl" - branch = "release/v0.12.0-binance.1" + branch = "add_set_version" # version = "=v0.12.0-binance.0" [[override]] diff --git a/server/mock/store.go b/server/mock/store.go index c6035fbd3..906238248 100644 --- a/server/mock/store.go +++ b/server/mock/store.go @@ -14,6 +14,10 @@ type multiStore struct { kv map[sdk.StoreKey]kvStore } +func (ms multiStore) SetVersion(version int64) { + panic("not implemented") +} + func (ms multiStore) CacheMultiStore() sdk.CacheMultiStore { panic("not implemented") } diff --git a/store/iavlstore.go b/store/iavlstore.go index 7de4beb90..ae6d3e832 100644 --- a/store/iavlstore.go +++ b/store/iavlstore.go @@ -70,6 +70,11 @@ func (st *IavlStore) GetImmutableTree() *iavl.ImmutableTree { return st.Tree.ImmutableTree } +func (st *IavlStore) SetVersion(version int64) { + st.Tree.SetVersion(version) + return +} + // Implements Committer. func (st *IavlStore) Commit() CommitID { // Save a new version. diff --git a/store/rootmultistore.go b/store/rootmultistore.go index 3274291e1..ca4de21db 100644 --- a/store/rootmultistore.go +++ b/store/rootmultistore.go @@ -199,6 +199,9 @@ func (rs *rootMultiStore) LastCommitID() CommitID { return rs.lastCommitID } +// Implements Committer/CommitStore. +func (rs *rootMultiStore) SetVersion(version int64) {} + // Implements Committer/CommitStore. func (rs *rootMultiStore) Commit() CommitID { version := rs.lastCommitID.Version + 1 @@ -476,9 +479,15 @@ func commitStores(version int64, storeMap map[StoreKey]CommitStore) CommitInfo { continue } + // set version for store to commit, just to keep the same with the other stores + if sdk.ShouldSetStoreVersion(key.Name()) { + store.SetVersion(version - 1) + } + // Commit commitID := store.Commit() + fmt.Printf("save %s %d\n", key.Name(), commitID.Version) if store.GetStoreType() == sdk.StoreTypeTransient { continue } diff --git a/store/transientstore.go b/store/transientstore.go index d3364e45f..588fe5732 100644 --- a/store/transientstore.go +++ b/store/transientstore.go @@ -1,8 +1,9 @@ package store import ( - sdk "github.com/cosmos/cosmos-sdk/types" dbm "github.com/tendermint/tendermint/libs/db" + + sdk "github.com/cosmos/cosmos-sdk/types" ) var _ KVStore = (*transientStore)(nil) @@ -33,6 +34,9 @@ func (ts *transientStore) LastCommitID() (id CommitID) { return } +// Implements CommitStore +func (ts *transientStore) SetVersion(version int64) {} + // Implements KVStore func (ts *transientStore) Prefix(prefix []byte) KVStore { return prefixStore{ts, prefix} diff --git a/types/store.go b/types/store.go index 2c3c5b714..90b70f787 100644 --- a/types/store.go +++ b/types/store.go @@ -36,6 +36,7 @@ type Committer interface { Commit() CommitID LastCommitID() CommitID SetPruning(PruningStrategy) + SetVersion(version int64) } // Stores of MultiStore must implement CommitStore. diff --git a/types/upgrade.go b/types/upgrade.go index 4c45524f0..263870973 100644 --- a/types/upgrade.go +++ b/types/upgrade.go @@ -155,6 +155,15 @@ func ShouldCommitStore(storeKeyName string) bool { return UpgradeMgr.GetHeight() >= storeKeyHeight } +func ShouldSetStoreVersion(storeKeyName string) bool { + storeKeyHeight := UpgradeMgr.GetStoreKeyHeight(storeKeyName) + if storeKeyHeight == 0 { + return false + } + + return UpgradeMgr.GetHeight() == storeKeyHeight +} + func IsMsgTypeSupported(msgType string) bool { msgTypeHeight := UpgradeMgr.GetMsgTypeHeight(msgType) if msgTypeHeight == 0 { From 82a32d4717d27c18496c5b4b7e814270ed98e311 Mon Sep 17 00:00:00 2001 From: yutianwu Date: Mon, 17 Jun 2019 14:47:18 +0800 Subject: [PATCH 2/2] remove print --- store/iavlstore.go | 1 - store/rootmultistore.go | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/store/iavlstore.go b/store/iavlstore.go index ae6d3e832..1b2b21fab 100644 --- a/store/iavlstore.go +++ b/store/iavlstore.go @@ -72,7 +72,6 @@ func (st *IavlStore) GetImmutableTree() *iavl.ImmutableTree { func (st *IavlStore) SetVersion(version int64) { st.Tree.SetVersion(version) - return } // Implements Committer. diff --git a/store/rootmultistore.go b/store/rootmultistore.go index ca4de21db..781a3be1a 100644 --- a/store/rootmultistore.go +++ b/store/rootmultistore.go @@ -479,7 +479,7 @@ func commitStores(version int64, storeMap map[StoreKey]CommitStore) CommitInfo { continue } - // set version for store to commit, just to keep the same with the other stores + // set version for store to commit, just to keep the same as the other stores if sdk.ShouldSetStoreVersion(key.Name()) { store.SetVersion(version - 1) } @@ -487,7 +487,6 @@ func commitStores(version int64, storeMap map[StoreKey]CommitStore) CommitInfo { // Commit commitID := store.Commit() - fmt.Printf("save %s %d\n", key.Name(), commitID.Version) if store.GetStoreType() == sdk.StoreTypeTransient { continue }