From 9ebb53bb824f6b8fd7b9feb62a6a227754bddbd3 Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Wed, 31 Aug 2022 11:10:58 -1000 Subject: [PATCH 1/2] updates --- store/cachekv/store.go | 11 +++++++---- x/group/keeper/invariants.go | 18 +++++++++++++----- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/store/cachekv/store.go b/store/cachekv/store.go index bd467c418f9..6d38fd09181 100644 --- a/store/cachekv/store.go +++ b/store/cachekv/store.go @@ -6,6 +6,7 @@ import ( "sort" "sync" + "github.com/tendermint/tendermint/libs/math" dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/internal/conv" @@ -13,7 +14,6 @@ import ( "github.com/cosmos/cosmos-sdk/store/tracekv" "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/types/kv" - "github.com/tendermint/tendermint/libs/math" ) // cValue represents a cached value. @@ -378,11 +378,14 @@ func (store *Store) clearUnsortedCacheSubset(unsorted []*kv.Pair, sortState sort if item.Value == nil { // deleted element, tracked by store.deleted // setting arbitrary value - store.sortedCache.Set(item.Key, []byte{}) + if err := store.sortedCache.Set(item.Key, []byte{}); err != nil { + panic(err) + } + continue } - err := store.sortedCache.Set(item.Key, item.Value) - if err != nil { + + if err := store.sortedCache.Set(item.Key, item.Value); err != nil { panic(err) } } diff --git a/x/group/keeper/invariants.go b/x/group/keeper/invariants.go index 2008fd3c934..24b592a3702 100644 --- a/x/group/keeper/invariants.go +++ b/x/group/keeper/invariants.go @@ -38,12 +38,8 @@ func GroupTotalWeightInvariantHelper(ctx sdk.Context, key storetypes.StoreKey, g } defer groupIt.Close() + groups := make(map[uint64]group.GroupInfo) for { - membersWeight, err := groupmath.NewNonNegativeDecFromString("0") - if err != nil { - msg += fmt.Sprintf("error while parsing positive dec zero for group member\n%v\n", err) - return msg, broken - } var groupInfo group.GroupInfo _, err = groupIt.LoadNext(&groupInfo) if errors.ErrORMIteratorDone.Is(err) { @@ -54,6 +50,16 @@ func GroupTotalWeightInvariantHelper(ctx sdk.Context, key storetypes.StoreKey, g return msg, broken } + groups[groupInfo.Id] = groupInfo + } + + for _, groupInfo := range groups { + membersWeight, err := groupmath.NewNonNegativeDecFromString("0") + if err != nil { + msg += fmt.Sprintf("error while parsing positive dec zero for group member\n%v\n", err) + return msg, broken + } + memIt, err := groupMemberByGroupIndex.Get(ctx.KVStore(key), groupInfo.Id) if err != nil { msg += fmt.Sprintf("error while returning group member iterator for group with ID %d\n%v\n", groupInfo.Id, err) @@ -77,6 +83,7 @@ func GroupTotalWeightInvariantHelper(ctx sdk.Context, key storetypes.StoreKey, g msg += fmt.Sprintf("error while parsing non-nengative decimal for group member %s\n%v\n", groupMember.Member.Address, err) return msg, broken } + membersWeight, err = groupmath.Add(membersWeight, curMemWeight) if err != nil { msg += fmt.Sprintf("decimal addition error while adding group member voting weight to total voting weight\n%v\n", err) @@ -96,5 +103,6 @@ func GroupTotalWeightInvariantHelper(ctx sdk.Context, key storetypes.StoreKey, g break } } + return msg, broken } From 87a88b19efda13a21322c03a74010c9fc533b979 Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Wed, 31 Aug 2022 11:13:41 -1000 Subject: [PATCH 2/2] updates --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6aec95cd60..edcd3f325e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -126,10 +126,9 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### CLI Breaking Changes -* / - ### Bug Fixes +* [#13116](https://github.com/cosmos/cosmos-sdk/pull/13116) Fix a dead-lock in the `Group-TotalWeight` `x/group` invariant. * [#13046](https://github.com/cosmos/cosmos-sdk/pull/13046) Fix missing return statement in BaseApp.Query. * [#12548](https://github.com/cosmos/cosmos-sdk/pull/12548) Prevent signing from wrong key while using multisig. * (genutil) [#12140](https://github.com/cosmos/cosmos-sdk/pull/12140) Fix staking's genesis JSON migrate in the `simd migrate v0.46` CLI command.