Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
6ed9e1f
WIP: add ibc rate limit middleware to ibc transfer
gsk967 Nov 7, 2022
4ce49c9
Merge main
gsk967 Nov 9, 2022
aada85f
WIP: add cll tx,query cmds
gsk967 Nov 9, 2022
08e3d08
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Nov 10, 2022
16b50cd
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Nov 11, 2022
57870ca
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Nov 11, 2022
8412c70
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Nov 12, 2022
9a4d380
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Nov 12, 2022
28e2422
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Nov 12, 2022
8e24765
WIP: add check rate limits for ibc denom
gsk967 Nov 14, 2022
4ad23eb
remove ibc-rate-limits and move rate limits into ibctransfer module
gsk967 Nov 14, 2022
9bf0109
move the umme ibctransfer into ics20 folder
gsk967 Nov 14, 2022
a87ff0d
fix: fix the lint
gsk967 Nov 14, 2022
bdeaec3
refactor: change the module structure to 'authz' type of cosmos-sdk
gsk967 Nov 15, 2022
aba25e0
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Nov 15, 2022
7981d0d
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Nov 16, 2022
37b15b3
remove inflow_limit in rate limits
gsk967 Nov 16, 2022
ea1316e
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Nov 16, 2022
ac8381c
Merge remote-tracking branch 'origin/sai/ibc-rate-limit' into sai/ibc…
gsk967 Nov 16, 2022
a8206d3
chore: check the rate limits by exchange rate
gsk967 Nov 17, 2022
990db76
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Nov 17, 2022
49c2bbb
add denom exponent to calculate amount in USD
gsk967 Nov 17, 2022
b5435b1
calculating the sent amount with exponent of registerd token
gsk967 Nov 17, 2022
3143115
fix: fix the amount calculation
gsk967 Nov 17, 2022
db358cf
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Nov 17, 2022
0b30201
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Nov 19, 2022
bce7a99
Merge main
gsk967 Nov 22, 2022
30bbdfc
fix: fix the rate-limit reset issue
gsk967 Nov 22, 2022
c2d0bc5
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Nov 23, 2022
01ce260
refactor: update the params
gsk967 Nov 23, 2022
223f094
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Nov 24, 2022
7b55068
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Nov 28, 2022
c4b7de8
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Nov 29, 2022
b27ff0d
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Dec 5, 2022
e75b6f9
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Dec 23, 2022
90f82b5
fix: fix the build
gsk967 Dec 23, 2022
47f09be
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Dec 27, 2022
ff6239a
chore: update the limits and quota interval
gsk967 Dec 27, 2022
ecacc9e
chore: fix the lint issues
gsk967 Dec 27, 2022
6968250
chore: fix the lint issues
gsk967 Dec 27, 2022
0e2ef16
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Dec 27, 2022
eea2115
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Dec 29, 2022
be02147
chore: addree the pr comments
gsk967 Dec 29, 2022
e9a8717
chore: remove the param subspace from uibc
gsk967 Dec 29, 2022
be8bc11
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Dec 30, 2022
267e958
refactor: refactor the proto and logic
gsk967 Dec 30, 2022
1aeb647
chore: address the pr comments
gsk967 Dec 30, 2022
b952683
fix: fix the buf lint
gsk967 Dec 30, 2022
1b119c7
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Jan 2, 2023
1db2900
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Jan 10, 2023
aa1daea
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Jan 11, 2023
c5bfd75
chore: get the exchange price from TokenValue of leverage
gsk967 Jan 11, 2023
860795b
Merge remote-tracking branch 'origin/sai/ibc-rate-limit' into sai/ibc…
gsk967 Jan 11, 2023
b28f8f4
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Jan 11, 2023
e485b2a
chore: convert uToken to baseToken in ibc-transfer quota checking
gsk967 Jan 11, 2023
3ae43d4
chore: add typed events for emit events
gsk967 Jan 12, 2023
f1d1e54
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Jan 12, 2023
64600ef
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Jan 16, 2023
4da6298
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Jan 16, 2023
85e7486
address the review comments
gsk967 Jan 16, 2023
16e6488
refactor the code
gsk967 Jan 17, 2023
db8e103
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Jan 17, 2023
a3f01de
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Jan 18, 2023
07d05c5
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Jan 23, 2023
14cdcd3
address the pr comments
gsk967 Jan 23, 2023
1dee0e7
chore: fix the build issue
gsk967 Jan 23, 2023
8f052ec
chore: add tests for params
gsk967 Jan 23, 2023
0d71fd2
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Jan 23, 2023
07fe9b4
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Jan 24, 2023
8f1cbe9
fix: fix the update quota params
gsk967 Jan 24, 2023
14c2558
Merge remote-tracking branch 'origin/sai/ibc-rate-limit' into sai/ibc…
gsk967 Jan 24, 2023
a3c1e58
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Jan 24, 2023
14badea
chore: address the pr comments
gsk967 Jan 24, 2023
78184a5
chore: fix the lint
gsk967 Jan 24, 2023
e7ca80f
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Jan 27, 2023
6e8cde5
address the pr comments++
gsk967 Jan 27, 2023
d558dc9
Merge branch 'main' into sai/ibc-rate-limit
gsk967 Jan 30, 2023
b62b3db
address the pr comments
gsk967 Jan 30, 2023
9cc1660
Merge remote-tracking branch 'origin' into sai/ibc-rate-limit
gsk967 Jan 30, 2023
afcf52a
Merge remote-tracking branch 'origin/sai/ibc-rate-limit' into sai/ibc…
gsk967 Jan 30, 2023
16642e6
update reset quota
robert-zaremba Jan 30, 2023
f0ecf0a
move to Marshal to MustMarshal in uibc
gsk967 Jan 30, 2023
87d72ae
add TODO for ibc middleware acknowledgement
gsk967 Jan 30, 2023
8feec2a
add comment to outflow_sum
gsk967 Jan 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: address the pr comments
  • Loading branch information
