Skip to content

Commit

Permalink
fix GetVersionedParamsWithTs Semantics to contains equal
Browse files Browse the repository at this point in the history
  • Loading branch information
jingjunLi committed May 6, 2023
1 parent e779503 commit 2e120e2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions x/storage/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,12 @@ func (k Keeper) SetVersionedParamsWithTs(ctx sdk.Context, verParams types.Versio
return nil
}

// GetVersionedParamsWithTs find the latest params before the given time
// GetVersionedParamsWithTs find the latest params before and equal than the specific timestamp
func (k Keeper) GetVersionedParamsWithTs(ctx sdk.Context, ts int64) (verParams types.VersionedParams, err error) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.VersionedParamsKeyPrefix)

startKey := types.GetParamsKeyWithTimestamp(ts)
// ReverseIterator will exclusive end, so we increment ts by 1
startKey := types.GetParamsKeyWithTimestamp(ts + 1)
iterator := store.ReverseIterator(nil, startKey)
defer iterator.Close()
if !iterator.Valid() {
Expand Down
6 changes: 3 additions & 3 deletions x/storage/keeper/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func TestMultiVersiontParams(t *testing.T) {

require.EqualValues(t, params, k.GetParams(ctx))
// default params
require.EqualValues(t, GetVersionedParamsWithTimestamp(k, ctx, blockTimeT1+1).MaxSegmentSize, 1)
require.EqualValues(t, GetVersionedParamsWithTimestamp(k, ctx, blockTimeT2+1).MaxSegmentSize, 2)
require.EqualValues(t, GetVersionedParamsWithTimestamp(k, ctx, blockTimeT3+1).MaxSegmentSize, 3)
require.EqualValues(t, GetVersionedParamsWithTimestamp(k, ctx, blockTimeT1).MaxSegmentSize, 1)
require.EqualValues(t, GetVersionedParamsWithTimestamp(k, ctx, blockTimeT2).MaxSegmentSize, 2)
require.EqualValues(t, GetVersionedParamsWithTimestamp(k, ctx, blockTimeT3).MaxSegmentSize, 3)

}

0 comments on commit 2e120e2

Please sign in to comment.