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
  • Loading branch information
ValarDragon authored Jun 17, 2024
1 parent 3b71637 commit 837b58c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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
12 changes: 8 additions & 4 deletions x/ibc-rate-limit/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/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"
Expand Down Expand Up @@ -110,12 +109,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 837b58c

Please sign in to comment.