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

[Service] Rename the ServiceId proto to Service #150

Merged
merged 19 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 132 additions & 34 deletions docs/static/openapi.yml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pkg/relayer/proxy/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ type RelayServer interface {
// Stop terminates the service server and returns an error if it fails.
Stop(ctx context.Context) error

// ServiceId returns the serviceId of the service.
ServiceId() *sharedtypes.ServiceId
// Service returns the serviceId of the service.
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
Service() *sharedtypes.Service
}
14 changes: 7 additions & 7 deletions pkg/relayer/proxy/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
var _ RelayServer = (*jsonRPCServer)(nil)

type jsonRPCServer struct {
// serviceId is the id of the service that the server is responsible for.
serviceId *sharedtypes.ServiceId
// service is the id of the service that the server is responsible for.
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
service *sharedtypes.Service

// serverEndpoint is the advertised endpoint configuration that the server uses to
// listen for incoming relay requests.
Expand All @@ -38,14 +38,14 @@ type jsonRPCServer struct {
// It takes the serviceId, endpointUrl, and the main RelayerProxy as arguments and returns
// a RelayServer that listens to incoming RelayRequests
func NewJSONRPCServer(
serviceId *sharedtypes.ServiceId,
service *sharedtypes.Service,
supplierEndpoint *sharedtypes.SupplierEndpoint,
proxiedServiceEndpoint url.URL,
servedRelaysProducer chan<- *types.Relay,
proxy RelayerProxy,
) RelayServer {
return &jsonRPCServer{
serviceId: serviceId,
service: service,
serverEndpoint: supplierEndpoint,
server: &http.Server{Addr: supplierEndpoint.Url},
relayerProxy: proxy,
Expand All @@ -71,9 +71,9 @@ func (j *jsonRPCServer) Stop(ctx context.Context) error {
return j.server.Shutdown(ctx)
}

// ServiceId returns the serviceId of the JSON-RPC service.
func (j *jsonRPCServer) ServiceId() *sharedtypes.ServiceId {
return j.serviceId
// Service returns the serviceId of the JSON-RPC service.
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
func (j *jsonRPCServer) Service() *sharedtypes.Service {
return j.service
}

// ServeHTTP listens for incoming relay requests. It implements the respective
Expand Down
8 changes: 4 additions & 4 deletions pkg/relayer/proxy/server_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func (rp *relayerProxy) BuildProvidedServices(ctx context.Context) error {
// Build the advertised relay servers map. For each service's endpoint, create the appropriate RelayServer.
providedServices := make(relayServersMap)
for _, serviceConfig := range services {
serviceId := serviceConfig.ServiceId
proxiedServicesEndpoints := rp.proxiedServicesEndpoints[serviceId.Id]
service := serviceConfig.Service
proxiedServicesEndpoints := rp.proxiedServicesEndpoints[service.Id]
serviceEndpoints := make([]RelayServer, len(serviceConfig.Endpoints))

for _, endpoint := range serviceConfig.Endpoints {
Expand All @@ -40,7 +40,7 @@ func (rp *relayerProxy) BuildProvidedServices(ctx context.Context) error {
switch endpoint.RpcType {
case sharedtypes.RPCType_JSON_RPC:
server = NewJSONRPCServer(
serviceId,
service,
endpoint,
proxiedServicesEndpoints,
rp.servedRelaysProducer,
Expand All @@ -53,7 +53,7 @@ func (rp *relayerProxy) BuildProvidedServices(ctx context.Context) error {
serviceEndpoints = append(serviceEndpoints, server)
}

providedServices[serviceId.Id] = serviceEndpoints
providedServices[service.Id] = serviceEndpoints
}

rp.advertisedRelayServers = providedServices
Expand Down
2 changes: 1 addition & 1 deletion proto/pocket/application/application.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ import "pocket/shared/service.proto";
message Application {
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
repeated shared.ApplicationServiceConfig service_configs = 3; // The ID of the service this session is servicing
repeated shared.ApplicationServiceConfig service_configs = 3; // The list of services this appliccation is configured to request service for
repeated string delegatee_gateway_addresses = 4 [(cosmos_proto.scalar) = "cosmos.AddressString", (gogoproto.nullable) = false]; // The Bech32 encoded addresses for all delegatee Gateways, in a non-nullable slice
}
2 changes: 1 addition & 1 deletion proto/pocket/session/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ message QueryParamsResponse {

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
shared.Service service = 2; // The service id to query the session for
int64 block_height = 3; // The block height to query the session for
}

Expand Down
2 changes: 1 addition & 1 deletion proto/pocket/session/session.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +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
shared.ServiceId service_id = 2; // The ID of the service this session is servicing
shared.Service service = 2; // The service this session is for
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 Down
15 changes: 5 additions & 10 deletions proto/pocket/shared/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,19 @@ package pocket.shared;

option go_package = "github.com/pokt-network/poktroll/x/shared/types";

// TODO_CLEANUP(@Olshansk): Add native optional identifiers once its supported; https://github.com/ignite/cli/issues/3698
Olshansk marked this conversation as resolved.
Show resolved Hide resolved

// ServiceId message to encapsulate unique and semantic identifiers for a service on the network
message ServiceId {
// NOTE: `ServiceId.Id` may seem redundant but was desigtned created to enable more complex service identification
// Service message to encapsulate unique and semantic identifiers for a service on the network
message Service {
// NOTE: `Service.Id` may seem redundant but was desigtned created to enable more complex service identification
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
// For example, what if we want to request a session for a certain service but with some additional configs that identify it?
string id = 1; // Unique identifier for the service

// TODO_TECHDEBT: Name is currently unused but acts as a reminder than an optional onchain representation of the service is necessary
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?
}

// ApplicationServiceConfig holds the service configuration the application stakes for
message ApplicationServiceConfig {
ServiceId service_id = 1; // Unique and semantic identifier for the service
Service service = 1; // Unique and semantic identifier for the service
Olshansk marked this conversation as resolved.
Show resolved Hide resolved

// 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.
Expand All @@ -32,7 +27,7 @@ message ApplicationServiceConfig {

// SupplierServiceConfig holds the service configuration the supplier stakes for
message SupplierServiceConfig {
ServiceId service_id = 1; // Unique and semantic identifier for the service
Service service = 1; // Unique and semantic identifier for the service
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
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.
Expand Down
12 changes: 6 additions & 6 deletions testutil/keeper/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ var (
Stake: &sdk.Coin{Denom: "upokt", Amount: sdk.NewInt(100)},
ServiceConfigs: []*sharedtypes.ApplicationServiceConfig{
{
ServiceId: &sharedtypes.ServiceId{Id: TestServiceId1},
Service: &sharedtypes.Service{Id: TestServiceId1},
},
{
ServiceId: &sharedtypes.ServiceId{Id: TestServiceId2},
Service: &sharedtypes.Service{Id: TestServiceId2},
},
},
}
Expand All @@ -50,10 +50,10 @@ var (
Stake: &sdk.Coin{Denom: "upokt", Amount: sdk.NewInt(100)},
ServiceConfigs: []*sharedtypes.ApplicationServiceConfig{
{
ServiceId: &sharedtypes.ServiceId{Id: TestServiceId1},
Service: &sharedtypes.Service{Id: TestServiceId1},
},
{
ServiceId: &sharedtypes.ServiceId{Id: TestServiceId2},
Service: &sharedtypes.Service{Id: TestServiceId2},
},
},
}
Expand All @@ -65,7 +65,7 @@ var (
Stake: &sdk.Coin{Denom: "upokt", Amount: sdk.NewInt(100)},
Services: []*sharedtypes.SupplierServiceConfig{
{
ServiceId: &sharedtypes.ServiceId{Id: TestServiceId1},
Service: &sharedtypes.Service{Id: TestServiceId1},
Endpoints: []*sharedtypes.SupplierEndpoint{
{
Url: TestSupplierUrl,
Expand All @@ -75,7 +75,7 @@ var (
},
},
{
ServiceId: &sharedtypes.ServiceId{Id: TestServiceId2},
Service: &sharedtypes.Service{Id: TestServiceId2},
Endpoints: []*sharedtypes.SupplierEndpoint{
{
Url: TestSupplierUrl,
Expand Down
4 changes: 2 additions & 2 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func DefaultApplicationModuleGenesisState(t *testing.T, n int) *apptypes.Genesis
Stake: &stake,
ServiceConfigs: []*sharedtypes.ApplicationServiceConfig{
{
ServiceId: &sharedtypes.ServiceId{Id: fmt.Sprintf("svc%d", i)},
Service: &sharedtypes.Service{Id: fmt.Sprintf("svc%d", i)},
},
},
}
Expand Down Expand Up @@ -152,7 +152,7 @@ func DefaultSupplierModuleGenesisState(t *testing.T, n int) *suppliertypes.Genes
Stake: &stake,
Services: []*sharedtypes.SupplierServiceConfig{
{
ServiceId: &sharedtypes.ServiceId{Id: fmt.Sprintf("svc%d", i)},
Service: &sharedtypes.Service{Id: fmt.Sprintf("svc%d", i)},
Endpoints: []*sharedtypes.SupplierEndpoint{
{
Url: fmt.Sprintf("http://localhost:%d", i),
Expand Down
4 changes: 2 additions & 2 deletions x/application/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestGenesis(t *testing.T) {
Stake: &sdk.Coin{Denom: "upokt", Amount: sdk.NewInt(100)},
ServiceConfigs: []*sharedtypes.ApplicationServiceConfig{
{
ServiceId: &sharedtypes.ServiceId{Id: "svc1"},
Service: &sharedtypes.Service{Id: "svc1"},
},
},
},
Expand All @@ -33,7 +33,7 @@ func TestGenesis(t *testing.T) {
Stake: &sdk.Coin{Denom: "upokt", Amount: sdk.NewInt(100)},
ServiceConfigs: []*sharedtypes.ApplicationServiceConfig{
{
ServiceId: &sharedtypes.ServiceId{Id: "svc2"},
Service: &sharedtypes.Service{Id: "svc2"},
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion x/application/keeper/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func createNApplication(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.A
app.Stake = &sdk.Coin{Denom: "upokt", Amount: sdk.NewInt(int64(i))}
app.ServiceConfigs = []*sharedtypes.ApplicationServiceConfig{
{
ServiceId: &sharedtypes.ServiceId{Id: fmt.Sprintf("svc%d", i)},
Service: &sharedtypes.Service{Id: fmt.Sprintf("svc%d", i)},
},
}
keeper.SetApplication(ctx, *app)
Expand Down
8 changes: 4 additions & 4 deletions x/application/keeper/msg_server_delegate_to_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestMsgServer_DelegateToGateway_SuccessfullyDelegate(t *testing.T) {
Stake: &sdk.Coin{Denom: "upokt", Amount: sdk.NewInt(100)},
Services: []*sharedtypes.ApplicationServiceConfig{
{
ServiceId: &sharedtypes.ServiceId{Id: "svc1"},
Service: &sharedtypes.Service{Id: "svc1"},
},
},
}
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestMsgServer_DelegateToGateway_FailDuplicate(t *testing.T) {
Stake: &sdk.Coin{Denom: "upokt", Amount: sdk.NewInt(100)},
Services: []*sharedtypes.ApplicationServiceConfig{
{
ServiceId: &sharedtypes.ServiceId{Id: "svc1"},
Service: &sharedtypes.Service{Id: "svc1"},
},
},
}
Expand Down Expand Up @@ -158,7 +158,7 @@ func TestMsgServer_DelegateToGateway_FailGatewayNotStaked(t *testing.T) {
Stake: &sdk.Coin{Denom: "upokt", Amount: sdk.NewInt(100)},
Services: []*sharedtypes.ApplicationServiceConfig{
{
ServiceId: &sharedtypes.ServiceId{Id: "svc1"},
Service: &sharedtypes.Service{Id: "svc1"},
},
},
}
Expand Down Expand Up @@ -203,7 +203,7 @@ func TestMsgServer_DelegateToGateway_FailMaxReached(t *testing.T) {
Stake: &sdk.Coin{Denom: "upokt", Amount: sdk.NewInt(100)},
Services: []*sharedtypes.ApplicationServiceConfig{
{
ServiceId: &sharedtypes.ServiceId{Id: "svc1"},
Service: &sharedtypes.Service{Id: "svc1"},
},
},
}
Expand Down
24 changes: 12 additions & 12 deletions x/application/keeper/msg_server_stake_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestMsgServer_StakeApplication_SuccessfulCreateAndUpdate(t *testing.T) {
Stake: &sdk.Coin{Denom: "upokt", Amount: sdk.NewInt(100)},
Services: []*sharedtypes.ApplicationServiceConfig{
{
ServiceId: &sharedtypes.ServiceId{Id: "svc1"},
Service: &sharedtypes.Service{Id: "svc1"},
},
},
}
Expand All @@ -46,18 +46,18 @@ func TestMsgServer_StakeApplication_SuccessfulCreateAndUpdate(t *testing.T) {
require.Equal(t, addr, appFound.Address)
require.Equal(t, int64(100), appFound.Stake.Amount.Int64())
require.Len(t, appFound.ServiceConfigs, 1)
require.Equal(t, "svc1", appFound.ServiceConfigs[0].ServiceId.Id)
require.Equal(t, "svc1", appFound.ServiceConfigs[0].Service.Id)

// Prepare an updated application with a higher stake and another service
updateStakeMsg := &types.MsgStakeApplication{
Address: addr,
Stake: &sdk.Coin{Denom: "upokt", Amount: sdk.NewInt(200)},
Services: []*sharedtypes.ApplicationServiceConfig{
{
ServiceId: &sharedtypes.ServiceId{Id: "svc1"},
Service: &sharedtypes.Service{Id: "svc1"},
},
{
ServiceId: &sharedtypes.ServiceId{Id: "svc2"},
Service: &sharedtypes.Service{Id: "svc2"},
},
},
}
Expand All @@ -69,8 +69,8 @@ func TestMsgServer_StakeApplication_SuccessfulCreateAndUpdate(t *testing.T) {
require.True(t, isAppFound)
require.Equal(t, int64(200), appFound.Stake.Amount.Int64())
require.Len(t, appFound.ServiceConfigs, 2)
require.Equal(t, "svc1", appFound.ServiceConfigs[0].ServiceId.Id)
require.Equal(t, "svc2", appFound.ServiceConfigs[1].ServiceId.Id)
require.Equal(t, "svc1", appFound.ServiceConfigs[0].Service.Id)
require.Equal(t, "svc2", appFound.ServiceConfigs[1].Service.Id)
}

func TestMsgServer_StakeApplication_FailRestakingDueToInvalidServices(t *testing.T) {
Expand All @@ -86,7 +86,7 @@ func TestMsgServer_StakeApplication_FailRestakingDueToInvalidServices(t *testing
Stake: &sdk.Coin{Denom: "upokt", Amount: sdk.NewInt(100)},
Services: []*sharedtypes.ApplicationServiceConfig{
{
ServiceId: &sharedtypes.ServiceId{Id: "svc1"},
Service: &sharedtypes.Service{Id: "svc1"},
},
},
}
Expand All @@ -111,15 +111,15 @@ func TestMsgServer_StakeApplication_FailRestakingDueToInvalidServices(t *testing
require.True(t, isAppFound)
require.Equal(t, appAddr, app.Address)
require.Len(t, app.ServiceConfigs, 1)
require.Equal(t, "svc1", app.ServiceConfigs[0].ServiceId.Id)
require.Equal(t, "svc1", app.ServiceConfigs[0].Service.Id)

// Prepare the application stake message with an invalid service ID
updateStakeMsg = &types.MsgStakeApplication{
Address: appAddr,
Stake: &sdk.Coin{Denom: "upokt", Amount: sdk.NewInt(100)},
Services: []*sharedtypes.ApplicationServiceConfig{
{
ServiceId: &sharedtypes.ServiceId{Id: "svc1 INVALID ! & *"},
Service: &sharedtypes.Service{Id: "svc1 INVALID ! & *"},
},
},
}
Expand All @@ -133,7 +133,7 @@ func TestMsgServer_StakeApplication_FailRestakingDueToInvalidServices(t *testing
require.True(t, isAppFound)
require.Equal(t, appAddr, app.Address)
require.Len(t, app.ServiceConfigs, 1)
require.Equal(t, "svc1", app.ServiceConfigs[0].ServiceId.Id)
require.Equal(t, "svc1", app.ServiceConfigs[0].Service.Id)
}

func TestMsgServer_StakeApplication_FailLoweringStake(t *testing.T) {
Expand All @@ -148,7 +148,7 @@ func TestMsgServer_StakeApplication_FailLoweringStake(t *testing.T) {
Stake: &sdk.Coin{Denom: "upokt", Amount: sdk.NewInt(100)},
Services: []*sharedtypes.ApplicationServiceConfig{
{
ServiceId: &sharedtypes.ServiceId{Id: "svc1"},
Service: &sharedtypes.Service{Id: "svc1"},
},
},
}
Expand All @@ -165,7 +165,7 @@ func TestMsgServer_StakeApplication_FailLoweringStake(t *testing.T) {
Stake: &sdk.Coin{Denom: "upokt", Amount: sdk.NewInt(50)},
Services: []*sharedtypes.ApplicationServiceConfig{
{
ServiceId: &sharedtypes.ServiceId{Id: "svc1"},
Service: &sharedtypes.Service{Id: "svc1"},
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestMsgServer_UndelegateFromGateway_SuccessfullyUndelegate(t *testing.T) {
Stake: &sdk.Coin{Denom: "upokt", Amount: sdk.NewInt(100)},
Services: []*sharedtypes.ApplicationServiceConfig{
{
ServiceId: &sharedtypes.ServiceId{Id: "svc1"},
Service: &sharedtypes.Service{Id: "svc1"},
},
},
}
Expand Down Expand Up @@ -113,7 +113,7 @@ func TestMsgServer_UndelegateFromGateway_FailNotDelegated(t *testing.T) {
Stake: &sdk.Coin{Denom: "upokt", Amount: sdk.NewInt(100)},
Services: []*sharedtypes.ApplicationServiceConfig{
{
ServiceId: &sharedtypes.ServiceId{Id: "svc1"},
Service: &sharedtypes.Service{Id: "svc1"},
},
},
}
Expand Down Expand Up @@ -174,7 +174,7 @@ func TestMsgServer_UndelegateFromGateway_SuccessfullyUndelegateFromUnstakedGatew
Stake: &sdk.Coin{Denom: "upokt", Amount: sdk.NewInt(100)},
Services: []*sharedtypes.ApplicationServiceConfig{
{
ServiceId: &sharedtypes.ServiceId{Id: "svc1"},
Service: &sharedtypes.Service{Id: "svc1"},
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestMsgServer_UnstakeApplication_Success(t *testing.T) {
Stake: &initialStake,
Services: []*sharedtypes.ApplicationServiceConfig{
{
ServiceId: &sharedtypes.ServiceId{Id: "svc1"},
Service: &sharedtypes.Service{Id: "svc1"},
},
},
}
Expand Down
Loading