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

[RelayMiner] Use gas for claim and proof txs #1018

Merged
merged 25 commits into from
Jan 7, 2025
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
separate gas and fees
okdas committed Dec 21, 2024
commit 28544052ab128ce4024099e08983112d6e4f8e13
37 changes: 30 additions & 7 deletions pkg/client/supplier/client.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@ package supplier

import (
"context"
"os"
"strconv"
"sync"

"cosmossdk.io/depinject"
@@ -16,14 +18,35 @@ import (
var _ client.SupplierClient = (*supplierClient)(nil)

const (
// TODO_TECHDEBT(@okdas): Gas limit and price should have their dedicated configuration entry.
// gasLimit is the default gas limit of the relay miner transactions.
gasLimit = 420000000069
// Default values for gas limit and price
defaultGasLimit int64 = 420000000069
defaultTxFeeUpokt int64 = 1

// gasPrice is the gas price used to calculate the fee of the relay miner transactions.
gasPrice = 1
// TODO_IN_THIS_PR: Remove Environment variable names. Added them to modify values w/o rebuilding the binary.
envGasLimit = "POKT_GAS_LIMIT"
envTxFeeUpokt = "POKT_TX_FEE_UPOKT"
)

// getGasLimit returns the gas limit from environment variable or falls back to default
func getGasLimit() int64 {
if envVal := os.Getenv(envGasLimit); envVal != "" {
if val, err := strconv.ParseInt(envVal, 10, 64); err == nil {
return val
}
}
return defaultGasLimit
}

// getTxFeeUpokt returns the transaction fee from environment variable or falls back to default
func getTxFeeUpokt() int64 {
if envVal := os.Getenv(envTxFeeUpokt); envVal != "" {
if val, err := strconv.ParseInt(envVal, 10, 64); err == nil {
return val
}
}
return defaultTxFeeUpokt
}

// supplierClient
type supplierClient struct {
// signingKeyName is the name of the operator key in the keyring that will be
@@ -91,7 +114,7 @@ func (sClient *supplierClient) SubmitProofs(

// TODO(@bryanchriswhite): reconcile splitting of supplier & proof modules
// with off-chain pkgs/nomenclature.
eitherErr := sClient.txClient.SignAndBroadcast(ctx, gasLimit, gasPrice, msgs...)
eitherErr := sClient.txClient.SignAndBroadcast(ctx, getGasLimit(), getTxFeeUpokt(), msgs...)
err, errCh := eitherErr.SyncOrAsyncError()
if err != nil {
return err
@@ -137,7 +160,7 @@ func (sClient *supplierClient) CreateClaims(

// TODO(@bryanchriswhite): reconcile splitting of supplier & proof modules
// with off-chain pkgs/nomenclature.
eitherErr := sClient.txClient.SignAndBroadcast(ctx, gasLimit, gasPrice, msgs...)
eitherErr := sClient.txClient.SignAndBroadcast(ctx, getGasLimit(), getTxFeeUpokt(), msgs...)
err, errCh := eitherErr.SyncOrAsyncError()
if err != nil {
return err
4 changes: 2 additions & 2 deletions pkg/client/tx/client.go
Original file line number Diff line number Diff line change
@@ -213,7 +213,7 @@ func NewTxClient(
// transaction results in an asynchronous error or times out.
func (txnClient *txClient) SignAndBroadcast(
ctx context.Context,
gasLimit, gasPrice int64,
gasLimit, txFeeUpokt int64,
msgs ...cosmostypes.Msg,
) either.AsyncError {
var validationErrs error
@@ -241,7 +241,7 @@ func (txnClient *txClient) SignAndBroadcast(
timeoutHeight := txnClient.blockClient.LastBlock(ctx).
Height() + txnClient.commitTimeoutHeightOffset

fee := cosmostypes.NewCoins(cosmostypes.NewInt64Coin("upokt", gasLimit*gasPrice))
fee := cosmostypes.NewCoins(cosmostypes.NewInt64Coin("upokt", txFeeUpokt))
txBuilder.SetGasLimit(uint64(gasLimit))
txBuilder.SetFeeAmount(fee)
txBuilder.SetTimeoutHeight(uint64(timeoutHeight))
Loading