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

fix(rollapp): make genesis info nullable #1263

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (s *KeeperTestHelper) CreateRollappByName(name string) {
InitialSequencer: "*",
Alias: strings.ToLower(rand.Str(7)),
VmType: rollapptypes.Rollapp_EVM,
GenesisInfo: rollapptypes.GenesisInfo{
GenesisInfo: &rollapptypes.GenesisInfo{
Bech32Prefix: strings.ToLower(rand.Str(3)),
GenesisChecksum: "1234567890abcdefg",
InitialSupply: sdk.NewInt(1000),
Expand Down
2 changes: 1 addition & 1 deletion ibctesting/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (s *utilSuite) createRollapp(transfersEnabled bool, channelID *string) {
Telegram: "https://t.me/rolly",
X: "https://x.dymension.xyz",
},
rollapptypes.GenesisInfo{
&rollapptypes.GenesisInfo{
GenesisChecksum: "somechecksum",
Bech32Prefix: "eth",
NativeDenom: rollapptypes.DenomMetadata{
Expand Down
4 changes: 2 additions & 2 deletions proto/dymensionxyz/dymension/rollapp/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ message MsgCreateRollapp {
// metadata is the rollapp metadata
RollappMetadata metadata = 13;
// genesis_info is the genesis information
GenesisInfo genesis_info = 14 [(gogoproto.nullable) = false ];
GenesisInfo genesis_info = 14 [(gogoproto.nullable) = true ];
// vm_type is the type of rollapp machine: EVM or WASM
Rollapp.VMType vm_type = 15;
}
Expand All @@ -60,7 +60,7 @@ message MsgUpdateRollappInformation {
// metadata is the rollapp metadata
RollappMetadata metadata = 5 [(gogoproto.nullable) = true ];
// genesis_info is the genesis information
GenesisInfo genesis_info = 6 [(gogoproto.nullable) = false ];
GenesisInfo genesis_info = 6 [(gogoproto.nullable) = true ];
}

message MsgUpdateRollappInformationResponse {
Expand Down
4 changes: 4 additions & 0 deletions x/denommetadata/ibc_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ func (im IBCModule) OnRecvPacket(
return uevent.NewErrorAcknowledgement(ctx, gerrc.ErrNotFound)
}

if im.keeper.HasDenomMetadata(ctx, ibcDenom) {
return im.IBCModule.OnRecvPacket(ctx, packet, relayer)
}

dm.Base = ibcDenom
dm.DenomUnits[0].Denom = dm.Base

Expand Down
8 changes: 6 additions & 2 deletions x/denommetadata/ibc_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,15 +596,19 @@ func (m *mockIBCModule) OnRecvPacket(_ sdk.Context, p channeltypes.Packet, _ sdk
return emptyResult
}

func (m *mockIBCModule) OnAcknowledgementPacket(_ sdk.Context, _ channeltypes.Packet, ack []byte, _ sdk.AccAddress) error {
func (m *mockIBCModule) OnAcknowledgementPacket(sdk.Context, channeltypes.Packet, []byte, sdk.AccAddress) error {
return nil
}

type mockDenomMetadataKeeper struct {
hasDenomMetaData, created bool
}

func (m *mockDenomMetadataKeeper) CreateDenomMetadata(ctx sdk.Context, metadata banktypes.Metadata) error {
func (m *mockDenomMetadataKeeper) HasDenomMetadata(sdk.Context, string) bool {
return true
}

func (m *mockDenomMetadataKeeper) CreateDenomMetadata(sdk.Context, banktypes.Metadata) error {
m.created = true
return nil
}
Expand Down
2 changes: 2 additions & 0 deletions x/denommetadata/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank/types"

rollapptypes "github.com/dymensionxyz/dymension/v3/x/rollapp/types"
)

Expand All @@ -14,6 +15,7 @@ type BankKeeper interface {

type DenomMetadataKeeper interface {
CreateDenomMetadata(ctx sdk.Context, metadata types.Metadata) error
HasDenomMetadata(ctx sdk.Context, base string) bool
}

type RollappKeeper interface {
Expand Down
2 changes: 1 addition & 1 deletion x/incentives/client/cli/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (suite *QueryTestSuite) CreateDefaultRollapp() string {
RollappId: urand.RollappID(),
Alias: strings.ToLower(tmrand.Str(7)),
VmType: rollapptypes.Rollapp_EVM,
GenesisInfo: rollapptypes.GenesisInfo{
GenesisInfo: &rollapptypes.GenesisInfo{
Bech32Prefix: strings.ToLower(tmrand.Str(3)),
},
}
Expand Down
2 changes: 1 addition & 1 deletion x/incentives/keeper/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (suite *KeeperTestSuite) CreateDefaultRollapp(addr sdk.AccAddress) string {
InitialSequencer: addr.String(),
Alias: strings.ToLower(tmrand.Str(7)),
VmType: rollapptypes.Rollapp_EVM,
GenesisInfo: rollapptypes.GenesisInfo{
GenesisInfo: &rollapptypes.GenesisInfo{
Bech32Prefix: strings.ToLower(tmrand.Str(3)),
GenesisChecksum: "checksum",
NativeDenom: rollapptypes.DenomMetadata{
Expand Down
16 changes: 8 additions & 8 deletions x/rollapp/client/cli/tx_create_rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,43 +69,43 @@ func CmdCreateRollapp() *cobra.Command {
return cmd
}

func parseGenesisInfo(cmd *cobra.Command) (types.GenesisInfo, error) {
func parseGenesisInfo(cmd *cobra.Command) (*types.GenesisInfo, error) {
var (
genesisInfo types.GenesisInfo
genesisInfo = &types.GenesisInfo{}
err error
ok bool
)

genesisInfo.GenesisChecksum, err = cmd.Flags().GetString(FlagGenesisChecksum)
if err != nil {
return types.GenesisInfo{}, err
return nil, err
}

genesisInfo.Bech32Prefix, err = cmd.Flags().GetString(FlagBech32Prefix)
if err != nil {
return types.GenesisInfo{}, err
return nil, err
}

nativeDenomFlag, err := cmd.Flags().GetString(FlagNativeDenom)
if err != nil {
return types.GenesisInfo{}, err
return nil, err
}

if nativeDenomFlag != "" {
if err = utils.ParseJsonFromFile(nativeDenomFlag, &genesisInfo.NativeDenom); err != nil {
return types.GenesisInfo{}, err
return nil, err
}
}

initialSupplyFlag, err := cmd.Flags().GetString(FlagInitialSupply)
if err != nil {
return types.GenesisInfo{}, err
return nil, err
}

if initialSupplyFlag != "" {
genesisInfo.InitialSupply, ok = sdk.NewIntFromString(initialSupplyFlag)
if !ok {
return types.GenesisInfo{}, fmt.Errorf("invalid initial supply: %s", initialSupplyFlag)
return nil, fmt.Errorf("invalid initial supply: %s", initialSupplyFlag)
}
}

Expand Down
4 changes: 2 additions & 2 deletions x/rollapp/keeper/msg_server_create_rollapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ func (suite *RollappTestSuite) createRollappWithCreatorAndVerify(
InitialSequencer: rollapp.GetInitialSequencer(),
VmType: types.Rollapp_EVM,
Metadata: rollapp.GetMetadata(),
GenesisInfo: rollapp.GetGenesisInfo(),
GenesisInfo: *rollapp.GetGenesisInfo(),
}
rollappExpect.GenesisState.TransfersEnabled = true

Expand Down Expand Up @@ -385,7 +385,7 @@ var mockRollappMetadata = types.RollappMetadata{
X: "https://x.dymension.xyz",
}

var mockGenesisInfo = types.GenesisInfo{
var mockGenesisInfo = &types.GenesisInfo{
Bech32Prefix: "rol",
GenesisChecksum: "checksum",
NativeDenom: types.DenomMetadata{
Expand Down
4 changes: 2 additions & 2 deletions x/rollapp/keeper/msg_server_transfer_ownership_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (suite *RollappTestSuite) TestTransferOwnership() {
expRollapp: types.Rollapp{
Owner: bob,
RollappId: rollappId,
GenesisInfo: mockGenesisInfo,
GenesisInfo: *mockGenesisInfo,
},
}, {
name: "Transfer rollapp ownership: failed, rollapp not found",
Expand Down Expand Up @@ -75,7 +75,7 @@ func (suite *RollappTestSuite) TestTransferOwnership() {
rollapp := types.Rollapp{
RollappId: rollappId,
Owner: alice,
GenesisInfo: mockGenesisInfo,
GenesisInfo: *mockGenesisInfo,
}

if tc.malleate != nil {
Expand Down
46 changes: 39 additions & 7 deletions x/rollapp/keeper/msg_server_update_rollapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (suite *RollappTestSuite) TestUpdateRollapp() {
RollappId: rollappId,
InitialSequencer: initialSequencerAddress,
Metadata: &mockRollappMetadata,
GenesisInfo: types.GenesisInfo{
GenesisInfo: &types.GenesisInfo{
Bech32Prefix: "new",
GenesisChecksum: "new_checksum",
InitialSupply: sdk.NewInt(1000),
Expand Down Expand Up @@ -103,7 +103,7 @@ func (suite *RollappTestSuite) TestUpdateRollapp() {
RollappId: rollappId,
InitialSequencer: "",
Metadata: nil,
GenesisInfo: types.GenesisInfo{
GenesisInfo: &types.GenesisInfo{
GenesisChecksum: "new_checksum",
},
},
Expand All @@ -114,7 +114,7 @@ func (suite *RollappTestSuite) TestUpdateRollapp() {
update: &types.MsgUpdateRollappInformation{
Owner: alice,
RollappId: rollappId,
GenesisInfo: types.GenesisInfo{
GenesisInfo: &types.GenesisInfo{
Bech32Prefix: "new",
},
},
Expand All @@ -125,7 +125,7 @@ func (suite *RollappTestSuite) TestUpdateRollapp() {
update: &types.MsgUpdateRollappInformation{
Owner: alice,
RollappId: rollappId,
GenesisInfo: types.GenesisInfo{
GenesisInfo: &types.GenesisInfo{
NativeDenom: types.DenomMetadata{
Display: "DEN",
Base: "aden",
Expand All @@ -140,7 +140,7 @@ func (suite *RollappTestSuite) TestUpdateRollapp() {
update: &types.MsgUpdateRollappInformation{
Owner: alice,
RollappId: rollappId,
GenesisInfo: types.GenesisInfo{
GenesisInfo: &types.GenesisInfo{
InitialSupply: sdk.NewInt(1000),
},
},
Expand Down Expand Up @@ -178,6 +178,38 @@ func (suite *RollappTestSuite) TestUpdateRollapp() {
Sealed: true,
},
},
}, {
name: "Update rollapp: success - unsealed, update rollapp without genesis info",
update: &types.MsgUpdateRollappInformation{
Owner: alice,
RollappId: rollappId,
Metadata: &mockRollappMetadata,
},
rollappLaunched: false,
genInfoSealed: false,
expError: nil,
expRollapp: types.Rollapp{
RollappId: rollappId,
Owner: alice,
InitialSequencer: "",
ChannelId: "",
Frozen: false,
RegisteredDenoms: nil,
Launched: false,
VmType: types.Rollapp_EVM,
Metadata: &mockRollappMetadata,
GenesisInfo: types.GenesisInfo{
Bech32Prefix: "old",
GenesisChecksum: "old",
InitialSupply: sdk.NewInt(1000),
NativeDenom: types.DenomMetadata{
Display: "OLD",
Base: "aold",
Exponent: 18,
},
Sealed: false,
},
},
},
}

Expand Down Expand Up @@ -238,7 +270,7 @@ func (suite *RollappTestSuite) TestCreateAndUpdateRollapp() {
InitialSequencer: "",
Alias: "default",
VmType: types.Rollapp_EVM,
GenesisInfo: types.GenesisInfo{
GenesisInfo: &types.GenesisInfo{
Bech32Prefix: "rol",
GenesisChecksum: "checksum",
InitialSupply: sdk.NewInt(1000),
Expand All @@ -265,7 +297,7 @@ func (suite *RollappTestSuite) TestCreateAndUpdateRollapp() {
Owner: alice,
RollappId: rollappId,
InitialSequencer: addrInit,
GenesisInfo: types.GenesisInfo{GenesisChecksum: "checksum1"},
GenesisInfo: &types.GenesisInfo{GenesisChecksum: "checksum1"},
})
suite.Require().NoError(err)

Expand Down
2 changes: 1 addition & 1 deletion x/rollapp/keeper/msg_server_update_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (suite *RollappTestSuite) TestUpdateStateErrLogicUnpermissioned() {
RollappId: rollappID,
Owner: alice,
InitialSequencer: sample.AccAddress(),
GenesisInfo: mockGenesisInfo,
GenesisInfo: *mockGenesisInfo,
}
suite.App.RollappKeeper.SetRollapp(suite.Ctx, rollapp)

Expand Down
29 changes: 18 additions & 11 deletions x/rollapp/keeper/rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,22 @@ func (k Keeper) CheckAndUpdateRollappFields(ctx sdk.Context, update *types.MsgUp
current.InitialSequencer = update.InitialSequencer
}

if update.GenesisInfo.GenesisChecksum != "" {
current.GenesisInfo.GenesisChecksum = update.GenesisInfo.GenesisChecksum
}
if update.GenesisInfo != nil {
if update.GenesisInfo.GenesisChecksum != "" {
current.GenesisInfo.GenesisChecksum = update.GenesisInfo.GenesisChecksum
}

if update.GenesisInfo.Bech32Prefix != "" {
current.GenesisInfo.Bech32Prefix = update.GenesisInfo.Bech32Prefix
}
if update.GenesisInfo.Bech32Prefix != "" {
current.GenesisInfo.Bech32Prefix = update.GenesisInfo.Bech32Prefix
}

if update.GenesisInfo.NativeDenom.Base != "" {
current.GenesisInfo.NativeDenom = update.GenesisInfo.NativeDenom
}
if update.GenesisInfo.NativeDenom.Base != "" {
current.GenesisInfo.NativeDenom = update.GenesisInfo.NativeDenom
}

if !update.GenesisInfo.InitialSupply.IsNil() {
current.GenesisInfo.InitialSupply = update.GenesisInfo.InitialSupply
if !update.GenesisInfo.InitialSupply.IsNil() {
current.GenesisInfo.InitialSupply = update.GenesisInfo.InitialSupply
}
}

if update.Metadata != nil && !update.Metadata.IsEmpty() {
Expand Down Expand Up @@ -141,6 +143,11 @@ func (k Keeper) SetIROPlanToRollapp(ctx sdk.Context, rollapp *types.Rollapp, pre
if rollapp.Launched {
return errorsmod.Wrap(gerrc.ErrFailedPrecondition, "rollapp already launched")
}

if rollapp.GenesisInfo.Sealed {
return errorsmod.Wrap(gerrc.ErrFailedPrecondition, "genesis info already sealed")
}

if !rollapp.GenesisInfoFieldsAreSet() {
return errorsmod.Wrap(gerrc.ErrFailedPrecondition, "genesis info not set")
}
Expand Down
2 changes: 1 addition & 1 deletion x/rollapp/simulation/create_rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func SimulateMsgCreateRollapp(ak simulationtypes.AccountKeeper, bk simulationtyp
Telegram: "https://t.me/rolly",
X: "https://x.dymension.xyz",
},
GenesisInfo: types.GenesisInfo{
GenesisInfo: &types.GenesisInfo{
GenesisChecksum: "checksum",
Bech32Prefix: "bech",
NativeDenom: types.DenomMetadata{
Expand Down
8 changes: 6 additions & 2 deletions x/rollapp/types/message_create_rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func NewMsgCreateRollapp(
alias string,
vmType Rollapp_VMType,
metadata *RollappMetadata,
genesisInfo GenesisInfo,
genesisInfo *GenesisInfo,
) *MsgCreateRollapp {
return &MsgCreateRollapp{
Creator: creator,
Expand Down Expand Up @@ -50,13 +50,17 @@ func (msg *MsgCreateRollapp) GetSignBytes() []byte {
}

func (msg *MsgCreateRollapp) GetRollapp() Rollapp {
genInfo := GenesisInfo{}
if msg.GenesisInfo != nil {
genInfo = *msg.GenesisInfo
}
return NewRollapp(
msg.Creator,
msg.RollappId,
msg.InitialSequencer,
msg.VmType,
msg.Metadata,
msg.GenesisInfo,
genInfo,
true,
)
}
Expand Down
Loading
Loading