-
Notifications
You must be signed in to change notification settings - Fork 642
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
ICS 29: Fee Middleware #276
Changes from 1 commit
18feadf
4b9a832
158a251
c63af4a
e3704c6
70c58af
dd4f8c7
67bd594
405f193
8ebbe18
d419972
4dbc83e
c4dff6c
edd11c6
885fb9a
a737132
53b2f67
e0cc81a
120fd76
0fbc6bb
dbda885
9285133
f3e9f95
26731ce
764df84
d761982
f552fb2
16e452b
b16353e
b618f02
13f77de
6cb4a38
e0161a7
dedbb57
6f19978
ea2984b
323c574
fb243c6
8d226de
2c1ff0b
39ef8d7
1fb4b5a
9895948
acc699d
9b2d96d
06f2730
ff15335
d8b9821
adc66d2
4326c14
ad7827f
7c6076f
179c4f4
c14d2b4
99db143
74afccd
6928af7
6999e10
4fb6d18
b02d193
15fa37b
9350d53
f1ba06f
fcea26d
9c508d2
7991f79
9ece5da
f8b4345
e51e2c9
5f8fc9f
4623772
8d380ba
9137084
d788adf
478db4f
71167c4
4bf859a
b33b0a7
f3ee8de
db88c84
637652d
4a0e00c
ab90f07
3ab2251
e1cca36
e65e881
39d4c56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
* feat: adding MsgServer for RegisterCounterPartyAddress & EscrowPacketFree * test: adding test for ValidateBasic * fix: removing validate basic check * fix: removing empty file * Update modules/apps/29-fee/keeper/msg_server.go Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * Update modules/apps/29-fee/types/msgs.go Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * Update modules/apps/29-fee/types/keys.go Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * Update modules/apps/29-fee/keeper/keeper.go Co-authored-by: Aditya <adityasripal@gmail.com> * fix: fixing typos, variable names, comments * fix: updating import comments * test: adding test for KeyRelayerAddress * update: comments & key_test * Update modules/apps/29-fee/keeper/msg_server.go Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * fix: error message * docs: updating RegisterCounterpartyAddress fn description Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> Co-authored-by: Aditya <adityasripal@gmail.com>
- Loading branch information
There are no files selected for viewing
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 on the source chain since the destination chain must send back relayer's source address (counterparty address) in acknowledgement | ||
// This function may be called more than once by relayers, in which case, the previous counterparty address will be overwritten by the new counterparty address | ||
func (k Keeper) RegisterCounterpartyAddress(goCtx context.Context, msg *types.MsgRegisterCounterpartyAddress) (*types.MsgRegisterCounterpartyAddressResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
k.SetCounterpartyAddress( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may want to validate that On the other hand, we cannot really validate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This will already be checked during antehandler, since address must sign message. Do you have suggestions on Counterparty address validation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can do basic validation with an acceptable address format for the majority of blockchains that exist today. Something like |
||
ctx, msg.Address, msg.CounterpartyAddress, | ||
) | ||
|
||
k.Logger(ctx).Info("Registering counterparty address for relayer.", "Address:", msg.Address, "Counterparty Address:", msg.CounterpartyAddress) | ||
|
||
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 | ||
} |
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 | ||
|
||
// RelayerAddressKeyPrefix is the key prefix for relayer address mapping | ||
RelayerAddressKeyPrefix = "relayerAddress" | ||
) | ||
|
||
// KeyRelayerAddress returns the key for relayer address -> counteryparty address mapping | ||
func KeyRelayerAddress(address string) []byte { | ||
return []byte(fmt.Sprintf("%s/%s", RelayerAddressKeyPrefix, address)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package types_test | ||
|
||
import ( | ||
fmt "fmt" | ||
"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), fmt.Sprintf("%s/relayer_address", types.RelayerAddressKeyPrefix)) | ||
} |
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(address, counterpartyAddress string) *MsgRegisterCounterpartyAddress { | ||
return &MsgRegisterCounterpartyAddress{ | ||
Address: address, | ||
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.CounterpartyAddress into sdk.AccAddress") | ||
} | ||
|
||
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} | ||
} | ||
*/ |
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) | ||
} | ||
} | ||
} | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks to me like a global API, as I do not see the
channelEnd
being specified anywhere. But in a multi-chain setting, a relayer usually use the same wallet to relay from multiple chains. We cannot use the same counterparty address address for all channels that are relayed by the same relayer wallet, as the relayer's counterparty address for each chain is different.