Skip to content

Commit

Permalink
feat: CNS 930: new epoch payments objects (#1335)
Browse files Browse the repository at this point in the history
* CNS-930: define proto of new epoch cu structs

* CNS-930: create epoch CU objects + basic unit tests

* CNS-930: updated epoch CU objects implementation

* CNS-930: added check for valid key when decoding

* CNS-930: updated genesis with new epoch cu objects

* CNS-930: added chain ID to epoch CU objects

* CNS-930: change the epoch payments mechanism to the new one

* CNS-930: add fixed time work around for time dependent unit tests

* CNS-930: added provider epoch CU query and updated E2E

* CNS-930: migrator

* CNS-930: lint fixes

* CNS-930: changed query name ProviderEpochCu to ProvidersEpochCu

* CNS-930: changed UniqueEpochSessionGenesis to hold the decoded key

* CNS-930: change functions names

* CNS-930: change get all store return types

* CNS-930: fix TODO

* CNS-930: change unique session key order

* CNS-930: improve unresponsive CU count efficiency

* CNS-930: insert the epoch to the key

* CNS-930: add cache to epoch CU

* CNS-930: small fix

* CNS-930: lint

* CNS-930: fix protocol proto script

* updated

* Revert "updated"

This reverts commit ec2852e.

* CNS-930: change GetAllProviderConsumerEpochCu return type

* CNS-930: update unresponsive count to be efficient

* CNS-930: small PR fix

* CNS-930: another small PR fix

* CNS-930: sort complainedProviders keys

* CNS-930: small PR fix

* make a object just for complainer cu

* encode uint instead of convert to string

* fix iterators

* validate genesis

---------

Co-authored-by: Yarom Swisa <yarom@lavanet.xyz git config --global user.name Yarom>
Co-authored-by: Yaroms <103432884+Yaroms@users.noreply.github.com>
  • Loading branch information
3 people committed Apr 3, 2024
1 parent 67c24df commit c665e6a
Show file tree
Hide file tree
Showing 64 changed files with 6,178 additions and 7,627 deletions.
4 changes: 1 addition & 3 deletions ecosystem/lava-sdk/scripts/protoc_grpc_relay.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ protoc \
"$LAVA_PROTO_DIR/lavanet/lava/pairing/badges.proto" \
"$LAVA_PROTO_DIR/lavanet/lava/pairing/params.proto" \
"$LAVA_PROTO_DIR/lavanet/lava/pairing/query.proto" \
"$LAVA_PROTO_DIR/lavanet/lava/pairing/provider_payment_storage.proto" \
"$LAVA_PROTO_DIR/lavanet/lava/pairing/unique_payment_storage_client_provider.proto" \
"$LAVA_PROTO_DIR/lavanet/lava/subscription/subscription.proto" \
"$LAVA_PROTO_DIR/lavanet/lava/projects/project.proto" \
"$LAVA_PROTO_DIR/lavanet/lava/plans/policy.proto" \
"$LAVA_PROTO_DIR/lavanet/lava/pairing/epoch_payments.proto" \
"$LAVA_PROTO_DIR/lavanet/lava/pairing/epoch_cu.proto" \
"$LAVA_PROTO_DIR/lavanet/lava/spec/spec.proto" \
"$LAVA_PROTO_DIR/lavanet/lava/spec/api_collection.proto" \
"$LAVA_PROTO_DIR/lavanet/lava/epochstorage/stake_entry.proto" \
Expand Down
29 changes: 29 additions & 0 deletions proto/lavanet/lava/pairing/epoch_cu.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
syntax = "proto3";
package lavanet.lava.pairing;

option go_package = "github.com/lavanet/lava/x/pairing/types";

// UniqueEpochSession is used to detect double spend attacks
// It's kept in a epoch-prefixed store with a unique index: provider, project ID, chain ID and session ID
message UniqueEpochSession {
}

// ProviderEpochCu is used to track the CU of a specific provider in a specific epoch
// It's kept in a epoch-prefixed store with a unique index: provider address
message ProviderEpochCu {
uint64 serviced_cu = 1;
}

// ProviderEpochComplainerCu is used to track the CU complained of a specific provider in a specific epoch
// It's kept in a epoch-prefixed store with a unique index: provider address
message ProviderEpochComplainerCu {
uint64 complainers_cu = 1;
}

// ProviderConsumerEpochCu is used to track the CU between a specific provider and
// consumer in a specific epoch
// It's kept in a epoch-prefixed store with a unique index: provider and project ID
message ProviderConsumerEpochCu {
uint64 cu = 1;
}

11 changes: 0 additions & 11 deletions proto/lavanet/lava/pairing/epoch_payments.proto

This file was deleted.

44 changes: 38 additions & 6 deletions proto/lavanet/lava/pairing/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package lavanet.lava.pairing;

import "gogoproto/gogo.proto";
import "lavanet/lava/pairing/params.proto";
import "lavanet/lava/pairing/unique_payment_storage_client_provider.proto";
import "lavanet/lava/pairing/provider_payment_storage.proto";
import "lavanet/lava/pairing/epoch_payments.proto";
import "lavanet/lava/pairing/epoch_cu.proto";
import "lavanet/lava/fixationstore/fixation.proto";
import "lavanet/lava/timerstore/timer.proto";

Expand All @@ -21,11 +19,45 @@ message BadgeUsedCu {
// GenesisState defines the pairing module's genesis state.
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
repeated UniquePaymentStorageClientProvider uniquePaymentStorageClientProviderList = 2 [(gogoproto.nullable) = false];
repeated ProviderPaymentStorage providerPaymentStorageList = 3 [(gogoproto.nullable) = false];
repeated EpochPayments epochPaymentsList = 4 [(gogoproto.nullable) = false];
reserved 2;
reserved 3;
reserved 4;
repeated BadgeUsedCu badgeUsedCuList = 5 [(gogoproto.nullable) = false];
lavanet.lava.timerstore.GenesisState badgesTS = 6 [(gogoproto.nullable) = false];
lavanet.lava.fixationstore.GenesisState providerQosFS = 7 [(gogoproto.nullable) = false];
repeated UniqueEpochSessionGenesis unique_epoch_sessions = 8 [(gogoproto.nullable) = false];
repeated ProviderEpochCuGenesis provider_epoch_cus = 9 [(gogoproto.nullable) = false];
repeated ProviderEpochComplainerCuGenesis provider_epoch_complained_cus = 10 [(gogoproto.nullable) = false];
repeated ProviderConsumerEpochCuGenesis provider_consumer_epoch_cus = 11 [(gogoproto.nullable) = false];
// this line is used by starport scaffolding # genesis/proto/state
}

message UniqueEpochSessionGenesis {
uint64 epoch = 1;
string provider = 2;
string project = 3;
string chain_id = 4;
uint64 session_id = 5;
}

message ProviderEpochCuGenesis {
uint64 epoch = 1;
string provider = 2;
string chain_id = 3;
ProviderEpochCu provider_epoch_cu = 4 [(gogoproto.nullable) = false];
}

message ProviderEpochComplainerCuGenesis {
uint64 epoch = 1;
string provider = 2;
string chain_id = 3;
ProviderEpochComplainerCu provider_epoch_complainer_cu = 4 [(gogoproto.nullable) = false];
}

message ProviderConsumerEpochCuGenesis {
uint64 epoch = 1;
string provider = 2;
string project = 3;
string chain_id = 4;
ProviderConsumerEpochCu provider_consumer_epoch_cu = 5 [(gogoproto.nullable) = false];
}
23 changes: 0 additions & 23 deletions proto/lavanet/lava/pairing/provider_payment_storage.proto

This file was deleted.

113 changes: 23 additions & 90 deletions proto/lavanet/lava/pairing/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "lavanet/lava/pairing/params.proto";
import "lavanet/lava/pairing/epoch_payments.proto";
import "lavanet/lava/spec/spec.proto";


// this line is used by starport scaffolding # 1
import "lavanet/lava/plans/policy.proto";
import "lavanet/lava/pairing/provider_payment_storage.proto";
import "lavanet/lava/pairing/unique_payment_storage_client_provider.proto";
import "lavanet/lava/epochstorage/stake_entry.proto";
import "lavanet/lava/subscription/subscription.proto";
import "lavanet/lava/projects/project.proto";
Expand Down Expand Up @@ -42,36 +39,6 @@ service Query {
option (google.api.http).get = "/lavanet/lava/pairing/verify_pairing/{chainID}/{client}/{provider}/{block}";
}

// Queries a UniquePaymentStorageClientProvider by index.
rpc UniquePaymentStorageClientProvider(QueryGetUniquePaymentStorageClientProviderRequest) returns (QueryGetUniquePaymentStorageClientProviderResponse) {
option (google.api.http).get = "/lavanet/lava/pairing/unique_payment_storage_client_provider/{index}";
}

// Queries a list of UniquePaymentStorageClientProvider items.
rpc UniquePaymentStorageClientProviderAll(QueryAllUniquePaymentStorageClientProviderRequest) returns (QueryAllUniquePaymentStorageClientProviderResponse) {
option (google.api.http).get = "/lavanet/lava/pairing/unique_payment_storage_client_provider";
}

// Queries a ProviderPaymentStorage by index.
rpc ProviderPaymentStorage(QueryGetProviderPaymentStorageRequest) returns (QueryGetProviderPaymentStorageResponse) {
option (google.api.http).get = "/lavanet/lava/pairing/provider_payment_storage/{index}";
}

// Queries a list of ProviderPaymentStorage items.
rpc ProviderPaymentStorageAll(QueryAllProviderPaymentStorageRequest) returns (QueryAllProviderPaymentStorageResponse) {
option (google.api.http).get = "/lavanet/lava/pairing/provider_payment_storage";
}

// Queries a EpochPayments by index.
rpc EpochPayments(QueryGetEpochPaymentsRequest) returns (QueryGetEpochPaymentsResponse) {
option (google.api.http).get = "/lavanet/lava/pairing/epoch_payments/{index}";
}

// Queries a list of EpochPayments items.
rpc EpochPaymentsAll(QueryAllEpochPaymentsRequest) returns (QueryAllEpochPaymentsResponse) {
option (google.api.http).get = "/lavanet/lava/pairing/epoch_payments";
}

// Queries a UserEntry items.
rpc UserEntry(QueryUserEntryRequest) returns (QueryUserEntryResponse) {
option (google.api.http).get = "/lavanet/lava/pairing/user_entry/{address}/{chainID}";
Expand All @@ -97,11 +64,18 @@ service Query {
option (google.api.http).get = "/lavanet/lava/pairing/subscription_monthly_payout/{consumer}";
}

// this line is used by starport scaffolding # 2
// Queries a list of SdkPairing items.
rpc SdkPairing (QueryGetPairingRequest) returns (QuerySdkPairingResponse) {
option (google.api.http).get = "/lavanet/lava/pairing/sdk_pairing";
// Queries a list of SdkPairing items.
rpc SdkPairing (QueryGetPairingRequest) returns (QuerySdkPairingResponse) {
option (google.api.http).get = "/lavanet/lava/pairing/sdk_pairing";
}

// Queries a for the aggregated CU of all ProviderEpochCu objects all the providers.
rpc ProvidersEpochCu(QueryProvidersEpochCuRequest) returns (QueryProvidersEpochCuResponse) {
option (google.api.http).get = "/lavanet/lava/pairing/providers_epoch_cu";
}

// this line is used by starport scaffolding # 2

}

// QueryParamsRequest is request type for the Query/Params RPC method.
Expand Down Expand Up @@ -151,59 +125,6 @@ message QueryVerifyPairingResponse {
string project_id = 5;
}

message QueryGetUniquePaymentStorageClientProviderRequest {
string index = 1;
}

message QueryGetUniquePaymentStorageClientProviderResponse {
UniquePaymentStorageClientProvider uniquePaymentStorageClientProvider = 1 [(gogoproto.nullable) = false];
}

message QueryAllUniquePaymentStorageClientProviderRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

message QueryAllUniquePaymentStorageClientProviderResponse {
repeated UniquePaymentStorageClientProvider uniquePaymentStorageClientProvider = 1 [(gogoproto.nullable) = false];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

message QueryGetProviderPaymentStorageRequest {
string index = 1;

}

message QueryGetProviderPaymentStorageResponse {
ProviderPaymentStorage providerPaymentStorage = 1 [(gogoproto.nullable) = false];
}

message QueryAllProviderPaymentStorageRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

message QueryAllProviderPaymentStorageResponse {
repeated ProviderPaymentStorage providerPaymentStorage = 1 [(gogoproto.nullable) = false];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

message QueryGetEpochPaymentsRequest {
string index = 1;

}

message QueryGetEpochPaymentsResponse {
EpochPayments epochPayments = 1 [(gogoproto.nullable) = false];
}

message QueryAllEpochPaymentsRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

message QueryAllEpochPaymentsResponse {
repeated EpochPayments epochPayments = 1 [(gogoproto.nullable) = false];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

message QueryUserEntryRequest {
string address = 1;
string chainID = 2;
Expand Down Expand Up @@ -276,3 +197,15 @@ message QuerySubscriptionMonthlyPayoutResponse {
uint64 total = 1;
repeated ChainIDPayout details = 2;
}

message QueryProvidersEpochCuRequest {
}

message QueryProvidersEpochCuResponse {
repeated ProviderCuInfo info = 1 [(gogoproto.nullable) = false];
}

message ProviderCuInfo {
string provider = 1;
uint64 cu = 2;
}

This file was deleted.

4 changes: 1 addition & 3 deletions scripts/cli_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ trace lavad q pairing params >/dev/null
trace lavad q pairing account-info $(lavad keys show alice -a) >/dev/null
trace lavad q pairing effective-policy ETH1 $(lavad keys show alice -a) >/dev/null
trace lavad q pairing get-pairing STRK $(lavad keys show alice -a) >/dev/null
trace lavad q pairing list-epoch-payments >/dev/null
trace lavad q pairing list-provider-payment-storage >/dev/null
trace lavad q pairing list-unique-payment-storage-client-provider >/dev/null
trace lavad q pairing provider-epoch-cu $(lavad keys show servicer1) >/dev/null
trace lavad q pairing providers STRK >/dev/null
trace lavad q pairing sdk-pairing STRK $(lavad keys show alice -a) >/dev/null
trace lavad q pairing provider-monthly-payout $(lavad keys show servicer1 -a) >/dev/null
Expand Down
12 changes: 6 additions & 6 deletions testutil/common/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -788,12 +788,6 @@ func (ts *Tester) QueryPairingGetPairing(chainID, client string) (*pairingtypes.
return ts.Keepers.Pairing.GetPairing(ts.GoCtx, msg)
}

// QueryPairingListEpochPayments implements 'q pairing list-epoch-payments'
func (ts *Tester) QueryPairingListEpochPayments() (*pairingtypes.QueryAllEpochPaymentsResponse, error) {
msg := &pairingtypes.QueryAllEpochPaymentsRequest{}
return ts.Keepers.Pairing.EpochPaymentsAll(ts.GoCtx, msg)
}

// QueryPairingProviders: implement 'q pairing providers'
func (ts *Tester) QueryPairingProviders(chainID string, frozen bool) (*pairingtypes.QueryProvidersResponse, error) {
msg := &pairingtypes.QueryProvidersRequest{
Expand Down Expand Up @@ -831,6 +825,12 @@ func (ts *Tester) QueryPairingProviderMonthlyPayout(provider string) (*pairingty
return ts.Keepers.Pairing.ProviderMonthlyPayout(ts.GoCtx, msg)
}

// QueryPairingProviderEpochCu implements 'q pairing provider-epoch-cu'
func (ts *Tester) QueryPairingProviderEpochCu(provider string, project string, chainID string) (*pairingtypes.QueryProvidersEpochCuResponse, error) {
msg := &pairingtypes.QueryProvidersEpochCuRequest{}
return ts.Keepers.Pairing.ProvidersEpochCu(ts.GoCtx, msg)
}

// QueryPairingSubscriptionMonthlyPayout implements 'q pairing subscription-monthly-payout'
func (ts *Tester) QueryPairingSubscriptionMonthlyPayout(consumer string) (*pairingtypes.QuerySubscriptionMonthlyPayoutResponse, error) {
msg := &pairingtypes.QuerySubscriptionMonthlyPayoutRequest{
Expand Down
Loading

0 comments on commit c665e6a

Please sign in to comment.