diff --git a/proto/lavanet/lava/projects/tx.proto b/proto/lavanet/lava/projects/tx.proto index a704eb89c4..0807c10289 100644 --- a/proto/lavanet/lava/projects/tx.proto +++ b/proto/lavanet/lava/projects/tx.proto @@ -39,7 +39,7 @@ message MsgDelKeysResponse { message MsgSetPolicy { string creator = 1; string project = 2; - lavanet.lava.plans.Policy policy = 3 [(gogoproto.nullable) = false]; + lavanet.lava.plans.Policy policy = 3; } message MsgSetPolicyResponse { @@ -48,7 +48,7 @@ message MsgSetPolicyResponse { message MsgSetSubscriptionPolicy { string creator = 1; repeated string projects = 2; - lavanet.lava.plans.Policy policy = 3 [(gogoproto.nullable) = false]; + lavanet.lava.plans.Policy policy = 3; } message MsgSetSubscriptionPolicyResponse { diff --git a/testutil/common/tester.go b/testutil/common/tester.go index e21e1372e0..bab8c589a1 100644 --- a/testutil/common/tester.go +++ b/testutil/common/tester.go @@ -515,7 +515,7 @@ func (ts *Tester) TxProjectDelKeys(projectID, creator string, projectKeys ...pro } // TxProjectSetSubscriptionPolicy: implement 'tx project set-subscription-policy' -func (ts *Tester) TxProjectSetSubscriptionPolicy(projectID, subkey string, policy planstypes.Policy) (*projectstypes.MsgSetSubscriptionPolicyResponse, error) { +func (ts *Tester) TxProjectSetSubscriptionPolicy(projectID, subkey string, policy *planstypes.Policy) (*projectstypes.MsgSetSubscriptionPolicyResponse, error) { msg := &projectstypes.MsgSetSubscriptionPolicy{ Creator: subkey, Policy: policy, @@ -525,7 +525,7 @@ func (ts *Tester) TxProjectSetSubscriptionPolicy(projectID, subkey string, polic } // TxProjectSetPolicy: implement 'tx project set-policy' -func (ts *Tester) TxProjectSetPolicy(projectID, subkey string, policy planstypes.Policy) (*projectstypes.MsgSetPolicyResponse, error) { +func (ts *Tester) TxProjectSetPolicy(projectID, subkey string, policy *planstypes.Policy) (*projectstypes.MsgSetPolicyResponse, error) { msg := &projectstypes.MsgSetPolicy{ Creator: subkey, Policy: policy, diff --git a/x/pairing/keeper/grpc_query_effective_policy_test.go b/x/pairing/keeper/grpc_query_effective_policy_test.go index 9ad33ec43a..447218409d 100644 --- a/x/pairing/keeper/grpc_query_effective_policy_test.go +++ b/x/pairing/keeper/grpc_query_effective_policy_test.go @@ -36,7 +36,7 @@ func TestEffectivePolicy(t *testing.T) { MaxProvidersToPair: 3, GeolocationProfile: 1, } - _, err = ts.TxProjectSetPolicy(project.ProjectID, clientAddr, adminPolicy) + _, err = ts.TxProjectSetPolicy(project.ProjectID, clientAddr, &adminPolicy) require.Nil(t, err) subPolicy := planstypes.Policy{ @@ -45,7 +45,7 @@ func TestEffectivePolicy(t *testing.T) { MaxProvidersToPair: 2, GeolocationProfile: planstypes.Geolocation_value["GL"], } - _, err = ts.TxProjectSetSubscriptionPolicy(project.ProjectID, clientAddr, subPolicy) + _, err = ts.TxProjectSetSubscriptionPolicy(project.ProjectID, clientAddr, &subPolicy) require.Nil(t, err) // the effective policy function calcaulates the effective chain policy within it @@ -70,7 +70,7 @@ func TestEffectivePolicy(t *testing.T) { require.Nil(t, res.PendingPolicy) // there should be no pending policy // set a new policy without applying it (no advanceEpoch) - _, err = ts.TxProjectSetPolicy(project.ProjectID, clientAddr, planstypes.Policy{ + _, err = ts.TxProjectSetPolicy(project.ProjectID, clientAddr, &planstypes.Policy{ TotalCuLimit: 80000, EpochCuLimit: 5000, MaxProvidersToPair: 3, diff --git a/x/pairing/keeper/pairing_subscription_test.go b/x/pairing/keeper/pairing_subscription_test.go index 29394870e2..8a2eb3ffd1 100644 --- a/x/pairing/keeper/pairing_subscription_test.go +++ b/x/pairing/keeper/pairing_subscription_test.go @@ -232,12 +232,12 @@ func TestStrictestPolicyGeolocation(t *testing.T) { MaxProvidersToPair: 2, } - _, err = ts.TxProjectSetPolicy(projectID, client1Addr, *adminPolicy) + _, err = ts.TxProjectSetPolicy(projectID, client1Addr, adminPolicy) require.Nil(t, err) ts.AdvanceEpoch() - _, err = ts.TxProjectSetSubscriptionPolicy(projectID, client1Addr, *subscriptionPolicy) + _, err = ts.TxProjectSetSubscriptionPolicy(projectID, client1Addr, subscriptionPolicy) require.Nil(t, err) ts.AdvanceEpoch() @@ -292,7 +292,7 @@ func TestStrictestPolicyProvidersToPair(t *testing.T) { MaxProvidersToPair: tt.providersToPairSubPolicy, } - _, err = ts.TxProjectSetPolicy(proj.Index, client1Addr, *adminPolicy) + _, err = ts.TxProjectSetPolicy(proj.Index, client1Addr, adminPolicy) if !tt.adminPolicyValid { require.NotNil(t, err) return @@ -302,7 +302,7 @@ func TestStrictestPolicyProvidersToPair(t *testing.T) { ts.AdvanceEpoch() - _, err = ts.TxProjectSetSubscriptionPolicy(proj.Index, client1Addr, *subscriptionPolicy) + _, err = ts.TxProjectSetSubscriptionPolicy(proj.Index, client1Addr, subscriptionPolicy) if !tt.subscriptionPolicyValid { require.NotNil(t, err) return @@ -394,12 +394,12 @@ func TestStrictestPolicyCuPerEpoch(t *testing.T) { MaxProvidersToPair: ts.plan.PlanPolicy.MaxProvidersToPair, } - _, err = ts.TxProjectSetPolicy(proj.Index, client1Addr, *adminPolicy) + _, err = ts.TxProjectSetPolicy(proj.Index, client1Addr, adminPolicy) require.Nil(t, err) ts.AdvanceEpoch() - _, err = ts.TxProjectSetSubscriptionPolicy(proj.Index, client1Addr, *subscriptionPolicy) + _, err = ts.TxProjectSetSubscriptionPolicy(proj.Index, client1Addr, subscriptionPolicy) require.Nil(t, err) ts.AdvanceEpoch() @@ -529,7 +529,7 @@ func TestAddProjectAfterPlanUpdate(t *testing.T) { adminPolicy := ts.plan.PlanPolicy adminPolicy.EpochCuLimit = oldEpochCuLimit - 30 - _, err = ts.TxProjectSetPolicy(proj.Project.Index, dev1Addr, adminPolicy) + _, err = ts.TxProjectSetPolicy(proj.Project.Index, dev1Addr, &adminPolicy) require.Nil(t, err) // advance epoch to set the new policy diff --git a/x/pairing/keeper/pairing_test.go b/x/pairing/keeper/pairing_test.go index 44bbf64363..935f972232 100644 --- a/x/pairing/keeper/pairing_test.go +++ b/x/pairing/keeper/pairing_test.go @@ -532,7 +532,7 @@ func TestAddonPairing(t *testing.T) { if tt.projChainPolicy != nil { projPolicy := defaultPolicy() projPolicy.ChainPolicies = []planstypes.ChainPolicy{*tt.projChainPolicy} - _, err = ts.TxProjectSetPolicy(projectID, sub1Addr, projPolicy) + _, err = ts.TxProjectSetPolicy(projectID, sub1Addr, &projPolicy) require.Nil(t, err) } @@ -542,7 +542,7 @@ func TestAddonPairing(t *testing.T) { if tt.subscChainPolicy != nil { subscPolicy := defaultPolicy() subscPolicy.ChainPolicies = []planstypes.ChainPolicy{*tt.subscChainPolicy} - _, err = ts.TxProjectSetSubscriptionPolicy(projectID, sub1Addr, subscPolicy) + _, err = ts.TxProjectSetSubscriptionPolicy(projectID, sub1Addr, &subscPolicy) require.Nil(t, err) } @@ -724,7 +724,7 @@ func TestSelectedProvidersPairing(t *testing.T) { policy.SelectedProvidersMode = tt.projMode policy.SelectedProviders = providersSet.projProviders - _, err = ts.TxProjectSetPolicy(project.Index, sub1Addr, *policy) + _, err = ts.TxProjectSetPolicy(project.Index, sub1Addr, policy) require.Nil(t, err) // skip epoch for the policy change to take effect @@ -733,7 +733,7 @@ func TestSelectedProvidersPairing(t *testing.T) { policy.SelectedProvidersMode = tt.subMode policy.SelectedProviders = providersSet.subProviders - _, err = ts.TxProjectSetSubscriptionPolicy(project.Index, sub1Addr, *policy) + _, err = ts.TxProjectSetSubscriptionPolicy(project.Index, sub1Addr, policy) require.Nil(t, err) // skip epoch for the policy change to take effect @@ -1051,7 +1051,7 @@ func TestGeolocationPairingScores(t *testing.T) { if tt.changePolicy { newPolicy = tt.planPolicy newPolicy.GeolocationProfile = tt.newGeo - _, err = ts.TxProjectSetPolicy(projIndex, tt.dev.Addr.String(), newPolicy) + _, err = ts.TxProjectSetPolicy(projIndex, tt.dev.Addr.String(), &newPolicy) require.Nil(t, err) policies = append(policies, &newPolicy) } @@ -1942,7 +1942,7 @@ func TestExtensionAndAddonPairing(t *testing.T) { if tt.projChainPolicy != nil { projPolicy := defaultPolicy() projPolicy.ChainPolicies = []planstypes.ChainPolicy{*tt.projChainPolicy} - _, err = ts.TxProjectSetPolicy(projectID, sub1Addr, projPolicy) + _, err = ts.TxProjectSetPolicy(projectID, sub1Addr, &projPolicy) require.Nil(t, err) } @@ -1952,7 +1952,7 @@ func TestExtensionAndAddonPairing(t *testing.T) { if tt.subscChainPolicy != nil { subscPolicy := defaultPolicy() subscPolicy.ChainPolicies = []planstypes.ChainPolicy{*tt.subscChainPolicy} - _, err = ts.TxProjectSetSubscriptionPolicy(projectID, sub1Addr, subscPolicy) + _, err = ts.TxProjectSetSubscriptionPolicy(projectID, sub1Addr, &subscPolicy) require.Nil(t, err) } diff --git a/x/plans/types/policy.go b/x/plans/types/policy.go index 279c8ea5e9..db4027a3f9 100644 --- a/x/plans/types/policy.go +++ b/x/plans/types/policy.go @@ -27,6 +27,9 @@ var policyDefaultValues = map[string]interface{}{ } func (policy *Policy) ContainsChainID(chainID string) bool { + if policy == nil { + return false + } if len(policy.ChainPolicies) == 0 { // empty chainPolicies -> support all chains return true diff --git a/x/projects/client/cli/tx_set_admin_policy.go b/x/projects/client/cli/tx_set_admin_policy.go index e20ebafe6c..7ef9e8ee89 100644 --- a/x/projects/client/cli/tx_set_admin_policy.go +++ b/x/projects/client/cli/tx_set_admin_policy.go @@ -16,6 +16,8 @@ import ( var _ = strconv.Itoa(0) +const DeletePolicyFlagName = "delete-policy" + func CmdSetPolicy() *cobra.Command { cmd := &cobra.Command{ Use: "set-policy project-index [policy-file-path]", @@ -23,37 +25,48 @@ func CmdSetPolicy() *cobra.Command { Long: `The set-policy command allows a project admin to set a new policy to its project. The policy file is a YAML file (see cookbook/projects/example_policy.yml for reference). The new policy will be applied from the next epoch. To define a geolocation in the policy file, use the available geolocations: ` + planstypes.PrintGeolocations(), Example: `required flags: --from lavad tx project set-policy [project-index] [policy-file-path] --from - lavad tx project set-policy [policy-file-path] --from (use this for the default admin policy)`, + lavad tx project set-policy admin [policy-file-path] --from (use this for the default admin policy) + lavad tx project set-policy [project-index] --delete-policy --from `, Args: cobra.RangeArgs(1, 2), RunE: func(cmd *cobra.Command, args []string) (err error) { clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err } - var projectId string - var adminPolicyFilePath string - if len(args) == 2 { - projectId = args[0] - adminPolicyFilePath = args[1] - } else { - adminPolicyFilePath = args[0] + + projectId := args[0] + if projectId == "admin" { projectId = clientCtx.GetFromAddress().String() + "-admin" } - policy, err := planstypes.ParsePolicyFromYamlPath(adminPolicyFilePath) - if err != nil { - return err + // check if the command includes --delete-policy + deletePolicyFlag := cmd.Flags().Lookup(DeletePolicyFlagName) + if deletePolicyFlag == nil { + return fmt.Errorf("%s flag wasn't found", DeletePolicyFlagName) } + deletePolicy := deletePolicyFlag.Changed - err = verifyChainPoliciesAreCorrectlySet(clientCtx, policy) - if err != nil { - return err + var policy *planstypes.Policy + if !deletePolicy { + if len(args) < 2 { + return fmt.Errorf("not enough arguments") + } + adminPolicyFilePath := args[1] + policy, err = planstypes.ParsePolicyFromYamlPath(adminPolicyFilePath) + if err != nil { + return err + } + + err = verifyChainPoliciesAreCorrectlySet(clientCtx, policy) + if err != nil { + return err + } } msg := types.NewMsgSetPolicy( clientCtx.GetFromAddress().String(), projectId, - *policy, + policy, ) if err := msg.ValidateBasic(); err != nil { return err @@ -64,6 +77,7 @@ func CmdSetPolicy() *cobra.Command { flags.AddTxFlagsToCmd(cmd) cmd.MarkFlagRequired(flags.FlagFrom) + cmd.Flags().Bool(DeletePolicyFlagName, false, "deletes the policy") return cmd } diff --git a/x/projects/client/cli/tx_set_subscription_policy.go b/x/projects/client/cli/tx_set_subscription_policy.go index ae15e80081..43e97ffede 100644 --- a/x/projects/client/cli/tx_set_subscription_policy.go +++ b/x/projects/client/cli/tx_set_subscription_policy.go @@ -1,6 +1,7 @@ package cli import ( + "fmt" "strconv" "strings" @@ -20,8 +21,9 @@ func CmdSetSubscriptionPolicy() *cobra.Command { Short: "set subscription policy to a project", Long: `The set-subscription-policy command allows the project's subscription consumer to set a new policy to its subscription which will affect some/all of the subscription's projects. The policy file is a YAML file (see cookbook/projects/example_policy.yml for reference). The new policy will be applied from the next epoch. To define a geolocation in the policy file, use the available geolocations: ` + planstypes.PrintGeolocations(), Example: `required flags: --from - lavad tx project set-subscription-policy [project-indices] [policy-file-path] --from `, - Args: cobra.ExactArgs(2), + lavad tx project set-subscription-policy [project-indices] [policy-file-path] --from + lavad tx project set-subscription-policy [project-indices] --delete-policy --from `, + Args: cobra.RangeArgs(1, 2), RunE: func(cmd *cobra.Command, args []string) (err error) { argProjects := strings.Split(args[0], listSeparator) @@ -30,17 +32,29 @@ func CmdSetSubscriptionPolicy() *cobra.Command { return err } - subscriptionPolicyFilePath := args[1] + // check if the command includes --delete-policy + deletePolicyFlag := cmd.Flags().Lookup(DeletePolicyFlagName) + if deletePolicyFlag == nil { + return fmt.Errorf("%s flag wasn't found", DeletePolicyFlagName) + } + deletePolicy := deletePolicyFlag.Changed - policy, err := planstypes.ParsePolicyFromYamlPath(subscriptionPolicyFilePath) - if err != nil { - return err + var policy *planstypes.Policy + if !deletePolicy { + if len(args) < 2 { + return fmt.Errorf("not enough arguments") + } + subscriptionPolicyFilePath := args[1] + policy, err = planstypes.ParsePolicyFromYamlPath(subscriptionPolicyFilePath) + if err != nil { + return err + } } msg := types.NewMsgSetSubscriptionPolicy( clientCtx.GetFromAddress().String(), argProjects, - *policy, + policy, ) if err := msg.ValidateBasic(); err != nil { return err @@ -50,6 +64,7 @@ func CmdSetSubscriptionPolicy() *cobra.Command { } flags.AddTxFlagsToCmd(cmd) + cmd.Flags().Bool(DeletePolicyFlagName, false, "deletes the policy") return cmd } diff --git a/x/projects/keeper/msg_server_set_admin_policy.go b/x/projects/keeper/msg_server_set_admin_policy.go index 1a2b170345..04cca64f37 100644 --- a/x/projects/keeper/msg_server_set_admin_policy.go +++ b/x/projects/keeper/msg_server_set_admin_policy.go @@ -12,13 +12,14 @@ func (k msgServer) SetPolicy(goCtx context.Context, msg *types.MsgSetPolicy) (*t policy := msg.GetPolicy() - err := policy.ValidateBasicPolicy(false) - if err != nil { - return nil, err + if policy != nil { + err := policy.ValidateBasicPolicy(false) + if err != nil { + return nil, err + } } - err = k.SetProjectPolicy(ctx, []string{msg.GetProject()}, &policy, msg.GetCreator(), types.SET_ADMIN_POLICY) - + err := k.SetProjectPolicy(ctx, []string{msg.GetProject()}, policy, msg.GetCreator(), types.SET_ADMIN_POLICY) if err != nil { return nil, err } diff --git a/x/projects/keeper/msg_server_set_subscription_policy.go b/x/projects/keeper/msg_server_set_subscription_policy.go index 7a2b5d0413..140c4a3f64 100644 --- a/x/projects/keeper/msg_server_set_subscription_policy.go +++ b/x/projects/keeper/msg_server_set_subscription_policy.go @@ -12,13 +12,14 @@ func (k msgServer) SetSubscriptionPolicy(goCtx context.Context, msg *types.MsgSe policy := msg.GetPolicy() - err := policy.ValidateBasicPolicy(false) - if err != nil { - return nil, err + if policy != nil { + err := policy.ValidateBasicPolicy(false) + if err != nil { + return nil, err + } } - err = k.SetProjectPolicy(ctx, msg.GetProjects(), &policy, msg.GetCreator(), types.SET_SUBSCRIPTION_POLICY) - + err := k.SetProjectPolicy(ctx, msg.GetProjects(), policy, msg.GetCreator(), types.SET_SUBSCRIPTION_POLICY) if err != nil { return nil, err } diff --git a/x/projects/keeper/project_test.go b/x/projects/keeper/project_test.go index 2d491b6141..6485077ba0 100644 --- a/x/projects/keeper/project_test.go +++ b/x/projects/keeper/project_test.go @@ -536,7 +536,7 @@ func setPolicyTest(t *testing.T, testAdminPolicy bool) { } if testAdminPolicy { - _, err := ts.TxProjectSetPolicy(tt.projectID, tt.creator, newPolicy) + _, err := ts.TxProjectSetPolicy(tt.projectID, tt.creator, &newPolicy) if tt.setAdminPolicySuccess { require.Nil(t, err) ts.AdvanceEpoch() @@ -547,7 +547,7 @@ func setPolicyTest(t *testing.T, testAdminPolicy bool) { require.NotNil(t, err) } } else { - _, err := ts.TxProjectSetSubscriptionPolicy(tt.projectID, tt.creator, newPolicy) + _, err := ts.TxProjectSetSubscriptionPolicy(tt.projectID, tt.creator, &newPolicy) if tt.setSubscriptionPolicySuccess { require.Nil(t, err) ts.AdvanceEpoch() @@ -1063,7 +1063,7 @@ func TestSetPolicySelectedProviders(t *testing.T) { policy.SelectedProvidersMode = tt.projMode policy.SelectedProviders = providersSet.projProviders - _, err = ts.TxProjectSetPolicy(admProject.Index, sub1Addr, policy) + _, err = ts.TxProjectSetPolicy(admProject.Index, sub1Addr, &policy) if tt.projPolicyValid { require.Nil(t, err) } else { @@ -1073,7 +1073,7 @@ func TestSetPolicySelectedProviders(t *testing.T) { policy.SelectedProvidersMode = tt.subMode policy.SelectedProviders = providersSet.subProviders - _, err = ts.TxProjectSetSubscriptionPolicy(admProject.Index, sub1Addr, policy) + _, err = ts.TxProjectSetSubscriptionPolicy(admProject.Index, sub1Addr, &policy) if tt.subPolicyValid { require.Nil(t, err) } else { @@ -1182,7 +1182,7 @@ func TestSetPolicyByGeolocation(t *testing.T) { _, err = servers.ProjectServer.SetPolicy(_ctx, &types.MsgSetPolicy{ Creator: tt.dev.Addr.String(), Project: projIndex, - Policy: planstypes.Policy{ + Policy: &planstypes.Policy{ GeolocationProfile: tt.setGeo, TotalCuLimit: 10, EpochCuLimit: 2, @@ -1232,7 +1232,7 @@ func TestPendingProject(t *testing.T) { projectID := res.Projects[0] adminPolicy := ts.Plan("free").PlanPolicy - _, err = ts.TxProjectSetPolicy(projectID, sub, adminPolicy) + _, err = ts.TxProjectSetPolicy(projectID, sub, &adminPolicy) require.Nil(t, err) // we didn't advance an epoch yet so querying for the project should have a pending project diff --git a/x/projects/types/message_set_admin_policy.go b/x/projects/types/message_set_admin_policy.go index c6c63ead48..a698ccfbf0 100644 --- a/x/projects/types/message_set_admin_policy.go +++ b/x/projects/types/message_set_admin_policy.go @@ -11,7 +11,7 @@ const TypeMsgSetPolicy = "set_admin_policy" var _ sdk.Msg = &MsgSetPolicy{} -func NewMsgSetPolicy(creator, project string, policy planstypes.Policy) *MsgSetPolicy { +func NewMsgSetPolicy(creator, project string, policy *planstypes.Policy) *MsgSetPolicy { return &MsgSetPolicy{ Creator: creator, Project: project, diff --git a/x/projects/types/message_set_admin_policy_test.go b/x/projects/types/message_set_admin_policy_test.go index e7e19b48b3..67d88bda6a 100644 --- a/x/projects/types/message_set_admin_policy_test.go +++ b/x/projects/types/message_set_admin_policy_test.go @@ -19,7 +19,7 @@ func TestMsgSetPolicy_ValidateBasic(t *testing.T) { name: "invalid address", msg: MsgSetPolicy{ Creator: "invalid_address", - Policy: planstypes.Policy{ + Policy: &planstypes.Policy{ EpochCuLimit: 100, TotalCuLimit: 1000, MaxProvidersToPair: 3, @@ -30,7 +30,7 @@ func TestMsgSetPolicy_ValidateBasic(t *testing.T) { name: "valid address", msg: MsgSetPolicy{ Creator: sample.AccAddress(), - Policy: planstypes.Policy{ + Policy: &planstypes.Policy{ EpochCuLimit: 100, TotalCuLimit: 1000, MaxProvidersToPair: 3, diff --git a/x/projects/types/message_set_subscription_policy.go b/x/projects/types/message_set_subscription_policy.go index 99b56b7c11..7f1ce3c2f2 100644 --- a/x/projects/types/message_set_subscription_policy.go +++ b/x/projects/types/message_set_subscription_policy.go @@ -11,7 +11,7 @@ const TypeMsgSetSubscriptionPolicy = "set_subscription_policy" var _ sdk.Msg = &MsgSetSubscriptionPolicy{} -func NewMsgSetSubscriptionPolicy(creator string, projects []string, policy planstypes.Policy) *MsgSetSubscriptionPolicy { +func NewMsgSetSubscriptionPolicy(creator string, projects []string, policy *planstypes.Policy) *MsgSetSubscriptionPolicy { return &MsgSetSubscriptionPolicy{ Creator: creator, Projects: projects, diff --git a/x/projects/types/message_set_subscription_policy_test.go b/x/projects/types/message_set_subscription_policy_test.go index 03cccbf71d..5487ea5c9b 100644 --- a/x/projects/types/message_set_subscription_policy_test.go +++ b/x/projects/types/message_set_subscription_policy_test.go @@ -19,7 +19,7 @@ func TestMsgSetSubscriptionPolicy_ValidateBasic(t *testing.T) { name: "invalid address", msg: MsgSetSubscriptionPolicy{ Creator: "invalid_address", - Policy: planstypes.Policy{ + Policy: &planstypes.Policy{ EpochCuLimit: 10, TotalCuLimit: 100, MaxProvidersToPair: 3, @@ -30,7 +30,7 @@ func TestMsgSetSubscriptionPolicy_ValidateBasic(t *testing.T) { name: "valid address", msg: MsgSetSubscriptionPolicy{ Creator: sample.AccAddress(), - Policy: planstypes.Policy{ + Policy: &planstypes.Policy{ EpochCuLimit: 10, TotalCuLimit: 100, MaxProvidersToPair: 3, diff --git a/x/projects/types/tx.pb.go b/x/projects/types/tx.pb.go index f8a9a3b1e2..bef09a8afc 100644 --- a/x/projects/types/tx.pb.go +++ b/x/projects/types/tx.pb.go @@ -222,9 +222,9 @@ func (m *MsgDelKeysResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgDelKeysResponse proto.InternalMessageInfo type MsgSetPolicy struct { - Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` - Project string `protobuf:"bytes,2,opt,name=project,proto3" json:"project,omitempty"` - Policy types.Policy `protobuf:"bytes,3,opt,name=policy,proto3" json:"policy"` + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + Project string `protobuf:"bytes,2,opt,name=project,proto3" json:"project,omitempty"` + Policy *types.Policy `protobuf:"bytes,3,opt,name=policy,proto3" json:"policy,omitempty"` } func (m *MsgSetPolicy) Reset() { *m = MsgSetPolicy{} } @@ -274,11 +274,11 @@ func (m *MsgSetPolicy) GetProject() string { return "" } -func (m *MsgSetPolicy) GetPolicy() types.Policy { +func (m *MsgSetPolicy) GetPolicy() *types.Policy { if m != nil { return m.Policy } - return types.Policy{} + return nil } type MsgSetPolicyResponse struct { @@ -318,9 +318,9 @@ func (m *MsgSetPolicyResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgSetPolicyResponse proto.InternalMessageInfo type MsgSetSubscriptionPolicy struct { - Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` - Projects []string `protobuf:"bytes,2,rep,name=projects,proto3" json:"projects,omitempty"` - Policy types.Policy `protobuf:"bytes,3,opt,name=policy,proto3" json:"policy"` + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + Projects []string `protobuf:"bytes,2,rep,name=projects,proto3" json:"projects,omitempty"` + Policy *types.Policy `protobuf:"bytes,3,opt,name=policy,proto3" json:"policy,omitempty"` } func (m *MsgSetSubscriptionPolicy) Reset() { *m = MsgSetSubscriptionPolicy{} } @@ -370,11 +370,11 @@ func (m *MsgSetSubscriptionPolicy) GetProjects() []string { return nil } -func (m *MsgSetSubscriptionPolicy) GetPolicy() types.Policy { +func (m *MsgSetSubscriptionPolicy) GetPolicy() *types.Policy { if m != nil { return m.Policy } - return types.Policy{} + return nil } type MsgSetSubscriptionPolicyResponse struct { @@ -427,35 +427,35 @@ func init() { func init() { proto.RegisterFile("lavanet/lava/projects/tx.proto", fileDescriptor_a4f8e20515314f9d) } var fileDescriptor_a4f8e20515314f9d = []byte{ - // 439 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x94, 0x4b, 0xab, 0xd3, 0x40, - 0x14, 0xc7, 0x33, 0x8d, 0xb4, 0xf6, 0xb4, 0xab, 0xd0, 0x4a, 0xc8, 0x22, 0x8d, 0xe9, 0x26, 0x22, - 0x24, 0x50, 0x17, 0xba, 0xb5, 0xb8, 0xb2, 0x14, 0x4a, 0xba, 0x10, 0x04, 0x91, 0x34, 0x1d, 0x62, - 0x34, 0x66, 0x42, 0x66, 0x2a, 0x0d, 0xb8, 0x71, 0x2b, 0x2e, 0x5c, 0xfb, 0x89, 0xba, 0xec, 0xd2, - 0x95, 0x48, 0xfb, 0x45, 0x2e, 0x69, 0x66, 0xd2, 0xc7, 0xed, 0xe3, 0x3e, 0x36, 0x77, 0x95, 0x33, - 0x73, 0xfe, 0xe7, 0x3f, 0xbf, 0xcc, 0x39, 0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 0x7c, 0x02, 0xad, - 0xdd, 0xd3, 0x4b, 0xaa, 0x9f, 0x08, 0xd4, 0x22, 0x31, 0x9e, 0x4d, 0xa8, 0x9f, 0x86, 0x09, 0x0b, - 0x49, 0x7c, 0x11, 0x51, 0x83, 0xc7, 0xe2, 0x32, 0xd4, 0x8a, 0x21, 0x5b, 0x75, 0xb7, 0x5c, 0xdf, - 0x03, 0xd2, 0x04, 0xe3, 0x14, 0x8b, 0x00, 0xee, 0xfd, 0x91, 0x41, 0x1e, 0xd2, 0x40, 0x79, 0x07, - 0x35, 0x31, 0x94, 0xa7, 0xba, 0xb4, 0x9d, 0x14, 0xed, 0xd9, 0x45, 0x89, 0x38, 0x20, 0x37, 0x16, - 0x83, 0x74, 0xc6, 0x98, 0x4b, 0xce, 0x19, 0x1f, 0x0c, 0x80, 0xf2, 0x01, 0xea, 0xdb, 0xee, 0x77, - 0x4f, 0xd7, 0x95, 0x22, 0xed, 0xf9, 0x0d, 0x44, 0xa5, 0xfd, 0x0f, 0x04, 0xed, 0xe3, 0x6d, 0x74, - 0xce, 0xda, 0x5c, 0x2f, 0xd0, 0x5e, 0xde, 0xb2, 0x40, 0x30, 0xf4, 0xfb, 0x8b, 0x95, 0x8e, 0x96, - 0x2b, 0x1d, 0xfd, 0x5f, 0xe9, 0xe8, 0xf7, 0x5a, 0x97, 0x96, 0x6b, 0x5d, 0xfa, 0xbb, 0xd6, 0xa5, - 0xf7, 0x56, 0x10, 0xb2, 0x4f, 0xb3, 0x89, 0xed, 0x93, 0xaf, 0xce, 0xde, 0x4b, 0x34, 0xdf, 0x79, - 0xe7, 0xb2, 0x04, 0xd3, 0x49, 0x75, 0xf3, 0xf0, 0xbc, 0xb8, 0x0a, 0x00, 0x00, 0xff, 0xff, 0x0e, - 0xfe, 0x87, 0xe9, 0x0d, 0x05, 0x00, 0x00, + // 434 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff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83, 0xc1, 0x6a, 0xa3, 0xa3, 0xf5, 0x46, 0x47, 0xbf, 0x36, 0x3a, + 0xfa, 0xb6, 0xd5, 0xa5, 0xf5, 0x56, 0x97, 0x7e, 0x6c, 0x75, 0xe9, 0x8d, 0x15, 0x46, 0xec, 0xfd, + 0x7c, 0x6a, 0x07, 0xe4, 0x93, 0x73, 0x34, 0x7d, 0x96, 0x07, 0xb3, 0x2d, 0x4f, 0x31, 0x9d, 0xd6, + 0x77, 0xc3, 0xe6, 0xd9, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0x25, 0xd1, 0x97, 0xef, 0x01, 0x05, + 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -814,16 +814,18 @@ func (m *MsgSetPolicy) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - { - size, err := m.Policy.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err + if m.Policy != nil { + { + size, err := m.Policy.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0x1a } - i-- - dAtA[i] = 0x1a if len(m.Project) > 0 { i -= len(m.Project) copy(dAtA[i:], m.Project) @@ -884,16 +886,18 @@ func (m *MsgSetSubscriptionPolicy) MarshalToSizedBuffer(dAtA []byte) (int, error _ = i var l int _ = l - { - size, err := m.Policy.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err + if m.Policy != nil { + { + size, err := m.Policy.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0x1a } - i-- - dAtA[i] = 0x1a if len(m.Projects) > 0 { for iNdEx := len(m.Projects) - 1; iNdEx >= 0; iNdEx-- { i -= len(m.Projects[iNdEx]) @@ -1025,8 +1029,10 @@ func (m *MsgSetPolicy) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = m.Policy.Size() - n += 1 + l + sovTx(uint64(l)) + if m.Policy != nil { + l = m.Policy.Size() + n += 1 + l + sovTx(uint64(l)) + } return n } @@ -1055,8 +1061,10 @@ func (m *MsgSetSubscriptionPolicy) Size() (n int) { n += 1 + l + sovTx(uint64(l)) } } - l = m.Policy.Size() - n += 1 + l + sovTx(uint64(l)) + if m.Policy != nil { + l = m.Policy.Size() + n += 1 + l + sovTx(uint64(l)) + } return n } @@ -1593,6 +1601,9 @@ func (m *MsgSetPolicy) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } + if m.Policy == nil { + m.Policy = &types.Policy{} + } if err := m.Policy.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -1790,6 +1801,9 @@ func (m *MsgSetSubscriptionPolicy) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } + if m.Policy == nil { + m.Policy = &types.Policy{} + } if err := m.Policy.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err }