Skip to content

Commit

Permalink
Merge branch 'main' into CNS-516-add-unit-test-to-check-the-distribut…
Browse files Browse the repository at this point in the history
…ion-of-picked-providers-when-pairing
  • Loading branch information
oren-lava committed Jul 27, 2023
2 parents 65acd8b + cfb9cee commit 57f5f43
Show file tree
Hide file tree
Showing 57 changed files with 4,867 additions and 343 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ ecosystem/lava-sdk/package-lock.json
ecosystem/lava-sdk/examples/jsonRPC_test.ts
ecosystem/lava-sdk/examples/restAPI_test.ts
ecosystem/lava-sdk/examples/tendermintRPC_test.ts
ecosystem/lava-sdk/examples/tendermintRPC_test2.ts
ecosystem/lava-sdk/examples/jsonRPC_badge_test.ts
ecosystem/lava-sdk/pairingList.json

Expand Down
16 changes: 15 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ import (
conflictmodule "github.com/lavanet/lava/x/conflict"
conflictmodulekeeper "github.com/lavanet/lava/x/conflict/keeper"
conflictmoduletypes "github.com/lavanet/lava/x/conflict/types"
downtimemodule "github.com/lavanet/lava/x/downtime"
downtimekeeper "github.com/lavanet/lava/x/downtime/keeper"
downtimemoduletypes "github.com/lavanet/lava/x/downtime/types"
epochstoragemodule "github.com/lavanet/lava/x/epochstorage"
epochstoragemodulekeeper "github.com/lavanet/lava/x/epochstorage/keeper"
epochstoragemoduletypes "github.com/lavanet/lava/x/epochstorage/types"
Expand Down Expand Up @@ -188,6 +191,7 @@ var (
projectsmodule.AppModuleBasic{},
protocolmodule.AppModuleBasic{},
plansmodule.AppModuleBasic{},
downtimemodule.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic
)

Expand Down Expand Up @@ -287,6 +291,7 @@ func New(
conflictmoduletypes.StoreKey,
projectsmoduletypes.StoreKey,
plansmoduletypes.StoreKey,
downtimemoduletypes.StoreKey,
// this line is used by starport scaffolding # stargate/app/storeKey
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down Expand Up @@ -492,6 +497,10 @@ func New(
)
protocolModule := protocolmodule.NewAppModule(appCodec, app.ProtocolKeeper)

// downtime module
app.DowntimeKeeper = downtimekeeper.NewKeeper(appCodec, keys[downtimemoduletypes.StoreKey], app.GetSubspace(downtimemoduletypes.ModuleName), app.EpochstorageKeeper)
downtimeModule := downtimemodule.NewAppModule(app.DowntimeKeeper)

// this line is used by starport scaffolding # stargate/app/keeperDefinition

// Create static IBC router, add transfer route, then set and seal it
Expand Down Expand Up @@ -539,6 +548,7 @@ func New(
projectsModule,
plansModule,
protocolModule,
downtimeModule,
// this line is used by starport scaffolding # stargate/app/appModule
)

Expand All @@ -564,6 +574,7 @@ func New(
epochstoragemoduletypes.ModuleName,
subscriptionmoduletypes.ModuleName,
conflictmoduletypes.ModuleName, // conflict needs to change state before pairing changes stakes
downtimemoduletypes.ModuleName, // downtime needs to run before pairing
pairingmoduletypes.ModuleName,
projectsmoduletypes.ModuleName,
plansmoduletypes.ModuleName,
Expand Down Expand Up @@ -598,7 +609,8 @@ func New(
vestingtypes.ModuleName,
upgradetypes.ModuleName,
feegrant.ModuleName,
paramstypes.ModuleName)
paramstypes.ModuleName,
downtimemoduletypes.ModuleName) // downtime has no end block but module manager requires it.

// NOTE: The genutils module must occur after staking so that pools are
// properly initialized with tokens from genesis accounts.
Expand All @@ -622,6 +634,7 @@ func New(
specmoduletypes.ModuleName,
epochstoragemoduletypes.ModuleName, // epochStyorage end block must come before pairing for proper epoch handling
subscriptionmoduletypes.ModuleName,
downtimemoduletypes.ModuleName,
pairingmoduletypes.ModuleName,
projectsmoduletypes.ModuleName,
plansmoduletypes.ModuleName,
Expand Down Expand Up @@ -884,6 +897,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(projectsmoduletypes.ModuleName)
paramsKeeper.Subspace(protocolmoduletypes.ModuleName)
paramsKeeper.Subspace(plansmoduletypes.ModuleName)
paramsKeeper.Subspace(downtimemoduletypes.ModuleName)
// this line is used by starport scaffolding # stargate/app/paramSubspace

return paramsKeeper
Expand Down
2 changes: 2 additions & 0 deletions app/keepers/lavaKeepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
ibctransferkeeper "github.com/cosmos/ibc-go/v3/modules/apps/transfer/keeper"
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"
conflictmodulekeeper "github.com/lavanet/lava/x/conflict/keeper"
downtimekeeper "github.com/lavanet/lava/x/downtime/keeper"
epochstoragemodulekeeper "github.com/lavanet/lava/x/epochstorage/keeper"
pairingmodulekeeper "github.com/lavanet/lava/x/pairing/keeper"
plansmodulekeeper "github.com/lavanet/lava/x/plans/keeper"
Expand Down Expand Up @@ -58,4 +59,5 @@ type LavaKeepers struct {
ProjectsKeeper projectsmodulekeeper.Keeper
PlansKeeper plansmodulekeeper.Keeper
ProtocolKeeper protocolmodulekeeper.Keeper
DowntimeKeeper downtimekeeper.Keeper
}
12 changes: 3 additions & 9 deletions app/test_helper.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
//go:build ignore

package app

import (
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/lavanet/lava/app"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmdb "github.com/tendermint/tm-db"
)

// Setup a new App for testing purposes
func TestSetup() (app.LavaApp, sdk.Context) {
func TestSetup() (*LavaApp, sdk.Context) {
db := tmdb.NewMemDB()
stateStore := store.NewCommitMultiStore(db)
ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())
encoding := app.MakeEncodingConfig(ModuleBasics)
encoding := MakeEncodingConfig()
app := New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, encoding, simapp.EmptyAppOptions{})
return app, ctx
return app, app.NewContext(true, tmproto.Header{})
}
57 changes: 41 additions & 16 deletions common/types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,53 @@ import (
"golang.org/x/exp/constraints"
)

func FindMin[T constraints.Ordered](s []T) (m T) {
if len(s) > 0 {
m = s[0]
for _, v := range s[1:] {
if m > v {
m = v
}
func FindMin[T constraints.Ordered](s []T) T {
ind := FindIndexOfMin(s)
if ind == -1 {
var zero T
return zero
}

return s[ind]
}

func FindIndexOfMin[T constraints.Ordered](s []T) int {
if len(s) == 0 {
return -1
}
m := s[0]
mInd := 0
for i := range s {
if m > s[i] {
mInd = i
}
}
return m
return mInd
}

func FindMax[T constraints.Ordered](s []T) (m T) {
if len(s) > 0 {
m = s[0]
for _, v := range s[1:] {
if m < v {
m = v
}
func FindMax[T constraints.Ordered](s []T) T {
ind := FindIndexOfMax(s)
if ind == -1 {
var zero T
return zero
}

return s[ind]
}

func FindIndexOfMax[T constraints.Ordered](s []T) int {
if len(s) == 0 {
return -1
}
m := s[0]
mInd := 0
for i := range s {
if m < s[i] {
m = s[i]
mInd = i
}
}
return m
return mInd
}

func Intersection[T comparable](arrays ...[]T) []T {
Expand Down
12 changes: 6 additions & 6 deletions cookbook/plans/adventurer.json → cookbook/plans/basic.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"proposal": {
"title": "Add plan proposal: advneturer",
"description": "A proposal for a new plan for a mid-range user",
"title": "Add plan proposal: Basic",
"description": "A proposal for a new plan for a basic user",
"plans": [
{
"index": "adventurer",
"description": "Plan for the Lava adventurer",
"index": "basic",
"description": "Plan for the basic Lava user",
"type": "rpc",
"price": {
"denom": "ulava",
Expand All @@ -15,10 +15,10 @@
"allow_overuse": false,
"overuse_rate": "0",
"plan_policy": {
"geolocation_profile": "18446744073709551615",
"geolocation_profile": "0",
"total_cu_limit": "1000000000",
"epoch_cu_limit": "5000000",
"max_providers_to_pair": "5"
"max_providers_to_pair": "14"
}
}
]
Expand Down
27 changes: 27 additions & 0 deletions cookbook/plans/enterprise.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"proposal": {
"title": "Add plan proposal: Enterprise",
"description": "A proposal for a new plan for a enterprise user",
"plans": [
{
"index": "enterprise",
"description": "Plan for the enterprise Lava user",
"type": "rpc",
"price": {
"denom": "ulava",
"amount": "600000000000"
},
"annual_discount_percentage": "0",
"allow_overuse": false,
"overuse_rate": "0",
"plan_policy": {
"geolocation_profile": "65535",
"total_cu_limit": "9223372036854775807",
"epoch_cu_limit": "9223372036854775807",
"max_providers_to_pair": "28"
}
}
]
},
"deposit": "10000000ulava"
}
10 changes: 5 additions & 5 deletions cookbook/plans/explorer.json → cookbook/plans/free.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"proposal": {
"title": "Add plan proposal: explorer",
"description": "A proposal for a new plan for a beginner user",
"title": "Add plan proposal: free",
"description": "A proposal for a new plan for a free user",
"plans": [
{
"index": "explorer",
"description": "Plan for the Lava explorer",
"index": "free",
"description": "Plan for the free Lava user",
"type": "rpc",
"price": {
"denom": "ulava",
Expand All @@ -15,7 +15,7 @@
"allow_overuse": false,
"overuse_rate": "0",
"plan_policy": {
"geolocation_profile": "18446744073709551615",
"geolocation_profile": "4",
"total_cu_limit": "10000000",
"epoch_cu_limit": "100000",
"max_providers_to_pair": "5"
Expand Down
14 changes: 7 additions & 7 deletions cookbook/plans/whale.json → cookbook/plans/premium.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"proposal": {
"title": "Add plan proposal: whale",
"description": "A proposal for a new plan for an advanced user",
"title": "Add plan proposal: Premium",
"description": "A proposal for a new plan for a premium user",
"plans": [
{
"index": "whale",
"description": "Plan for the Lava whale",
"index": "premium",
"description": "Plan for the premium Lava user",
"type": "rpc",
"price": {
"denom": "ulava",
"amount": "100000000000000"
"amount": "600000000000"
},
"annual_discount_percentage": "0",
"allow_overuse": false,
"overuse_rate": "0",
"plan_policy": {
"geolocation_profile": "18446744073709551615",
"geolocation_profile": "65535",
"total_cu_limit": "9223372036854775807",
"epoch_cu_limit": "9223372036854775807",
"max_providers_to_pair": "5"
"max_providers_to_pair": "14"
}
}
]
Expand Down
Loading

0 comments on commit 57f5f43

Please sign in to comment.