Skip to content

Commit

Permalink
perf: Speedup one JSON unmarshal (#8398)
Browse files Browse the repository at this point in the history
* Speedup one JSON unmarshal

* Update changelog

(cherry picked from commit 837b58c)

# Conflicts:
#	x/ibc-rate-limit/ibc_module.go
  • Loading branch information
ValarDragon authored and mergify[bot] committed Jun 17, 2024
1 parent 2f19aac commit 7dd129a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### State Compatible

* [#8398](https://github.com/osmosis-labs/osmosis/pull/8398) Lower JSON unmarshalling overhead in IBC packet logic.

## v25.0.3

* [#8329](https://github.com/osmosis-labs/osmosis/pull/8329) Overwrite `flush_throttle_timeout` to 80ms instead of 10ms
Expand Down
19 changes: 16 additions & 3 deletions x/ibc-rate-limit/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,20 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

<<<<<<< HEAD
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
=======
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
"github.com/cosmos/ibc-go/v8/modules/core/exported"
>>>>>>> 837b58c3 (perf: Speedup one JSON unmarshal (#8398))

"github.com/osmosis-labs/osmosis/v25/x/ibc-rate-limit/types"
)
Expand Down Expand Up @@ -110,12 +118,17 @@ func (im *IBCModule) OnChanCloseConfirm(
return im.app.OnChanCloseConfirm(ctx, portID, channelID)
}

type receiverParser struct {
Receiver string `protobuf:"bytes,4,opt,name=receiver,proto3" json:"receiver,omitempty"`
}

func ValidateReceiverAddress(packet exported.PacketI) error {
var packetData transfertypes.FungibleTokenPacketData
if err := json.Unmarshal(packet.GetData(), &packetData); err != nil {
var receiverObj receiverParser

if err := json.Unmarshal(packet.GetData(), &receiverObj); err != nil {
return err
}
if len(packetData.Receiver) >= 4096 {
if len(receiverObj.Receiver) >= 4096 {
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "IBC Receiver address too long. Max supported length is %d", 4096)
}
return nil
Expand Down

0 comments on commit 7dd129a

Please sign in to comment.