Skip to content

Commit

Permalink
pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
KonradStaniec committed Dec 3, 2024
1 parent 1f856cf commit 8660102
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 116 deletions.
3 changes: 3 additions & 0 deletions proto/babylon/btcstaking/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ message QueryParamsByBTCHeightRequest {
message QueryParamsByBTCHeightResponse {
// params holds all the parameters of this module.
Params params = 1 [(gogoproto.nullable) = false];

// version is the version of the params for the given BTC height
uint32 version = 2;
}

// QueryFinalityProvidersRequest is the request type for the
Expand Down
4 changes: 2 additions & 2 deletions x/btcstaking/keeper/query_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ func (k Keeper) ParamsByBTCHeight(
}
ctx := sdk.UnwrapSDKContext(goCtx)

p, _, err := k.GetParamsForBtcHeight(ctx, uint64(req.BtcHeight))
p, version, err := k.GetParamsForBtcHeight(ctx, uint64(req.BtcHeight))
if err != nil {
return nil, types.ErrParamsNotFound.Wrapf("params for btc height %d not found", req.BtcHeight)
}

return &types.QueryParamsByBTCHeightResponse{Params: *p}, nil
return &types.QueryParamsByBTCHeightResponse{Params: *p, Version: version}, nil
}
4 changes: 2 additions & 2 deletions x/btcstaking/keeper/query_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ func TestParamsByBTCHeightQuery(t *testing.T) {

resp0, err := keeper.ParamsByBTCHeight(ctx, &types.QueryParamsByBTCHeightRequest{BtcHeight: params1.BtcActivationHeight})
require.NoError(t, err)
require.Equal(t, &types.QueryParamsByBTCHeightResponse{Params: params1}, resp0)
require.Equal(t, &types.QueryParamsByBTCHeightResponse{Params: params1, Version: 1}, resp0)

resp1, err := keeper.ParamsByBTCHeight(ctx, &types.QueryParamsByBTCHeightRequest{BtcHeight: params2.BtcActivationHeight})
require.NoError(t, err)
require.Equal(t, &types.QueryParamsByBTCHeightResponse{Params: params2}, resp1)
require.Equal(t, &types.QueryParamsByBTCHeightResponse{Params: params2, Version: 2}, resp1)
}
8 changes: 8 additions & 0 deletions x/btcstaking/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,21 @@ func (m *HeightToVersionMap) GetLastPair() *HeightVersionPair {
return m.Pairs[len(m.Pairs)-1]
}

// AddNewPair adds a new pair to the map it preserves the following invariants:
// 1. pairs are sorted by start height in ascending order
// 2. versions are strictly increasing by increments of 1
// If newPair breaks any of the invariants, it returns an error
func (m *HeightToVersionMap) AddNewPair(startHeight uint64, version uint32) error {
return m.AddPair(&HeightVersionPair{
StartHeight: startHeight,
Version: version,
})
}

// AddPair adds a new pair to the map it preserves the following invariants:
// 1. pairs are sorted by start height in ascending order
// 2. versions are strictly increasing by increments of 1
// If newPair breaks any of the invariants, it returns an error
func (m *HeightToVersionMap) AddPair(newPair *HeightVersionPair) error {
if len(m.Pairs) == 0 && newPair.Version != 0 {
return fmt.Errorf("version must be 0 for the first pair")
Expand Down
Loading

0 comments on commit 8660102

Please sign in to comment.