fetchai/agents-aea

cosmos based tx fail on-chain for intial tx from a new wallet

Opened this issue · 2 comments

Describe the bug
Cosmos based txs do NOT get settled for intial txs from an account.

This is because the sequence is not present on the request to cosmos for a wallet which has not made any txs.

To Reproduce

  1. run simple buyer demo with an account which has not txed on chain before.
---
public_id: fetchai/ledger:0.18.0
type: connection
config:
  ledger_apis:
    fetchai:
      address: https://rest-andromeda.fetch.ai:443
      denom: nanomobx
      chain_id: andromeda-1
    ethereum:
      address: https://hidden-bold-glitter.matic.quiknode.pro/878802d4df1c01517caa777f1e82f23d806b3fb5/
      gas_price_api_key: null

Expected behavior
tx is submitted and settled on chain.

Screenshots

here is a working implementation of the function from the /aea_ledger_fetchai/_cosmos.py (line 1075)

    @try_decorator(
        "Encountered exception when trying to get account number and sequence: {}",
        logger_method=_default_logger.warning,
    )
    def _try_get_account_number_and_sequence(
        self, address: Address
    ) -> Tuple[Optional[int], Optional[int]]:
        """
        Try get account number and sequence for an address.

        :param address: the address
        :return: a tuple of account number and sequence
        """
        result: Tuple[Optional[int], Optional[int]] = (None, None)
        url = self.network_address + f"/auth/accounts/{address}"
        response = requests.get(url=url)
        if response.status_code != 200:  # pragma: nocover
            raise ValueError(
                "Cannot get account number and sequence: {}".format(response.json())
            )
        try:
            if response.json()["result"]["value"].get("sequence",None) is None:
                print("account unused, sequence set to 0")
                result = (
                    int(response.json()["result"]["value"]["account_number"]),
                    0
                )
            else:
                result = (
                    int(response.json()["result"]["value"]["account_number"]),
                    int(response.json()["result"]["value"]["sequence"]),
                )
        except KeyError:  # pragma: nocover
            raise ValueError(
                f"keys `account_number` and `sequence` not found in response_json={response.json()}."
            )
        return result


NOTE the response DOES NOT contain sequence if this is the intial tx from the acocunt, hence the simple check for if this field is present.

If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • AEA Version [e.g. 1.0.0]

Additional context
Add any other context about the problem here.

5A11 commented

In cosmos based networks, it is not possible to create a transaction with an unfunded account because you'll need account number. You will need to fund the account first and then proceed.

I dont think I articulated myself properly.
So. If i create a new cosmos based key.
Then I send for example Mobix to it, I am unable to then send that Mobix onwards without the modification i reference above, which basically does a check to see if there is an existing sequence, and if not puts 0 in there.