From 3cc2cc99b8e3cad8b12f8c1d61ca2a38145abd30 Mon Sep 17 00:00:00 2001 From: Kevin Davis Date: Wed, 29 Apr 2020 18:02:31 -0400 Subject: [PATCH] fix: enforce sorting of cdp ids when storing (#475) --- x/cdp/keeper/cdp.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/x/cdp/keeper/cdp.go b/x/cdp/keeper/cdp.go index ba140aa2..712f817f 100644 --- a/x/cdp/keeper/cdp.go +++ b/x/cdp/keeper/cdp.go @@ -2,6 +2,7 @@ package keeper import ( "fmt" + "sort" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" @@ -271,6 +272,7 @@ func (k Keeper) IndexCdpByOwner(ctx sdk.Context, cdp types.CDP) { return } cdpIDs = append(cdpIDs, cdp.ID) + sort.Slice(cdpIDs, func(i, j int) bool { return cdpIDs[i] < cdpIDs[j] }) store.Set(cdp.Owner, k.cdc.MustMarshalBinaryLengthPrefixed(cdpIDs)) }