Delays

Overview

There are four phases of a transaction sent to THORChain.
  1. 1.
    Layer1 Inbound Confirmation
  2. 2.
    Observation Counting
  3. 3.
    Confirmation Counting
  4. 4.
    TXOut Delay
  5. 5.
    Layer1 Outbound Confirmation

Inbound Confirmation

This depends purely on the host chain and is out of the control of THORChain.
  • Bitcoin/BitcoinCash: ~10 minutes
  • Litecoin: ~2.5 minutes
  • Dogecoin: ~60 seconds
  • ETH: ~15 seconds
  • Cosmos: ~6 seconds

Observation Counting

THORNodes have to witness to THORChain when they see a transaction. It could seconds to minutes depending on how fast nodes can scan their blockchains to find transactions. Once 67% of THORNodes see a tx, then it can be confirmed. You can count the number of nodes that have seen a tx by counting the signatures in the signers parameter on the /tx endpoint
Example:

Confirmation Counting

THORChain has to defend against 51% attacks, which it does by counting to economic finality for each block (the value of the block relative to the value of the block reward). It tracks both, then computes the number of blocks to wait. It then populates this on the /tx endpoint.
Example:
block_height is the external height it first saw it.
finalise_height is the external height it needs to see before it will confirm it.
An event is not sent until the external block height crosses finalise_height so Midgard will NOT see the tx until confirmation-counted.
Examples:
  • 10 BTC: 2 blocks
  • 50 ETH: 16 blocks
  • 100 LTC: 9 blocks

TXOut Delay

THORChain throttles all outputs to prevent fund loss attacks, but the maximum delay is 1hr. It does this by computing the value of the outbound transaction then applying an artificial delay. If the tx is in "scheduled", it will be delayed by a number of blocks. Once it is "outbound" it is being processeed.
Queue
Delayed txOuts:
Finalised txOuts:

Outbound Confirmation

This depends purely on the host chain and is out of the control of THORChain.
  • Bitcoin/BitcoinCash: ~10 minutes
  • Litecoin: ~2.5 minutes
  • Dogecoin: ~60 seconds
  • ETH: ~15 seconds
  • Cosmos: ~6 seconds

How to Handle Delays

Follow these guidelines
  1. 1.
    Always tell your user a swap could take "5-10 minutes"
  2. 2.
    Don't leave the user with a swap screen spinner, instead, move the swap to a "pending state" with a 10minute countdown. Let the user exit the app, perhaps even send them a notification after.
  3. 3.
    Every minute, poll Midgard and see if the swap is processed.
  4. 4.
    Once processed, you can inform the user, perhaps surprise them if the swap is done faster
Copy link
Outline
Overview
Inbound Confirmation
Observation Counting
Confirmation Counting
TXOut Delay
Outbound Confirmation
How to Handle Delays