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] Harden settlement (part 1: TLM isolation) #889

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

bryanchriswhite
Copy link
Contributor

@bryanchriswhite bryanchriswhite commented Oct 22, 2024

Summary

Refactors claim settlement and token logic module processing:

  • Isolates TLM processors from the tokenomics keeper
  • Restructures settlement and TLM processing to avoid non-determinism
  • Consolidates and postpones ALL state modification until the end of settlement

Issue

Type of change

Select one or more from the following:

Testing

  • Documentation: make docusaurus_start; only needed if you make doc changes
  • Unit Tests: make go_develop_and_test
  • LocalNet E2E Tests: make test_e2e
  • DevNet E2E Tests: Add the devnet-test-e2e label to the PR.

Sanity Checklist

  • I have tested my changes using the available tooling
  • I have commented my code
  • I have performed a self-review of my own code; both comments & source code
  • I create and reference any new tickets, if applicable
  • I have left TODOs throughout the codebase, if applicable

@bryanchriswhite bryanchriswhite added on-chain On-chain business logic code health Cleans up some code devnet-test-e2e tokenomics Token Economics - what else do you need? labels Oct 22, 2024
@bryanchriswhite bryanchriswhite self-assigned this Oct 22, 2024
Copy link

The CI will now also run the e2e tests on devnet, which increases the time it takes to complete all CI checks.

You may need to run make trigger_ci to submit an empty commit that'll trigger the tests.

GCP workloads (requires changing the namespace to 889)
Grafana network dashboard for devnet-issue-889

@github-actions github-actions bot added devnet push-image CI related - pushes images to ghcr.io labels Oct 22, 2024
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

linter-name (fail-on-found)

x/tokenomics/token_logic_module/result.go|76 col 4| // TODO_IN_THIS_COMMIT: godoc...
x/tokenomics/token_logic_module/result.go|88 col 4| // TODO_IN_THIS_COMMIT: godoc...
x/tokenomics/token_logic_module/result.go|93 col 4| // TODO_IN_THIS_COMMIT: godoc...
x/tokenomics/token_logic_module/result.go|98 col 4| // TODO_IN_THIS_COMMIT: godoc...
x/tokenomics/token_logic_module/result.go|103 col 4| // TODO_IN_THIS_COMMIT: godoc...
x/tokenomics/token_logic_module/result.go|108 col 4| // TODO_IN_THIS_COMMIT: godoc...
x/tokenomics/token_logic_module/result.go|113 col 4| // TODO_IN_THIS_COMMIT: godoc... use for determinstic loops
x/tokenomics/token_logic_module/result.go|118 col 4| // TODO_IN_THIS_COMMIT: godoc...
x/tokenomics/token_logic_module/result.go|123 col 4| // TODO_IN_THIS_COMMIT: godoc...
x/tokenomics/token_logic_module/result.go|128 col 4| // TODO_IN_THIS_COMMIT: godoc...
x/tokenomics/token_logic_module/result.go|133 col 4| // TODO_IN_THIS_COMMIT: godoc...
x/tokenomics/token_logic_module/result.go|138 col 4| // TODO_IN_THIS_COMMIT: godoc...
x/tokenomics/token_logic_module/result.go|152 col 4| // TODO_IN_THIS_COMMIT: godoc...
x/tokenomics/token_logic_module/result.go|166 col 4| // TODO_IN_THIS_COMMIT: godoc...
x/tokenomics/token_logic_module/result.go|172 col 4| // TODO_IN_THIS_COMMIT: godoc...
x/tokenomics/token_logic_module/result.go|180 col 4| // TODO_IN_THIS_COMMIT: godoc...
x/tokenomics/token_logic_module/result.go|188 col 4| // TODO_IN_THIS_COMMIT: godoc... use for determinstic loops
x/tokenomics/token_logic_module/result.go|196 col 4| // TODO_IN_THIS_COMMIT: godoc... // SHOULD NEVER be used for loops
x/tokenomics/token_logic_module/result.go|213 col 4| // TODO_IN_THIS_COMMIT: godoc... // SHOULD NEVER be used for loops

