Skip to content

Commit

Permalink
[Tokenomics] Refactoring claim settlement to enable Token Logic Modul…
Browse files Browse the repository at this point in the history
…es (#708)


_NOTE: No actual changes in minting/burning amounts were created_
- Rename `SettleSessionAccounting` to `ProcessTokenLogicModules
- Modularize the `TokenLogicModules` so we can start adding the different modules
- Introduced a global mint + distribution function (set to 0 right now) as a foundation for how we can distribute minted 
  rewards across different actors
- The core logic is in `x/tokenomics/keeper/token_logic_modules.go`

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Redouane Lakrache <[email protected]>
Co-authored-by: Dima K. <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Aug 7, 2024
1 parent 6ae0523 commit e07cb5f
Show file tree
Hide file tree
Showing 42 changed files with 1,135 additions and 482 deletions.
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
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

0 comments on commit e07cb5f

Please sign in to comment.