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

GMP message handler #27

Merged
merged 44 commits into from
Dec 12, 2024
Merged

GMP message handler #27

merged 44 commits into from
Dec 12, 2024

Conversation

luckychess
Copy link
Contributor

@luckychess luckychess commented Dec 6, 2024

This PR introduces a GMP middleware for Axelar transactions. The main goal is to make possible to transfer funds from Ethereum to chainlets and vice versa. The basic docs for GMP could be found at https://docs.axelar.dev/dev/cosmos-gmp/overview/, a sample implementation which the current one is based on is https://github.com/axelarnetwork/evm-cosmos-gmp-sample/blob/main/native-integration/multi-send/cosmos/gmp_middleware.go.

x/gmp/module_ibc.go Outdated Show resolved Hide resolved
@luckychess luckychess changed the base branch from mainnet-v2-prep to release/0.2 December 6, 2024 18:56
@luckychess luckychess changed the base branch from release/0.2 to mainnet-v2-prep December 6, 2024 18:57
Base automatically changed from mainnet-v2-prep to release/0.2 December 6, 2024 19:12
@ashishchandr70
Copy link
Contributor

@luckychess please add a description of what this PR does and also indicate whether CI tests are enough or is there anything we should specifically test.

Copy link
Contributor

@ashishchandr70 ashishchandr70 left a comment

Choose a reason for hiding this comment

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

Have not tested but looks good otherwise.

SourceChain string `json:"source_chain"`
SourceAddress string `json:"source_address"`
Payload []byte `json:"payload"`
Type int64 `json:"type"`
Copy link
Contributor

@rkollar rkollar Dec 11, 2024

Choose a reason for hiding this comment

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

Shouldn't it be MessageType?

Also it should probably be just uint8 considering the possible values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, good point, I followed the example integration and it was declared and not used there. The int64 type also comes from the example and I think that's how it's defined in Axelar core.


const (
// TypeUnrecognized means coin type is unrecognized
TypeUnrecognized = iota
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be TypeUnrecognized MessageType = iota to use the type.


var data transfertypes.FungibleTokenPacketData
var err error
if err := types.ModuleCdc.UnmarshalJSON(modulePacket.GetData(), &data); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to create another local err var.

ctx.Logger().Info(fmt.Sprintf("failed to unpack: %s", err.Error()))
return channeltypes.NewErrorAcknowledgement(cosmossdkerrors.Wrapf(transfertypes.ErrInvalidMemo, "unable to unpack payload (%s)", err.Error()))
}
ctx.Logger().Info(fmt.Sprintf("Unpacked data: %+v", args))
Copy link
Contributor

Choose a reason for hiding this comment

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

It would probably be better to have this kind of debugging messages as a lower loglevel, not info.


// x/gmp module sentinel errors
var (
ErrSample = cosmossdkerrors.Register(ModuleName, 1100, "sample error")
Copy link
Contributor

Choose a reason for hiding this comment

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

Not used.


"github.com/cosmos/cosmos-sdk/client"
// "github.com/cosmos/cosmos-sdk/client/flags"
// sdk "github.com/cosmos/cosmos-sdk/types"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be just removed if unused.

)

var (
DefaultRelativePacketTimeoutTimestamp = uint64((time.Duration(10) * time.Minute).Nanoseconds())
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to cast an untyped constant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The funny part is that it was generated this way.

x/gmp/genesis.go Outdated
// InitGenesis initializes the module's state from a provided genesis state.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {
// this line is used by starport scaffolding # genesis/module/init
k.SetPort(ctx, genState.PortId)
Copy link
Contributor

Choose a reason for hiding this comment

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

Incorrect indentation. There are also other formatting errors across the entire module. Please run gofmt on every file in this PR (except generated files).

@luckychess luckychess requested a review from rkollar December 11, 2024 23:47
Copy link
Contributor

@lukitsbrian lukitsbrian left a comment

Choose a reason for hiding this comment

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

lgtm!

@luckychess luckychess merged commit 7d22cba into release/0.2 Dec 12, 2024
1 check passed
@luckychess luckychess deleted the feature/gmp2 branch December 12, 2024 00:51
luckychess added a commit that referenced this pull request Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants