Merge PR #4613: Only change rootmultistore hash when substore hashes change
This commit is contained in:
committed by
Alexander Bezobchuk
parent
0feee1c160
commit
891eb8eec5
@@ -477,7 +477,7 @@ type storeCore struct {
|
||||
func (si storeInfo) Hash() []byte {
|
||||
// Doesn't write Name, since merkle.SimpleHashFromMap() will
|
||||
// include them via the keys.
|
||||
bz, _ := cdc.MarshalBinaryLengthPrefixed(si.Core)
|
||||
bz := si.Core.CommitID.Hash
|
||||
hasher := tmhash.New()
|
||||
|
||||
_, err := hasher.Write(bz)
|
||||
|
||||
@@ -77,6 +77,33 @@ func TestCacheMultiStoreWithVersion(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestHashStableWithEmptyCommit(t *testing.T) {
|
||||
var db dbm.DB = dbm.NewMemDB()
|
||||
if useDebugDB {
|
||||
db = dbm.NewDebugDB("CMS", db)
|
||||
}
|
||||
ms := newMultiStoreWithMounts(db)
|
||||
err := ms.LoadLatestVersion()
|
||||
require.Nil(t, err)
|
||||
|
||||
commitID := types.CommitID{}
|
||||
checkStore(t, ms, commitID, commitID)
|
||||
|
||||
k, v := []byte("wind"), []byte("blows")
|
||||
|
||||
store1 := ms.getStoreByName("store1").(types.KVStore)
|
||||
store1.Set(k, v)
|
||||
|
||||
cID := ms.Commit()
|
||||
require.Equal(t, int64(1), cID.Version)
|
||||
hash := cID.Hash
|
||||
|
||||
// make an empty commit, it should update version, but not affect hash
|
||||
cID = ms.Commit()
|
||||
require.Equal(t, int64(2), cID.Version)
|
||||
require.Equal(t, hash, cID.Hash)
|
||||
}
|
||||
|
||||
func TestMultistoreCommitLoad(t *testing.T) {
|
||||
var db dbm.DB = dbm.NewMemDB()
|
||||
if useDebugDB {
|
||||
|
||||
Reference in New Issue
Block a user