hirosystems / stacks-blockchain-api

API for the Stacks blockchain
https://stacks-blockchain-api.vercel.app
GNU General Public License v3.0
178 stars 114 forks source link

Rosetta: /construction/submit endpoint times out on first/second use after Node/API start #2169

Open crustywhale opened 6 days ago

crustywhale commented 6 days ago

Node: 3.0.0.0.2 API: 8.2.2

After starting or restarting a stacks node and stacks api, the first 1 or 2 attempts to use the /construction/submit endpoint to broadcast a transaction will fail (timeout). By the third or fourth attempt it will start working, and once it does the problem will not reappear again until the stacks node and stacks API are restarted.

zone117x commented 5 days ago

I suspect the services (stacks-node and/or stacks-blockchain-api) are not ready for N second after boot, and that the broadcast is succeeding after that period of time rather than number of retries.

The rosetta /construction/submit endpoint is essentially a wrapper around the stacks-core POST /v2/transactions endpoint. It can only succeed once the stack-core RPC endpoints are responsive.

The API and postgres typically don't take long to start (maybe a few seconds?), so I'm assuming stacks-core isn't yet ready.

Here's a few things you can try:

  1. Specify the env var SKIP_STACKS_CHAIN_ID_CHECK=1 in the API. This instructs the API to skip the startup validation request to the stacks-node at http://$STACKS_CORE_RPC_HOST:$STACKS_CORE_RPC_PORT. This can shave off up 2.5 seconds from the API http server init time (if we assume the stacks-node is ready immediately just after the first API validation request).

  2. Determine how long stacks-node takes to be ready by polling http://$STACKS_CORE_RPC_HOST:$STACKS_CORE_RPC_PORT/v2/pox. This is the earliest possible time the Rosetta submit endpoint can work.