Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Add comments and use interface for ack success (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
agouin committed Nov 2, 2022
1 parent 33768c4 commit d7d7073
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions proto/router/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ option go_package = "github.com/strangelove-ventures/packet-forward-middleware/v
import "gogoproto/gogo.proto";

// GenesisState defines the router genesis state

message GenesisState {
Params params = 1 [ (gogoproto.nullable) = false ];

// key - information about forwarded packet: src_channel (parsedReceiver.Channel), src_port (parsedReceiver.Port), sequence
// value - information about original packet for refunding if necessary: retries, srcPacketSender, srcPacket.DestinationChannel, srcPacket.DestinationPort
map<string, InFlightPacket> in_flight_packets = 2 [
(gogoproto.moretags) = "yaml:\"in_flight_packets\"",
(gogoproto.nullable) = false
Expand All @@ -24,6 +28,7 @@ message Params {
];
}

// InFlightPacket contains information about original packet for refunding if necessary.
message InFlightPacket {
string original_sender_address = 1;
string refund_channel_id = 2;
Expand Down
1 change: 1 addition & 0 deletions router/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) {
k.SetParams(ctx, state.Params)

// Initialize store refund path for forwarded packets in genesis state that have not yet been acked.
store := ctx.KVStore(k.storeKey)
for key, value := range state.InFlightPackets {
bz := k.cdc.MustMarshal(&value)
Expand Down
15 changes: 11 additions & 4 deletions router/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
Expand Down Expand Up @@ -310,13 +311,19 @@ func (am AppModule) OnAcknowledgementPacket(ctx sdk.Context, packet channeltypes
return err
}

var ackErr channeltypes.Acknowledgement_Error
if err := json.Unmarshal(acknowledgement, &ackErr); err == nil && len(ackErr.Error) > 0 {
var ack channeltypes.Acknowledgement
if err := json.Unmarshal(acknowledgement, &ack); err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrJSONUnmarshal, err.Error())
}

if !ack.Success() {
// If acknowledgement indicates error, no retries should be attempted. Refund will be initiated now.
am.keeper.RefundForwardedPacket(ctx, packet, am.refundTimeout)
} else {
am.keeper.RemoveInFlightPacket(ctx, packet)
return nil
}

// For successful ack, we no longer need to track this packet.
am.keeper.RemoveInFlightPacket(ctx, packet)
return nil
}

Expand Down

0 comments on commit d7d7073

Please sign in to comment.