x/tokenomics/keeper/settle_pending_claims.go Outdated Show resolved Hide resolved
x/tokenomics/keeper/settle_pending_claims.go Outdated Show resolved Hide resolved
x/tokenomics/keeper/settle_pending_claims.go Outdated Show resolved Hide resolved
x/tokenomics/keeper/settle_pending_claims.go Outdated Show resolved Hide resolved
x/tokenomics/keeper/settle_pending_claims.go Outdated Show resolved Hide resolved
x/tokenomics/token_logic_module/result.go Outdated Show resolved Hide resolved
x/tokenomics/token_logic_module/result.go Outdated Show resolved Hide resolved
x/tokenomics/token_logic_module/result.go Outdated Show resolved Hide resolved
x/tokenomics/token_logic_module/result.go Outdated Show resolved Hide resolved
x/tokenomics/token_logic_module/result.go Outdated Show resolved Hide resolved
@bryanchriswhite bryanchriswhite linked an issue Oct 23, 2024 that may be closed by this pull request
6 tasks
testutil/keeper/tokenomics.go Outdated Show resolved Hide resolved
testutil/integration/options.go Outdated Show resolved Hide resolved
tests/integration/tokenomics/token_logic_modules_test.go Outdated Show resolved Hide resolved
x/tokenomics/token_logic_module/result.go Outdated Show resolved Hide resolved
x/tokenomics/token_logic_module/result.go Outdated Show resolved Hide resolved
x/tokenomics/token_logic_module/result.go Outdated Show resolved Hide resolved
x/tokenomics/token_logic_module/result.go Outdated Show resolved Hide resolved
x/tokenomics/token_logic_module/result.go Outdated Show resolved Hide resolved
x/tokenomics/token_logic_module/result.go Outdated Show resolved Hide resolved
x/tokenomics/token_logic_module/result.go Outdated Show resolved Hide resolved
testutil/sample/sample.go Outdated Show resolved Hide resolved
testutil/sample/sample.go Outdated Show resolved Hide resolved
testutil/sample/sample.go Outdated Show resolved Hide resolved
tests/integration/tokenomics/token_logic_modules_test.go Outdated Show resolved Hide resolved
tests/integration/tokenomics/token_logic_modules_test.go Outdated Show resolved Hide resolved
tests/integration/tokenomics/token_logic_modules_test.go Outdated Show resolved Hide resolved
tests/integration/tokenomics/token_logic_modules_test.go Outdated Show resolved Hide resolved
tests/integration/tokenomics/token_logic_modules_test.go Outdated Show resolved Hide resolved
x/tokenomics/token_logic_module/distribution.go Outdated Show resolved Hide resolved
x/tokenomics/token_logic_module/global_mint.go Outdated Show resolved Hide resolved
@bryanchriswhite bryanchriswhite marked this pull request as ready for review October 25, 2024 12:17
@bryanchriswhite
Copy link
Contributor Author

bryanchriswhite commented Oct 25, 2024

@red-0ne, @Olshansk, I still need to fix a few tests but otherwise I think this is ready for initial review.

@bryanchriswhite
Copy link
Contributor Author

Log entire PendingSettlementResult immediately prior to execution.

Copy link

gitguardian bot commented Oct 25, 2024

⚠️ GitGuardian has uncovered 2 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
14297015 Triggered Generic High Entropy Secret aecfe41 testutil/testclient/localnet.go View secret
12819930 Triggered Generic Password 3187418 localnet/kubernetes/observability-prometheus-stack.yaml View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

…tlement

