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

[Bug]: spendable balance 0uatom is smaller than 1uatom: insufficient funds with gas used #21072

Closed
1 task done
Ekzer opened this issue Jul 25, 2024 · 14 comments
Closed
1 task done
Assignees
Labels

Comments

@Ekzer
Copy link

Ekzer commented Jul 25, 2024

Is there an existing issue for this?

  • I have searched the existing issues

What happened?

Hi,
version
For some reasons, since switch to v0.50.8-lsm, when I try to simulate send tx with full balance, I always get now that error :

\"spendable balance 0uatom is smaller than 1uatom: insufficient funds with gas used: '63581'

However, I didn't change anything regarding simulation.
I simulate with fee=0 in reference to that previous issue #17266
and then calculate the right amount to withdraw including fees.
This works since the beginning

Cosmos SDK Version

v0.50.8-lsm

How to reproduce?

It only fails on testnet right now. Mainnet is working still

You can try with these inputs :

{
    "tx_bytes": "CpMBCpABChwvY29zbW9zLmJhbmsudjFiZXRhMS5Nc2dTZW5kEnAKLWNvc21vczE2ZHF2bDg2a2M1bHI5cThyNWUwY3lsbjRnYXQ0NWg5enFocHR4MxItY29zbW9zMTlkczI2Nnp2NHdlM2x3ZjN3NzJrZHJoemV1cDhwZnlsNmN2MDJoGhAKBXVhdG9tEgc3NDM3ODYyElMKTwpGCh8vY29zbW9zLmNyeXB0by5zZWNwMjU2azEuUHViS2V5EiMKIQPd/rryoq14vd0oDxGpzGRzrNYfYdb7XkCk0BlrG6r2OhICCgAYlBgSABoA",
    "mode": "BROADCAST_MODE_SYNC"
}

Want to withdraw the full balance of this one for example https://www.mintscan.io/cosmoshub-testnet/address/cosmos16dqvl86kc5lr9q8r5e0cyln4gat45h9zqhptx3/
but you can pick any random address with some tokens, this results the same

EDIT :
After some more investigations, it works if you subtract 1 uatom to the amount...

@Ekzer Ekzer added the T:Bug label Jul 25, 2024
@facundomedica
Copy link
Member

Hey, as you correctly pointed out this is a feature we don't have yet. I understand that the simulation of tx would succeed on the previous version, but did the actual tx execution suceed? That is with the full amount of the wallet.

What might have happened is that now the simulation is "more truer" than before, so it fails just like it would fail on execution (I haven't found it in the changelog, so it's just a guess).

I think we should close this issue and track it with #17266

@Ekzer
Copy link
Author

Ekzer commented Jul 25, 2024

Hi @facundomedica , no this is not what I mean. The tx simulation fails now since v0.50.x
As I explained, I could simulate with full amount and fee = 0 without any issues. Now, it's not.
And it seems to pass when I substract just 1 uatom to the full amount, which sounds very strange.

@Ekzer
Copy link
Author

Ekzer commented Jul 25, 2024

The issue #17266 will allow estimation with full amount and fee > 0

@Ekzer
Copy link
Author

Ekzer commented Jul 25, 2024

From what I see, this error can only come from 2 places :

if _, hasNeg := spendable.SafeSub(coin); hasNeg {
if len(spendable) == 0 {
spendable = sdk.Coins{sdk.NewCoin(coin.Denom, math.ZeroInt())}
}
return errorsmod.Wrapf(
sdkerrors.ErrInsufficientFunds,
"spendable balance %s is smaller than %s",
spendable, coin,
)
}

or

"spendable balance %s is smaller than %s",

Same logic.

That means the spendable amount is somehow equal to 0 and coin equals 1 🤔

		if _, hasNeg := spendable.SafeSub(coin); hasNeg {
			if len(spendable) == 0 {
				spendable = sdk.Coins{sdk.Coin{Denom: coin.Denom, Amount: math.ZeroInt()}}
			}

@facundomedica
Copy link
Member

Can you provide a practical example? Like the step by step you do to get this error, CLI commands or API requests you do. I wasn't able to replicate from CLI, I can do --dry-run and also tx simulate.

@facundomedica facundomedica self-assigned this Jul 26, 2024
@Ekzer
Copy link
Author

Ekzer commented Jul 31, 2024

Hey @facundomedica :)
It's through REST Api.
You can test it once again with my example above.

