diff --git a/pkg/client/tx/client.go b/pkg/client/tx/client.go index 917ed6346..d1bde4465 100644 --- a/pkg/client/tx/client.go +++ b/pkg/client/tx/client.go @@ -105,7 +105,7 @@ type txClient struct { txTimeoutPool txTimeoutPool // gasPrices is the gas unit prices used for sending transactions. - gasPrices cosmostypes.Coins + gasPrices cosmostypes.DecCoins // connRetryLimit is the number of times the underlying replay client // should retry in the event that it encounters an error or its connection is interrupted. @@ -253,8 +253,19 @@ func (txnClient *txClient) SignAndBroadcast( // Coin multiplication prevents doing it using a zero value. if gasLimit > 0 { txBuilder.SetGasLimit(gasLimit) - feeAmount := txnClient.gasPrices.MulInt(math.NewIntFromUint64(gasLimit)) - txBuilder.SetFeeAmount(feeAmount) + + gasLimitDec := math.LegacyNewDec(int64(gasLimit)) + feeAmountDec := txnClient.gasPrices.MulDec(gasLimitDec) + + feeCoins, changeCoins := feeAmountDec.TruncateDecimal() + // Ensure that any decimal remainder is added to the corresponding coin as a + // whole number. + for i, coin := range feeCoins { + if !changeCoins[i].IsZero() { + feeCoins[i] = coin.AddAmount(math.OneInt()) + } + } + txBuilder.SetFeeAmount(feeCoins) } txBuilder.SetTimeoutHeight(uint64(timeoutHeight)) diff --git a/pkg/client/tx/options.go b/pkg/client/tx/options.go index cb902c730..f31736bcc 100644 --- a/pkg/client/tx/options.go +++ b/pkg/client/tx/options.go @@ -34,7 +34,7 @@ func WithConnRetryLimit(limit int) client.TxClientOption { } // WithGasPrices sets the gas price to be used when constructing transactions. -func WithGasPrices(gasPrices cosmostypes.Coins) client.TxClientOption { +func WithGasPrices(gasPrices cosmostypes.DecCoins) client.TxClientOption { return func(client client.TxClient) { client.(*txClient).gasPrices = gasPrices } diff --git a/pkg/deps/config/suppliers.go b/pkg/deps/config/suppliers.go index 9978df7f9..ad8357cba 100644 --- a/pkg/deps/config/suppliers.go +++ b/pkg/deps/config/suppliers.go @@ -12,6 +12,7 @@ import ( "github.com/cosmos/gogoproto/grpc" "github.com/spf13/cobra" + "github.com/pokt-network/poktroll/app/volatile" "github.com/pokt-network/poktroll/pkg/client/block" "github.com/pokt-network/poktroll/pkg/client/delegation" "github.com/pokt-network/poktroll/pkg/client/events" @@ -359,7 +360,7 @@ func NewSupplySupplierClientsFn(signingKeyNames []string) SupplierFn { return nil, err } - gasPrices, err := cosmostypes.ParseCoinsNormalized(gasPriceStr) + gasPrices, err := cosmostypes.ParseDecCoins(gasPriceStr) if err != nil { return nil, err } @@ -482,10 +483,18 @@ func newSupplyTxClientsFn( ctx context.Context, deps depinject.Config, signingKeyName string, - gasPrices cosmostypes.Coins, + gasPrices cosmostypes.DecCoins, ) (depinject.Config, error) { - uPOKTFound, _ := gasPrices.Find("upokt") - if !uPOKTFound { + // Ensure that the gas prices include upokt + uPOKTDenomFound := false + for _, gasPrice := range gasPrices { + if gasPrice.Denom == volatile.DenomuPOKT { + uPOKTDenomFound = true + break + } + } + + if !uPOKTDenomFound { return nil, fmt.Errorf("gas prices must include upokt") }