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] Refactoring claim settlement to enable Token Logic Modules #708

Merged
merged 51 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
a40ada7
WIP
Olshansk Jul 21, 2024
259a0db
Merge with main
Olshansk Jul 25, 2024
96a45a5
Early WIP
Olshansk Jul 26, 2024
7d49bb3
Work session with ramiro
Olshansk Jul 26, 2024
7cd7885
Merge with main
Olshansk Jul 30, 2024
8b33993
Code mostly cleaned up
Olshansk Jul 31, 2024
2a2f5e5
Compiles
Olshansk Jul 31, 2024
f09cbab
Unit tests beginning to pass
Olshansk Jul 31, 2024
beed2f7
Properly parsing consensus address
Olshansk Jul 31, 2024
c2ab024
Properly parsing consensus address
Olshansk Jul 31, 2024
0831311
Removed extra burn
Olshansk Jul 31, 2024
fe30985
Removed extra burn
Olshansk Jul 31, 2024
9247101
Fixed more unit tests
Olshansk Jul 31, 2024
757a84a
Tokenomic unit tests pass
Olshansk Jul 31, 2024
eade404
Update x/tokenomics/keeper/token_logic_modules.go
Olshansk Aug 2, 2024
66fb467
Update x/tokenomics/keeper/token_logic_modules.go
Olshansk Aug 2, 2024
b6310f0
[Quick PR] Add authz authorizations for core modules param changes (#…
okdas Jul 31, 2024
937d956
build(deps): bump github.com/docker/docker from 27.0.3+incompatible t…
dependabot[bot] Jul 31, 2024
adca883
Replying to review comments
Olshansk Aug 2, 2024
e029a5d
Compute units -> relays
Olshansk Aug 2, 2024
095e913
Merge branch 'main' into token_logic_module_base
Olshansk Aug 2, 2024
c902ef8
Update tests after fixing red0ne's bug
Olshansk Aug 2, 2024
362434b
Merge branch 'main' into token_logic_module_base
Olshansk Aug 5, 2024
45bba6d
Replying to review comments
Olshansk Aug 5, 2024
192521a
Reply to Red0ne's comment: https://github.com/pokt-network/poktroll/p…
Olshansk Aug 5, 2024
3253ba5
Empty commit
Olshansk Aug 5, 2024
9d0aa62
Skip flaky tests
Olshansk Aug 6, 2024
18d5276
Fixing flaky tests
Olshansk Aug 6, 2024
322d4c8
Fixing more tests
Olshansk Aug 6, 2024
cec5a90
More timeouts
Olshansk Aug 6, 2024
4cc2c3c
Self review
Olshansk Aug 6, 2024
4cf0a8a
Merge with skip_flaky_tests
Olshansk Aug 6, 2024
c6e25ed
Empty commit
Olshansk Aug 6, 2024
0058a8f
Empty commit
Olshansk Aug 6, 2024
6ea6974
fix another flaky test
Olshansk Aug 6, 2024
19dd7d1
Add source owners to genesis file
Olshansk Aug 6, 2024
ce7e2f9
Fixed TestFeatures/Relay_Namespace/
Olshansk Aug 6, 2024
b71809a
Merge branch 'skip_flaky_tests' into token_logic_module_base
Olshansk Aug 6, 2024
ab0ed2e
Update the show-service query and improve how we retrieve cupr from t…
Olshansk Aug 6, 2024
8447d4e
Verified tests work locally again
Olshansk Aug 7, 2024
7809bbf
Update pkg/relayer/session/sessiontree.go
Olshansk Aug 7, 2024
92d71b0
Reply to red0ne's comments
Olshansk Aug 7, 2024
4762ccb
Merge branch 'skip_flaky_tests' into token_logic_module_base
Olshansk Aug 7, 2024
2d50d85
Update TODOs in .proto files
Olshansk Aug 7, 2024
0d02517
Merge with main
Olshansk Aug 7, 2024
e82d432
Merge with main
Olshansk Aug 7, 2024
132391c
Merge with main
Olshansk Aug 7, 2024
e61849c
Fixed another test
Olshansk Aug 7, 2024
19258de
Fixed another test
Olshansk Aug 7, 2024
b0910c7
Comment out E2E test
Olshansk Aug 7, 2024
0f33c4f
Remove a breaking E2E test line
Olshansk Aug 7, 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
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -752,13 +752,13 @@ acc_balance_query: ## Query the balance of the account specified (make acc_balan

.PHONY: acc_balance_query_modules
acc_balance_query_modules: ## Query the balance of the network level module accounts
@echo "### Application ###"
@echo "### Application Module ###\n"
make acc_balance_query ACC=$(APPLICATION_MODULE_ADDRESS)
@echo "### Supplier ###"
@echo "### Supplier Module ###\n"
make acc_balance_query ACC=$(SUPPLIER_MODULE_ADDRESS)
@echo "### Gateway ###"
@echo "### Gateway Module ###\n"
make acc_balance_query ACC=$(GATEWAY_MODULE_ADDRESS)
@echo "### Service ###"
@echo "### Service Module ###\n"
make acc_balance_query ACC=$(SERVICE_MODULE_ADDRESS)

.PHONY: acc_balance_query_app1
Expand Down
4 changes: 3 additions & 1 deletion api/poktroll/shared/service.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func New(
//
// STAKING
//
// For provinding a different validator and consensus address codec, add it below.
// For providing a different validator and consensus address codec, add it below.
// By default the staking module uses the bech32 prefix provided in the auth config,
// and appends "valoper" and "valcons" for validator and consensus addresses respectively.
// When providing a custom address codec in auth, custom address codecs must be provided here as well.
Expand Down
48 changes: 33 additions & 15 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ accounts:
mnemonic: "elder spatial erosion soap athlete tide subject recipe also awkward head pattern cart version beach usual oxygen confirm erupt diamond maze smooth census garment"
coins:
- 300000000upokt
- name: source_owner_anvil
mnemonic: "burden effort glue note honey erupt fiscal vote gold addict toy flag spare wrap chest table bomb sort arena phone sadness sustain urge wink"
coins:
- 6900000000000upokt
- name: source_owner_ollama
mnemonic: "initial scorpion soccer decrease sorry convince donor canoe bid pill monster today cycle slot judge bulb dismiss reject hurt mesh glare fork sustain wash"
coins:
- 6900000000000upokt
- name: unauthorized
mnemonic: "abuse tumble whip pioneer immense pipe method note upon glory switch rail metal camp gasp top require rain party total struggle glance between fossil"
coins:
Expand Down Expand Up @@ -87,9 +95,21 @@ validators:
# We can persist arbitrary genesis values via 1 to 1 mapping to genesis.json
genesis:
app_state:
# https://docs.cosmos.network/main/build/modules/mint
mint:
params:
mint_denom: upokt
# Note that in Pocket Network, the majority of the inflation/deflation
# comes from the utility of network, not just the validators that
# secure it. Therefore, the inflation params of x/mint are set to 0.
# See x/tokenomics for all details related to token inflation.
inflation_rate_change: "0.0"
inflation_max: "0.0"
inflation_min: "0.0"
# These parameters are included for posterity but commented out for clarity
# goal_bonded: "NA"
# blocks_per_year: "NA"
# max_supply: "NA"
staking:
params:
bond_denom: upokt
Expand Down Expand Up @@ -140,12 +160,8 @@ genesis:
service_configs:
- service:
id: anvil
name: ""
compute_units_per_relay: 1
- service:
id: ollama
name: ""
compute_units_per_relay: 1
stake:
# NB: This value should be exactly 1upokt smaller than the value in
# `supplier1_stake_config.yaml` so that the stake command causes a state change.
Expand All @@ -155,22 +171,18 @@ genesis:
supplierList:
- address: pokt19a3t4yunp0dlpfjrp7qwnzwlrzd5fzs2gjaaaj
services:
- endpoints:
- service:
id: anvil
Copy link
Contributor

Choose a reason for hiding this comment

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

Only referencing the Service.Id makes sense and also raises the question about embedding full entities into others (the whole Service is embedded into the Supplier in this case) .

It pushes devs to use the embedded data instead of querying the source of truth.

You already solved one of these which was about the service's ComputeUnitsPerRelay where the dev used the value embedded in the Application.Services.ComputeUnitsPerRelay instead of fetching the Service which is the source of truth.

We should (at some point) only embed ids and enforce fetching the rest of the data from the SOT.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated some TODOs. PTAL

This also made me realize that onchain data structures are like micro-services.

endpoints:
- configs: []
rpc_type: JSON_RPC
url: http://relayminer1:8545
service:
compute_units_per_relay: 1
id: anvil
name: ""
- endpoints:
- service:
id: ollama
endpoints:
- configs: []
rpc_type: REST
url: http://relayminer1:8545
service:
compute_units_per_relay: 1
id: ollama
name: ""
stake:
# NB: This value should be exactly 1upokt smaller than the value in
# `application1_stake_config.yaml` so that the stake command causes a state change.
Expand All @@ -189,7 +201,13 @@ genesis:
add_service_fee: "1000000000"
serviceList:
- id: anvil
name: ""
name: "anvil"
compute_units_per_relay: 1
owner_address: pokt1cwnu460557x0z78jv3hhc7356hhkrgc86c87q5
- id: ollama
name: "ollama"
compute_units_per_relay: 1
owner_address: pokt1mx0klkkrj6v3dw8gs4nzlq0cq8lsktmx35t03e
proof:
params:
proof_request_probability: "0.25"
Expand Down
35 changes: 30 additions & 5 deletions e2e/tests/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/pokt-network/poktroll/testutil/yaml"
apptypes "github.com/pokt-network/poktroll/x/application/types"
prooftypes "github.com/pokt-network/poktroll/x/proof/types"
servicetypes "github.com/pokt-network/poktroll/x/service/types"
sessiontypes "github.com/pokt-network/poktroll/x/session/types"
shared "github.com/pokt-network/poktroll/x/shared"
sharedtypes "github.com/pokt-network/poktroll/x/shared/types"
Expand Down Expand Up @@ -359,15 +360,20 @@ func (s *suite) TheServiceRegisteredForApplicationHasAComputeUnitsPerRelayOf(ser
app, ok := accNameToAppMap[appName]
require.True(s, ok, "application %s not found", appName)

// CHeck if the application is registered for the service
isRegistered := false
for _, serviceConfig := range app.ServiceConfigs {
if serviceConfig.Service.Id == serviceId {
cupr, err := strconv.ParseUint(cuprStr, 10, 64)
require.NoError(s, err)
require.Equal(s, cupr, serviceConfig.Service.ComputeUnitsPerRelay)
return
isRegistered = true
break
}
}
s.Fatalf("ERROR: service %s is not registered for application %s", serviceId, appName)
require.True(s, isRegistered, "application %s is not registered for service %s", appName, serviceId)

cuprActual := s.getServiceComputeUnitsPerRelay(serviceId)
cuprExpected, err := strconv.ParseUint(cuprStr, 10, 64)
require.NoError(s, err)
require.Equal(s, cuprExpected, cuprActual, "compute units per relay for service %s is not %d", serviceId, cuprExpected)
}

func (s *suite) TheUserVerifiesTheForAccountIsNotStaked(actorType, accName string) {
Expand Down Expand Up @@ -682,6 +688,25 @@ func (s *suite) getSupplierUnbondingHeight(accName string) int64 {
return unbondingHeight
}

// getServiceComputeUnitsPerRelay returns the compute units per relay for a given service ID
func (s *suite) getServiceComputeUnitsPerRelay(serviceId string) uint64 {
args := []string{
"query",
"service",
"show-service",
serviceId,
"--output=json",
}

res, err := s.pocketd.RunCommandOnHostWithRetry("", numQueryRetries, args...)
require.NoError(s, err, "error getting shared module params")

var resp servicetypes.QueryGetServiceResponse
responseBz := []byte(strings.TrimSpace(res.Stdout))
s.cdc.MustUnmarshalJSON(responseBz, &resp)
return resp.Service.ComputeUnitsPerRelay
}

// accBalanceKey is a helper function to create a key to store the balance
// for accName in the context of a scenario state.
func accBalanceKey(accName string) string {
Expand Down
15 changes: 8 additions & 7 deletions e2e/tests/relay.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ Feature: Relay Namespace
And the session for application "app1" and service "anvil" contains the supplier "supplier1"
Then the application "app1" sends the supplier "supplier1" a successful request for service "anvil" with path "" and data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'

Scenario: App can send a REST relay to Supplier
Given the user has the pocketd binary installed
And the application "app1" is staked for service "ollama"
And the supplier "supplier1" is staked for service "ollama"
And the session for application "app1" and service "ollama" contains the supplier "supplier1"
When the application "app1" sends the supplier "supplier1" a successful request for service "ollama" with path "/api/chat" and data '{"model": "qwen:0.5b", "stream": false, "messages": [{"role": "user", "content":"count from 1 to 10"}]}'
And a "tokenomics" module "ClaimSettled" end block event is broadcast
# TODO(#727): Add this test back.
# Scenario: App can send a REST relay to Supplier
# Given the user has the pocketd binary installed
# And the application "app1" is staked for service "ollama"
# And the supplier "supplier1" is staked for service "ollama"
# And the session for application "app1" and service "ollama" contains the supplier "supplier1"
# When the application "app1" sends the supplier "supplier1" a successful request for service "ollama" with path "/api/chat" and data '{"model": "qwen:0.5b", "stream": false, "messages": [{"role": "user", "content":"count from 1 to 10"}]}'
# And a "tokenomics" module "ClaimSettled" end block event is broadcast

# TODO_TEST(@Olshansk):
# - Successful relay through applicat's sovereign appgate server
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ require (
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/cometbft/cometbft-db v0.9.1 // indirect
github.com/containerd/continuity v0.4.2 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.15.1 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
Expand Down Expand Up @@ -263,7 +264,7 @@ require (
github.com/vbatts/tar-split v0.11.5 // indirect
github.com/zondax/hid v0.9.2 // indirect
github.com/zondax/ledger-go v0.14.3 // indirect
go.etcd.io/bbolt v1.3.8 // indirect
go.etcd.io/bbolt v1.3.10 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ github.com/cometbft/cometbft v0.38.7 h1:ULhIOJ9+LgSy6nLekhq9ae3juX3NnQUMMPyVdhZV
github.com/cometbft/cometbft v0.38.7/go.mod h1:HIyf811dFMI73IE0F7RrnY/Fr+d1+HuJAgtkEpQjCMY=
github.com/cometbft/cometbft-db v0.9.1 h1:MIhVX5ja5bXNHF8EYrThkG9F7r9kSfv8BX4LWaxWJ4M=
github.com/cometbft/cometbft-db v0.9.1/go.mod h1:iliyWaoV0mRwBJoizElCwwRA9Tf7jZJOURcRZF9m60U=
github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvAXZJ/eg=
github.com/containerd/continuity v0.3.0/go.mod h1:wJEAIwKOm/pBZuBd0JmeTvnLquTB1Ag8espWhkykbPM=
github.com/containerd/continuity v0.4.2 h1:v3y/4Yz5jwnvqPKJJ+7Wf93fyWoCB3F5EclWG023MDM=
github.com/containerd/continuity v0.4.2/go.mod h1:F6PTNCKepoxEaXLQp3wDAjygEnImnZ/7o4JzpodfroQ=
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
github.com/containerd/stargz-snapshotter/estargz v0.15.1 h1:eXJjw9RbkLFgioVaTG+G/ZW/0kEe2oEKCdS/ZxIyoCU=
Expand Down Expand Up @@ -1160,8 +1160,8 @@ github.com/zondax/hid v0.9.2/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWp
github.com/zondax/ledger-go v0.14.3 h1:wEpJt2CEcBJ428md/5MgSLsXLBos98sBOyxNmCjfUCw=
github.com/zondax/ledger-go v0.14.3/go.mod h1:IKKaoxupuB43g4NxeQmbLXv7T9AlQyie1UpHb342ycI=
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/bbolt v1.3.8 h1:xs88BrvEv273UsB79e0hcVrlUWmS0a8upikMFhSyAtA=
go.etcd.io/bbolt v1.3.8/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw=
go.etcd.io/bbolt v1.3.10 h1:+BqfJTcCzTItrop8mq/lbzL8wSGtj94UO/3U31shqG0=
go.etcd.io/bbolt v1.3.10/go.mod h1:bK3UQLPJZly7IlNmV7uVHJDxfe5aK9Ll93e/74Y9oEQ=
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
Expand Down
2 changes: 1 addition & 1 deletion localnet/grafana-dashboards/claim_proof_logs.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"uid": "P8E80F9AEF21F6940"
},
"editorMode": "builder",
"expr": "{container=\"poktrolld-validator\"} | json | method = `SettleSessionAccounting`",
"expr": "{container=\"poktrolld-validator\"} | json | method = `ProcessTokenLogicModules`",
"queryType": "range",
"refId": "Claim Settlement"
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/crypto/protocol/hasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ const (
RelayHasherSize = sha256.Size
TrieHasherSize = sha256.Size
TrieRootSize = TrieHasherSize + trieRootMetadataSize
TrieRootSumSize = 8 // TODO_CONSIDERATION: Export this from the SMT package.
trieRootMetadataSize = 16 // TODO_CONSIDERATION: Export this from the SMT package.

)

var (
Expand Down
7 changes: 4 additions & 3 deletions pkg/relayer/miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ type miner struct {

// relay_difficulty is the target hash which a relay hash must be less than to be volume/reward applicable.
//
// TODO_MAINNET(#543): This is populated by querying the corresponding on-chain parameter during construction.
// If this parameter is updated on-chain the relayminer will need to be restarted to query the new value.
// TODO_FOLLOWUP(@olshansk, #690): This needs to be maintained (and updated) on a per service level.
// TODO_BETA(#705): This is populated by querying the corresponding on-chain parameter during construction.
// If this parameter is updated on-chain the relayminer will need to be restarted to query the new value.
// TODO_BETA(#705): This needs to be maintained (and updated) on a per service level.
// Make sure to update the `smst.Update` call in `relayer/session` alongside it.
relayDifficultyTargetHash []byte
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/relayer/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ func (rs *relayerSessionsManager) mapAddMinedRelayToSessionTree(
With("application", smst.GetSessionHeader().GetApplicationAddress()).
With("supplier_address", smst.GetSupplierAddress().String())

// TODO_BETA(#705): Make sure to update the weight of each relay to the value
// associated with `relayDifficultyTargetHash` in the `miner/miner.go`.
if err := smst.Update(relay.Hash, relay.Bytes, 1); err != nil {
// TODO_IMPROVE: log additional info?
logger.Error().Err(err).Msg("failed to update smt")
Expand Down
4 changes: 3 additions & 1 deletion proto/poktroll/shared/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ message Service {
// 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_BETA: Name is currently unused but acts as a reminder that an optional onchain representation of the service is necessary
// TODO_MAINNET: Remove this.
string name = 2; // (Optional) Semantic human readable name for the service

// The cost of a single relay for this service in terms of compute units.
Expand All @@ -30,6 +30,7 @@ message Service {

// ApplicationServiceConfig holds the service configuration the application stakes for
message ApplicationServiceConfig {
// TODO_MAINNET: Avoid embedding the full Service because we just need the ID.
Service service = 1; // The Service for which the application is configured

// TODO_MAINNET: There is an opportunity for applications to advertise the max
Expand All @@ -39,6 +40,7 @@ message ApplicationServiceConfig {

// SupplierServiceConfig holds the service configuration the supplier stakes for
message SupplierServiceConfig {
// TODO_MAINNET: Avoid embedding the full Service because we just need the ID.
Service service = 1; // The Service for which the supplier is configured
repeated SupplierEndpoint endpoints = 2; // List of endpoints for the service
// TODO_MAINNET: There is an opportunity for supplier to advertise the min
Expand Down
Loading
Loading