Skip to content

Commit

Permalink
Fix packet can't be unmarshal
Browse files Browse the repository at this point in the history
  • Loading branch information
p0p3yee committed Dec 28, 2023
1 parent 54c66f6 commit 017680a
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 19 deletions.
4 changes: 4 additions & 0 deletions hermes_config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[global]
log_level = 'info'

[mode.clients]
enabled = true
refresh = true
Expand All @@ -16,6 +17,7 @@ enabled = true
clear_interval = 100
clear_on_start = true
tx_confirmation = false
auto_register_counterparty_payee = false

[rest]
enabled = false
Expand Down Expand Up @@ -44,6 +46,7 @@ max_msg_num = 30
max_tx_size = 2097152
clock_drift = '5s'
max_block_time = '30s'
trusting_period = '14days'
memo_prefix = ''
sequential_batch_tx = false

Expand Down Expand Up @@ -76,6 +79,7 @@ max_msg_num = 30
max_tx_size = 2097152
clock_drift = '5s'
max_block_time = '30s'
trusting_period = '14days'
memo_prefix = ''
sequential_batch_tx = false

Expand Down
4 changes: 2 additions & 2 deletions proto/fairyring/pep/packet.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ message CurrentKeysPacketData {

// CurrentKeysPacketAck defines a struct for the packet acknowledgment
message CurrentKeysPacketAck {
ActivePubKey activeKey = 2;
QueuedPubKey queuedKey = 3;
ActivePubKey activeKey = 1;
QueuedPubKey queuedKey = 2;
}
6 changes: 5 additions & 1 deletion x/pep/keeper/current_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"errors"
cosmoserror "github.com/cosmos/cosmos-sdk/types/errors"
"time"

"fairyring/x/pep/types"
Expand Down Expand Up @@ -61,7 +62,10 @@ func (k Keeper) TransmitCurrentKeysPacket(
return sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability")
}

packetBytes := packetData.GetBytes()
packetBytes, err := packetData.GetBytes()
if err != nil {
return sdkerrors.Wrap(cosmoserror.ErrJSONMarshal, "cannot marshal the packet: "+err.Error())
}

if _, err := k.ChannelKeeper.SendPacket(ctx, channelCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, packetBytes); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion x/pep/module_ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func (im IBCModule) OnAcknowledgementPacket(
// this line is used by starport scaffolding # oracle/packet/module/ack

var modulePacketData types.PepPacketData
if err := modulePacketData.Unmarshal(modulePacket.GetData()); err != nil {
if err := types.ModuleCdc.UnmarshalJSON(modulePacket.GetData(), &modulePacketData); err != nil {
return sdkerrors.Wrapf(cosmoserror.ErrUnknownRequest, "cannot unmarshal packet data: %s", err.Error())
}

Expand Down
8 changes: 4 additions & 4 deletions x/pep/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func init() {
// NOTE: Copied from https://github.com/cosmos/cosmos-sdk/blob/971c542453e0972ef1dfc5a80159ad5049c7211c/codec/json.go
// and modified in order to allow `EmitDefaults` to be set to false for ics20 packet marshalling.
// This allows for the introduction of the memo field to be backwards compatible.
func MustProtoMarshalJSON(msg proto.Message) []byte {
func MustProtoMarshalJSON(msg proto.Message) ([]byte, error) {
anyResolver := cdctypes.NewInterfaceRegistry()

// EmitDefaults is set to false to prevent marshalling of unpopulated fields (memo)
Expand All @@ -59,13 +59,13 @@ func MustProtoMarshalJSON(msg proto.Message) []byte {

err := cdctypes.UnpackInterfaces(msg, cdctypes.ProtoJSONPacker{JSONPBMarshaler: jm})
if err != nil {
panic(err)
return nil, err
}

buf := new(bytes.Buffer)
if err := jm.Marshal(buf, msg); err != nil {
panic(err)
return nil, err
}

return buf.Bytes()
return buf.Bytes(), err
}
8 changes: 6 additions & 2 deletions x/pep/types/current_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ func (p CurrentKeysPacketData) ValidateBasic() error {
}

// GetBytes is a helper for serialising
func (p CurrentKeysPacketData) GetBytes() []byte {
func (p CurrentKeysPacketData) GetBytes() ([]byte, error) {
var modulePacket PepPacketData

modulePacket.Packet = &PepPacketData_CurrentKeysPacket{&p}

return sdk.MustSortJSON(MustProtoMarshalJSON(&modulePacket))
b, err := MustProtoMarshalJSON(&modulePacket)
if err != nil {
return nil, err
}
return sdk.MustSortJSON(b), nil
}
18 changes: 9 additions & 9 deletions x/pep/types/packet.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 017680a

Please sign in to comment.