Skip to content

Commit

Permalink
Handle mismatching coins in estimateFee gasPrices and feeDenoms
Browse files Browse the repository at this point in the history
The existing issue with the estimateFee function is that the
'gasPricesCoins' variable can end up being an empty 'Coins' value.
One way the issue can be manifested is as in the following scenario:

1. The 'feeDenoms' const is initialized with ['uluna'].
2. gasPrices are not given with a 'uluna' denominator.
3. The 'gasPricesCoins' is filtered and left as an empty 'Coins'.
4. This array will be sent in the 'gas_prices' argument to the
   '/txs/estimate_fee' route in the lcd.
5. The lcd will process the request and will ignore the gas portion of
   the fee, incurring only stability fees and send the response to the
   client.
6. The client, trying to broadcast the resutling transaction based on
   the fee received in the previous step will receive an 'insufficient fees'
   error from the network.

The suggested solution checks that if the filter results in an empty
'Coins' value then the feeDenoms will be ignored and the fee
denominators that will be used are any of those constituted within the
'gasPrices' variable.

It is worth mentioning that this solution is a best-effort to avoid
breaking the API in which the estimateFee could possibly return
'Promise<StdFee|undefined>' where an 'undefined' value can be returned
if the aforementioned filter will result in an empty set of Coins.
  • Loading branch information
MatanHamilis authored and hanjukim committed Jul 29, 2021
1 parent 944f97b commit dd3e71c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/client/lcd/api/TxAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,12 @@ export class TxAPI extends BaseAPI {
if (gasPrices) {
gasPricesCoins = new Coins(gasPrices);
if (feeDenoms) {
gasPricesCoins = gasPricesCoins.filter(c =>
const gasPricesCoinsFiltered = gasPricesCoins.filter(c =>
feeDenoms.includes(c.denom)
);
if (gasPricesCoinsFiltered.toArray().length > 0) {
gasPricesCoins = gasPricesCoinsFiltered;
}
}
}

Expand Down

0 comments on commit dd3e71c

Please sign in to comment.