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

CNS-169: create module subscription #328

Merged
merged 11 commits into from
Mar 3, 2023
2 changes: 2 additions & 0 deletions .github/workflows/consensus_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ jobs:
- name: lava plans unit Tests
run: go test ./x/plans/ ./x/plans/keeper ./x/plans/types -v

- name: lava subscription unit Tests
run: go test ./x/subscription/... -v
44 changes: 34 additions & 10 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,17 @@ import (
pairingmodule "github.com/lavanet/lava/x/pairing"
pairingmodulekeeper "github.com/lavanet/lava/x/pairing/keeper"
pairingmoduletypes "github.com/lavanet/lava/x/pairing/types"
plans "github.com/lavanet/lava/x/plans"
plansmodule "github.com/lavanet/lava/x/plans"
plansmoduleclient "github.com/lavanet/lava/x/plans/client"
plansmodulekeeper "github.com/lavanet/lava/x/plans/keeper"
plansmoduletypes "github.com/lavanet/lava/x/plans/types"
"github.com/lavanet/lava/x/spec"
specmodule "github.com/lavanet/lava/x/spec"
specmoduleclient "github.com/lavanet/lava/x/spec/client"
specmodulekeeper "github.com/lavanet/lava/x/spec/keeper"
specmoduletypes "github.com/lavanet/lava/x/spec/types"
subscriptionmodule "github.com/lavanet/lava/x/subscription"
subscriptionmodulekeeper "github.com/lavanet/lava/x/subscription/keeper"
subscriptionmoduletypes "github.com/lavanet/lava/x/subscription/types"
"github.com/spf13/cast"
abci "github.com/tendermint/tendermint/abci/types"
tmjson "github.com/tendermint/tendermint/libs/json"
Expand Down Expand Up @@ -182,11 +185,12 @@ var (
evidence.AppModuleBasic{},
transfer.AppModuleBasic{},
vesting.AppModuleBasic{},
spec.AppModuleBasic{},
specmodule.AppModuleBasic{},
epochstoragemodule.AppModuleBasic{},
subscriptionmodule.AppModuleBasic{},
pairingmodule.AppModuleBasic{},
conflictmodule.AppModuleBasic{},
plans.AppModuleBasic{},
plansmodule.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic
)

Expand All @@ -200,6 +204,7 @@ var (
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
epochstoragemoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking},
subscriptionmoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking},
pairingmoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking},
conflictmoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking},
// this line is used by starport scaffolding # stargate/app/maccPerms
Expand Down Expand Up @@ -281,6 +286,7 @@ func New(
evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey,
specmoduletypes.StoreKey,
epochstoragemoduletypes.StoreKey,
subscriptionmoduletypes.StoreKey,
pairingmoduletypes.StoreKey,
conflictmoduletypes.StoreKey,
plansmoduletypes.StoreKey,
Expand Down Expand Up @@ -358,15 +364,14 @@ func New(
appCodec, keys[ibchost.StoreKey], app.GetSubspace(ibchost.ModuleName), app.StakingKeeper, app.UpgradeKeeper, scopedIBCKeeper,
)

//
// Initialize SpecKeeper prior to govRouter (order is critical)
app.SpecKeeper = *specmodulekeeper.NewKeeper(
appCodec,
keys[specmoduletypes.StoreKey],
keys[specmoduletypes.MemStoreKey],
app.GetSubspace(specmoduletypes.ModuleName),
)
specModule := spec.NewAppModule(appCodec, app.SpecKeeper, app.AccountKeeper, app.BankKeeper)
specModule := specmodule.NewAppModule(appCodec, app.SpecKeeper, app.AccountKeeper, app.BankKeeper)

// Initialize PackagesKeeper prior to govRouter (order is critical)
app.PlansKeeper = *plansmodulekeeper.NewKeeper(
Expand All @@ -375,18 +380,18 @@ func New(
keys[plansmoduletypes.MemStoreKey],
app.GetSubspace(plansmoduletypes.ModuleName),
)
plansModule := plans.NewAppModule(appCodec, app.PlansKeeper)
plansModule := plansmodule.NewAppModule(appCodec, app.PlansKeeper)

// register the proposal types
govRouter := govtypes.NewRouter()
govRouter.AddRoute(govtypes.RouterKey, govtypes.ProposalHandler).
//
// user defined
AddRoute(specmoduletypes.ProposalsRouterKey, spec.NewSpecProposalsHandler(app.SpecKeeper)).
AddRoute(specmoduletypes.ProposalsRouterKey, specmodule.NewSpecProposalsHandler(app.SpecKeeper)).
// copied the code from param and changed the handler to enable functionality
AddRoute(paramproposal.RouterKey, spec.NewParamChangeProposalHandler(app.ParamsKeeper)).
AddRoute(paramproposal.RouterKey, specmodule.NewParamChangeProposalHandler(app.ParamsKeeper)).
// user defined
AddRoute(plansmoduletypes.ProposalsRouterKey, plans.NewPlansProposalsHandler(app.PlansKeeper)).
AddRoute(plansmoduletypes.ProposalsRouterKey, plansmodule.NewPlansProposalsHandler(app.PlansKeeper)).

//
// default
Expand Down Expand Up @@ -440,6 +445,19 @@ func New(
)
pairingModule := pairingmodule.NewAppModule(appCodec, app.PairingKeeper, app.AccountKeeper, app.BankKeeper)

app.SubscriptionKeeper = *subscriptionmodulekeeper.NewKeeper(
appCodec,
keys[subscriptionmoduletypes.StoreKey],
keys[subscriptionmoduletypes.MemStoreKey],
app.GetSubspace(subscriptionmoduletypes.ModuleName),

app.BankKeeper,
app.AccountKeeper,
&app.EpochstorageKeeper,
app.PlansKeeper,
)
subscriptionModule := subscriptionmodule.NewAppModule(appCodec, app.SubscriptionKeeper, app.AccountKeeper, app.BankKeeper)

app.ConflictKeeper = *conflictmodulekeeper.NewKeeper(
appCodec,
keys[conflictmoduletypes.StoreKey],
Expand Down Expand Up @@ -495,6 +513,7 @@ func New(
transferModule,
specModule,
epochstorageModule,
subscriptionModule,
pairingModule,
conflictModule,
plansModule,
Expand All @@ -521,6 +540,7 @@ func New(
ibctransfertypes.ModuleName,
specmoduletypes.ModuleName,
epochstoragemoduletypes.ModuleName,
subscriptionmoduletypes.ModuleName,
conflictmoduletypes.ModuleName, // conflict needs to change state before pairing changes stakes
pairingmoduletypes.ModuleName,
plansmoduletypes.ModuleName,
Expand All @@ -545,6 +565,7 @@ func New(
ibctransfertypes.ModuleName,
specmoduletypes.ModuleName,
epochstoragemoduletypes.ModuleName,
subscriptionmoduletypes.ModuleName,
conflictmoduletypes.ModuleName,
pairingmoduletypes.ModuleName,
plansmoduletypes.ModuleName,
Expand Down Expand Up @@ -574,6 +595,7 @@ func New(
ibctransfertypes.ModuleName,
specmoduletypes.ModuleName,
epochstoragemoduletypes.ModuleName, // epochStyorage end block must come before pairing for proper epoch handling
subscriptionmoduletypes.ModuleName,
pairingmoduletypes.ModuleName,
plansmoduletypes.ModuleName,
vestingtypes.ModuleName,
Expand Down Expand Up @@ -609,6 +631,7 @@ func New(
transferModule,
specModule,
epochstorageModule,
subscriptionModule,
pairingModule,
conflictModule,
plansModule,
Expand Down Expand Up @@ -828,6 +851,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(ibchost.ModuleName)
paramsKeeper.Subspace(specmoduletypes.ModuleName)
paramsKeeper.Subspace(epochstoragemoduletypes.ModuleName)
paramsKeeper.Subspace(subscriptionmoduletypes.ModuleName)
paramsKeeper.Subspace(pairingmoduletypes.ModuleName)
paramsKeeper.Subspace(conflictmoduletypes.ModuleName)
paramsKeeper.Subspace(plansmoduletypes.ModuleName)
Expand Down
2 changes: 2 additions & 0 deletions app/keepers/lavaKeepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
pairingmodulekeeper "github.com/lavanet/lava/x/pairing/keeper"
plansmodulekeeper "github.com/lavanet/lava/x/plans/keeper"
specmodulekeeper "github.com/lavanet/lava/x/spec/keeper"
subscriptionmodulekeeper "github.com/lavanet/lava/x/subscription/keeper"
// this line is used by starport scaffolding # stargate/app/moduleImport
)

Expand Down Expand Up @@ -48,6 +49,7 @@ type LavaKeepers struct {

// Special Keepers
SpecKeeper specmodulekeeper.Keeper
SubscriptionKeeper subscriptionmodulekeeper.Keeper
EpochstorageKeeper epochstoragemodulekeeper.Keeper
PairingKeeper pairingmodulekeeper.Keeper
ConflictKeeper conflictmodulekeeper.Keeper
Expand Down
164 changes: 164 additions & 0 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32599,6 +32599,103 @@ paths:
type: string
tags:
- Query
'/lavanet/lava/subscription/current_subscription/{consumer}':
get:
summary: Queries a list of CurrentSubscription items.
operationId: LavanetLavaSubscriptionCurrentSubscription
responses:
'200':
description: A successful response.
schema:
type: object
properties:
sub:
type: object
properties:
creator:
type: string
consumer:
type: string
block:
type: string
format: int64
packageIndex:
type: string
packageBlock:
type: string
format: int64
isYearly:
type: boolean
expiryTime:
type: string
format: uint64
usedCU:
type: string
format: uint64
remainingCU:
type: string
format: uint64
default:
description: An unexpected error response.
schema:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
'@type':
type: string
additionalProperties: {}
parameters:
- name: consumer
in: path
required: true
type: string
tags:
- Query
/lavanet/lava/subscription/params:
get:
summary: Parameters queries the parameters of the module.
operationId: LavanetLavaSubscriptionParams
responses:
'200':
description: A successful response.
schema:
type: object
properties:
params:
description: params holds all the parameters of this module.
type: object
description: >-
QueryParamsResponse is response type for the Query/Params RPC
method.
default:
description: An unexpected error response.
schema:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
'@type':
type: string
additionalProperties: {}
tags:
- Query
definitions:
cosmos.auth.v1beta1.Params:
type: object
Expand Down Expand Up @@ -56100,3 +56197,70 @@ definitions:
type: array
items:
type: string
lavanet.lava.subscription.MsgSubscribeResponse:
type: object
lavanet.lava.subscription.Params:
type: object
description: Params defines the parameters for the module.
lavanet.lava.subscription.QueryCurrentSubscriptionResponse:
type: object
properties:
sub:
type: object
properties:
creator:
type: string
consumer:
type: string
block:
type: string
format: int64
packageIndex:
type: string
packageBlock:
type: string
format: int64
isYearly:
type: boolean
expiryTime:
type: string
format: uint64
usedCU:
type: string
format: uint64
remainingCU:
type: string
format: uint64
lavanet.lava.subscription.QueryParamsResponse:
type: object
properties:
params:
description: params holds all the parameters of this module.
type: object
description: QueryParamsResponse is response type for the Query/Params RPC method.
lavanet.lava.subscription.Subscription:
type: object
properties:
creator:
type: string
consumer:
type: string
block:
type: string
format: int64
packageIndex:
type: string
packageBlock:
type: string
format: int64
isYearly:
type: boolean
expiryTime:
type: string
format: uint64
usedCU:
type: string
format: uint64
remainingCU:
type: string
format: uint64
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/stretchr/testify v1.8.1
github.com/tendermint/tendermint v0.34.23
github.com/tendermint/tm-db v0.6.7
google.golang.org/genproto v0.0.0-20230221151758-ace64dc21148
google.golang.org/genproto v0.0.0-20230223222841-637eb2293923
google.golang.org/grpc v1.53.0
google.golang.org/protobuf v1.28.2-0.20220831092852-f930b1dc76e8
gopkg.in/yaml.v2 v2.4.0
Expand Down Expand Up @@ -48,6 +48,8 @@ require (
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/gogo/googleapis v1.4.0 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
golang.org/x/mod v0.7.0 // indirect
golang.org/x/tools v0.2.0 // indirect
Expand Down
Loading