Skip to content

Commit d6941c5

Browse files
committed
fix: Use gas for claim and proof txs
1 parent ab97af8 commit d6941c5

8 files changed

Lines changed: 39 additions & 11 deletions

File tree

‎makefiles/relay.mk‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ send_relay_path_JSONRPC: test_e2e_env ## Send a JSONRPC relay through PATH to a
77
curl -X POST -H "Content-Type: application/json" \
88
-H "X-App-Address: pokt1mrqt5f7qh8uxs27cjm9t7v9e74a9vvdnq5jva4" \
99
--data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \
10-
http://anvil.localhost:3000/v1
10+
http://anvil.localhost:3000/v1/
1111
# $(subst http://,http://anvil.,$(PATH_URL))/v1
1212

1313
# TODO_MAINNET(@red-0ne): Re-enable this once PATH Gateway supports REST.

‎pkg/client/interface.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ type SupplierClient interface {
8181
type TxClient interface {
8282
SignAndBroadcast(
8383
ctx context.Context,
84+
gasLimit int64,
85+
gasPrice int64,
8486
msgs ...cosmostypes.Msg,
8587
) either.AsyncError
8688
}

‎pkg/client/supplier/client.go‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ import (
1515

1616
var _ client.SupplierClient = (*supplierClient)(nil)
1717

18+
const (
19+
// TODO_TECHDEBT: Gas limit and price should have their dedicated configuration entry.
20+
// gasLimit is the default gas limit of the relay miner transactions.
21+
gasLimit = 100000
22+
23+
// gasPrice is the gas price used to calculate the fee of the relay miner transactions.
24+
gasPrice = 1
25+
)
26+
1827
// supplierClient
1928
type supplierClient struct {
2029
// signingKeyName is the name of the operator key in the keyring that will be
@@ -82,7 +91,7 @@ func (sClient *supplierClient) SubmitProofs(
8291

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

129138
// TODO(@bryanchriswhite): reconcile splitting of supplier & proof modules
130139
// with off-chain pkgs/nomenclature.
131-
eitherErr := sClient.txClient.SignAndBroadcast(ctx, msgs...)
140+
eitherErr := sClient.txClient.SignAndBroadcast(ctx, gasLimit, gasPrice, msgs...)
132141
err, errCh := eitherErr.SyncOrAsyncError()
133142
if err != nil {
134143
return err

‎pkg/client/tx/client.go‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ func NewTxClient(
213213
// transaction results in an asynchronous error or times out.
214214
func (txnClient *txClient) SignAndBroadcast(
215215
ctx context.Context,
216+
gasLimit int64,
217+
gasPrice int64,
216218
msgs ...cosmostypes.Msg,
217219
) either.AsyncError {
218220
var validationErrs error
@@ -240,8 +242,9 @@ func (txnClient *txClient) SignAndBroadcast(
240242
timeoutHeight := txnClient.blockClient.LastBlock(ctx).
241243
Height() + txnClient.commitTimeoutHeightOffset
242244

243-
// TODO_TECHDEBT: this should be configurable
244-
txBuilder.SetGasLimit(690000042)
245+
fee := cosmostypes.NewCoins(cosmostypes.NewInt64Coin("upokt", gasLimit*gasPrice))
246+
txBuilder.SetGasLimit(uint64(gasLimit))
247+
txBuilder.SetFeeAmount(fee)
245248
txBuilder.SetTimeoutHeight(uint64(timeoutHeight))
246249

247250
// sign transactions

‎pkg/client/tx/client_integration_test.go‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ import (
2020
apptypes "github.com/pokt-network/poktroll/x/application/types"
2121
)
2222

23+
const (
24+
// Set gas limit and price to 0 since tests do not need require actual gas.
25+
gasLimit = 0
26+
gasPrice = 0
27+
)
28+
2329
func TestTxClient_SignAndBroadcast_Integration(t *testing.T) {
2430
t.Skip(
2531
"TODO_TECHDEBT: this test depends on some setup which is currently not implemented in this test: staked application and servicer with matching services",
@@ -62,7 +68,7 @@ func TestTxClient_SignAndBroadcast_Integration(t *testing.T) {
6268
}
6369

6470
// Sign and broadcast the message.
65-
eitherErr := txClient.SignAndBroadcast(ctx, appStakeMsg)
71+
eitherErr := txClient.SignAndBroadcast(ctx, gasLimit, gasPrice, appStakeMsg)
6672
err, _ = eitherErr.SyncOrAsyncError()
6773
require.NoError(t, err)
6874
}

‎pkg/client/tx/client_test.go‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ const (
3838
// maxServiceIdLen.
3939
testServiceIdPrefix = "testsvc"
4040
txCommitTimeout = 10 * time.Millisecond
41+
42+
// Set gas limit and price to 0 since tests do not need require actual gas.
43+
txGasLimit = 0
44+
txGasPrice = 0
4145
)
4246

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

108112
// Sign and broadcast the message.
109-
eitherErr := txClient.SignAndBroadcast(ctx, appStakeMsg)
113+
eitherErr := txClient.SignAndBroadcast(ctx, txGasLimit, txGasPrice, appStakeMsg)
110114
err, errCh := eitherErr.SyncOrAsyncError()
111115
require.NoError(t, err)
112116

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

268-
eitherErr := txClient.SignAndBroadcast(ctx, appStakeMsg)
272+
eitherErr := txClient.SignAndBroadcast(ctx, gasLimit, gasPrice, appStakeMsg)
269273
err, _ = eitherErr.SyncOrAsyncError()
270274
require.ErrorIs(t, err, tx.ErrInvalidMsg)
271275

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

345349
// Sign and broadcast the message.
346-
eitherErr := txClient.SignAndBroadcast(ctx, appStakeMsg)
350+
eitherErr := txClient.SignAndBroadcast(ctx, gasLimit, gasPrice, appStakeMsg)
347351
err, _ = eitherErr.SyncOrAsyncError()
348352
require.ErrorIs(t, err, tx.ErrCheckTx)
349353
require.ErrorContains(t, err, expectedErrMsg)
@@ -415,7 +419,7 @@ func TestTxClient_SignAndBroadcast_Timeout(t *testing.T) {
415419
}
416420

417421
// Sign and broadcast the message in a transaction.
418-
eitherErr := txClient.SignAndBroadcast(ctx, appStakeMsg)
422+
eitherErr := txClient.SignAndBroadcast(ctx, gasLimit, gasPrice, appStakeMsg)
419423
err, errCh := eitherErr.SyncOrAsyncError()
420424
require.NoError(t, err)
421425

‎pkg/client/tx/context.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ func (txCtx cosmosTxContext) EncodeTx(txBuilder cosmosclient.TxBuilder) ([]byte,
8686
// ABCI operation completes and returns a TxResponse of the transaction status at that point in time.
8787
func (txCtx cosmosTxContext) BroadcastTx(txBytes []byte) (*cosmostypes.TxResponse, error) {
8888
clientCtx := cosmosclient.Context(txCtx.clientCtx)
89-
return clientCtx.BroadcastTxAsync(txBytes)
89+
// BroadcastTxSync is used to capture any transaction error that occurs during
90+
// the check-tx ABCI operation, otherwise errors would be returned.
91+
return clientCtx.BroadcastTxSync(txBytes)
9092
}
9193

9294
// QueryTx queries the transaction based on its hash and optionally provides proof

‎testutil/testclient/testtx/client.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ func NewOneTimeSignAndBroadcastTxClient(
7373
txClient.EXPECT().SignAndBroadcast(
7474
gomock.Eq(ctx),
7575
gomock.Any(),
76+
gomock.Any(),
77+
gomock.Any(),
7678
).DoAndReturn(signAndBroadcast).Times(1)
7779

7880
return txClient

0 commit comments

Comments
 (0)