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

feat: CNS-962-user-spec-implementation #1505

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
3 changes: 1 addition & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ func New(
keys[specmoduletypes.MemStoreKey],
app.GetSubspace(specmoduletypes.ModuleName),
app.StakingKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
specModule := specmodule.NewAppModule(appCodec, app.SpecKeeper, app.AccountKeeper, app.BankKeeper)

Expand Down Expand Up @@ -608,10 +609,8 @@ func New(
govRouter.AddRoute(govtypes.RouterKey, v1beta1.ProposalHandler).
//
// user defined
AddRoute(specmoduletypes.ProposalsRouterKey, specmodule.NewSpecProposalsHandler(app.SpecKeeper)).
// copied the code from param and changed the handler to enable functionality
AddRoute(paramproposal.RouterKey, specmodule.NewParamChangeProposalHandler(app.ParamsKeeper)).
// user defined
AddRoute(plansmoduletypes.ProposalsRouterKey, plansmodule.NewPlansProposalsHandler(app.PlansKeeper)).
AddRoute(pairingmoduletypes.ProposalsRouterKey, pairingmodule.NewPairingProposalsHandler(app.PairingKeeper)).

Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/upgrade_0_35_0.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func v_35_0(
params := lk.SpecKeeper.GetParams(ctx)
params.AllowlistedExpeditedMsgs = []string{
proto.MessageName(&protocoltypes.MsgSetVersion{}),
proto.MessageName(&spectypes.SpecAddProposal{}),
proto.MessageName(&spectypes.MsgAddSpecs{}),
proto.MessageName(&ibctypes.ClientUpdateProposal{}),
proto.MessageName(&ibctypes.UpgradeProposal{}),
}
Expand Down
1 change: 1 addition & 0 deletions proto/lavanet/lava/spec/spec.proto
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ message Spec {
];
uint64 shares = 19;
string identity = 20;
bool user_spec = 21;
}
18 changes: 0 additions & 18 deletions proto/lavanet/lava/spec/spec_add_proposal.proto

This file was deleted.

13 changes: 12 additions & 1 deletion proto/lavanet/lava/spec/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,21 @@ package lavanet.lava.spec;
// this line is used by starport scaffolding # proto/tx/import

option go_package = "github.com/lavanet/lava/x/spec/types";
import "gogoproto/gogo.proto";
import "lavanet/lava/spec/spec.proto";

// Msg defines the Msg service.
service Msg {
rpc AddSpecs(MsgAddSpecs) returns (MsgAddSpecsResponse);
// this line is used by starport scaffolding # proto/tx/rpc
}

// this line is used by starport scaffolding # proto/tx/message
// this line is used by starport scaffolding # proto/tx/message

message MsgAddSpecs {
string creator = 1;
repeated Spec specs = 2 [(gogoproto.nullable) = false];
}

message MsgAddSpecsResponse {
}
6 changes: 4 additions & 2 deletions testutil/common/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ func CreateMockSpec() spectypes.Spec {
spec.BlockDistanceForFinalizedData = 0
spec.DataReliabilityEnabled = true
spec.MinStakeProvider = sdk.NewCoin(commonconsts.TestTokenDenom, sdk.NewInt(1000))
spec.ApiCollections = []*spectypes.ApiCollection{{Enabled: true, CollectionData: spectypes.CollectionData{ApiInterface: "stub", Type: "GET"}, Apis: []*spectypes.Api{{Name: specName + "API", ComputeUnits: 100, Enabled: true}}}}
spec.BlockDistanceForFinalizedData = 0
spec.ApiCollections = []*spectypes.ApiCollection{{Enabled: true, CollectionData: spectypes.CollectionData{ApiInterface: spectypes.APIInterfaceJsonRPC, Type: "GET"}, Apis: []*spectypes.Api{{Name: specName + "API", ComputeUnits: 100, Enabled: true}}}}
spec.BlocksInFinalizationProof = 10
spec.Shares = 1
spec.AverageBlockTime = 10000
spec.AllowedBlockLagForQosSync = 5
return spec
}

Expand Down
2 changes: 1 addition & 1 deletion testutil/keeper/dualstaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func DualstakingKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
nil,
&mockAccountKeeper{},
epochstorageKeeper,
speckeeper.NewKeeper(cdc, nil, nil, paramsSubspaceSpec, nil),
speckeeper.NewKeeper(cdc, nil, nil, paramsSubspaceSpec, nil, ""),
fixationkeeper.NewKeeper(cdc, tsKeeper, epochstorageKeeper.BlocksToSaveRaw),
)

Expand Down
11 changes: 2 additions & 9 deletions testutil/keeper/keepers_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func InitAllKeepers(t testing.TB) (*Servers, *Keepers, context.Context) {
init_balance()
ks.StakingKeeper = *stakingkeeper.NewKeeper(cdc, stakingStoreKey, ks.AccountKeeper, ks.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String())
ks.Distribution = distributionkeeper.NewKeeper(cdc, distributionStoreKey, ks.AccountKeeper, ks.BankKeeper, ks.StakingKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String())
ks.Spec = *speckeeper.NewKeeper(cdc, specStoreKey, specMemStoreKey, specparamsSubspace, ks.StakingKeeper)
ks.Spec = *speckeeper.NewKeeper(cdc, specStoreKey, specMemStoreKey, specparamsSubspace, ks.StakingKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String())
ks.Epochstorage = *epochstoragekeeper.NewKeeper(cdc, epochStoreKey, epochMemStoreKey, epochparamsSubspace, &ks.BankKeeper, &ks.AccountKeeper, ks.Spec, ks.StakingKeeper)
ks.FixationStoreKeeper = fixationkeeper.NewKeeper(cdc, ks.TimerStoreKeeper, ks.Epochstorage.BlocksToSaveRaw)
ks.Dualstaking = *dualstakingkeeper.NewKeeper(cdc, dualstakingStoreKey, dualstakingMemStoreKey, dualstakingparamsSubspace, &ks.BankKeeper, &ks.StakingKeeper, &ks.AccountKeeper, ks.Epochstorage, ks.Spec, ks.FixationStoreKeeper)
Expand Down Expand Up @@ -383,14 +383,7 @@ func SimulatePlansDelProposal(ctx sdk.Context, plansKeeper planskeeper.Keeper, p
}

func SimulateSpecAddProposal(ctx sdk.Context, specKeeper speckeeper.Keeper, specsToPropose []spectypes.Spec) error {
proposal := spectypes.NewSpecAddProposal("mockProposal", "mockProposal specs add for testing", specsToPropose)
err := proposal.ValidateBasic()
if err != nil {
return err
}
proposalHandler := spec.NewSpecProposalsHandler(specKeeper)
err = proposalHandler(ctx, proposal)
return err
return specKeeper.HandleSpecs(ctx, specsToPropose, specKeeper.GetAuthority())
}

func SimulateUnstakeProposal(ctx sdk.Context, pairingKeeper pairingkeeper.Keeper, providersInfo []pairingtypes.ProviderUnstakeInfo, delegatorsSlashing []pairingtypes.DelegatorSlashing) error {
Expand Down
2 changes: 1 addition & 1 deletion testutil/keeper/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func PlanKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
memStoreKey,
paramsSubspace,
epochstorageKeeper,
speckeeper.NewKeeper(cdc, nil, nil, paramsSubspaceSpec, nil),
speckeeper.NewKeeper(cdc, nil, nil, paramsSubspaceSpec, nil, ""),
fixationkeeper.NewKeeper(cdc, timerstorekeeper.NewKeeper(cdc), epochstorageKeeper.BlocksToSaveRaw),
nil,
)
Expand Down
3 changes: 2 additions & 1 deletion testutil/keeper/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func specKeeper() (*keeper.Keeper, sdk.Context, error) {
memStoreKey,
paramsSubspace,
nil,
"",
)

ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())
Expand All @@ -79,7 +80,7 @@ func GetASpec(specIndex, getToTopMostPath string, ctxArg *sdk.Context, keeper *k
}
proposalFile := "./cookbook/specs/ibc.json,./cookbook/specs/cosmoswasm.json,./cookbook/specs/tendermint.json,./cookbook/specs/cosmossdk.json,./cookbook/specs/cosmossdk_full.json,./cookbook/specs/ethereum.json,./cookbook/specs/cosmoshub.json,./cookbook/specs/lava.json,./cookbook/specs/osmosis.json,./cookbook/specs/fantom.json,./cookbook/specs/celo.json,./cookbook/specs/optimism.json,./cookbook/specs/arbitrum.json,./cookbook/specs/starknet.json,./cookbook/specs/aptos.json,./cookbook/specs/juno.json,./cookbook/specs/polygon.json,./cookbook/specs/evmos.json,./cookbook/specs/base.json,./cookbook/specs/canto.json,./cookbook/specs/sui.json,./cookbook/specs/solana.json,./cookbook/specs/bsc.json,./cookbook/specs/axelar.json,./cookbook/specs/avalanche.json,./cookbook/specs/fvm.json"
for _, fileName := range strings.Split(proposalFile, ",") {
proposal := utils.SpecAddProposalJSON{}
proposal := utils.SpecAddProposalWithDepositJSON{}

contents, err := os.ReadFile(getToTopMostPath + fileName)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions x/conflict/keeper/msg_server_detection.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ func (k msgServer) Detection(goCtx context.Context, msg *types.MsgDetection) (*t
utils.Attribute{Key: "client", Value: msg.Creator},
)
}

spec, found := k.specKeeper.GetSpec(ctx, msg.ResponseConflict.ConflictRelayData0.Request.RelaySession.SpecId)
if !found || spec.UserSpec {
return nil, utils.LavaFormatWarning("Simulation: invalid spec for conflict (not found or user spec)", err,
utils.Attribute{Key: "found", Value: found},
utils.Attribute{Key: "userSpec", Value: spec.UserSpec},
)
}

if msg.FinalizationConflict != nil && msg.ResponseConflict == nil && msg.SameProviderConflict == nil {
err := k.Keeper.ValidateFinalizationConflict(ctx, msg.FinalizationConflict, clientAddr)
if err != nil {
Expand Down
39 changes: 23 additions & 16 deletions x/conflict/keeper/msg_server_detection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,14 @@ func TestDetection(t *testing.T) {
ts := newTester(t)
ts.setupForConflict(ProvidersCount)

userSpec := ts.spec
userSpec.Index = "USERSPEC"
userSpec.UserSpec = true
ts.AddSpec(userSpec.Index, userSpec)

tests := []struct {
name string
Name string
Spec spectypes.Spec
Creator sigs.Account
Provider0 sigs.Account
Provider1 sigs.Account
Expand All @@ -87,24 +93,25 @@ func TestDetection(t *testing.T) {
ReplyData []byte
Valid bool
}{
{"HappyFlow", ts.consumer, ts.providers[0], ts.providers[1], "", "", 0, "", []byte{}, 0, 100, 0, 0, &types.QualityOfServiceReport{Latency: sdk.OneDec(), Availability: sdk.OneDec(), Sync: sdk.OneDec()}, []byte("DIFF"), true},
{"CuSumChange", ts.consumer, ts.providers[0], ts.providers[2], "", "", 0, "", []byte{}, 0, 0, 100, 0, &types.QualityOfServiceReport{Latency: sdk.OneDec(), Availability: sdk.OneDec(), Sync: sdk.OneDec()}, []byte("DIFF"), true},
{"RelayNumChange", ts.consumer, ts.providers[0], ts.providers[3], "", "", 0, "", []byte{}, 0, 0, 0, 0, &types.QualityOfServiceReport{Latency: sdk.OneDec(), Availability: sdk.OneDec(), Sync: sdk.OneDec()}, []byte("DIFF"), true},
{"SessionIDChange", ts.consumer, ts.providers[0], ts.providers[4], "", "", 0, "", []byte{}, 0, 0, 0, 1, &types.QualityOfServiceReport{Latency: sdk.OneDec(), Availability: sdk.OneDec(), Sync: sdk.OneDec()}, []byte("DIFF"), true},
{"QoSNil", ts.consumer, ts.providers[2], ts.providers[3], "", "", 0, "", []byte{}, 0, 0, 0, 0, nil, []byte("DIFF"), true},
{"BadCreator", ts.providers[4], ts.providers[0], ts.providers[1], "", "", 0, "", []byte{}, 0, 0, 0, 0, &types.QualityOfServiceReport{Latency: sdk.OneDec(), Availability: sdk.OneDec(), Sync: sdk.OneDec()}, []byte("DIFF"), false},
{"BadConnectionType", ts.consumer, ts.providers[0], ts.providers[1], "DIFF", "", 0, "", []byte{}, 0, 0, 0, 0, &types.QualityOfServiceReport{Latency: sdk.OneDec(), Availability: sdk.OneDec(), Sync: sdk.OneDec()}, []byte("DIFF"), false},
{"BadURL", ts.consumer, ts.providers[0], ts.providers[1], "", "DIFF", 0, "", []byte{}, 0, 0, 0, 0, &types.QualityOfServiceReport{Latency: sdk.OneDec(), Availability: sdk.OneDec(), Sync: sdk.OneDec()}, []byte("DIFF"), false},
{"BadBlockHeight", ts.consumer, ts.providers[0], ts.providers[1], "", "", 10, "", []byte{}, 0, 0, 0, 0, &types.QualityOfServiceReport{Latency: sdk.OneDec(), Availability: sdk.OneDec(), Sync: sdk.OneDec()}, []byte("DIFF"), false},
{"BadChainID", ts.consumer, ts.providers[0], ts.providers[1], "", "", 0, "DIFF", []byte{}, 0, 0, 0, 0, &types.QualityOfServiceReport{Latency: sdk.OneDec(), Availability: sdk.OneDec(), Sync: sdk.OneDec()}, []byte("DIFF"), false},
{"BadData", ts.consumer, ts.providers[0], ts.providers[1], "", "", 0, "", []byte("DIFF"), 0, 0, 0, 0, &types.QualityOfServiceReport{Latency: sdk.OneDec(), Availability: sdk.OneDec(), Sync: sdk.OneDec()}, []byte("DIFF"), false},
{"BadRequestBlock", ts.consumer, ts.providers[0], ts.providers[1], "", "", 0, "", []byte{}, 10, 0, 0, 0, &types.QualityOfServiceReport{Latency: sdk.OneDec(), Availability: sdk.OneDec(), Sync: sdk.OneDec()}, []byte("DIFF"), false},
{"SameReplyData", ts.consumer, ts.providers[0], ts.providers[1], "", "", 0, "", []byte{}, 10, 0, 0, 0, &types.QualityOfServiceReport{Latency: sdk.OneDec(), Availability: sdk.OneDec(), Sync: sdk.OneDec()}, []byte{}, false},
{"HappyFlow", ts.spec, ts.consumer, ts.providers[0], ts.providers[1], "", "", 0, "", []byte{}, 0, 100, 0, 0, &types.QualityOfServiceReport{Latency: sdk.OneDec(), Availability: sdk.OneDec(), Sync: sdk.OneDec()}, []byte("DIFF"), true},
{"UserSpec", userSpec, ts.consumer, ts.providers[0], ts.providers[1], "", "", 0, "", []byte{}, 0, 100, 0, 0, &types.QualityOfServiceReport{Latency: sdk.OneDec(), Availability: sdk.OneDec(), Sync: sdk.OneDec()}, []byte("DIFF"), false},
{"CuSumChange", ts.spec, ts.consumer, ts.providers[0], ts.providers[2], "", "", 0, "", []byte{}, 0, 0, 100, 0, &types.QualityOfServiceReport{Latency: sdk.OneDec(), Availability: sdk.OneDec(), Sync: sdk.OneDec()}, []byte("DIFF"), true},
{"RelayNumChange", ts.spec, ts.consumer, ts.providers[0], ts.providers[3], "", "", 0, "", []byte{}, 0, 0, 0, 0, &types.QualityOfServiceReport{Latency: sdk.OneDec(), Availability: sdk.OneDec(), Sync: sdk.OneDec()}, []byte("DIFF"), true},
{"SessionIDChange", ts.spec, ts.consumer, ts.providers[0], ts.providers[4], "", "", 0, "", []byte{}, 0, 0, 0, 1, &types.QualityOfServiceReport{Latency: sdk.OneDec(), Availability: sdk.OneDec(), Sync: sdk.OneDec()}, []byte("DIFF"), true},
{"QoSNil", ts.spec, ts.consumer, ts.providers[2], ts.providers[3], "", "", 0, "", []byte{}, 0, 0, 0, 0, nil, []byte("DIFF"), true},
{"BadCreator", ts.spec, ts.providers[4], ts.providers[0], ts.providers[1], "", "", 0, "", []byte{}, 0, 0, 0, 0, &types.QualityOfServiceReport{Latency: sdk.OneDec(), Availability: sdk.OneDec(), Sync: sdk.OneDec()}, []byte("DIFF"), false},
{"BadConnectionType", ts.spec, ts.consumer, ts.providers[0], ts.providers[1], "DIFF", "", 0, "", []byte{}, 0, 0, 0, 0, &types.QualityOfServiceReport{Latency: sdk.OneDec(), Availability: sdk.OneDec(), Sync: sdk.OneDec()}, []byte("DIFF"), false},
{"BadURL", ts.spec, ts.consumer, ts.providers[0], ts.providers[1], "", "DIFF", 0, "", []byte{}, 0, 0, 0, 0, &types.QualityOfServiceReport{Latency: sdk.OneDec(), Availability: sdk.OneDec(), Sync: sdk.OneDec()}, []byte("DIFF"), false},
{"BadBlockHeight", ts.spec, ts.consumer, ts.providers[0], ts.providers[1], "", "", 10, "", []byte{}, 0, 0, 0, 0, &types.QualityOfServiceReport{Latency: sdk.OneDec(), Availability: sdk.OneDec(), Sync: sdk.OneDec()}, []byte("DIFF"), false},
{"BadChainID", ts.spec, ts.consumer, ts.providers[0], ts.providers[1], "", "", 0, "DIFF", []byte{}, 0, 0, 0, 0, &types.QualityOfServiceReport{Latency: sdk.OneDec(), Availability: sdk.OneDec(), Sync: sdk.OneDec()}, []byte("DIFF"), false},
{"BadData", ts.spec, ts.consumer, ts.providers[0], ts.providers[1], "", "", 0, "", []byte("DIFF"), 0, 0, 0, 0, &types.QualityOfServiceReport{Latency: sdk.OneDec(), Availability: sdk.OneDec(), Sync: sdk.OneDec()}, []byte("DIFF"), false},
{"BadRequestBlock", ts.spec, ts.consumer, ts.providers[0], ts.providers[1], "", "", 0, "", []byte{}, 10, 0, 0, 0, &types.QualityOfServiceReport{Latency: sdk.OneDec(), Availability: sdk.OneDec(), Sync: sdk.OneDec()}, []byte("DIFF"), false},
{"SameReplyData", ts.spec, ts.consumer, ts.providers[0], ts.providers[1], "", "", 0, "", []byte{}, 10, 0, 0, 0, &types.QualityOfServiceReport{Latency: sdk.OneDec(), Availability: sdk.OneDec(), Sync: sdk.OneDec()}, []byte{}, false},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
msg, _, reply, err := common.CreateMsgDetectionTest(ts.GoCtx, tt.Creator, tt.Provider0, tt.Provider1, ts.spec)
t.Run(tt.Name, func(t *testing.T) {
msg, _, reply, err := common.CreateMsgDetectionTest(ts.GoCtx, tt.Creator, tt.Provider0, tt.Provider1, tt.Spec)
require.NoError(t, err)

msg.Creator = tt.Creator.Addr.String()
Expand Down
1 change: 1 addition & 0 deletions x/conflict/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type EpochstorageKeeper interface {
type SpecKeeper interface {
IsSpecFoundAndActive(ctx sdk.Context, chainID string) (foundAndActive, found bool, providersType spectypes.Spec_ProvidersTypes)
IsFinalizedBlock(ctx sdk.Context, chainID string, requestedBlock, latestBlock int64) bool
GetSpec(ctx sdk.Context, index string) (val spectypes.Spec, found bool)
}

// AccountKeeper defines the expected account keeper used for simulations (noalias)
Expand Down
6 changes: 3 additions & 3 deletions x/pairing/keeper/msg_server_relay_payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func (k msgServer) RelayPayment(goCtx context.Context, msg *types.MsgRelayPaymen
utils.LogLavaEvent(ctx, logger, types.RelayPaymentEventName, successDetails, "New Proof Of Work Was Accepted")

cuAfterQos := rewardedCUDec.TruncateInt().Uint64()
err = k.chargeCuToSubscriptionAndCreditProvider(ctx, project, relay, cuAfterQos)
err = k.chargeCuToSubscriptionAndCreditProvider(ctx, project, relay, cuAfterQos, spec.UserSpec)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding more detailed error messages or handling for the chargeCuToSubscriptionAndCreditProvider function.

This function now includes a userSpec boolean which affects the charging logic. However, the error messages could be more descriptive to help in debugging, especially since userSpec influences the flow. Consider enhancing the error handling to provide more context about the failure, particularly how userSpec impacts the outcome.

if err != nil {
return nil, utils.LavaFormatError("Failed charging CU to project and subscription", err)
}
Expand Down Expand Up @@ -393,7 +393,7 @@ func (k EpochCuCache) updateProvidersComplainerCU(ctx sdk.Context, unresponsiveP
return nil
}

func (k Keeper) chargeCuToSubscriptionAndCreditProvider(ctx sdk.Context, project projectstypes.Project, relay *types.RelaySession, cuAfterQos uint64) error {
func (k Keeper) chargeCuToSubscriptionAndCreditProvider(ctx sdk.Context, project projectstypes.Project, relay *types.RelaySession, cuAfterQos uint64, userSpec bool) error {
epoch := uint64(relay.Epoch)

err := k.projectsKeeper.ChargeComputeUnitsToProject(ctx, project, epoch, relay.CuSum)
omerlavanet marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -406,7 +406,7 @@ func (k Keeper) chargeCuToSubscriptionAndCreditProvider(ctx sdk.Context, project
return fmt.Errorf("failed to add CU to the subscription")
}

err = k.subscriptionKeeper.AddTrackedCu(ctx, sub.Consumer, relay.Provider, relay.SpecId, cuAfterQos, sub.Block)
err = k.subscriptionKeeper.AddTrackedCu(ctx, sub.Consumer, relay.Provider, relay.SpecId, cuAfterQos, sub.Block, userSpec)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure the new parameter userSpec is correctly documented and tested.

The addition of the userSpec parameter to the AddTrackedCu method modifies how CU tracking is handled. It would be beneficial to update the method's documentation to reflect this change and to ensure that unit tests cover scenarios where userSpec is both true and false. Would you like assistance in updating the documentation or creating the necessary tests?

if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion x/pairing/keeper/msg_server_stake_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func TestCmdStakeProviderGeoConfigAndEnum(t *testing.T) {
require.NoError(t, err)
// adjust endpoints to match the default API interfaces and addons generated with ts
for i := 0; i < len(endpoints); i++ {
endpoints[i].ApiInterfaces = []string{"stub"}
endpoints[i].ApiInterfaces = []string{spectypes.APIInterfaceJsonRPC}
endpoints[i].Addons = []string{}
}
_, err = ts.TxPairingStakeProvider(provider, acc.GetVaultAddr(), ts.spec.Index, ts.spec.MinStakeProvider, endpoints, geo, common.MockDescription())
Expand Down
2 changes: 1 addition & 1 deletion x/pairing/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ type SubscriptionKeeper interface {
GetAllSubTrackedCuIndices(ctx sdk.Context, sub string) []string
GetTrackedCu(ctx sdk.Context, sub string, provider string, chainID string, block uint64) (cu uint64, found bool, key string)
CalcTotalMonthlyReward(ctx sdk.Context, totalAmount math.Int, trackedCu uint64, totalCuUsedBySub uint64) math.Int
AddTrackedCu(ctx sdk.Context, sub string, provider string, chainID string, cu uint64, block uint64) error
AddTrackedCu(ctx sdk.Context, sub string, provider string, chainID string, cu uint64, block uint64, userSpec bool) error
GetAllSubscriptionsIndices(ctx sdk.Context) []string
AppendAdjustment(ctx sdk.Context, consumer string, provider string, totalConsumerUsage uint64, usageWithThisProvider uint64)
CalculateParticipationFees(ctx sdk.Context, reward sdk.Coin) (sdk.Coins, sdk.Coins, error)
Expand Down
8 changes: 7 additions & 1 deletion x/rewards/keeper/iprpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/lavanet/lava/testutil/common"
"github.com/lavanet/lava/utils/sigs"
rewardstypes "github.com/lavanet/lava/x/rewards/types"
spectypes "github.com/lavanet/lava/x/spec/types"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -630,7 +631,12 @@ func TestMultipleIprpcSpec(t *testing.T) {
spec3 := common.CreateMockSpec()
spec3.Index = mockSpec3
spec3.Name = mockSpec3
ts.specs = append(ts.specs, ts.AddSpec(mockSpec3, spec3).Spec(mockSpec3))
msgSpec := spectypes.MsgAddSpecs{}
msgSpec.Specs = append(msgSpec.Specs, spec3)
msgSpec.Creator = c1Acc.Addr.String()
ts.Servers.SpecServer.AddSpecs(ts.Ctx, &msgSpec)

ts.specs = append(ts.specs, spec3)
err := ts.StakeProvider(p1Acc.GetVaultAddr(), p1, ts.specs[2], testStake)
require.NoError(ts.T, err)
err = ts.StakeProvider(p2Acc.GetVaultAddr(), p2, ts.specs[2], testStake)
Expand Down
Loading
Loading