Skip to content

Commit

Permalink
Merge pull request #147 from binance-chain/add_set_version
Browse files Browse the repository at this point in the history
set version
  • Loading branch information
yutianwu authored Jun 18, 2019
2 parents b89caab + 82a32d4 commit 93eb442
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 9 deletions.
15 changes: 8 additions & 7 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
4 changes: 4 additions & 0 deletions server/mock/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
4 changes: 4 additions & 0 deletions store/iavlstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ func (st *IavlStore) GetImmutableTree() *iavl.ImmutableTree {
return st.Tree.ImmutableTree
}

func (st *IavlStore) SetVersion(version int64) {
st.Tree.SetVersion(version)
}

// Implements Committer.
func (st *IavlStore) Commit() CommitID {
// Save a new version.
Expand Down
8 changes: 8 additions & 0 deletions store/rootmultistore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -476,6 +479,11 @@ func commitStores(version int64, storeMap map[StoreKey]CommitStore) CommitInfo {
continue
}

// set version for store to commit, just to keep the same as the other stores
if sdk.ShouldSetStoreVersion(key.Name()) {
store.SetVersion(version - 1)
}

// Commit
commitID := store.Commit()

Expand Down
6 changes: 5 additions & 1 deletion store/transientstore.go
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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}
Expand Down
1 change: 1 addition & 0 deletions types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Committer interface {
Commit() CommitID
LastCommitID() CommitID
SetPruning(PruningStrategy)
SetVersion(version int64)
}

// Stores of MultiStore must implement CommitStore.
Expand Down
9 changes: 9 additions & 0 deletions types/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 93eb442

Please sign in to comment.