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

[Tokenomics] SettleSessionAccounting first implementation (emissions=burn) #323

Merged
merged 68 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
6f32dac
move protox to the right place
Olshansk Dec 10, 2023
1d4e475
Merge branch 'main' into issues/243/update_tokenomics_module
Olshansk Dec 20, 2023
86cca4f
Fix proto imports
Olshansk Dec 20, 2023
f317d89
Merge branch 'main' into issues/243/update_tokenomics_module
Olshansk Dec 21, 2023
2c44d26
Documented the plan for this PR before I forget
Olshansk Dec 22, 2023
4b1d025
Merge branch 'main' into issues/243/update_tokenomics_module
Olshansk Jan 5, 2024
f2519ea
Merge branch 'main' into issues/243/update_tokenomics_module
Olshansk Jan 5, 2024
c8b4b6b
Merge branch 'main' into issues/243/update_tokenomics_module
Olshansk Jan 8, 2024
6364101
Update deps
Olshansk Jan 8, 2024
9620a24
Unit test for updating tokenomic params succeeds
Olshansk Jan 8, 2024
5b4949d
Added a placeholder for SettleSessionAccounting
Olshansk Jan 8, 2024
565195b
Rename Compute to ComputeUnits
Olshansk Jan 8, 2024
ee71f7d
Remove some unused comments
Olshansk Jan 8, 2024
7fe5ecb
Before scaffold
Olshansk Jan 8, 2024
0079a32
Ran the following command to fill in some missing gaps: ignite scaffo…
Olshansk Jan 10, 2024
581c947
Merge branch 'main' into issues/243/update_tokenomics_module
Olshansk Jan 10, 2024
7939b4c
Incomplete unit tests for parameter update passing
Olshansk Jan 10, 2024
1c32614
Checkpoint for the day
Olshansk Jan 11, 2024
fa80df8
Merge with main
Olshansk Jan 15, 2024
ee787d0
Update /msg_server_update_params_test.go and figurign some stuff out …
Olshansk Jan 15, 2024
4aca865
Unit tests passing
Olshansk Jan 16, 2024
fe9a645
Remove session accounting implementation
Olshansk Jan 16, 2024
4176971
Add session accounting implementation
Olshansk Jan 16, 2024
e32bc93
Completed self review
Olshansk Jan 16, 2024
ebf5a79
Merge branch 'issues/243/update_tokenomics_module' into issues/243/se…
Olshansk Jan 16, 2024
7d7cc8e
Unit tests in progress
Olshansk Jan 17, 2024
398e4d6
Update x/tokenomics/client/cli/tx_update_params.go
Olshansk Jan 18, 2024
cab8bee
change k8s DNS endpoint for celestia secret (#314)
okdas Jan 16, 2024
d95e1f7
[LocalNet] Add sequencer block persistence (#277)
okdas Jan 17, 2024
fd9662c
[Config, Docs] Add supplier staking config documentation (#318)
red-0ne Jan 18, 2024
4eeda85
[Docs] Add AppGateServer config documentation (#317)
red-0ne Jan 18, 2024
6d566eb
[Config, Docs] Add gateway staking config documentation (#321)
red-0ne Jan 18, 2024
eda0816
[Config, Docs] Add application staking config documentation (#320)
red-0ne Jan 18, 2024
629bf6c
Fixed some tests
Olshansk Jan 18, 2024
9a79163
Update proto/pocket/tokenomics/query.proto
Olshansk Jan 19, 2024
fa45776
Update Makefile
Olshansk Jan 19, 2024
f149a74
Update x/tokenomics/client/cli/tx_update_params.go
Olshansk Jan 19, 2024
4b8a5b5
Update x/tokenomics/keeper/keeper.go
Olshansk Jan 19, 2024
de19c54
Reply to some review comments
Olshansk Jan 19, 2024
1871007
Ran make go_imports and make go_lint
Olshansk Jan 19, 2024
526d90e
Merge with main
Olshansk Jan 19, 2024
bdbbcc8
Start multi-lining
Olshansk Jan 19, 2024
d1fcf9b
Renamed some tokenomics errors
Olshansk Jan 19, 2024
23fb106
Reply to PR review comments
Olshansk Jan 19, 2024
7972eef
foundation/pnf
Olshansk Jan 19, 2024
3f92915
Ran make go_imports and make go_lint
Olshansk Jan 19, 2024
d708df0
Fix outdated test
Olshansk Jan 19, 2024
90b5255
Merge with main
Olshansk Jan 19, 2024
9faf89c
Fix log usage
Olshansk Jan 19, 2024
05a8924
Update Makefile
Olshansk Jan 22, 2024
70eea62
fix: add yarn.lock (#334)
bryanchriswhite Jan 22, 2024
4b92864
[Off-chain] Simplify `TxClient` with `EventsQueryClient` (#330)
bryanchriswhite Jan 22, 2024
3e447db
Merge branch 'main' into issues/243/update_tokenomics_module
Olshansk Jan 22, 2024
3b74750
Merge with issues/243/update_tokenomics_module
Olshansk Jan 22, 2024
e980a64
Added x/session/types/session_header_test.go
Olshansk Jan 22, 2024
691f236
Unit tests passing
Olshansk Jan 23, 2024
a92ce85
Merge with master - not compiling yet
Olshansk Jan 24, 2024
db43050
Merge branch 'main' into issues/243/settle_session_accounting_impleme…
Olshansk Jan 24, 2024
5b90116
Reply to some review comments
Olshansk Jan 24, 2024
1d11fa2
Make go_test works again
Olshansk Jan 24, 2024
abe5173
Enforce smstRootSize
Olshansk Jan 24, 2024
aab2413
Merge branch 'main' into issues/243/settle_session_accounting_impleme…
Olshansk Jan 25, 2024
e1c8913
Update go.mod
Olshansk Jan 25, 2024
3082237
Merge branch 'main' into issues/243/settle_session_accounting_impleme…
Olshansk Jan 31, 2024
40a21f2
Added a WIP E2E test
Olshansk Feb 1, 2024
31aa811
Merge branch 'main' into issues/243/settle_session_accounting_impleme…
Olshansk Feb 1, 2024
ba4d76b
Update a couple comments
Olshansk Feb 1, 2024
6697a09
Merge with main and reply to some comments
Olshansk Feb 2, 2024
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
7 changes: 5 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"os"
"path/filepath"

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

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
dbm "github.com/cometbft/cometbft-db"
Expand Down Expand Up @@ -108,8 +110,6 @@ import (
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
solomachine "github.com/cosmos/ibc-go/v7/modules/light-clients/06-solomachine"
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
"github.com/spf13/cast"

appparams "github.com/pokt-network/poktroll/app/params"
"github.com/pokt-network/poktroll/docs"
applicationmodule "github.com/pokt-network/poktroll/x/application"
Expand All @@ -133,6 +133,7 @@ import (
tokenomicsmodule "github.com/pokt-network/poktroll/x/tokenomics"
tokenomicsmodulekeeper "github.com/pokt-network/poktroll/x/tokenomics/keeper"
tokenomicsmoduletypes "github.com/pokt-network/poktroll/x/tokenomics/types"
"github.com/spf13/cast"
)

const (
Expand Down Expand Up @@ -660,6 +661,8 @@ func New(
keys[tokenomicsmoduletypes.MemStoreKey],
app.GetSubspace(tokenomicsmoduletypes.ModuleName),
app.BankKeeper,
app.ApplicationKeeper,
app.SupplierKeeper,
authority,
)
tokenomicsModule := tokenomicsmodule.NewAppModule(appCodec, app.TokenomicsKeeper, app.AccountKeeper, app.BankKeeper)
Expand Down
26 changes: 8 additions & 18 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47184,7 +47184,7 @@ paths:
service:
title: >-
The Service for which the application is
configured
configured for
type: object
properties:
id:
Expand Down Expand Up @@ -47251,7 +47251,7 @@ paths:
service:
title: >-
The Service for which the supplier is
configured
configured for
type: object
properties:
id:
Expand Down Expand Up @@ -47287,14 +47287,12 @@ paths:
- GRPC
- WEBSOCKET
- JSON_RPC
- REST
default: UNKNOWN_RPC
description: |-
- UNKNOWN_RPC: Undefined RPC type
- GRPC: gRPC
- WEBSOCKET: WebSocket
- JSON_RPC: JSON-RPC
- REST: REST
configs:
type: array
items:
Expand Down Expand Up @@ -77918,7 +77916,7 @@ definitions:
type: object
properties:
service:
title: The Service for which the application is configured
title: The Service for which the application is configured for
type: object
properties:
id:
Expand Down Expand Up @@ -77982,7 +77980,7 @@ definitions:
type: object
properties:
service:
title: The Service for which the supplier is configured
title: The Service for which the supplier is configured for
type: object
properties:
id:
Expand Down Expand Up @@ -78017,14 +78015,12 @@ definitions:
- GRPC
- WEBSOCKET
- JSON_RPC
- REST
default: UNKNOWN_RPC
description: |-
- UNKNOWN_RPC: Undefined RPC type
- GRPC: gRPC
- WEBSOCKET: WebSocket
- JSON_RPC: JSON-RPC
- REST: REST
configs:
type: array
items:
Expand Down Expand Up @@ -78174,7 +78170,7 @@ definitions:
type: object
properties:
service:
title: The Service for which the application is configured
title: The Service for which the application is configured for
type: object
properties:
id:
Expand Down Expand Up @@ -78236,7 +78232,7 @@ definitions:
type: object
properties:
service:
title: The Service for which the supplier is configured
title: The Service for which the supplier is configured for
type: object
properties:
id:
Expand Down Expand Up @@ -78271,14 +78267,12 @@ definitions:
- GRPC
- WEBSOCKET
- JSON_RPC
- REST
default: UNKNOWN_RPC
description: |-
- UNKNOWN_RPC: Undefined RPC type
- GRPC: gRPC
- WEBSOCKET: WebSocket
- JSON_RPC: JSON-RPC
- REST: REST
configs:
type: array
items:
Expand Down Expand Up @@ -78425,7 +78419,6 @@ definitions:
- GRPC: gRPC
- WEBSOCKET: WebSocket
- JSON_RPC: JSON-RPC
- REST: REST
title: Enum to define RPC types
pocket.shared.Supplier:
type: object
Expand Down Expand Up @@ -78454,7 +78447,7 @@ definitions:
type: object
properties:
service:
title: The Service for which the supplier is configured
title: The Service for which the supplier is configured for
type: object
properties:
id:
Expand Down Expand Up @@ -78494,7 +78487,6 @@ definitions:
- GRPC: gRPC
- WEBSOCKET: WebSocket
- JSON_RPC: JSON-RPC
- REST: REST
configs:
type: array
items:
Expand Down Expand Up @@ -78553,7 +78545,6 @@ definitions:
- GRPC: gRPC
- WEBSOCKET: WebSocket
- JSON_RPC: JSON-RPC
- REST: REST
configs:
type: array
items:
Expand Down Expand Up @@ -78587,7 +78578,7 @@ definitions:
type: object
properties:
service:
title: The Service for which the supplier is configured
title: The Service for which the supplier is configured for
type: object
properties:
id:
Expand Down Expand Up @@ -78626,7 +78617,6 @@ definitions:
- GRPC: gRPC
- WEBSOCKET: WebSocket
- JSON_RPC: JSON-RPC
- REST: REST
configs:
type: array
items:
Expand Down
5 changes: 3 additions & 2 deletions e2e/tests/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ import (

tmcli "github.com/cometbft/cometbft/libs/cli"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/regen-network/gocuke"
"github.com/stretchr/testify/require"

"github.com/pokt-network/poktroll/app"
"github.com/pokt-network/poktroll/testutil/testclient"
apptypes "github.com/pokt-network/poktroll/x/application/types"
sessiontypes "github.com/pokt-network/poktroll/x/session/types"
sharedtypes "github.com/pokt-network/poktroll/x/shared/types"
suppliertypes "github.com/pokt-network/poktroll/x/supplier/types"
"github.com/regen-network/gocuke"
"github.com/stretchr/testify/require"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/session.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Feature: Session Namespace
Scenario: Supplier completes claim/proof lifecycle for a valid session
Given the user has the pocketd binary installed
When the supplier "supplier1" has serviced a session with "5" relays for service "svc1" for application "app1"
And after the supplier creates a claim for the session for service "svc1" for application "app1"
And the user should wait for "5" seconds
Then the claim created by supplier "supplier1" for service "svc1" for application "app1" should be persisted on-chain
# TODO_IMPROVE: ...
# And an event should be emitted...
Expand Down
13 changes: 13 additions & 0 deletions e2e/tests/tokenomics.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Feature: Tokenomics Namespaces

# This test
Scenario: Basic tokenomics validation that Supplier mint equals Application burn
Given the user has the pocketd binary installed
And an account exists for "supplier1"
And an account exists for "app1"
When the supplier "supplier1" has serviced a session with "20" relays for service "svc1" for application "app1"
And the user should wait for "5" seconds
# TODO_UPNEXT(@Olshansk, #359): Expand on the two expectations below after integrating the tokenomics module
# into the supplier module.
# Then the account balance of "supplier1" should be "1000" uPOKT "more" than before
# And the account balance of "app1" should be "1000" uPOKT "less" than before
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ require (
github.com/athanorlabs/go-dleq v0.1.0
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.5
github.com/cosmos/gogoproto v1.4.11
github.com/cosmos/ibc-go/v7 v7.3.1
Expand All @@ -50,6 +51,7 @@ require (
golang.org/x/crypto v0.15.0
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
golang.org/x/sync v0.5.0
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb
google.golang.org/grpc v1.59.0
gopkg.in/yaml.v2 v2.4.0
)
Expand Down Expand Up @@ -96,7 +98,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 @@ -293,7 +294,6 @@ require (
google.golang.org/api v0.143.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
7 changes: 6 additions & 1 deletion pkg/sdk/errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package sdk

import sdkerrors "cosmossdk.io/errors"
import (
sdkerrors "cosmossdk.io/errors"
)

// TODO_TECHDEBT: Do a source code wise find-replace using regex pattern match
// of `sdkerrors\.Wrapf\(([a-zA-Z]+), ` with `$1.Wrapf(`

var (
codespace = "poktrollsdk"
Expand Down
63 changes: 55 additions & 8 deletions testutil/keeper/tokenomics.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,71 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"

"github.com/pokt-network/poktroll/testutil/sample"
mocks "github.com/pokt-network/poktroll/testutil/tokenomics/mocks"
apptypes "github.com/pokt-network/poktroll/x/application/types"
sharedtypes "github.com/pokt-network/poktroll/x/shared/types"
suppliertypes "github.com/pokt-network/poktroll/x/supplier/types"
"github.com/pokt-network/poktroll/x/tokenomics/keeper"
"github.com/pokt-network/poktroll/x/tokenomics/types"
)

func TokenomicsKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
func TokenomicsKeeper(t testing.TB) (
k *keeper.Keeper, s sdk.Context,
appAddr, supplierAddr string,
) {
storeKey := sdk.NewKVStoreKey(types.StoreKey)
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)

// Initialize the in-memory tendermint database
db := tmdb.NewMemDB()
stateStore := store.NewCommitMultiStore(db)
stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db)
stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil)
require.NoError(t, stateStore.LoadLatestVersion())

// Initialize the codec and other necessary components
registry := codectypes.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(registry)
ctrl := gomock.NewController(t)

// The on-chain governance address
authority := authtypes.NewModuleAddress("gov").String()

ctrl := gomock.NewController(t)
// Prepare the test application
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think referencing:

So you can control applications/suppliers in tests and modify the methods with custom DoAndReturn methods will help you better catch some errors. Maybe not applicable here, just a thought.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tl;dr Thought about it but do not believe it is worth the tradeoff in this chase.

cc @bryanchriswhite for additional thoughts or pushback.


I can steelman both sides here.

Firstly, I always bias to writing less code wherever possible: less code => less bugs => less to maintain => less to learn => more time on other things.

With that said, Complex state management in mocks is nice when you're testing some business logic, but in this specific instance, I feel that:

  1. I would spend a lot of time implementing this business logic, which will be quickly deprecated by in-memory testing network
  2. A single e2e test might provide just as much benefit
  3. I documented the unit tests (in x/tokenomics/keeper/settle_session_accounting_test.go) that I want to add once we have (1)
  4. There is the risk of that logic having bugs too.

It's a very delicate balance and don't think there's a definitive answer to when to do which one.

application := apptypes.Application{
Address: sample.AccAddress(),
Stake: &sdk.Coin{Denom: "upokt", Amount: sdk.NewInt(100000)},
}

// Prepare the test supplier
supplier := sharedtypes.Supplier{
Address: sample.AccAddress(),
Stake: &sdk.Coin{Denom: "upokt", Amount: sdk.NewInt(100000)},
}

// Mock the application keeper
mockApplicationKeeper := mocks.NewMockApplicationKeeper(ctrl)
mockApplicationKeeper.EXPECT().
GetApplication(gomock.Any(), gomock.Eq(application.Address)).
Return(application, true).
AnyTimes()
mockApplicationKeeper.EXPECT().
GetApplication(gomock.Any(), gomock.Not(application.Address)).
Return(apptypes.Application{}, false).
AnyTimes()
mockApplicationKeeper.EXPECT().
SetApplication(gomock.Any(), gomock.Any()).
AnyTimes()
Olshansk marked this conversation as resolved.
Show resolved Hide resolved

// Mock the supplier keeper
mockSupplierKeeper := mocks.NewMockSupplierKeeper(ctrl)
mockSupplierKeeper.EXPECT().
GetSupplier(gomock.Any(), supplier.Address).
Return(supplier, true).
AnyTimes()

// Mock the bank keeper
mockBankKeeper := mocks.NewMockBankKeeper(ctrl)
mockBankKeeper.EXPECT().
MintCoins(gomock.Any(), gomock.Any(), gomock.Any()).
Expand All @@ -45,36 +89,39 @@ func TokenomicsKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
BurnCoins(gomock.Any(), gomock.Any(), gomock.Any()).
AnyTimes()
mockBankKeeper.EXPECT().
SendCoinsFromModuleToAccount(gomock.Any(), gomock.Any(), types.ModuleName, gomock.Any()).
SendCoinsFromModuleToAccount(gomock.Any(), suppliertypes.ModuleName, gomock.Any(), gomock.Any()).
AnyTimes()
mockBankKeeper.EXPECT().
SendCoinsFromModuleToModule(gomock.Any(), types.ModuleName, gomock.Any(), gomock.Any()).
SendCoinsFromAccountToModule(gomock.Any(), gomock.Any(), apptypes.ModuleName, gomock.Any()).
AnyTimes()
mockBankKeeper.EXPECT().
SendCoinsFromAccountToModule(gomock.Any(), types.ModuleName, gomock.Any(), gomock.Any()).
UndelegateCoinsFromModuleToAccount(gomock.Any(), apptypes.ModuleName, gomock.Any(), gomock.Any()).
AnyTimes()

// Initialize the tokenomics keeper
paramsSubspace := typesparams.NewSubspace(cdc,
types.Amino,
storeKey,
memStoreKey,
"TokenomicsParams",
)
k := keeper.NewKeeper(
tokenomicsKeeper := keeper.NewKeeper(
cdc,
storeKey,
memStoreKey,
paramsSubspace,

mockBankKeeper,
mockApplicationKeeper,
mockSupplierKeeper,

authority,
)

ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())

// Initialize params
k.SetParams(ctx, types.DefaultParams())
tokenomicsKeeper.SetParams(ctx, types.DefaultParams())

return k, ctx
return tokenomicsKeeper, ctx, application.Address, supplier.Address
}
1 change: 1 addition & 0 deletions x/session/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ var (
ErrSessionInvalidAppAddress = sdkerrors.Register(ModuleName, 5, "invalid application address for session")
ErrSessionInvalidService = sdkerrors.Register(ModuleName, 6, "invalid service in session")
ErrSessionInvalidBlockHeight = sdkerrors.Register(ModuleName, 7, "invalid block height for session")
ErrSessionInvalidSessionId = sdkerrors.Register(ModuleName, 8, "invalid sessionId")
)
Loading
Loading