Skip to content

Commit

Permalink
[BP: release/v4 <- #118] rename: router -> packetforward (#119)
Browse files Browse the repository at this point in the history
* rename: `router` -> `packetforward` (#118)

* rename: `router` -> `packetforward`

* use RouterKey for the Module keys

(cherry picked from commit 47f2ae0)

# Conflicts:
#	middleware/packet-forward-middleware/Makefile
#	middleware/packet-forward-middleware/packetforward/client/cli/cli.go
#	middleware/packet-forward-middleware/packetforward/ibc_middleware.go
#	middleware/packet-forward-middleware/packetforward/keeper/genesis.go
#	middleware/packet-forward-middleware/packetforward/keeper/grpc_query.go
#	middleware/packet-forward-middleware/packetforward/keeper/keeper.go
#	middleware/packet-forward-middleware/packetforward/keeper/params.go
#	middleware/packet-forward-middleware/packetforward/module.go
#	middleware/packet-forward-middleware/packetforward/module_test.go
#	middleware/packet-forward-middleware/packetforward/types/forward_test.go
#	middleware/packet-forward-middleware/packetforward/types/genesis.pb.go
#	middleware/packet-forward-middleware/packetforward/types/query.pb.go
#	middleware/packet-forward-middleware/packetforward/types/query.pb.gw.go
#	middleware/packet-forward-middleware/proto/packetforward/v1/genesis.proto
#	middleware/packet-forward-middleware/proto/packetforward/v1/query.proto
#	middleware/packet-forward-middleware/scripts/protocgen.sh
#	middleware/packet-forward-middleware/test/mock/bank_keeper.go
#	middleware/packet-forward-middleware/test/mock/channel_keeper.go
#	middleware/packet-forward-middleware/test/mock/distribution_keeper.go
#	middleware/packet-forward-middleware/test/mock/transfer_keeper.go
#	middleware/packet-forward-middleware/test/setup.go

* move to v4 namespace

* packetforward for mocks

---------

Co-authored-by: Reece Williams <31943163+Reecepbcups@users.noreply.github.com>
Co-authored-by: Reece Williams <reecepbcups@gmail.com>
  • Loading branch information
3 people authored Oct 11, 2023
1 parent 281e546 commit 3e84390
Show file tree
Hide file tree
Showing 28 changed files with 176 additions and 179 deletions.
10 changes: 5 additions & 5 deletions middleware/packet-forward-middleware/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ cosmovisor:

mocks: $(MOCKS_DIR)
go install go.uber.org/mock/mockgen@v0.2.0
mockgen -package=mock -destination=./test/mock/transfer_keeper.go $(GOMOD)/router/types TransferKeeper
mockgen -package=mock -destination=./test/mock/channel_keeper.go $(GOMOD)/router/types ChannelKeeper
mockgen -package=mock -destination=./test/mock/distribution_keeper.go $(GOMOD)/router/types DistributionKeeper
mockgen -package=mock -destination=./test/mock/bank_keeper.go $(GOMOD)/router/types BankKeeper
mockgen -package=mock -destination=./test/mock/channel_keeper.go $(GOMOD)/router/types ChannelKeeper
mockgen -package=mock -destination=./test/mock/transfer_keeper.go $(GOMOD)/packetforward/types TransferKeeper
mockgen -package=mock -destination=./test/mock/channel_keeper.go $(GOMOD)/packetforward/types ChannelKeeper
mockgen -package=mock -destination=./test/mock/distribution_keeper.go $(GOMOD)/packetforward/types DistributionKeeper
mockgen -package=mock -destination=./test/mock/bank_keeper.go $(GOMOD)/packetforward/types BankKeeper
mockgen -package=mock -destination=./test/mock/channel_keeper.go $(GOMOD)/packetforward/types ChannelKeeper
mockgen -package=mock -destination=./test/mock/ics4_wrapper.go github.com/cosmos/ibc-go/v4/modules/core/05-port/types ICS4Wrapper
mockgen -package=mock -destination=./test/mock/ibc_module.go github.com/cosmos/ibc-go/v4/modules/core/05-port/types IBCModule

Expand Down
2 changes: 1 addition & 1 deletion middleware/packet-forward-middleware/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ The examples above show the intended usage of the `receiver` field for one or mu

## Implementation details

Flow sequence mainly encoded in [middleware](router/ibc_middleware.go) and in [keeper](router/keeper/keeper.go).
Flow sequence mainly encoded in [middleware](packetforward/ibc_middleware.go) and in [keeper](packetforward/keeper/keeper.go).

Describes `A` sending to `C` via `B` in several scenarios with operational opened channels, enabled denom composition, fees and available to refund, but no retries.

Expand Down
6 changes: 3 additions & 3 deletions middleware/packet-forward-middleware/docs/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ Integration of the PFM should take approximately 20 minutes.

// Import the packet forward middleware
import (
packetforward "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/router"
packetforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/router/keeper"
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/router/types"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward"
packetforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/keeper"
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types"
)

...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ package cli
import (
"fmt"

"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/router/types"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/packetforward/types"
"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/version"
)

// GetQueryCmd returns the query commands for router
// GetQueryCmd returns the query commands for packetforward
func GetQueryCmd() *cobra.Command {
queryCmd := &cobra.Command{
Use: "ibc-router",
Use: "packetforward",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
}
Expand All @@ -26,14 +26,14 @@ func GetQueryCmd() *cobra.Command {
return queryCmd
}

// GetCmdParams returns the command handler for ibc-router parameter querying.
// GetCmdParams returns the command handler for packetforward parameter querying.
func GetCmdParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "Query the current ibc-router parameters",
Long: "Query the current ibc-router parameters",
Short: "Query the current packetforward parameters",
Long: "Query the current packetforward parameters",
Args: cobra.NoArgs,
Example: fmt.Sprintf("%s query ibc-router params", version.AppName),
Example: fmt.Sprintf("%s query packetforward params", version.AppName),
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
Expand All @@ -54,7 +54,7 @@ func GetCmdParams() *cobra.Command {
return cmd
}

// NewTxCmd returns the transaction commands for router
// NewTxCmd returns the transaction commands for packetforward
func NewTxCmd() *cobra.Command {
return nil
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package router
package packetforward

import (
"encoding/json"
Expand All @@ -7,8 +7,8 @@ import (
"time"

"github.com/armon/go-metrics"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/router/keeper"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/router/types"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/packetforward/keeper"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/packetforward/types"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package keeper

import (
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/router/types"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/packetforward/types"

sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package keeper
import (
"context"

"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/router/types"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/packetforward/types"

sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

"github.com/armon/go-metrics"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/router/types"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/packetforward/types"
"github.com/tendermint/tendermint/libs/log"

"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -37,7 +37,7 @@ var (
// DefaultForwardTransferPacketTimeoutTimestamp is the timeout timestamp following IBC defaults
DefaultForwardTransferPacketTimeoutTimestamp = time.Duration(transfertypes.DefaultRelativePacketTimeoutTimestamp) * time.Nanosecond

// DefaultRefundTransferPacketTimeoutTimestamp is a 28-day timeout for refund packets since funds are stuck in router module otherwise.
// DefaultRefundTransferPacketTimeoutTimestamp is a 28-day timeout for refund packets since funds are stuck in packetforward module otherwise.
DefaultRefundTransferPacketTimeoutTimestamp = 28 * 24 * time.Hour
)

Expand Down Expand Up @@ -374,14 +374,14 @@ func (k *Keeper) RetryTimeout(

amount, ok := sdk.NewIntFromString(data.Amount)
if !ok {
k.Logger(ctx).Error("packetForwardMiddleware error parsing amount from string for router retry on timeout",
k.Logger(ctx).Error("packetForwardMiddleware error parsing amount from string for packetforward retry on timeout",
"original-sender-address", inFlightPacket.OriginalSenderAddress,
"refund-channel-id", inFlightPacket.RefundChannelId,
"refund-port-id", inFlightPacket.RefundPortId,
"retries-remaining", inFlightPacket.RetriesRemaining,
"amount", data.Amount,
)
return fmt.Errorf("error parsing amount from string for router retry: %s", data.Amount)
return fmt.Errorf("error parsing amount from string for packetforward retry: %s", data.Amount)
}

denom := transfertypes.ParseDenomTrace(data.Denom).IBCDenom()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package keeper

import (
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/router/types"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/packetforward/types"

sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package router
package packetforward

import (
"context"
"encoding/json"
"fmt"
"math/rand"

"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/router/client/cli"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/router/keeper"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/router/types"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/packetforward/client/cli"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/packetforward/keeper"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/packetforward/types"
"github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
Expand All @@ -28,7 +28,7 @@ var (
_ module.AppModuleSimulation = AppModule{}
)

// AppModuleBasic is the router AppModuleBasic
// AppModuleBasic is the packetforward AppModuleBasic
type AppModuleBasic struct{}

// Name implements AppModuleBasic interface
Expand All @@ -43,12 +43,12 @@ func (AppModuleBasic) RegisterLegacyAminoCodec(_ *codec.LegacyAmino) {}
func (AppModuleBasic) RegisterInterfaces(_ codectypes.InterfaceRegistry) {}

// DefaultGenesis returns default genesis state as raw bytes for the ibc
// router module.
// packetforward module.
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(types.DefaultGenesisState())
}

// ValidateGenesis performs genesis state validation for the router module.
// ValidateGenesis performs genesis state validation for the packetforward module.
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error {
var gs types.GenesisState
if err := cdc.UnmarshalJSON(bz, &gs); err != nil {
Expand All @@ -61,7 +61,7 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingCo
// RegisterRESTRoutes implements AppModuleBasic interface
func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {}

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the ibc-router module.
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the packetforward module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
_ = types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
}
Expand All @@ -82,7 +82,7 @@ type AppModule struct {
keeper *keeper.Keeper
}

// NewAppModule creates a new router module
// NewAppModule creates a new packetforward module
func NewAppModule(k *keeper.Keeper) AppModule {
return AppModule{
keeper: k,
Expand Down Expand Up @@ -112,7 +112,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
}

// InitGenesis performs genesis initialization for the ibc-router module. It returns
// InitGenesis performs genesis initialization for the packetforward module. It returns
// no validator updates.
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate {
err := am.ValidateGenesis(cdc, nil, data)
Expand All @@ -126,7 +126,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.
return []abci.ValidatorUpdate{}
}

// ExportGenesis returns the exported genesis state as raw bytes for the ibc-router
// ExportGenesis returns the exported genesis state as raw bytes for the packetforward
// module.
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
gs := am.keeper.ExportGenesis(ctx)
Expand All @@ -146,7 +146,7 @@ func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.Valid

// AppModuleSimulation functions

// GenerateGenesisState creates a randomized GenState of the router module.
// GenerateGenesisState creates a randomized GenState of the packetforward module.
func (AppModule) GenerateGenesisState(_ *module.SimulationState) {}

// ProposalContents doesn't return any content functions for governance proposals.
Expand All @@ -159,10 +159,10 @@ func (AppModule) RandomizedParams(_ *rand.Rand) []simtypes.ParamChange {
return nil
}

// RegisterStoreDecoder registers a decoder for router module's types
// RegisterStoreDecoder registers a decoder for packetforward module's types
func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {}

// WeightedOperations returns the all the router module operations with their respective weights.
// WeightedOperations returns the all the packetforward module operations with their respective weights.
func (am AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation {
return nil
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package router_test
package packetforward_test

import (
"encoding/json"
"fmt"
"testing"

"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/router/keeper"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/router/types"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/packetforward/keeper"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/packetforward/types"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/test"
"github.com/iancoleman/orderedmap"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -291,7 +291,7 @@ func TestOnRecvPacket_ForwardNoFee(t *testing.T) {
Return(nil),
)

// chain B with router module receives packet and forwards. ack should be nil so that it is not written yet.
// chain B with packetforward module receives packet and forwards. ack should be nil so that it is not written yet.
ack := forwardMiddleware.OnRecvPacket(ctx, packetOrig, senderAccAddr)
require.Nil(t, ack)

Expand Down Expand Up @@ -351,7 +351,7 @@ func TestOnRecvPacket_ForwardAmountInt256(t *testing.T) {
Return(nil),
)

// chain B with router module receives packet and forwards. ack should be nil so that it is not written yet.
// chain B with packetforward module receives packet and forwards. ack should be nil so that it is not written yet.
ack := forwardMiddleware.OnRecvPacket(ctx, packetOrig, senderAccAddr)
require.Nil(t, ack)

Expand All @@ -370,7 +370,7 @@ func TestOnRecvPacket_ForwardWithFee(t *testing.T) {
forwardMiddleware := setup.ForwardMiddleware

// Set fee param to 10%
setup.Keepers.RouterKeeper.SetParams(ctx, types.NewParams(sdk.NewDecWithPrec(10, 2)))
setup.Keepers.PacketForwardKeeper.SetParams(ctx, types.NewParams(sdk.NewDecWithPrec(10, 2)))

denom := makeIBCDenom(testDestinationPort, testDestinationChannel, testDenom)
senderAccAddr := test.AccAddress(t)
Expand Down Expand Up @@ -416,7 +416,7 @@ func TestOnRecvPacket_ForwardWithFee(t *testing.T) {
Return(nil),
)

// chain B with router module receives packet and forwards. ack should be nil so that it is not written yet.
// chain B with packetforward module receives packet and forwards. ack should be nil so that it is not written yet.
ack := forwardMiddleware.OnRecvPacket(ctx, packetOrig, senderAccAddr)
require.Nil(t, ack)

Expand Down Expand Up @@ -516,11 +516,11 @@ func TestOnRecvPacket_ForwardMultihopStringNext(t *testing.T) {
Return(nil),
)

// chain B with router module receives packet and forwards. ack should be nil so that it is not written yet.
// chain B with packetforward module receives packet and forwards. ack should be nil so that it is not written yet.
ack := forwardMiddleware.OnRecvPacket(ctx, packetOrig, senderAccAddr)
require.Nil(t, ack)

// chain C with router module receives packet and forwards. ack should be nil so that it is not written yet.
// chain C with packetforward module receives packet and forwards. ack should be nil so that it is not written yet.
ack = forwardMiddleware.OnRecvPacket(ctx, packet2, senderAccAddr2)
require.Nil(t, ack)

Expand Down Expand Up @@ -626,11 +626,11 @@ func TestOnRecvPacket_ForwardMultihopJSONNext(t *testing.T) {
Return(nil),
)

// chain B with router module receives packet and forwards. ack should be nil so that it is not written yet.
// chain B with packetforward module receives packet and forwards. ack should be nil so that it is not written yet.
ack := forwardMiddleware.OnRecvPacket(ctx, packetOrig, senderAccAddr)
require.Nil(t, ack)

// chain C with router module receives packet and forwards. ack should be nil so that it is not written yet.
// chain C with packetforward module receives packet and forwards. ack should be nil so that it is not written yet.
ack = forwardMiddleware.OnRecvPacket(ctx, packet2, senderAccAddr2)
require.Nil(t, ack)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"testing"

"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/router/types"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/packetforward/types"
"github.com/stretchr/testify/require"
)

Expand Down
Loading

0 comments on commit 3e84390

Please sign in to comment.