Skip to content

Commit

Permalink
Merge PR #4613: Only change rootmultistore hash when substore hashes …
Browse files Browse the repository at this point in the history
…change
  • Loading branch information
ethanfrey authored and alexanderbez committed Jun 25, 2019
1 parent 0feee1c commit 891eb8e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions .pending/bugfixes/sdk/1351-https-github-co
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[\#1351](https://github.com/cosmos/cosmos-sdk/issues/1351) Stable AppHash allows no_empty_blocks
2 changes: 1 addition & 1 deletion store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions store/rootmulti/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 10 additions & 4 deletions types/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ package types

import abci "github.com/tendermint/tendermint/abci/types"

// initialize application state at genesis
// InitChainer initializes application state at genesis
type InitChainer func(ctx Context, req abci.RequestInitChain) abci.ResponseInitChain

// run code before the transactions in a block
// BeginBlocker runs code before the transactions in a block
//
// Note: applications which set create_empty_blocks=false will not have regular block timing and should use
// e.g. BFT timestamps rather than block height for any periodic BeginBlock logic
type BeginBlocker func(ctx Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock

// run code after the transactions in a block and return updates to the validator set
// EndBlocker runs code after the transactions in a block and return updates to the validator set
//
// Note: applications which set create_empty_blocks=false will not have regular block timing and should use
// e.g. BFT timestamps rather than block height for any periodic EndBlock logic
type EndBlocker func(ctx Context, req abci.RequestEndBlock) abci.ResponseEndBlock

// respond to p2p filtering queries from Tendermint
// PeerFilter responds to p2p filtering queries from Tendermint
type PeerFilter func(info string) abci.ResponseQuery

0 comments on commit 891eb8e

Please sign in to comment.