From 2899dcf82f1608f91fd44a0673cf40e0b5d8b69b Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 9 Nov 2022 10:38:01 +0100 Subject: [PATCH] refactor: add error log when iavl set failed (backport #13803) (#13804) * refactor: add error log when iavl set failed (#13803) * add error log when iavl set failed Ref: #12012 * Update CHANGELOG.md * play safe (cherry picked from commit 22f326128559065b33606184bddcde9ad9fbcec3) # Conflicts: # CHANGELOG.md * fix conflicts Co-authored-by: yihuang --- CHANGELOG.md | 1 + store/iavl/store.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e803b9515539..d3d683e35313 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes * (x/gov) [#13728](https://github.com/cosmos/cosmos-sdk/pull/13728) Fix propagation of message events to the current context in `EndBlocker`. +* (store) [#13803](https://github.com/cosmos/cosmos-sdk/pull/13803) Add an error log if iavl set operation failed. ## [v0.46.4](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.4) - 2022-11-01 diff --git a/store/iavl/store.go b/store/iavl/store.go index 398a66995a50..21b1e70069df 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -37,7 +37,8 @@ var ( // Store Implements types.KVStore and CommitKVStore. type Store struct { - tree Tree + tree Tree + logger log.Logger } // LoadStore returns an IAVL Store as a CommitKVStore. Internally, it will load the @@ -87,7 +88,8 @@ func LoadStoreWithInitialVersion(db dbm.DB, logger log.Logger, key types.StoreKe } return &Store{ - tree: tree, + tree: tree, + logger: logger, }, nil } @@ -198,7 +200,10 @@ func (st *Store) CacheWrapWithListeners(storeKey types.StoreKey, listeners []typ func (st *Store) Set(key, value []byte) { types.AssertValidKey(key) types.AssertValidValue(value) - st.tree.Set(key, value) + _, err := st.tree.Set(key, value) + if err != nil && st.logger != nil { + st.logger.Error("iavl set error", "error", err.Error()) + } } // Implements types.KVStore.