diff --git a/baseapp/abci.go b/baseapp/abci.go index 80d0011dca36..0a782a97943d 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -306,7 +306,6 @@ func (app *BaseApp) Commit() (res abci.ResponseCommit) { // MultiStore (app.cms) so when Commit() is called is persists those values. app.deliverState.ms.Write() commitID := app.cms.Commit() - app.logger.Info("commit synced", "commit", fmt.Sprintf("%X", commitID)) // Reset the Check state to the latest committed. // @@ -339,6 +338,7 @@ func (app *BaseApp) Commit() (res abci.ResponseCommit) { go app.snapshot(header.Height) } + app.logger.Info("commited - baseapp", "height", commitID.Version, "commit_hash", commitID.Hash, "retain_height", retainHeight) return abci.ResponseCommit{ Data: commitID.Hash, RetainHeight: retainHeight, diff --git a/store/rootmulti/proof_test.go b/store/rootmulti/proof_test.go index 06152eceffb5..5edc0cbe527b 100644 --- a/store/rootmulti/proof_test.go +++ b/store/rootmulti/proof_test.go @@ -58,7 +58,7 @@ func TestVerifyIAVLStoreQueryProof(t *testing.T) { func TestVerifyMultiStoreQueryProof(t *testing.T) { // Create main tree for testing. db := dbm.NewMemDB() - store := NewStore(db, nil) + store := NewStore(db, log.NewNopLogger()) iavlStoreKey := types.NewKVStoreKey("iavlStoreKey") store.MountStoreWithDB(iavlStoreKey, types.StoreTypeIAVL, nil) diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index 20204388fe74..9a42d25efd67 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -386,7 +386,7 @@ func (rs *Store) Commit() types.CommitID { version = previousHeight + 1 } - rs.lastCommitInfo = commitStores(version, rs.stores) + rs.lastCommitInfo = rs.commitStores(version, rs.stores) var pruneErr error defer func () { @@ -412,12 +412,16 @@ func (rs *Store) Commit() types.CommitID { // batch prune if the current height is a pruning interval height if rs.pruningOpts.Interval > 0 && version%int64(rs.pruningOpts.Interval) == 0 { + rs.logger.Info("pruning", "height", version, "to_prune", rs.pruneHeights) pruneErr = rs.pruneStores() } + hash, keys := rs.lastCommitInfo.Hash() + rs.logger.Info("calculated commit hash", "height", version, "commit_hash", hash, "keys", keys) + return types.CommitID{ Version: version, - Hash: rs.lastCommitInfo.Hash(), + Hash: hash, } } @@ -950,6 +954,30 @@ func (rs *Store) buildCommitInfo(version int64) *types.CommitInfo { } } +// Commits each store and returns a new commitInfo. +func (rs *Store) commitStores(version int64, storeMap map[types.StoreKey]types.CommitKVStore) *types.CommitInfo { + storeInfos := make([]types.StoreInfo, 0, len(storeMap)) + + for key, store := range storeMap { + commitID := store.Commit() + rs.logger.Info("commit kvstore", "height", commitID.Version, "key", key, "commit_store_hash", commitID.Hash) + + if store.GetStoreType() == types.StoreTypeTransient { + continue + } + + si := types.StoreInfo{} + si.Name = key.Name() + si.CommitId = commitID + storeInfos = append(storeInfos, si) + } + + return &types.CommitInfo{ + Version: version, + StoreInfos: storeInfos, + } +} + type storeParams struct { key types.StoreKey db dbm.DB @@ -974,29 +1002,6 @@ func getLatestVersion(db dbm.DB) int64 { return latestVersion } -// Commits each store and returns a new commitInfo. -func commitStores(version int64, storeMap map[types.StoreKey]types.CommitKVStore) *types.CommitInfo { - storeInfos := make([]types.StoreInfo, 0, len(storeMap)) - - for key, store := range storeMap { - commitID := store.Commit() - - if store.GetStoreType() == types.StoreTypeTransient { - continue - } - - si := types.StoreInfo{} - si.Name = key.Name() - si.CommitId = commitID - storeInfos = append(storeInfos, si) - } - - return &types.CommitInfo{ - Version: version, - StoreInfos: storeInfos, - } -} - // Gets commitInfo from disk. func getCommitInfo(db dbm.DB, ver int64) (*types.CommitInfo, error) { cInfoKey := fmt.Sprintf(commitInfoKeyFmt, ver) diff --git a/store/types/commit_info.go b/store/types/commit_info.go index e713040739f8..3df7ae14f41f 100644 --- a/store/types/commit_info.go +++ b/store/types/commit_info.go @@ -31,14 +31,14 @@ func (ci CommitInfo) toMap() map[string][]byte { } // Hash returns the simple merkle root hash of the stores sorted by name. -func (ci CommitInfo) Hash() []byte { +func (ci CommitInfo) Hash() ([]byte, []string) { // we need a special case for empty set, as SimpleProofsFromMap requires at least one entry if len(ci.StoreInfos) == 0 { - return nil + return nil, nil } - rootHash, _, _ := sdkmaps.ProofsFromMap(ci.toMap()) - return rootHash + rootHash, _, keys := sdkmaps.ProofsFromMap(ci.toMap()) + return rootHash, keys } func (ci CommitInfo) ProofOp(storeName string) tmcrypto.ProofOp { @@ -66,8 +66,9 @@ func (ci CommitInfo) ProofOp(storeName string) tmcrypto.ProofOp { } func (ci CommitInfo) CommitID() CommitID { + hash, _ := ci.Hash() return CommitID{ Version: ci.Version, - Hash: ci.Hash(), + Hash: hash, } }