Skip to content

Commit

Permalink
feat: disable inflow quota (#2022)
Browse files Browse the repository at this point in the history
* feat: disable inflow quota
* changelog
* lint

* update ibc e2e test
  • Loading branch information
robert-zaremba committed May 5, 2023
1 parent 38bb99e commit 5286641
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 19 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ the Github PR referenced in the following format:
Types of changes (Stanzas):
State Machine Breaking: for any changes that result in a divergent application state.
Features: for new features.
Improvements: for changes in existing functionality.
Deprecated: for soon-to-be removed features.
Bug Fixes: for any bug fixes.
Client Breaking: for breaking Protobuf, CLI, gRPC and REST routes used by clients.
API Breaking: for breaking exported Go APIs used by developers.
State Machine Breaking: for any changes that result in a divergent application state.
To release a new version, ensure an appropriate release branch exists. Add a
release version and date to the existing Unreleased section which takes the form
Expand All @@ -46,7 +46,13 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

## [v4.3.0](https://github.com/umee-network/umee/releases/tag/v4.3.0) - 2023-04-5
## [v4.4.0](https://github.com/umee-network/umee/releases/tag/v4.3.0) - 2023-05-05

### State Machine Breaking

- [2022](https://github.com/umee-network/umee/pull/2022) Disable IBC ICS-20 inflow of only x/leverage registered tokens.

## [v4.3.0](https://github.com/umee-network/umee/releases/tag/v4.3.0) - 2023-04-05

### Features

Expand Down
11 changes: 7 additions & 4 deletions tests/e2e/e2e_ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ func (s *IntegrationTestSuite) TestIBCTokenTransfer() {
s.checkSupply(gaiaAPIEndpoint, umeeIBCHash, token.Amount)
})

// Non registered tokens (not exists in oracle for quota test)
// IBC Transfer will failed because it is not registered in leverage on receiver chain (UMEE)
// IBC inbound transfer of non x/leverage registered tokens must fail, because
// because we won't have price for it.
s.Run("send_stake_to_umee", func() {
// require the recipient account receives the IBC tokens (IBC packets ACKd)
var (
Expand All @@ -186,12 +186,15 @@ func (s *IntegrationTestSuite) TestIBCTokenTransfer() {
func() bool {
balances, err = queryUmeeAllBalances(umeeAPIEndpoint, recipient)
s.Require().NoError(err)
return math.ZeroInt().Equal(balances.AmountOf(stakeIBCHash))
// uncomment whene we re-enable inflow limit
// return math.ZeroInt().Equal(balances.AmountOf(stakeIBCHash))
return token.Amount.Equal(balances.AmountOf(stakeIBCHash))
},
time.Minute,
5*time.Second,
)
s.checkSupply(umeeAPIEndpoint, stakeIBCHash, math.ZeroInt())
// s.checkSupply(umeeAPIEndpoint, stakeIBCHash, math.ZeroInt())
s.checkSupply(umeeAPIEndpoint, stakeIBCHash, token.Amount)
})

var ibcStakeERC20Addr string
Expand Down
19 changes: 12 additions & 7 deletions x/uibc/ics20/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ func (am IBCModule) OnRecvPacket(
}

// Allowing only registered token for ibc transfer
isSourceChain := ibctransfertypes.SenderChainIsSource(packet.GetSourcePort(), packet.GetSourceChannel(), data.Denom)
ackErr := CheckIBCInflow(ctx, packet, am.lkeeper, data.Denom, isSourceChain)
if ackErr != nil {
return ackErr
}
// TODO: re-enable inflow checks
// isSourceChain := ibctransfertypes.SenderChainIsSource(packet.GetSourcePort(), packet.GetSourceChannel(), data.Denom)
// ackErr := CheckIBCInflow(ctx, packet, am.lkeeper, data.Denom, isSourceChain)
// if ackErr != nil {
// return ackErr
// }

ack := am.IBCModule.OnRecvPacket(ctx, packet, relayer)
if ack.Success() {
Expand Down Expand Up @@ -79,8 +80,12 @@ func CheckIBCInflow(ctx sdk.Context,
// construct the denomination trace from the full raw denomination and get the ibc_denom
ibcDenom := ibctransfertypes.ParseDenomTrace(prefixedDenom).IBCDenom()
_, err := lkeeper.GetTokenSettings(ctx, ibcDenom)
if err != nil && ltypes.ErrNotRegisteredToken.Is(err) {
return channeltypes.NewErrorAcknowledgement(err)
if err != nil {
if ltypes.ErrNotRegisteredToken.Is(err) {
return channeltypes.NewErrorAcknowledgement(err)
}
// other leverage keeper error -> log the error and allow the inflow transfer.
ctx.Logger().Error("IBC inflows: can't load token registry", "err", err)
}
}

Expand Down
8 changes: 4 additions & 4 deletions x/uibc/quota/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (im ICS20Middleware) OnAcknowledgementPacket(ctx sdk.Context, packet channe
if _, ok := ack.Response.(*channeltypes.Acknowledgement_Error); ok {
params := im.keeper.GetParams(ctx)
if params.IbcStatus == uibc.IBCTransferStatus_IBC_TRANSFER_STATUS_QUOTA_ENABLED {
err := im.RevertQuotaUpdate(ctx, packet.Data)
err := im.revertQuotaUpdate(ctx, packet.Data)
emitOnRevertQuota(&ctx, "acknowledgement", packet.Data, err)
}
}
Expand All @@ -58,14 +58,14 @@ func (im ICS20Middleware) OnAcknowledgementPacket(ctx sdk.Context, packet channe

// OnTimeoutPacket implements types.Middleware
func (im ICS20Middleware) OnTimeoutPacket(ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress) error {
err := im.RevertQuotaUpdate(ctx, packet.Data)
err := im.revertQuotaUpdate(ctx, packet.Data)
emitOnRevertQuota(&ctx, "timeout", packet.Data, err)

return im.IBCModule.OnTimeoutPacket(ctx, packet, relayer)
}

// RevertQuotaUpdate Notifies the contract that a sent packet wasn't properly received
func (im ICS20Middleware) RevertQuotaUpdate(
// revertQuotaUpdate must be called on packet acknnowledgemenet error to revert necessary changes.
func (im ICS20Middleware) revertQuotaUpdate(
ctx sdk.Context,
packetData []byte,
) error {
Expand Down
2 changes: 1 addition & 1 deletion x/uibc/quota/keeper/ics4_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
* Implementation of ICS4Wrapper interface
******/

// SendPacket wraps IBC ChannelKeeper's SendPacket function
// SendPacket wraps IBC ChannelKeeper's SendPacket function to record quota outflows.
func (k Keeper) SendPacket(ctx sdk.Context,
chanCap *capabilitytypes.Capability,
sourcePort string,
Expand Down
2 changes: 1 addition & 1 deletion x/uibc/quota/keeper/quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (k Keeper) ResetAllQuotas(ctx sdk.Context) error {
return nil
}

// CheckAndUpdateQuota checks if adding a newOutflow is doesn't exceed the max quota and
// CheckAndUpdateQuota checks if adding a newOutflow doesn't exceed the max quota and
// updates the current quota metrics.
func (k Keeper) CheckAndUpdateQuota(ctx sdk.Context, denom string, newOutflow sdkmath.Int) error {
params := k.GetParams(ctx)
Expand Down

0 comments on commit 5286641

Please sign in to comment.