# By Redouane Lakrache (3) and others
# Via GitHub
* pokt/main:
  [Observability] Foundation for load testing telemetry (#832)
  [Tokenomics] Implement Global Mint Reimbursement Request (#878)
  [Docs] Assign owners to all `TODO_BETA` (#898)
  [Supplier] Add supplier staking fee (#883)
  [Application] Single Service Applications (#886)

# Conflicts:
#	testutil/keeper/tokenomics.go
#	x/tokenomics/keeper/settle_pending_claims.go
#	x/tokenomics/keeper/token_logic_modules.go
#	x/tokenomics/keeper/token_logic_modules_test.go
#	x/tokenomics/module/abci.go
#	x/tokenomics/types/errors.go
@bryanchriswhite bryanchriswhite added push-image CI related - pushes images to ghcr.io devnet devnet-test-e2e and removed push-image CI related - pushes images to ghcr.io devnet devnet-test-e2e labels Nov 4, 2024
Copy link

github-actions bot commented Nov 4, 2024

The CI will now also run the e2e tests on devnet, which increases the time it takes to complete all CI checks.

You may need to run make trigger_ci to submit an empty commit that'll trigger the tests.

GCP workloads (requires changing the namespace to 889)
Grafana network dashboard for devnet-issue-889

Copy link

github-actions bot commented Nov 4, 2024

The image is going to be pushed after the next commit.

You can use make trigger_ci to push an empty commit.

If you also want to run E2E tests, please add devnet-test-e2e label.

# This is the address that will receive the dao/foundation rewards during claim settlement (global mint TLM).
# DEV_NOTE: This is a temporary solution which allows us to configure the dao reward address between networks
# (e.g. localnet, testnet, etc.)
# TODO_TECHDEBT: Make this a tokenomics module parameter.
Copy link
Member

Choose a reason for hiding this comment

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

This is pretty important and I'd rather do it sooner rather than later.

Would prefer that we add a PR (before this) and avoid this TECHDEBT altogether. Wouldn't that be easier/faster/cleaner?

Copy link
Member

Choose a reason for hiding this comment

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

@bryanchriswhite

  1. How long would you say it takes you to add a new param right now?
  2. Do you think there's a way (a need?) to streamline/automate [1] in some way?

[1] https://dev.poktroll.com/develop/developer_guide/adding_params?_highlight=para

@@ -1,6 +1,13 @@
version: 1
build:
main: cmd/poktrolld
ldflags:
# The dao reward address SHOULD match that of the "pnf" below (i.e. `make poktrolld_addr ACC_NAME=pnf`).
Copy link
Member

Choose a reason for hiding this comment

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

Why is this a SHOULD and not a MUST?

@@ -4,6 +4,15 @@ import (
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

// DaoRewardAddress is the address that will receive the dao/foundation rewards
// during claim settlement (global mint TLM). It is intended to be assigned via
// -ldflags="-X github.com/pokt-network/poktroll/app.FoundationRewardAddress=<foundation_address>"
Copy link
Member

Choose a reason for hiding this comment

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

In config.yaml, the name is DaoRewardAddress and here its FoundationRewardAddress.

Per my other comment, I would like to avoid merging this flag-based approach to main altogether.

Copy link
Member

@Olshansk Olshansk left a comment

Choose a reason for hiding this comment

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

Really great work @bryanchriswhite!

My comments/messages are terse but I tried to go through the whole PR.

Overall, it's VERY clean. VERY easy to read. VERY well organized.

I honestly see no blockers and most of my comments are just minor NITS & comment improvements.

Again, very well designed 🔥

@@ -0,0 +1,5 @@
package token_logic_modules

// TODO_TEST(@bryanchriswhite): Settlement proceeds in the face of errors
Copy link
Member

Choose a reason for hiding this comment

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

  1. Please create tests w/ a skip inside of them (cleaner)
  2. Please add more details/steps on what you intended to test (it'll help you not to forget how to implement the test later)

# This is the address that will receive the dao/foundation rewards during claim settlement (global mint TLM).
# DEV_NOTE: This is a temporary solution which allows us to configure the dao reward address between networks
# (e.g. localnet, testnet, etc.)
# TODO_TECHDEBT: Make this a tokenomics module parameter.
Copy link
Member

Choose a reason for hiding this comment

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

Use TODO_TECHDEBT only when it's like a post mainnet and doesn't have a timeline sort of thing.

// TokenomicsKeepersOpt is a function which receives and potentially modifies the context
// and tokenomics keepers during construction of the aggregation.
type TokenomicsModuleKeepersOpt func(context.Context, *TokenomicsModuleKeepers) context.Context
// tokenomicsModuleKeepersConfig is a configuration struct for a TokenomicsModuleKeepers
Copy link
Member

Choose a reason for hiding this comment

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

Can you add test in the naming of all of these so its explicit its not for core business logic in prod?

}
}

func WithTLMProcessors(processors []tlm.TokenLogicModule) TokenomicsModuleKeepersOptFn {
Copy link
Member

Choose a reason for hiding this comment

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

godoc

@@ -38,6 +39,9 @@ var (
func init() {
cmd.InitSDKConfig()

// TODO_TECHDEBT: Remove once the DAO reward address is promoted to a tokenomics module param.
Copy link
Member

Choose a reason for hiding this comment

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

TODO_IN_THIS or PRIOR TO THIS

}

// The test description is a unique identifier for each permutation.
// E.g.: "permutaiton_1_of_2__TLMRelayBurnEqualsMint_TLMGlobalMint"
Copy link
Member

Choose a reason for hiding this comment

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

Thoughts on something like this?

Suggested change
// E.g.: "permutaiton_1_of_2__TLMRelayBurnEqualsMint_TLMGlobalMint"
// E.g.: "permutaiton_1_of_2:TLMRelayBurnEqualsMint_TLMGlobalMint"

s.createClaims(&s.keepers, 1000)
settledResults, expiredResults := s.settleClaims(t)

// Set the expected state based on the effects of the first iteration;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Set the expected state based on the effects of the first iteration;
// First iteration only.
// Set the expected state based on the effects of the first iteration.

settledResults, expiredResults := s.settleClaims(t)

// Set the expected state based on the effects of the first iteration;
// this decouples the assertions from any specific tlm effects.
Copy link
Member

Choose a reason for hiding this comment

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

Thoughts on actually having a function to assert on a results to make sure we don't assert on (for example) 0=0 everywhere?

keeper.WithApplication(*s.app),
keeper.WithSupplier(*s.supplier),
keeper.WithModuleParams(map[string]types.Msg{
// TODO_TECHDEBT: Set tokenomics mint allocation params to maximize coverage, once available.
Copy link
Member

Choose a reason for hiding this comment

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

TODO_BETA?

// assertExpectedSettlementState asserts that the current network state matches the
// expected settlement state, and that actualSettledResults and actualExpiredResults
// match their corresponding expectations.
func (s *tlmProcessorTestSuite) assertExpectedSettlementState(
Copy link
Member

Choose a reason for hiding this comment

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

Is there any way to update the test such that we moe forward one (or two) more sessions and confirm the state/balances are unchanged (since there are no new claims).

This is likely a different test, but just want to sanity checks the session start/end edge case + lingering claims.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code health Cleans up some code devnet devnet-test-e2e on-chain On-chain business logic push-image CI related - pushes images to ghcr.io tokenomics Token Economics - what else do you need?
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

[Tokenomics] Settlement safety
3 participants