Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extra logs during commit #146

Merged
merged 2 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion store/rootmulti/proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
55 changes: 30 additions & 25 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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("prunning", "height", version, "to_prune", rs.pruneHeights)
p0mvn marked this conversation as resolved.
Show resolved Hide resolved
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,
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions store/types/commit_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
}
}