Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: #258 Register Counterparty Address #376

Merged
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
- [ibc/applications/fee/v1/tx.proto](#ibc/applications/fee/v1/tx.proto)
- [MsgEscrowPacketFee](#ibc.applications.fee.v1.MsgEscrowPacketFee)
- [MsgEscrowPacketFeeResponse](#ibc.applications.fee.v1.MsgEscrowPacketFeeResponse)
- [MsgRegisterCounterPartyAddressResponse](#ibc.applications.fee.v1.MsgRegisterCounterPartyAddressResponse)
- [MsgRegisterCounterpartyAddress](#ibc.applications.fee.v1.MsgRegisterCounterpartyAddress)
- [MsgRegisterCounterpartyAddressResponse](#ibc.applications.fee.v1.MsgRegisterCounterpartyAddressResponse)

- [Msg](#ibc.applications.fee.v1.Msg)

Expand Down Expand Up @@ -915,16 +915,6 @@ MsgEscrowPacketFeeResponse defines the response type for Msg/EscrowPacketFee



<a name="ibc.applications.fee.v1.MsgRegisterCounterPartyAddressResponse"></a>

### MsgRegisterCounterPartyAddressResponse
MsgRegisterCounterPartyAddressResponse defines the Msg/RegisterCounteryPartyAddress response type






<a name="ibc.applications.fee.v1.MsgRegisterCounterpartyAddress"></a>

### MsgRegisterCounterpartyAddress
Expand All @@ -940,6 +930,16 @@ MsgRegisterCounterpartyAddress is the request type for registering the counter p




<a name="ibc.applications.fee.v1.MsgRegisterCounterpartyAddressResponse"></a>

### MsgRegisterCounterpartyAddressResponse
MsgRegisterCounterpartyAddressResponse defines the Msg/RegisterCounterypartyAddress response type





<!-- end messages -->

<!-- end enums -->
Expand All @@ -954,7 +954,7 @@ Msg defines the ibc/fee Msg service.

| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `RegisterCounterPartyAddress` | [MsgRegisterCounterpartyAddress](#ibc.applications.fee.v1.MsgRegisterCounterpartyAddress) | [MsgRegisterCounterPartyAddressResponse](#ibc.applications.fee.v1.MsgRegisterCounterPartyAddressResponse) | RegisterCounterpartyAddress defines a rpc handler method for MsgRegisterCounterpartyAddress RegisterCounterpartyAddress is called by the relayer on each channelEnd and allows them to specify their counterparty address before relaying. This ensures they will be properly compensated for forward relaying since destination chain must send back relayer's source address (counterparty address) in acknowledgement. This function may be called more than once by a relayer, in which case, latest counterparty address is always used. | |
| `RegisterCounterpartyAddress` | [MsgRegisterCounterpartyAddress](#ibc.applications.fee.v1.MsgRegisterCounterpartyAddress) | [MsgRegisterCounterpartyAddressResponse](#ibc.applications.fee.v1.MsgRegisterCounterpartyAddressResponse) | RegisterCounterpartyAddress defines a rpc handler method for MsgRegisterCounterpartyAddress RegisterCounterpartyAddress is called by the relayer on each channelEnd and allows them to specify their counterparty address before relaying. This ensures they will be properly compensated for forward relaying since destination chain must send back relayer's source address (counterparty address) in acknowledgement. This function may be called more than once by a relayer, in which case, latest counterparty address is always used. | |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| `RegisterCounterpartyAddress` | [MsgRegisterCounterpartyAddress](#ibc.applications.fee.v1.MsgRegisterCounterpartyAddress) | [MsgRegisterCounterpartyAddressResponse](#ibc.applications.fee.v1.MsgRegisterCounterpartyAddressResponse) | RegisterCounterpartyAddress defines a rpc handler method for MsgRegisterCounterpartyAddress RegisterCounterpartyAddress is called by the relayer on each channelEnd and allows them to specify their counterparty address before relaying. This ensures they will be properly compensated for forward relaying since destination chain must send back relayer's source address (counterparty address) in acknowledgement. This function may be called more than once by a relayer, in which case, latest counterparty address is always used. | |
| `RegisterCounterpartyAddress` | [MsgRegisterCounterpartyAddress](#ibc.applications.fee.v1.MsgRegisterCounterpartyAddress) | [MsgRegisterCounterpartyAddressResponse](#ibc.applications.fee.v1.MsgRegisterCounterpartyAddressResponse) | RegisterCounterpartyAddress defines a rpc handler method for MsgRegisterCounterpartyAddress. RegisterCounterpartyAddress is called by the relayer on each channelEnd and allows them to specify their counterparty address before relaying. This ensures they will be properly compensated for forward relaying on the source chain since destination chain must send back relayer's source address (counterparty address) in acknowledgement. This function may be called more than once by a relayer, in which case, the previous counterparty address will be overwritten by the new counterparty address. | |

for clarity?

| `EscrowPacketFee` | [MsgEscrowPacketFee](#ibc.applications.fee.v1.MsgEscrowPacketFee) | [MsgEscrowPacketFeeResponse](#ibc.applications.fee.v1.MsgEscrowPacketFeeResponse) | EscrowPacketFee defines a rpc handler method for MsgEscrowPacketFee EscrowPacketFee is an open callback that may be called by any module/user that wishes to escrow funds in order to incentivize the relaying of the given packet. | |

<!-- end services -->
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/29-fee/client/cli/cli.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package cli

import (
"github.com/spf13/cobra"

// external library imports
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can exclude these comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mentioned here splitting up the imports -> #337 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, splitting the imports is good 👍 I'm just not sure we need the comments (I mostly added those to explain it in the pseudocode)

Copy link
Contributor Author

@seantking seantking Sep 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My programmer's brain took that literally 😆 Please stamp for removal -> #385

"github.com/cosmos/cosmos-sdk/client"
"github.com/spf13/cobra"
)

// GetQueryCmd returns the query commands for 29-fee
Expand Down
37 changes: 25 additions & 12 deletions modules/apps/29-fee/keeper/keeper.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package keeper

/*
import (
"github.com/tendermint/tendermint/libs/log"

// external library imports
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/cosmos/ibc-go/modules/apps/transfer/types"
"github.com/tendermint/tendermint/libs/log"

// ibc-go imports
"github.com/cosmos/ibc-go/modules/apps/29-fee/types"
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
host "github.com/cosmos/ibc-go/modules/core/24-host"
)

Expand All @@ -25,7 +25,6 @@ type Keeper struct {
scopedKeeper capabilitykeeper.ScopedKeeper
}


// NewKeeper creates a new 29-fee Keeper instance
func NewKeeper(
cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace paramtypes.Subspace,
Expand All @@ -49,6 +48,7 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", "x/"+host.ModuleName+"-"+types.ModuleName)
}

/*
// IsBound checks if the transfer module is already bound to the desired port
func (k Keeper) IsBound(ctx sdk.Context, portID string) bool {
_, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID))
Expand All @@ -62,12 +62,6 @@ func (k Keeper) BindPort(ctx sdk.Context, portID string) error {
return k.ClaimCapability(ctx, cap, host.PortPath(portID))
}

// GetPort returns the portID for the transfer module. Used in ExportGenesis
func (k Keeper) GetPort(ctx sdk.Context) string {
store := ctx.KVStore(k.storeKey)
return string(store.Get(types.PortKey))
}

// SetPort sets the portID for the transfer module. Used in InitGenesis
func (k Keeper) SetPort(ctx sdk.Context, portID string) {
store := ctx.KVStore(k.storeKey)
Expand All @@ -85,3 +79,22 @@ func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability
return k.scopedKeeper.ClaimCapability(ctx, cap, name)
}
*/

// SetCounterpartyAddress maps the destination chain relayer address to the source relayer address
// The receiving chain must store the mapping from: address -> counterpartyAddress for the given channel
func (k Keeper) SetCounterpartyAddress(ctx sdk.Context, address, counterpartyAddress string) {
store := ctx.KVStore(k.storeKey)
store.Set(types.KeyRelayerAddress(address), []byte(counterpartyAddress))
}

// GetCounterpartyAddress gets the relayer counterparty address given a destination relayer address
func (k Keeper) GetCounterpartyAddress(ctx sdk.Context, address sdk.AccAddress) (sdk.AccAddress, bool) {
store := ctx.KVStore(k.storeKey)
key := types.KeyRelayerAddress(address.String())

if !store.Has(key) {
return []byte{}, false
}

return store.Get(key), true
}
17 changes: 3 additions & 14 deletions modules/apps/29-fee/keeper/keeper_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package keeper_test

/*
import (
// standard library importsn
"testing"

// external library imports
"github.com/stretchr/testify/suite"
"github.com/tendermint/tendermint/crypto"

"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/ibc-go/modules/apps/transfer/types"
// ibc-go imports
ibctesting "github.com/cosmos/ibc-go/testing"
)

Expand All @@ -31,15 +29,6 @@ func (suite *KeeperTestSuite) SetupTest() {
suite.chainC = suite.coordinator.GetChain(ibctesting.GetChainID(2))
}

func NewFeePath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path {
path := ibctesting.NewPath(chainA, chainB)
path.EndpointA.ChannelConfig.PortID = ibctesting.FeePort
path.EndpointB.ChannelConfig.PortID = ibctesting.FeePort

return path
}

func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(KeeperTestSuite))
}
*/
33 changes: 31 additions & 2 deletions modules/apps/29-fee/keeper/msg_server.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
package keeper

// TODO
//var _ types.MsgServer = Keeper{}
import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/ibc-go/modules/apps/29-fee/types"
)

var _ types.MsgServer = Keeper{}

// RegisterCounterpartyAddress is called by the relayer on each channelEnd and allows them to specify their counterparty address before relaying
// This ensures they will be properly compensated for forward relaying since destination chain must send back relayer's source address (counterparty address) in acknowledgement
// This function may be called more than once by relayer, in which case, latest counterparty address is always used.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AdityaSripal I took this to mean that the address can be overwritten by calling RegisterCounterPartyAddress more than once. Is that correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct

func (k Keeper) RegisterCounterpartyAddress(goCtx context.Context, msg *types.MsgRegisterCounterpartyAddress) (*types.MsgRegisterCounterpartyAddressResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

k.SetCounterpartyAddress(
ctx, msg.Address, msg.CounterpartyAddress,
)

k.Logger(ctx).Info("Registering counterparty address for relayer with", "Source address:", msg.Address, "With counterparty address:", msg.CounterpartyAddress)
seantking marked this conversation as resolved.
Show resolved Hide resolved

return &types.MsgRegisterCounterpartyAddressResponse{}, nil
}

// EscrowPacketFee defines a rpc handler method for MsgEscrowPacketFee
// EscrowPacketFee is an open callback that may be called by any module/user that wishes to escrow funds in order to
// incentivize the relaying of the given packet.
func (k Keeper) EscrowPacketFee(goCtx context.Context, msg *types.MsgEscrowPacketFee) (*types.MsgEscrowPacketFeeResponse, error) {
return &types.MsgEscrowPacketFeeResponse{}, nil
}
5 changes: 3 additions & 2 deletions modules/apps/29-fee/types/expected_keepers.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package types

/*
import (
//external library imports
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/types"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"

// ibc-go imports
connectiontypes "github.com/cosmos/ibc-go/modules/core/03-connection/types"
channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types"
ibcexported "github.com/cosmos/ibc-go/modules/core/exported"
Expand Down Expand Up @@ -47,4 +49,3 @@ type ConnectionKeeper interface {
type PortKeeper interface {
BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability
}
*/
14 changes: 14 additions & 0 deletions modules/apps/29-fee/types/keys.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
package types

// standard library imports
import "fmt"

const (
// ModuleName defines the 29-fee name
ModuleName = "ibcfee"

// StoreKey is the store key string for IBC transfer
StoreKey = ModuleName

// PortKey is the port id that is wrapped by fee middleware
PortKey = "feetransfer"

// RouterKey is the message route for IBC transfer
RouterKey = ModuleName

// QuerierRoute is the querier route for IBC transfer
QuerierRoute = ModuleName

// Key prefix for relayer address mapping
RelayerAddressKeyPrefix = "relayerAddress"
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
)

// Key for relayer source address -> counteryparty address mapping
func KeyRelayerAddress(address string) []byte {
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
return []byte(fmt.Sprintf("%s/%s", RelayerAddressKeyPrefix, address))
}
18 changes: 18 additions & 0 deletions modules/apps/29-fee/types/keys_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package types_test

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/cosmos/ibc-go/modules/apps/29-fee/types"
)

func TestKeyRelayerAddress(t *testing.T) {
var (
relayerAddress = "relayer_address"
)

key := types.KeyRelayerAddress(relayerAddress)
require.Equal(t, string(key), "relayerAddress/relayer_address")
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
}
38 changes: 25 additions & 13 deletions modules/apps/29-fee/types/msgs.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,44 @@
package types

/*
import (
"strings"

// external library imports
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
clienttypes "github.com/cosmos/ibc-go/modules/core/02-client/types"
host "github.com/cosmos/ibc-go/modules/core/24-host"
)

// NewMsg
func NewMsg() *Msg {
return &Msg{
// msg types
const (
TypeMsgRegisterCounterpartyAddress = "registerCounterpartyAddress"
)

// NewMsgRegisterCounterpartyAddress creates a new instance of MsgRegisterCounterpartyAddress
func NewMsgRegisterCounterpartyAddress(sourceAddress, counterpartyAddress string) *MsgRegisterCounterpartyAddress {
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
return &MsgRegisterCounterpartyAddress{
Address: sourceAddress,
CounterpartyAddress: counterpartyAddress,
}
}

// ValidateBasic performs a basic check of the Msg fields.
func (msg Msg) ValidateBasic() error {
// ValidateBasic performs a basic check of the MsgRegisterCounterpartyAddress fields
func (msg MsgRegisterCounterpartyAddress) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Address)
if err != nil {
return sdkerrors.Wrap(err, "failed to convert msg.Address into sdk.AccAddress")
}

_, err = sdk.AccAddressFromBech32(msg.CounterpartyAddress)
if err != nil {
return sdkerrors.Wrap(err, "failed to convert msg.Address into sdk.AccAddress")
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
}

return nil
}

// GetSigners implements sdk.Msg
func (msg MsgTransfer) GetSigners() []sdk.AccAddress {
signer, err := sdk.AccAddressFromBech32(msg.Sender)
func (msg MsgRegisterCounterpartyAddress) GetSigners() []sdk.AccAddress {
signer, err := sdk.AccAddressFromBech32(msg.Address)
if err != nil {
panic(err)
}
return []sdk.AccAddress{signer}
}
*/
38 changes: 19 additions & 19 deletions modules/apps/29-fee/types/msgs_test.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
package types

/*
import (
"fmt"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/secp256k1"
)

"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
sdk "github.com/cosmos/cosmos-sdk/types"
var (
validAddr = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String()
invalidAddr = "invalid_address"
)

func (suite *TypesTestSuite) TestMsgValidateBasic() {
// TestMsgTransferValidation tests ValidateBasic for MsgTransfer
func TestMsgRegisterCountepartyAddressValidation(t *testing.T) {
testCases := []struct {
name string
msg *types.Msg
msg *MsgRegisterCounterpartyAddress
expPass bool
}{
{"", types.NewMsg(), true},
{"validate with correct sdk.AccAddress", NewMsgRegisterCounterpartyAddress(validAddr, validAddr), true},
{"validate with incorrect destination relayer address", NewMsgRegisterCounterpartyAddress(invalidAddr, validAddr), false},
{"validate with incorrect counterparty relayer address", NewMsgRegisterCounterpartyAddress(validAddr, invalidAddr), false},
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
err := tc.msg.ValidateBasic()
if tc.expPass {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
}
})
for i, tc := range testCases {
err := tc.msg.ValidateBasic()
if tc.expPass {
require.NoError(t, err, "valid test case %d failed: %s", i, tc.name)
} else {
require.Error(t, err, "invalid test case %d passed: %s", i, tc.name)
}
}
}
*/
Loading