Skip to content

Commit

Permalink
[Session] Implement the 1st iteration of the SessionHydrator (#78)
Browse files Browse the repository at this point in the history
Add support for:
- Storing `ServiceConfigs` in the `Application` store
- Storing `ServiceConfigs` in the `Supplier` store
- Business logic for `GetSession` and the underlying `SessionHydrator`

Not adding support for:
- Staking/unstaking `Service(s)` for `Application` / `Supplier`
- Using the proper (prior) `BlockHash` for session generation
- The `cliContext` required to retrieve a `Session`

See #78 for more details

----

Co-authored-by: Bryan White <[email protected]>
Co-authored-by: Redouane Lakrache <[email protected]>
Co-authored-by: red-0ne <[email protected]>
Co-authored-by: Daniel Olshansky <[email protected]>
Co-authored-by: harry <[email protected]>
  • Loading branch information
4 people authored Oct 26, 2023
1 parent 14593da commit d7d87eb
Show file tree
Hide file tree
Showing 27 changed files with 2,425 additions and 98 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,11 @@ itest: go_version_check ## Run tests iteratively (see usage for more)

.PHONY: go_mockgen
go_mockgen: ## Use `mockgen` to generate mocks used for testing purposes of all the modules.
find . -name "*_mock.go" | xargs --no-run-if-empty rm
go generate ./x/application/types/
go generate ./x/gateway/types/
go generate ./x/supplier/types/
go generate ./x/session/types/

.PHONY: go_develop
go_develop: proto_regen go_mockgen ## Generate protos and mocks
Expand All @@ -156,6 +158,7 @@ go_develop_and_test: go_develop go_test ## Generate protos, mocks and run all te
# TODO - General Purpose catch-all.
# TODO_DECIDE - A TODO indicating we need to make a decision and document it using an ADR in the future; https://github.com/pokt-network/pocket-network-protocol/tree/main/ADRs
# TODO_TECHDEBT - Not a great implementation, but we need to fix it later.
# TODO_BLOCKER - Similar to TECHDEBT, but of higher priority, urgency & risk prior to the next release
# TODO_IMPROVE - A nice to have, but not a priority. It's okay if we never get to this.
# TODO_OPTIMIZE - An opportunity for performance improvement if/when it's necessary
# TODO_DISCUSS - Probably requires a lengthy offline discussion to understand next steps.
Expand Down
3 changes: 3 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,9 @@ func New(
keys[sessionmoduletypes.StoreKey],
keys[sessionmoduletypes.MemStoreKey],
app.GetSubspace(sessionmoduletypes.ModuleName),

app.ApplicationKeeper,
app.SupplierKeeper,
)
sessionModule := sessionmodule.NewAppModule(appCodec, app.SessionKeeper, app.AccountKeeper, app.BankKeeper)

Expand Down
1,567 changes: 1,529 additions & 38 deletions docs/static/openapi.yml

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
cosmossdk.io/math v1.0.1
github.com/cometbft/cometbft v0.37.2
github.com/cometbft/cometbft-db v0.8.0
github.com/cosmos/cosmos-proto v1.0.0-beta.2
github.com/cosmos/cosmos-sdk v0.47.3
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/ibc-go/v7 v7.1.0
Expand All @@ -21,7 +22,9 @@ require (
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
golang.org/x/crypto v0.12.0
golang.org/x/sync v0.3.0
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1
google.golang.org/grpc v1.56.1
gopkg.in/yaml.v2 v2.4.0
)
Expand Down Expand Up @@ -66,7 +69,6 @@ require (
github.com/containerd/cgroups v1.1.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.2 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v0.20.0 // indirect
Expand Down Expand Up @@ -252,7 +254,6 @@ require (
go.uber.org/fx v1.19.2 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/net v0.14.0 // indirect
Expand All @@ -265,7 +266,6 @@ require (
gonum.org/v1/gonum v0.11.0 // indirect
google.golang.org/api v0.122.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
2 changes: 1 addition & 1 deletion pkg/observable/channel/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (obsvr *channelObserver[V]) unsubscribe() {
// 1. this is library code; prefer fewer external dependencies, esp. I/O
// 2. the stdlib log pkg is pretty good, idiomatic, and globally
// configurable; perhaps it is sufficient
log.Printf("%s", observable.ErrObserverClosed.Wrap("redundant unsubscribe"))
log.Printf("%s", observable.ErrObserverClosed.Wrap("WARN: redundant unsubscribe"))
return
}

Expand Down
7 changes: 4 additions & 3 deletions proto/pocket/application/application.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ option go_package = "pocket/x/application/types";

import "cosmos_proto/cosmos.proto";
import "cosmos/base/v1beta1/coin.proto";
import "pocket/shared/service.proto";

// Application defines the type used to store an on-chain definition and state for an application
message Application {
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the application using cosmos' ScalarDescriptor to ensure deterministic deterministic encoding using cosmos' ScalarDescriptor to ensure deterministic deterministic encoding
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the application using cosmos' ScalarDescriptor to ensure deterministic encoding
cosmos.base.v1beta1.Coin stake = 2; // The total amount of uPOKT the application has staked
// TODO(@Olshansk): Uncomment the line below once the `ServiceId` proto is defined
// repeated service.ServiceId service_ids = 3; // The ID of the service this session is servicing
// TODO(@olshansk): Change this to `shared.ApplicationServiceConfig` in #95
repeated shared.ServiceId service_ids = 3; // The ID of the service this session is servicing
}

8 changes: 4 additions & 4 deletions proto/pocket/application/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ service Msg {
}
message MsgStakeApplication {
option (cosmos.msg.v1.signer) = "address"; // https://docs.cosmos.network/main/build/building-modules/messages-and-queries
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the application using cosmos' ScalarDescriptor to ensure deterministic deterministic encoding using cosmos' ScalarDescriptor to ensure deterministic deterministic encoding
cosmos.base.v1beta1.Coin stake = 2; // The total amount of uPOKT the application has staked. Must be ≥ to the current amount that the application has staked (if any)

// TODO(@Olshansk): Uncomment the line below once the `ServiceId` proto is defined
// repeated service.ServiceId service_ids = 3; // The ID of the service this session is servicing
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the application using cosmos' ScalarDescriptor to ensure deterministic encoding
cosmos.base.v1beta1.Coin stake = 2; // The total amount of uPOKT the application has staked. Must be ≥ to the current amount that the application has staked (if any)
// TODO(@Olshansk): Update the tx flow to add support for `services`
// repeated service.ApplicationServiceConfig services = 3; // The list of services this application is staked to request service for
}

message MsgStakeApplicationResponse {}
Expand Down
1 change: 0 additions & 1 deletion proto/pocket/pocket/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package pocket.pocket;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "pocket/pocket/params.proto";

option go_package = "pocket/x/pocket/types";
Expand Down
26 changes: 17 additions & 9 deletions proto/pocket/session/query.proto
Original file line number Diff line number Diff line change
@@ -1,40 +1,48 @@
syntax = "proto3";

package pocket.session;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "cosmos_proto/cosmos.proto";

import "pocket/session/params.proto";
import "pocket/session/session.proto";
import "pocket/shared/service.proto";

option go_package = "pocket/x/session/types";

// Query defines the gRPC querier service.
service Query {

// Parameters queries the parameters of the module.
rpc Params (QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/pocket/session/params";

}

// Queries a list of GetSession items.
rpc GetSession (QueryGetSessionRequest) returns (QueryGetSessionResponse) {
option (google.api.http).get = "/pocket/session/get_session";

}
}
// QueryParamsRequest is request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is response type for the Query/Params RPC method.
message QueryParamsResponse {

// params holds all the parameters of this module.
Params params = 1 [(gogoproto.nullable) = false];
}

message QueryGetSessionRequest {}
message QueryGetSessionRequest {
string application_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the application using cosmos' ScalarDescriptor to ensure deterministic encoding
shared.ServiceId service_id = 2; // The service id to query the session for
int64 block_height = 3; // The block height to query the session for
}

message QueryGetSessionResponse {}
message QueryGetSessionResponse {
session.Session session = 1;
}

12 changes: 4 additions & 8 deletions proto/pocket/session/session.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ package pocket.session;
option go_package = "pocket/x/session/types";

import "cosmos_proto/cosmos.proto";
// TODO(@Olshansk): Uncomment the line below once the service.proto file is added
// import "pocket/service/service.proto";
import "pocket/shared/service.proto";
import "pocket/application/application.proto";
import "pocket/shared/supplier.proto";

Expand All @@ -15,8 +14,7 @@ import "pocket/shared/supplier.proto";
// It is the minimal amount of data required to hydrate & retrieve all data relevant to the session.
message SessionHeader {
string application_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the application using cosmos' ScalarDescriptor to ensure deterministic encoding
// TODO(@Olshansk): Uncomment the line below once the `ServiceId` proto is defined
// service.ServiceId service_id = 2; // The ID of the service this session is servicing
shared.ServiceId service_id = 2; // The ID of the service this session is servicing
int64 session_start_block_height = 3; // The height at which this session started
// NOTE: session_id can be derived from the above values using on-chain but is included in the header for convenience
string session_id = 4; // A unique pseudoranom ID for this session
Expand All @@ -29,8 +27,6 @@ message Session {
string session_id = 2; // A unique pseudoranom ID for this session
int64 session_number = 3; // The session number since genesis
int64 num_blocks_per_session = 4; // The number of blocks per session when this session started
// TODO(@Olshansk): Uncomment the line below once the `Service` proto is defined
// service.Service service = 5; // A fully hydrated service object this session is for
application.Application application = 6; // A fully hydrated application object this session is for
repeated shared.Supplier suppliers = 7; // A fully hydrated set of servicers that are serving the application
application.Application application = 5; // A fully hydrated application object this session is for
repeated shared.Supplier suppliers = 6; // A fully hydrated set of servicers that are serving the application
}
20 changes: 12 additions & 8 deletions proto/pocket/shared/service.proto
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
syntax = "proto3";
package pocket.shared;

// NOTE that the `shared` package is not a Cosmos module,
// but rather a manually created package to resolve circular dependencies.

// TODO_CLEANUP(@Olshansk): Add native optional identifiers once its supported; https://github.com/ignite/cli/issues/3698
package pocket.shared;

option go_package = "pocket/x/shared/types";

// TODO_CLEANUP(@Olshansk): Add native optional identifiers once its supported; https://github.com/ignite/cli/issues/3698

// ServiceId message to encapsulate unique and semantic identifiers for a service on the network
message ServiceId {
string id = 1; // Unique identifier for the service
string name = 2; // Semantic name for the service
string name = 2; // (Optional) Semantic human readable name for the service
// NOTE: `ServiceId.Id` may seem redundant but was designed to enable more complex service identification.
// For example, what if we want to request a session for a certain service but with some additional configs that identify it?
}

// SupplierServiceConfig holds the service configuration the application stakes for
message ApplicationServiceConfig {
ServiceId id = 1; // Unique and semantic identifier for the service
// TODO_RESEARCH: There is an opportunity for applications to advertise what kind of configurations (and price)
// they want, but it is out of scope for the MVP.
repeated ServiceId service_id = 1; // Unique and semantic identifier for the service
// TODO_RESEARCH: There is an opportunity for applications to advertise the max
// they're willing to pay for a certain configuration/price, but this is outside of scope.
// repeated RPCConfig rpc_configs = 2; // List of endpoints for the service
}

// SupplierServiceConfig holds the service configuration the supplier stakes for
message SupplierServiceConfig {
ServiceId id = 1; // Unique and semantic identifier for the service
ServiceId service_id = 1; // Unique and semantic identifier for the service
repeated SupplierEndpoint endpoints = 2; // List of endpoints for the service
// TODO_RESEARCH: There is an opportunity for supplier to advertise the min
// they're willing to earn for a certain configuration/price, but this is outside of scope.
}

// Endpoint message to hold service configuration details
Expand Down
6 changes: 3 additions & 3 deletions proto/pocket/shared/supplier.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ option go_package = "pocket/x/shared/types";

import "cosmos_proto/cosmos.proto";
import "cosmos/base/v1beta1/coin.proto";
import "pocket/shared/service.proto";

// Supplier is the type defining the actor in Pocket Network that provides RPC services.
message Supplier {
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the supplier using cosmos' ScalarDescriptor to ensure deterministic deterministic encoding using cosmos' ScalarDescriptor to ensure deterministic deterministic encoding
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the supplier using cosmos' ScalarDescriptor to ensure deterministic encoding
cosmos.base.v1beta1.Coin stake = 2; // The total amount of uPOKT the supplier has staked
// TODO(@Olshansk): Uncomment the line below once the `ServiceId` proto is defined
// repeated service.SupplierServiceConfig services = 3; // The service configs this supplier can support
repeated SupplierServiceConfig services = 3; // The service configs this supplier can support
}

4 changes: 2 additions & 2 deletions proto/pocket/supplier/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ message MsgStakeSupplier {

string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the supplier using cosmos' ScalarDescriptor to ensure deterministic deterministic encoding using cosmos' ScalarDescriptor to ensure deterministic deterministic encoding
cosmos.base.v1beta1.Coin stake = 2; // The total amount of uPOKT the supplier has staked. Must be ≥ to the current amount that the supplier has staked (if any)
// TODO(@Olshansk): Uncomment the line below once the `ServiceId` proto is defined
// repeated service.SupplierServiceConfig services = 3; // The ID of the service this session is servicing
// TODO(@Olshansk): Update the tx flow to add support for `services`
// repeated service.SupplierServiceConfig services = 3; // The list of services this supplier is staked to provide service for
}

message MsgStakeSupplierResponse {}
Expand Down
Loading

0 comments on commit d7d87eb

Please sign in to comment.