curl --location 'http://$hostname/cosmos/tx/v1beta1/simulate' \
--header 'Content-Type: application/json' \
-XPOST
--data '{
    "tx_bytes": "CpMBCpABChwvY29zbW9zLmJhbmsudjFiZXRhMS5Nc2dTZW5kEnAKLWNvc21vczE2ZHF2bDg2a2M1bHI5cThyNWUwY3lsbjRnYXQ0NWg5enFocHR4MxItY29zbW9zMTlkczI2Nnp2NHdlM2x3ZjN3NzJrZHJoemV1cDhwZnlsNmN2MDJoGhAKBXVhdG9tEgc3NDE3NjM0ElMKTwpGCh8vY29zbW9zLmNyeXB0by5zZWNwMjU2azEuUHViS2V5EiMKIQPd/rryoq14vd0oDxGpzGRzrNYfYdb7XkCk0BlrG6r2OhICCgAYoBgSABoA",
    "mode": "BROADCAST_MODE_SYNC"
}'````

@facundomedica
Copy link
Member

Hey @Ekzer didn't see your last reply, where are you getting those tx bytes?

@Ekzer
Copy link
Author

Ekzer commented Aug 21, 2024

Hey @facundomedica ,
Through the JS SDK.
Something like that :

const uri = '/cosmos/tx/v1beta1/simulate';
      const tx = Tx.fromPartial({
        authInfo: AuthInfo.fromPartial({
          fee: Fee.fromPartial({}),
          signerInfos: [
            {
              publicKey: encodePubKey(signer),
              sequence: BigInt(sequence),
              modeInfo: { single: { mode: SignMode.SIGN_MODE_UNSPECIFIED } },
            },
          ],
        }),
        body: TxBody.fromPartial({
          messages: messages.map((message) => this.registry.encodeAsAny(message))
          memo,
        }),
        signatures: [new Uint8Array()],
      });
      const request = {
        tx_bytes: base64FromBytes(Tx.encode(tx).finish()),
        mode: 'BROADCAST_MODE_SYNC',
      };
this.registry

comes from something like that :

import { Registry } from '@cosmjs/proto-signing';
import { defaultRegistryTypes } from '@cosmjs/stargate';
import { MsgSetOrchestratorAddresses } from '@injectivelabs/core-proto-ts/cjs/injective/peggy/v1/msgs';
import { MsgUnjail } from 'cosmjs-types/cosmos/slashing/v1beta1/tx';

export function getRegistry(): Registry {
  const registry = new Registry(defaultRegistryTypes);
  registry.register('/injective.peggy.v1.MsgSetOrchestratorAddresses', MsgSetOrchestratorAddresses);
  registry.register('/cosmos.slashing.v1beta1.MsgUnjail', MsgUnjail);
  return registry;
}

This works like a gem since day 1

@facundomedica
Copy link
Member

facundomedica commented Aug 26, 2024

Hey @Ekzer, also provide the message you are sending, as what you provided isn't enough for me to replicate.

EDIT: to be clear, we need to be able to replicate the issue in order to find a fix. So please be as detailed as possible.

@Ekzer
Copy link
Author

Ekzer commented Aug 27, 2024

Hey @facundomedica , check your Github inbox :) I invited you to the test repo : https://github.com/Ekzer/cosmjs-issue-21072

@Ekzer
Copy link
Author

Ekzer commented Aug 27, 2024

Btw, got the same in mainnet

{
    "code": 2,
    "message": "failed to execute message; message index: 0: spendable balance 9999uatom is smaller than 10000uatom: insufficient funds [cosmos/[email protected]/x/bank/keeper/send.go:278] with gas used: '87635'",
    "details": []
}

@Ekzer
Copy link
Author

Ekzer commented Sep 10, 2024

Hey @facundomedica, were you able to reproduce it ? :)

@Ekzer
Copy link
Author

Ekzer commented Sep 18, 2024

It looks like it has been resolved now 🤔 Can't reproduce it anymore 🎉
Has anyone changed something since?

@julienrbrt
Copy link
Member

We weren't able to replicate the issue, but good to know that the problem was solved for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 🥳 Done
Development

No branches or pull requests

3 participants