fix: enforce sorting of cdp ids when storing (#475)

This commit is contained in:
Kevin Davis 2020-04-29 18:02:31 -04:00 committed by GitHub
parent c175e9e856
commit 3cc2cc99b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@ package keeper
import ( import (
"fmt" "fmt"
"sort"
"github.com/cosmos/cosmos-sdk/store/prefix" "github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
@ -271,6 +272,7 @@ func (k Keeper) IndexCdpByOwner(ctx sdk.Context, cdp types.CDP) {
return return
} }
cdpIDs = append(cdpIDs, cdp.ID) 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)) store.Set(cdp.Owner, k.cdc.MustMarshalBinaryLengthPrefixed(cdpIDs))
} }