gsk967 committed Jan 24, 2023
commit 14badeaa9f1affa7773ffbcc685da414c7501efd
3 changes: 0 additions & 3 deletions x/uibc/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,4 @@ var (
ErrIBCPauseStatus = sdkerrors.Register(ModuleName, 1, "invalid ibc pause status")
ErrQuotaExceeded = sdkerrors.Register(ModuleName, 2, "quota transfer exceeded")
ErrNoQuotaForIBCDenom = sdkerrors.Register(ModuleName, 3, "no quota for ibc denom")
ErrInvalidIBCDenom = sdkerrors.Register(ModuleName, 4, "invalid ibc denom")
ErrInvalidQuota = sdkerrors.Register(ModuleName, 5, "invalid quota")
ErrInvalidAmount = sdkerrors.Register(ModuleName, 6, "invalid transfer amount")
)
21 changes: 1 addition & 20 deletions x/uibc/module/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,16 @@ import (

// BeginBlock implements BeginBlock for the x/uibc module.
func BeginBlock(ctx sdk.Context, keeper keeper.Keeper) {
params := keeper.GetParams(ctx)
quotaExpires, err := keeper.GetExpire(ctx)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
if err != nil {
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
}

// reset quotas
if quotaExpires == nil || quotaExpires.Before(ctx.BlockTime()) {

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
newExpires := ctx.BlockTime().Add(params.QuotaDuration)
if err := keeper.SetExpire(ctx, newExpires); err != nil {
if err := keeper.ResetQuota(ctx); err != nil {

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
}
if err := keeper.SetTotalOutflowSum(ctx, sdk.NewDec(0)); err != nil {
panic(err)
}

quotaOfIBCDenoms, err := keeper.GetQuotaOfIBCDenoms(ctx)
if err != nil {
panic(err)
}

for _, quotaOfIBCDenom := range quotaOfIBCDenoms {
// reset the outflow sum to 0
quotaOfIBCDenom.OutflowSum = sdk.NewDec(0)
// storing the rate limits to store
if err := keeper.SetDenomQuota(ctx, quotaOfIBCDenom); err != nil {
panic(err)
}
}
}
}

Expand Down
14 changes: 7 additions & 7 deletions x/uibc/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ var (
_ sdk.Msg = &MsgGovSetIBCPause{}
)

// GetTitle returns the title of the proposal.
// GetTitle implements govv1b1.Content interface.
func (msg *MsgGovUpdateQuota) GetTitle() string { return msg.Title }

// GetDescription returns the description of the proposal.
// GetDescription implements govv1b1.Content interface.
func (msg *MsgGovUpdateQuota) GetDescription() string { return msg.Description }

// Route implements Msg
Expand All @@ -39,11 +39,11 @@ func (msg *MsgGovUpdateQuota) ValidateBasic() error {
}

if msg.Total.IsNil() || !msg.Total.IsPositive() {
return ErrInvalidQuota.Wrap("total quota must be positive")
return sdkerrors.ErrInvalidRequest.Wrap("total quota must be positive")
}

if msg.PerDenom.IsNil() || !msg.PerDenom.IsPositive() {
return ErrInvalidQuota.Wrap("quota per denom must be positive")
return sdkerrors.ErrInvalidRequest.Wrap("quota per denom must be positive")
}

return checkers.ValidateProposal(msg.Title, msg.Description, msg.Authority)
Expand All @@ -70,10 +70,10 @@ func NewUpdateIBCTransferPauseStatus(authority, title, description string,
}
}

// GetTitle returns the title of the proposal.
// GetTitle implements govv1b1.Content interface.
func (msg *MsgGovSetIBCPause) GetTitle() string { return msg.Title }

// GetDescription returns the description of the proposal.
// GetDescription implements govv1b1.Content interface.
func (msg *MsgGovSetIBCPause) GetDescription() string { return msg.Description }

// Route implements Msg
Expand Down Expand Up @@ -118,7 +118,7 @@ func (q *Quota) Validate() error {
}

if q.OutflowSum.IsNil() || q.OutflowSum.IsNegative() {
return ErrInvalidQuota.Wrap("ibc denom quota expires shouldn't be empty")
return sdkerrors.ErrInvalidRequest.Wrap("ibc denom quota expires shouldn't be empty")
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion x/uibc/quota/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (im IBCMiddleware) RevertSentPacket(

amount, ok := sdkmath.NewIntFromString(data.Amount)
if !ok {
return uibc.ErrInvalidAmount.Wrapf("amount %s", data.Amount)
return sdkerrors.ErrInvalidRequest.Wrapf("invalid transfer amount %s", data.Amount)
}

return im.keeper.UndoUpdateQuota(
Expand Down
10 changes: 0 additions & 10 deletions x/uibc/quota/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/umee-network/umee/v4/x/uibc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

var _ uibc.QueryServer = Querier{}
Expand All @@ -24,10 +22,6 @@ func NewQuerier(k Keeper) Querier {
func (q Querier) Params(goCtx context.Context, req *uibc.QueryParams) (
*uibc.QueryParamsResponse, error,
) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

ctx := sdk.UnwrapSDKContext(goCtx)
params := q.Keeper.GetParams(ctx)

Expand All @@ -38,10 +32,6 @@ func (q Querier) Params(goCtx context.Context, req *uibc.QueryParams) (
func (q Querier) Quota(goCtx context.Context, req *uibc.QueryQuota) (
*uibc.QueryQuotaResponse, error,
) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

ctx := sdk.UnwrapSDKContext(goCtx)

if len(req.Denom) == 0 {
Expand Down
29 changes: 29 additions & 0 deletions x/uibc/quota/keeper/quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,35 @@ func (k Keeper) GetExpire(ctx sdk.Context) (*time.Time, error) {
return &quotaExpires, nil
}

// ResetQuota will reset the ibc-transfer quotas
func (k Keeper) ResetQuota(ctx sdk.Context) error {
qd := k.GetParams(ctx).QuotaDuration
newExpires := ctx.BlockTime().Add(qd)
if err := k.SetExpire(ctx, newExpires); err != nil {
return err
}

if err := k.SetTotalOutflowSum(ctx, sdk.NewDec(0)); err != nil {
return err
}

quotaOfIBCDenoms, err := k.GetQuotaOfIBCDenoms(ctx)
if err != nil {
return err
}

for _, quotaOfIBCDenom := range quotaOfIBCDenoms {
// reset the outflow sum to 0
quotaOfIBCDenom.OutflowSum = sdk.NewDec(0)
// storing the rate limits to store
if err := k.SetDenomQuota(ctx, quotaOfIBCDenom); err != nil {
return err
}
}

return nil
}

// CheckAndUpdateQuota checks the quota of ibc-transfer of denom
func (k Keeper) CheckAndUpdateQuota(ctx sdk.Context, denom string, amount sdkmath.Int) error {
params := k.GetParams(ctx)
Expand Down
4 changes: 1 addition & 3 deletions x/uibc/quota/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
ibcexported "github.com/cosmos/ibc-go/v5/modules/core/exported"

"github.com/umee-network/umee/v4/x/uibc"
)

// SendPacket wraps IBC ChannelKeeper's SendPacket function
Expand All @@ -19,7 +17,7 @@ func (k Keeper) SendPacket(ctx sdk.Context, chanCap *capabilitytypes.Capability,

amount, ok := sdkmath.NewIntFromString(funds)
if !ok {
return uibc.ErrInvalidAmount.Wrapf("amount %s", funds)
return sdkerrors.ErrInvalidRequest.Wrapf("invalid transfer amount %s", funds)
}

if err := k.CheckAndUpdateQuota(ctx, denom, amount); err != nil {
Expand Down