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

[LocalNet] Add gas fees #940

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ acc_balance_total_supply: ## Query the total supply of the network
# (PNF was selected ambigously) to make sure their public keys are populated.
# TODO_TECHDEBT: One of the accounts involved in this command always errors
# so we need to understand why and fix it.


.PHONY: acc_initialize_pubkeys
acc_initialize_pubkeys: ## Make sure the account keeper has public keys for all available accounts
$(eval ADDRESSES=$(shell make -s ignite_acc_list | grep pokt | awk '{printf "%s ", $$2}' | sed 's/.$$//'))
Expand All @@ -268,8 +270,10 @@ acc_initialize_pubkeys: ## Make sure the account keeper has public keys for all
poktrolld tx bank send \
$(addr) $(PNF_ADDRESS) 1000upokt \
--yes \
--gas=auto \
--gas-prices=0.000000001upokt \
--home=$(POKTROLLD_HOME) \
--node $(POCKET_NODE);)
--node=$(POCKET_NODE);)

######################
### Ignite Helpers ###
Expand Down
2 changes: 1 addition & 1 deletion api/poktroll/application/tx.pulsar.go

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

3 changes: 3 additions & 0 deletions cmd/poktrolld/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ func txCommand() *cobra.Command {
authcmd.GetDecodeCommand(),
authcmd.GetSimulateCmd(),
)

// TODO_TECHDEBT: doesn't seem changing flags here has any effect (as commands use `flags.AddTxFlagsToCmd(cmd)`)
// consider moving to `clientconfig.DefaultClientConfigTemplate` and `initClientConfig()` on newer cosmos-sdk versions (currently at v0.50.9)
cmd.PersistentFlags().String(flags.FlagChainID, DefaultChainID, "The network chain ID")

return cmd
Expand Down
64 changes: 64 additions & 0 deletions cmd/poktrolld/cmd/config.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package cmd

