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

[Morse->Shannon Migration] Scaffold MsgUploadMorseState #1035

Closed
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
1,184 changes: 1,148 additions & 36 deletions api/poktroll/migration/tx.pulsar.go

Large diffs are not rendered by default.

40 changes: 39 additions & 1 deletion api/poktroll/migration/tx_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 25 additions & 12 deletions proto/poktroll/migration/tx.proto
Original file line number Diff line number Diff line change
@@ -1,41 +1,54 @@
syntax = "proto3";

package poktroll.migration;

import "amino/amino.proto";
import "cosmos/msg/v1/msg.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "poktroll/migration/params.proto";
import "poktroll/migration/types.proto";

option go_package = "github.com/pokt-network/poktroll/x/migration/types";
option (gogoproto.stable_marshaler_all) = true;

// Msg defines the Msg service.
service Msg {
option (cosmos.msg.v1.service) = true;

// UpdateParams defines a (governance) operation for updating the module
// parameters. The authority defaults to the x/gov module account.
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
rpc UpdateParams (MsgUpdateParams ) returns (MsgUpdateParamsResponse );
rpc UploadMorseState (MsgUploadMorseState) returns (MsgUploadMorseStateResponse);
}

// MsgUpdateParams is the Msg/UpdateParams request type.
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "poktroll/x/migration/MsgUpdateParams";

option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "poktroll/x/migration/MsgUpdateParams";
// authority is the address that controls the module (defaults to x/gov unless overwritten).
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// params defines the module parameters to update.
//

// NOTE: All parameters must be supplied.
Params params = 2 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];
Params params = 2 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}

// MsgUpdateParamsResponse defines the response structure for executing a
// MsgUpdateParams message.
message MsgUpdateParamsResponse {}
message MsgUpdateParamsResponse {}

// MsgUploadMorseState commits the "Morse migration" state to the Shannon state
// for subsequent migration operations on Shannon.
message MsgUploadMorseState {
option (cosmos.msg.v1.signer) = "authority";
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
MorseAccountState state = 2 [(gogoproto.nullable) = false];
}

message MsgUploadMorseStateResponse {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
string state_hash = 1 [(gogoproto.jsontag) = "state_hash"];
bytes state_hash = 1 [(gogoproto.jsontag) = "state_hash"];

string state_hash = 1 [(gogoproto.jsontag) = "state_hash"];
uint64 num_accounts = 2 [(gogoproto.jsontag) = "num_accounts"];
}

18 changes: 18 additions & 0 deletions x/migration/keeper/msg_server_upload_morse_state.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package keeper

import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/pokt-network/poktroll/x/migration/types"
)

func (k msgServer) UploadMorseState(goCtx context.Context, msg *types.MsgUploadMorseState) (*types.MsgUploadMorseStateResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

// TODO: Handling the message
_ = ctx

return &types.MsgUploadMorseStateResponse{}, nil
}
7 changes: 7 additions & 0 deletions x/migration/module/autocli.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
RpcMethod: "UpdateParams",
Skip: true, // skipped because authority gated
},
{
RpcMethod: "UploadMorseState",
Use: "upload-morse-state [state]",
Short: "Send a upload-morse-state tx",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "state"}},
Skip: true, // skipped because authority gated
},
// this line is used by ignite scaffolding # autocli/tx
},
},
Expand Down
25 changes: 24 additions & 1 deletion x/migration/module/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ var (
)

const (
// this line is used by starport scaffolding # simapp/module/const
opWeightMsgUploadMorseState = "op_weight_msg_upload_morse_state"
// TODO: Determine the simulation weight value
defaultWeightMsgUploadMorseState int = 100

// this line is used by starport scaffolding # simapp/module/const
)

// GenerateGenesisState creates a randomized GenState of the module.
Expand All @@ -46,6 +50,17 @@ func (am AppModule) RegisterStoreDecoder(_ simtypes.StoreDecoderRegistry) {}
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
operations := make([]simtypes.WeightedOperation, 0)

var weightMsgUploadMorseState int
simState.AppParams.GetOrGenerate(opWeightMsgUploadMorseState, &weightMsgUploadMorseState, nil,
func(_ *rand.Rand) {
weightMsgUploadMorseState = defaultWeightMsgUploadMorseState
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgUploadMorseState,
migrationsimulation.SimulateMsgUploadMorseState(am.accountKeeper, am.bankKeeper, am.keeper),
))

// this line is used by starport scaffolding # simapp/module/operation

return operations
Expand All @@ -54,6 +69,14 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp
// ProposalMsgs returns msgs used for governance proposals for simulations.
func (am AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg {
return []simtypes.WeightedProposalMsg{
simulation.NewWeightedProposalMsg(
opWeightMsgUploadMorseState,
defaultWeightMsgUploadMorseState,
func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) sdk.Msg {
migrationsimulation.SimulateMsgUploadMorseState(am.accountKeeper, am.bankKeeper, am.keeper)
return nil
},
),
// this line is used by starport scaffolding # simapp/module/OpMsg
}
}
30 changes: 30 additions & 0 deletions x/migration/simulation/upload_morse_state.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package simulation

import (
"math/rand"

"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"

"github.com/pokt-network/poktroll/x/migration/keeper"
"github.com/pokt-network/poktroll/x/migration/types"
)

func SimulateMsgUploadMorseState(
ak types.AccountKeeper,
bk types.BankKeeper,
k keeper.Keeper,
) simtypes.Operation {
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
simAccount, _ := simtypes.RandomAcc(r, accs)
msg := &types.MsgUploadMorseState{
Authority: simAccount.Address.String(),
}

// TODO: Handling the UploadMorseState simulation

return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "UploadMorseState simulation not implemented"), nil, nil
}
}
3 changes: 3 additions & 0 deletions x/migration/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
)

func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgUploadMorseState{},
)
// this line is used by starport scaffolding # 3

registry.RegisterImplementations((*sdk.Msg)(nil),
Expand Down
24 changes: 24 additions & 0 deletions x/migration/types/message_upload_morse_state.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package types

import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

var _ sdk.Msg = &MsgUploadMorseState{}

func NewMsgUploadMorseState(authority string, state MorseAccountState) *MsgUploadMorseState {
return &MsgUploadMorseState{
Authority: authority,
State: state,
}
}

func (msg *MsgUploadMorseState) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Authority)
if err != nil {
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid authority address (%s)", err)
}
return nil
}
41 changes: 41 additions & 0 deletions x/migration/types/message_upload_morse_state_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package types

import (
"testing"

sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/stretchr/testify/require"

"github.com/pokt-network/poktroll/testutil/sample"
)

func TestMsgUploadMorseState_ValidateBasic(t *testing.T) {
tests := []struct {
name string
msg MsgUploadMorseState
err error
}{
{
name: "invalid address",
msg: MsgUploadMorseState{
Authority: "invalid_address",
},
err: sdkerrors.ErrInvalidAddress,
}, {
name: "valid address",
msg: MsgUploadMorseState{
Authority: sample.AccAddress(),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.msg.ValidateBasic()
if tt.err != nil {
require.ErrorIs(t, err, tt.err)
return
}
require.NoError(t, err)
})
}
}
Loading
Loading