Skip to content

Commit

Permalink
fix: add legacy skyway message (#1234)
Browse files Browse the repository at this point in the history
# Related Github tickets

- Closes #1921

# Background

We need these messages to be registered so they can be correctly
unmarshalled, both on genesis import/export, as well as pruning the
skyway attestation queue.

# Testing completed

- [x] test coverage exists or has been added/updated
- [x] tested in a private testnet

# Breaking changes

- [x] I have checked my code for breaking changes
- [x] If there are breaking changes, there is a supporting migration.
  • Loading branch information
maharifu authored Jul 29, 2024
1 parent 3ca52e3 commit f236733
Show file tree
Hide file tree
Showing 4 changed files with 737 additions and 0 deletions.
26 changes: 26 additions & 0 deletions proto/palomachain/paloma/skyway/legacy_msgs.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
syntax = "proto3";
package palomachain.paloma.skyway;

import "cosmos/msg/v1/msg.proto";
import "gogoproto/gogo.proto";
import "palomachain/paloma/valset/common.proto";

option go_package = "github.com/palomachain/paloma/x/skyway/types";

// This message was renamed to `MsgBatchSendToRemoteClaim`. However, since we
// already had some messages in the skyway attestation queue, we now get errors
// on genesis import and when trying to prune the queue.
// The queue only keeps the latest 1000 events, so we can remove this file once
// the messages are rotated out.
message MsgBatchSendToEthClaim {
option (cosmos.msg.v1.signer) = "metadata";
uint64 event_nonce = 1;
uint64 eth_block_height = 2;
uint64 batch_nonce = 3;
string token_contract = 4;
string chain_reference_id = 5;
string orchestrator = 6;
palomachain.paloma.valset.MsgMetadata metadata = 7
[ (gogoproto.nullable) = false ];
uint64 skyway_nonce = 8;
}
4 changes: 4 additions & 0 deletions x/skyway/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ func init() {
// nolint: exhaustruct
func RegisterInterfaces(registry types.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
// Register legacy messages
&MsgBatchSendToEthClaim{},
&MsgSendToRemote{},
&MsgConfirmBatch{},
&MsgSendToPalomaClaim{},
Expand All @@ -32,6 +34,8 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
registry.RegisterInterface(
"palomachain.paloma.skyway.EthereumClaim",
(*EthereumClaim)(nil),
// Register legacy messages
&MsgBatchSendToEthClaim{},
&MsgSendToPalomaClaim{},
&MsgBatchSendToRemoteClaim{},
&MsgLightNodeSaleClaim{},
Expand Down
72 changes: 72 additions & 0 deletions x/skyway/types/legacy_msgs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package types

import (
fmt "fmt"

sdkerrors "cosmossdk.io/errors"
"github.com/cometbft/cometbft/crypto/tmhash"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/palomachain/paloma/util/libmeta"
)

var _ sdk.Msg = &MsgBatchSendToEthClaim{}

var _ EthereumClaim = &MsgBatchSendToEthClaim{}

func (msg *MsgBatchSendToEthClaim) SetOrchestrator(orchestrator sdk.AccAddress) {
msg.Orchestrator = orchestrator.String()
}

// GetType returns the claim type
func (msg *MsgBatchSendToEthClaim) GetType() ClaimType {
return CLAIM_TYPE_BATCH_SEND_TO_ETH
}

// ValidateBasic performs stateless checks
func (e *MsgBatchSendToEthClaim) ValidateBasic() error {
if err := libmeta.ValidateBasic(e); err != nil {
return err
}
if e.EventNonce == 0 {
return fmt.Errorf("event_nonce == 0")
}
if e.SkywayNonce == 0 {
return fmt.Errorf("skyway_nonce == 0")
}
if e.BatchNonce == 0 {
return fmt.Errorf("batch_nonce == 0")
}
if err := ValidateEthAddress(e.TokenContract); err != nil {
return sdkerrors.Wrap(err, "erc20 token")
}
return nil
}

// Hash implements WithdrawBatch.Hash
func (msg *MsgBatchSendToEthClaim) ClaimHash() ([]byte, error) {
path := fmt.Sprintf("%d/%d/%d/%s", msg.SkywayNonce, msg.EthBlockHeight, msg.BatchNonce, msg.TokenContract)
return tmhash.Sum([]byte(path)), nil
}

func (msg MsgBatchSendToEthClaim) GetClaimer() sdk.AccAddress {
err := msg.ValidateBasic()
if err != nil {
panic(fmt.Errorf("MsgBatchSendToEthClaim failed ValidateBasic! Should have been handled earlier: %v", err))
}
val, err := sdk.AccAddressFromBech32(msg.Orchestrator)
if err != nil {
panic(fmt.Errorf("Invalid orchestrator: %v", err))
}
return val
}

// GetSigners defines whose signature is required
func (msg MsgBatchSendToEthClaim) GetSigners() []sdk.AccAddress {
return libmeta.GetSigners(&msg)
}

// Route should return the name of the module
func (msg MsgBatchSendToEthClaim) Route() string { return RouterKey }

// Type should return the action
func (msg MsgBatchSendToEthClaim) Type() string { return "batch_send_to_eth_claim" }
Loading

0 comments on commit f236733

Please sign in to comment.