import (
"strings"
"sync"
"time"

cmtcfg "github.com/cometbft/cometbft/config"
clientconfig "github.com/cosmos/cosmos-sdk/client/config"
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
sdk "github.com/cosmos/cosmos-sdk/types"

Expand Down Expand Up @@ -176,3 +178,65 @@ func customPoktrollAppConfigTemplate() string {
cardinality-level = "{{ .Poktroll.Telemetry.CardinalityLevel }}"
`
}

// initClientConfig helps to override default client config (client.toml) template and configs.
// Allows to dynamically create client.toml file with custom values.
// TODO_TECHDEBT: make use of this with `clientconfig.DefaultClientConfigTemplate` on newer cosmos-sdk versions (currently at v0.50.9)
func initClientConfig() (string, interface{}) {
type GasConfig struct {
GasAdjustment float64 `mapstructure:"gas-adjustment"`
Gas string `mapstructure:"gas"`
}

type CustomClientConfig struct {
clientconfig.ClientConfig `mapstructure:",squash"`

GasConfig GasConfig `mapstructure:"gas"`
}

// Default configuration from cosmos-sdk
clientCfg := clientconfig.DefaultConfig()
// clientCfg.ChainID = "" TODO_MAINNET: set mainnet chain-id

// Now we set the custom config default values.
customClientConfig := CustomClientConfig{
ClientConfig: *clientCfg,
GasConfig: GasConfig{
GasAdjustment: 1.5, // default is 1.
Gas: "auto", // default is 200000
},
}

// According to cosmos-sdk documentation, the template is exported via clientconfig.DefaultClientConfigTemplate,
// however as of 0.50.9 - it is not, so we're copying their template.
// TODO_TECHDEBT: switch to `clientconfig.DefaultClientConfigTemplate` on newer cosmos-sdk versions.
defaultConfigTemplate := `# This is a TOML config file.
# For more information, see https://github.com/toml-lang/toml

###############################################################################
### Client Configuration ###
###############################################################################

# The network chain ID
chain-id = "{{ .ChainID }}"
# The keyring's backend, where the keys are stored (os|file|kwallet|pass|test|memory)
keyring-backend = "{{ .KeyringBackend }}"
# CLI output format (text|json)
output = "{{ .Output }}"
# <host>:<port> to CometBFT RPC interface for this chain
node = "{{ .Node }}"
# Transaction broadcasting mode (sync|async)
broadcast-mode = "{{ .BroadcastMode }}"
`

// Adding our custom config template
customClientConfigTemplate := defaultConfigTemplate + strings.TrimSpace(`
# This is default the gas adjustment factor used in tx commands.
# It can be overwritten by the --gas-adjustment flag in each tx command.
gas-adjustment = {{ .GasConfig.GasAdjustment }}
# Gas limit to set per-transaction; set to "auto" to calculate sufficient gas automatically
gas = "{{ .GasConfig.Gas }}"
`)

return customClientConfigTemplate, customClientConfig
}
5 changes: 1 addition & 4 deletions cmd/poktrolld/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func NewRootCmd() *cobra.Command {
return err
}

// TODO_TECHDEBT: switch to `config.CreateClientConfig` on newer cosmos-sdk versions. Make use of `initClientConfig()`
clientCtx, err = config.ReadFromClientConfig(clientCtx)
if err != nil {
return err
Expand All @@ -99,10 +100,6 @@ func NewRootCmd() *cobra.Command {
return err
}

if err = client.SetCmdClientContextHandler(clientCtx, cmd); err != nil {
return err
}

customAppTemplate, customAppConfig := initAppConfig()
customCMTConfig := initCometBFTConfig()

Expand Down
2 changes: 1 addition & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ validators:
# DEV_NOTE: Ignite does not carry over all defaults, so we are going to match `minimum-gas-prices` with `cmd/config.go`.
# See the enhancement request here: https://github.com/ignite/cli/issues/4340
# TODO_BETA(@okdas, #794): turn on `minimum-gas-prices` back
# minimum-gas-prices: 0.000000001upokt
minimum-gas-prices: 0.000000001upokt
telemetry:
enabled: true
poktroll:
Expand Down
10 changes: 5 additions & 5 deletions e2e/tests/0_settlement.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Feature: Tokenomics Namespace
And the "proof" module parameters are set as follows
| name | value | type |
| proof_request_probability | 0.25 | float |
| proof_requirement_threshold | 839 | coin |
| proof_missing_penalty | 320 | coin |
| proof_requirement_threshold | 839000000 | coin |
| proof_missing_penalty | 320000000 | coin |
| proof_submission_fee | 1000000 | coin |
And all "proof" module params should be updated
And the "shared" module parameters are set as follows
Expand Down Expand Up @@ -55,9 +55,9 @@ Feature: Tokenomics Namespace
# to make sure a proof is not required.
And the "proof" module parameters are set as follows
| name | value | type |
| proof_request_probability | 0 | float |
| proof_requirement_threshold | 421 | coin |
| proof_missing_penalty | 320 | coin |
| proof_request_probability | 0.25 | float |
| proof_requirement_threshold | 20000000 | coin |
| proof_missing_penalty | 320000000 | coin |
| proof_submission_fee | 1000000 | coin |
And all "proof" module params should be updated
And the "shared" module parameters are set as follows
Expand Down
3 changes: 3 additions & 0 deletions e2e/tests/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ func (s *suite) TheUserSendsUpoktFromAccountToAccount(amount int64, accName1, ac
fmt.Sprintf("%dupokt", amount),
keyRingFlag,
chainIdFlag,
"--gas=auto",
"--gas-prices=0.000001upokt",
"-y",
}
res, err := s.pocketd.RunCommandOnHost("", args...)
Expand Down Expand Up @@ -300,6 +302,7 @@ func (s *suite) TheUserStakesAWithUpoktForServiceFromTheAccount(actorType string
accName,
keyRingFlag,
chainIdFlag,
"--fees=1upokt",
"-y",
}
res, err := s.pocketd.RunCommandOnHost("", args...)
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/send.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Feature: Send Namespace
And the user should be able to see standard output containing "code: 0"
And the pocketd binary should exit without error
And the user should wait for "5" seconds
And the account balance of "app1" should be "1000" uPOKT "less" than before
And the account balance of "app1" should be "1001" uPOKT "less" than before
And the account balance of "app2" should be "1000" uPOKT "more" than before
12 changes: 6 additions & 6 deletions e2e/tests/session.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ Feature: Session Namespace

Scenario: Supplier completes claim/proof lifecycle for a valid session
Given the user has the pocketd binary installed
# Set proof_requirement_threshold to 209 < num_relays (5) * compute_units_per_relay (1) * compute_units_to_tokens_multiplier (42)
# Set proof_requirement_threshold to 209000000 < num_relays (5) * compute_units_per_relay (1) * compute_units_to_tokens_multiplier (42)
# to make sure a proof is required.
And the "proof" module parameters are set as follows
| name | value | type |
| proof_request_probability | 0.25 | float |
| proof_requirement_threshold | 209 | coin |
| proof_missing_penalty | 320 | coin |
| proof_submission_fee | 1000000 | coin |
| name | value | type |
| proof_request_probability | 0.25 | float |
| proof_requirement_threshold | 20000000 | coin |
| proof_missing_penalty | 320000000 | coin |
| proof_submission_fee | 1000000 | coin |
And all "proof" module params should be updated
And the "shared" module parameters are set as follows
| compute_units_to_tokens_multiplier | 42 | int64 |
Expand Down
37 changes: 29 additions & 8 deletions e2e/tests/stake_supplier_steps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,21 @@ func (s *suite) TheUnbondingPeriodParamIsSuccessfullySetToSessionsOfBlocks(
grantee, "user",
)

// NB: If new parameters are added to the shared module, they
// MUST be included here; otherwise, this step will fail.
// Get current params first
currentParams := s.queryAllModuleParams(paramModuleName)
currentSharedParams := currentParams.Params

// Only update the specific parameters we care about
sharedParams := sharedtypes.Params{
NumBlocksPerSession: uint64(numBlocksPerSession),
GracePeriodEndOffsetBlocks: 0,
ClaimWindowOpenOffsetBlocks: 0,
ClaimWindowCloseOffsetBlocks: 1,
ProofWindowOpenOffsetBlocks: 0,
ProofWindowCloseOffsetBlocks: 1,
GracePeriodEndOffsetBlocks: currentSharedParams.GracePeriodEndOffsetBlocks,
ClaimWindowOpenOffsetBlocks: currentSharedParams.ClaimWindowOpenOffsetBlocks,
ClaimWindowCloseOffsetBlocks: currentSharedParams.ClaimWindowCloseOffsetBlocks,
ProofWindowOpenOffsetBlocks: currentSharedParams.ProofWindowOpenOffsetBlocks,
ProofWindowCloseOffsetBlocks: currentSharedParams.ProofWindowCloseOffsetBlocks,
SupplierUnbondingPeriodSessions: uint64(unbondingPeriodSessions),
ApplicationUnbondingPeriodSessions: uint64(unbondingPeriodSessions),
ComputeUnitsToTokensMultiplier: sharedtypes.DefaultComputeUnitsToTokensMultiplier,
ComputeUnitsToTokensMultiplier: currentSharedParams.ComputeUnitsToTokensMultiplier,
}

// Convert params struct to the map type expected by
Expand Down Expand Up @@ -77,3 +80,21 @@ func paramsAnyMapFromParamsStruct(paramStruct any) paramsAnyMap {
}
return paramsMap
}

// queryAllModuleParams queries all parameters for the given module and returns them
// as a QueryParamsResponse.
func (s *suite) queryAllModuleParams(moduleName string) *sharedtypes.QueryParamsResponse {
argsAndFlags := []string{
"query",
moduleName,
"params",
"--output=json",
}

res, err := s.pocketd.RunCommandOnHostWithRetry("", numQueryRetries, argsAndFlags...)
require.NoError(s, err)

var paramsRes sharedtypes.QueryParamsResponse
s.cdc.MustUnmarshalJSON([]byte(res.Stdout), &paramsRes)
return &paramsRes
}
2 changes: 1 addition & 1 deletion localnet/poktrolld/config/app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ iavl-disable-fastnode = false
index-events = []
inter-block-cache = true
min-retain-blocks = 0
minimum-gas-prices = "0upokt"
minimum-gas-prices = "0.000000001upokt"
pruning = "nothing"
pruning-interval = "0"
pruning-keep-recent = "0"
Expand Down
2 changes: 2 additions & 0 deletions localnet/poktrolld/config/client.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
broadcast-mode = "sync"
chain-id = "poktroll"
gas = "auto"
gas-prices = "0.000000001upokt"
keyring-backend = "test"
node = "tcp://localhost:26657"
output = "text"