cosmos / cosmjs

The Swiss Army knife to power JavaScript based client solutions ranging from Web apps/explorers over browser extensions to server-side clients like faucets/scrapers.
https://cosmos.github.io/cosmjs/
Apache License 2.0
648 stars 332 forks source link

Log: invalid length: tx parse error #1525

Closed chalabi2 closed 9 months ago

chalabi2 commented 9 months ago

Context:

I am generating an amino message for the Gravity Bridge Fee Auction. The message generates, and I can sign/broadcast it just fine.

Issue:

Recently, one of the parameters which is required to submit the tx, BidFee, was raised. It was initially 3110 ugraviton but has been increased to 3110000000 ugraviton or 3110 graviton for short. After updating the parameter in the transaction, I am now getting

Error: Broadcasting transaction failed with code 2 (codespace: sdk). Log: invalid length: tx parse error

If i remove one digit from the fee number so instead of 3110000000 i use 311000000 it will sign and broadcast but ultimately fail as the chain will not accept any number lower then 3110000000.

I cant find anyone who's run into that error, and i'm having a hard time figuring out why that error appears. The issue is not with the chain or the transaction as I can sign and successfully broadcast the exact same transaction via cli and this was working before the fee change.

Any help or simply pointing me in the right direction would be awesome!

Link to successfully signed and broadcasted tx

Replicate

git clone https://github.com/chalabi2/auction-frontend
cd auction-frontend
npm install
npm run dev

OR Live Site

TX

export const bidOnAuction = (
  getSigningStargateClient: (
    signerOptions: SignerOptions
  ) => Promise<SigningStargateClient>,
  signerOptions: SignerOptions,
  setResp: (resp: string) => any,
  chainName: string,
  address: string,
  auctionId: string,
  bidAmount: string, 
  bidFeeAmount: string, 
  toast: ReturnType<typeof useToast>
) => {
  return async () => {
    const stargateClient = await getSigningStargateClient(signerOptions);
    if (!stargateClient || !address) {
      console.error("stargateClient undefined or address undefined.");
      return;
    }

    const { bid } = auction.v1.MessageComposer.withTypeUrl;

    const msg = bid({
      auctionId: BigInt(auctionId),
      bidder: address,
      amount: BigInt(bidAmount),
      bidFee: BigInt(bidFeeAmount),
    });

    const memo: string = "Submitted by Gravity Bridge Fee Auction App";

    const fee: StdFee = {
      gas: "1000000",
      amount: [
        {
          amount: "1000000",
          denom: "ugraviton",
        },
      ],
    };

    try {
      const response = await stargateClient.signAndBroadcast(
        address,
        [msg],
        fee,
        memo
      );
      setResp(JSON.stringify(response, null, 2));
      showSuccessToast(toast, response.transactionHash, chainName);
    } catch (error) {
      console.error("Error signing and sending transaction:", error);
      if (error instanceof Error) {
        showErrorToast(toast, error.message);
      }
    }
  };
};
webmaster128 commented 9 months ago

Two observations here:

Code 2, Codespace "sdk" is this error:

    // ErrTxDecode is returned if we cannot parse a transaction
    ErrTxDecode = errorsmod.Register(RootCodespace, 2, "tx parse error")

and 3110000000 exceeds signed in32 range while 311000000 does not.

But I think you better reach out to the maintainers of this chain or module since I have no idea about the message types and their expected value ranges.

chalabi2 commented 9 months ago

I think im the only person using cosmjs/telescope for gravity bridge signing. Generated my own packages and based off what you are saying I should probably open this issue elsewhere, thank you for your response!