-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: gov proposal for rollapp fraud event (#622)
- Loading branch information
Showing
26 changed files
with
943 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
syntax = "proto3"; | ||
package dymensionxyz.dymension.rollapp; | ||
|
||
|
||
import "gogoproto/gogo.proto"; | ||
|
||
option go_package = "github.com/dymensionxyz/dymension/v3/x/rollapp/types"; | ||
|
||
|
||
message SubmitFraudProposal { | ||
option (gogoproto.equal) = true; | ||
option (gogoproto.goproto_getters) = false; | ||
option (gogoproto.goproto_stringer) = false; | ||
|
||
string title = 1; | ||
string description = 2; | ||
|
||
// The rollapp id | ||
string rollapp_id = 3; | ||
// The ibc client id of the rollapp | ||
string ibc_client_id = 4; | ||
// The height of the fraudelent block | ||
uint64 fraudelent_height = 5; | ||
// The address of the fraudelent sequencer | ||
string fraudelent_sequencer_address = 6; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/osmosis-labs/osmosis/v15/osmoutils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func ParseProposal(cmd *cobra.Command) (osmoutils.Proposal, sdk.Coins, error) { | ||
proposal, err := osmoutils.ParseProposalFlags(cmd.Flags()) | ||
if err != nil { | ||
return osmoutils.Proposal{}, nil, fmt.Errorf("failed to parse proposal: %w", err) | ||
} | ||
|
||
deposit, err := sdk.ParseCoinsNormalized(proposal.Deposit) | ||
if err != nil { | ||
return osmoutils.Proposal{}, nil, err | ||
} | ||
return *proposal, deposit, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package cli | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/dymensionxyz/dymension/v3/x/rollapp/types" | ||
|
||
govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli" | ||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" | ||
|
||
"github.com/dymensionxyz/dymension/v3/utils" | ||
) | ||
|
||
// NewCmdSubmitFraudProposal submits a fraud proposal | ||
func NewCmdSubmitFraudProposal() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "submit-fraud-proposal <rollappID> <height> <propser_addr> <client_id>", | ||
Short: "submit a fraud proposal", | ||
Args: cobra.ExactArgs(4), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
proposal, deposit, err := utils.ParseProposal(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
rollappID := args[0] | ||
height, err := strconv.ParseUint(args[1], 10, 64) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
proposerAddr := args[2] | ||
ibcClientID := args[3] | ||
|
||
content := types.NewSubmitFraudProposal(proposal.Title, proposal.Description, rollappID, height, proposerAddr, ibcClientID) | ||
msg, err := govtypes.NewMsgSubmitProposal(content, deposit, clientCtx.GetFromAddress()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
txf := tx.NewFactoryCLI(clientCtx, cmd.Flags()).WithTxConfig(clientCtx.TxConfig).WithAccountRetriever(clientCtx.AccountRetriever) | ||
return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg) | ||
}, | ||
} | ||
|
||
cmd.Flags().String(govcli.FlagTitle, "", "The proposal title") | ||
cmd.Flags().String(govcli.FlagDescription, "", "The proposal description") | ||
cmd.Flags().String(govcli.FlagDeposit, "", "The proposal deposit") | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package client | ||
|
||
import ( | ||
govclient "github.com/cosmos/cosmos-sdk/x/gov/client" | ||
"github.com/dymensionxyz/dymension/v3/x/rollapp/client/cli" | ||
) | ||
|
||
var ( | ||
SubmitFraudHandler = govclient.NewProposalHandler(cli.NewCmdSubmitFraudProposal) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package keeper | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
|
||
clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" | ||
tmtypes "github.com/cosmos/ibc-go/v6/modules/light-clients/07-tendermint/types" | ||
"github.com/dymensionxyz/dymension/v3/x/rollapp/types" | ||
) | ||
|
||
// HandleFraud handles the fraud evidence submitted by the user. | ||
func (k Keeper) HandleFraud(ctx sdk.Context, rollappID, clientId string, height uint64, seqAddr string) error { | ||
// Get the rollapp from the store | ||
_, found := k.GetRollapp(ctx, rollappID) | ||
if !found { | ||
return sdkerrors.Wrapf(types.ErrInvalidRollappID, "rollapp with ID %s not found", rollappID) | ||
} | ||
|
||
stateInfo, err := k.FindStateInfoByHeight(ctx, rollappID, height) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
//TODO: mark the rollapp as frozen (if immutable) or mark the fraud height to allow overwriting | ||
|
||
if stateInfo.Sequencer != seqAddr { | ||
return sdkerrors.Wrapf(types.ErrInvalidSequencer, "sequencer address %s does not match the one in the state info", seqAddr) | ||
} | ||
|
||
// slash the sequencer | ||
err = k.hooks.FraudSubmitted(ctx, rollappID, height, seqAddr) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
//FIXME: make sure the clientId corresponds to the rollappID | ||
|
||
clientState, ok := k.ibcclientkeeper.GetClientState(ctx, clientId) | ||
if !ok { | ||
return sdkerrors.Wrapf(types.ErrInvalidClientState, "client state for clientID %s not found", clientId) | ||
} | ||
|
||
// Set the client state to frozen | ||
tmClientState, ok := clientState.(*tmtypes.ClientState) | ||
if !ok { | ||
return sdkerrors.Wrapf(types.ErrInvalidClientState, "client state with ID %s is not a tendermint client state", clientId) | ||
} | ||
|
||
tmClientState.FrozenHeight = clienttypes.NewHeight(tmClientState.GetLatestHeight().GetRevisionHeight(), tmClientState.GetLatestHeight().GetRevisionNumber()) | ||
k.ibcclientkeeper.SetClientState(ctx, clientId, tmClientState) | ||
|
||
// Emit an event | ||
ctx.EventManager().EmitEvent( | ||
sdk.NewEvent( | ||
types.EventTypeFraud, | ||
sdk.NewAttribute(types.AttributeKeyRollappId, rollappID), | ||
sdk.NewAttribute(types.AttributeKeyFraudHeight, fmt.Sprint(height)), | ||
sdk.NewAttribute(types.AttributeKeyFraudSequencer, seqAddr), | ||
), | ||
) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package rollapp | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/dymensionxyz/dymension/v3/x/rollapp/keeper" | ||
"github.com/dymensionxyz/dymension/v3/x/rollapp/types" | ||
|
||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" | ||
|
||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
func NewRollappProposalHandler(k *keeper.Keeper) govtypes.Handler { | ||
return func(ctx sdk.Context, content govtypes.Content) error { | ||
switch c := content.(type) { | ||
case *types.SubmitFraudProposal: | ||
return HandleSubmitFraudProposal(ctx, k, c) | ||
default: | ||
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized rollapp proposal content type: %T", c) | ||
} | ||
} | ||
} | ||
|
||
func HandleSubmitFraudProposal(ctx sdk.Context, k *keeper.Keeper, p *types.SubmitFraudProposal) error { | ||
err := k.HandleFraud(ctx, p.RollappId, p.IbcClientId, p.FraudelentHeight, p.FraudelentSequencerAddress) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.