Skip to content

State transitions wait for 80-second timeout even after blockchain confirmation #20

@thephez

Description

@thephez

Expected Behavior

State transitions should return immediately (within 5-10 seconds) after being confirmed on the blockchain, as verified by external block explorers.

Current Behavior

Most state transitions in wasm-sdk take approximately 90 seconds to return a response, even though they are confirmed on-chain within seconds. The SDK waits for an 80-second DAPI timeout (WAIT_FOR_ST_RESULT_TIMEOUT=80000) before returning, regardless of
whether the transaction has already been processed.

Occasionally, some transitions return quickly (5-10 seconds), but this behavior is inconsistent and appears to be timing-dependent.

Possible Solution

The issue lies in the DAPI layer's waitForTransactionToBeProvable function which uses a hardcoded 80-second timeout. The function races between:

  1. Checking for existing transaction results via RPC
  2. Waiting for transaction events via BlockchainListener
  3. An 80-second timeout

Solutions:

  1. Reduce the default WAIT_FOR_ST_RESULT_TIMEOUT from 80000ms to 10000-15000ms
  2. Implement a polling mechanism that checks getExistingTransactionResult every 1-2 seconds instead of relying solely on event listeners
  3. Fix the race condition by ensuring event subscription happens before checking for existing results
  4. Make the timeout configurable from the client side (wasm-sdk/rs-sdk)

Steps to Reproduce (for bugs)

  1. Use wasm-sdk to broadcast any state transition (identity creation, document creation, token transfer, etc.)
  2. Monitor an external block explorer to confirm when the transaction is included in a block (typically 5-10 seconds)
  3. Observe that the SDK's broadcast_and_wait doesn't return until ~90 seconds have elapsed
  4. Note that occasionally some transitions return quickly, suggesting a timing/race condition

Context

This issue severely impacts user experience in web applications using wasm-sdk. Users must wait 90 seconds for operations that actually complete in under 10 seconds. This makes the platform appear slow and unresponsive, even though the underlying blockchain
processes transactions quickly.

The inconsistent behavior (sometimes fast, usually slow) makes debugging difficult and creates unpredictable user experiences.

Your Environment

  • Version used: wasm-sdk latest
  • Environment name and version (e.g. Chrome 39, node.js 5.4): Web browsers (Chrome, Firefox, Safari)
  • Operating System and version (desktop, server, or mobile): All platforms
  • Link to your project: N/A

Technical Details

Root cause locations:

  • /packages/dapi/lib/externalApis/tenderdash/waitForTransactionToBeProvable/waitForTransactionToBeProvableFactory.js (lines 63-72)
  • /packages/dapi/.env.example (line 46: WAIT_FOR_ST_RESULT_TIMEOUT=80000)
  • /packages/dapi/lib/grpcServer/handlers/platform/platformHandlersFactory.js (line 114)

Code flow:

  1. wasm-sdk calls broadcast_and_wait with no timeout specified
  2. rs-sdk's wait_for_response uses default retry settings (3 retries, 10 sec each)
  3. DAPI's waitForTransactionToBeProvable waits up to 80 seconds
  4. If transaction exists when checked via RPC, returns immediately (race condition win)
  5. Otherwise, waits full 80 seconds even if transaction is confirmed seconds later

Additional Notes:

  • The platform-side wait_for_state_transition_result is marked as unimplemented in drive-abci, with implementation delegated to DAPI layer
  • All state transitions show up on the network immediately but SDK responses are delayed
  • This is not specific to token operations as initially suspected

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions