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
Show file tree
Hide file tree
Changes from 4 commits
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
2 changes: 1 addition & 1 deletion makefiles/relay.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ send_relay_path_JSONRPC: test_e2e_env ## Send a JSONRPC relay through PATH to a
curl -X POST -H "Content-Type: application/json" \
-H "X-App-Address: pokt1mrqt5f7qh8uxs27cjm9t7v9e74a9vvdnq5jva4" \
--data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \
http://anvil.localhost:3000/v1
http://anvil.localhost:3000/v1/
# $(subst http://,http://anvil.,$(PATH_URL))/v1

# TODO_MAINNET(@red-0ne): Re-enable this once PATH Gateway supports REST.
Expand Down
1 change: 1 addition & 0 deletions pkg/client/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type SupplierClient interface {
type TxClient interface {
SignAndBroadcast(
ctx context.Context,
gasLimit, gasPrice int64,
msgs ...cosmostypes.Msg,
) either.AsyncError
}
Expand Down
13 changes: 11 additions & 2 deletions pkg/client/supplier/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ 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 = 100000
okdas marked this conversation as resolved.
Show resolved Hide resolved

// gasPrice is the gas price used to calculate the fee of the relay miner transactions.
gasPrice = 1
)

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

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

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

// TODO_TECHDEBT: this should be configurable
txBuilder.SetGasLimit(690000042)
fee := cosmostypes.NewCoins(cosmostypes.NewInt64Coin("upokt", gasLimit*gasPrice))
txBuilder.SetGasLimit(uint64(gasLimit))
txBuilder.SetFeeAmount(fee)
txBuilder.SetTimeoutHeight(uint64(timeoutHeight))

// sign transactions
Expand Down
8 changes: 7 additions & 1 deletion pkg/client/tx/client_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import (
apptypes "github.com/pokt-network/poktroll/x/application/types"
)

const (
// Set gas limit and price to 0 since tests do not need require actual gas.
gasLimit = 0
gasPrice = 0
)

func TestTxClient_SignAndBroadcast_Integration(t *testing.T) {
t.Skip(
"TODO_TECHDEBT: this test depends on some setup which is currently not implemented in this test: staked application and servicer with matching services",
Expand Down Expand Up @@ -62,7 +68,7 @@ func TestTxClient_SignAndBroadcast_Integration(t *testing.T) {
}

// Sign and broadcast the message.
eitherErr := txClient.SignAndBroadcast(ctx, appStakeMsg)
eitherErr := txClient.SignAndBroadcast(ctx, gasLimit, gasPrice, appStakeMsg)
err, _ = eitherErr.SyncOrAsyncError()
require.NoError(t, err)
}
12 changes: 8 additions & 4 deletions pkg/client/tx/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ const (
// maxServiceIdLen.
testServiceIdPrefix = "testsvc"
txCommitTimeout = 10 * time.Millisecond

// Set gas limit and price to 0 since tests do not need require actual gas.
txGasLimit = 0
txGasPrice = 0
)

// TODO_TECHDEBT: add coverage for the transactions client handling an events bytes error either.
Expand Down Expand Up @@ -106,7 +110,7 @@ func TestTxClient_SignAndBroadcast_Succeeds(t *testing.T) {
}

// Sign and broadcast the message.
eitherErr := txClient.SignAndBroadcast(ctx, appStakeMsg)
eitherErr := txClient.SignAndBroadcast(ctx, txGasLimit, txGasPrice, appStakeMsg)
err, errCh := eitherErr.SyncOrAsyncError()
require.NoError(t, err)

Expand Down Expand Up @@ -265,7 +269,7 @@ func TestTxClient_SignAndBroadcast_SyncError(t *testing.T) {
// NB: explicitly omitting required fields
}

eitherErr := txClient.SignAndBroadcast(ctx, appStakeMsg)
eitherErr := txClient.SignAndBroadcast(ctx, txGasLimit, txGasPrice, appStakeMsg)
err, _ = eitherErr.SyncOrAsyncError()
require.ErrorIs(t, err, tx.ErrInvalidMsg)

Expand Down Expand Up @@ -343,7 +347,7 @@ $ go test -v -count=1 -run TestTxClient_SignAndBroadcast_CheckTxError ./pkg/clie
}

// Sign and broadcast the message.
eitherErr := txClient.SignAndBroadcast(ctx, appStakeMsg)
eitherErr := txClient.SignAndBroadcast(ctx, txGasLimit, txGasPrice, appStakeMsg)
err, _ = eitherErr.SyncOrAsyncError()
require.ErrorIs(t, err, tx.ErrCheckTx)
require.ErrorContains(t, err, expectedErrMsg)
Expand Down Expand Up @@ -415,7 +419,7 @@ func TestTxClient_SignAndBroadcast_Timeout(t *testing.T) {
}

// Sign and broadcast the message in a transaction.
eitherErr := txClient.SignAndBroadcast(ctx, appStakeMsg)
eitherErr := txClient.SignAndBroadcast(ctx, txGasLimit, txGasPrice, appStakeMsg)
err, errCh := eitherErr.SyncOrAsyncError()
require.NoError(t, err)

Expand Down
4 changes: 3 additions & 1 deletion pkg/client/tx/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ func (txCtx cosmosTxContext) EncodeTx(txBuilder cosmosclient.TxBuilder) ([]byte,
// ABCI operation completes and returns a TxResponse of the transaction status at that point in time.
func (txCtx cosmosTxContext) BroadcastTx(txBytes []byte) (*cosmostypes.TxResponse, error) {
clientCtx := cosmosclient.Context(txCtx.clientCtx)
return clientCtx.BroadcastTxAsync(txBytes)
// BroadcastTxSync is used to capture any transaction error that occurs during
red-0ne marked this conversation as resolved.
Show resolved Hide resolved
// the check-tx ABCI operation, otherwise errors would be returned.
red-0ne marked this conversation as resolved.
Show resolved Hide resolved
return clientCtx.BroadcastTxSync(txBytes)
}

// QueryTx queries the transaction based on its hash and optionally provides proof
Expand Down
2 changes: 2 additions & 0 deletions testutil/testclient/testtx/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ func NewOneTimeSignAndBroadcastTxClient(
txClient.EXPECT().SignAndBroadcast(
gomock.Eq(ctx),
gomock.Any(),
gomock.Any(),
gomock.Any(),
).DoAndReturn(signAndBroadcast).Times(1)

return txClient
Expand Down
Loading