Skip to main content

UTXO Management Heuristic

Goals

  1. To prevent a situation where a user has too few UTXOs to execute several quick transactions without waiting for the previous transaction confirmation.
  2. To prevent a situation where the count of UTXOs in the claims database grows uncontrollably, slowing down the requests for a specific user and the overall system speed.

Strategy

We look at three UTXO states:

  1. The count of UTXOs is less than MIN_PREFERRED_UTXOS.
  2. The count of UTXOs is in the range MIN_PREFERRED_UTXOS..MAX_PREFERRED_UTXOS.
  3. The count of UTXOs is greater than MAX_PREFERRED_UTXOS.

The algorithm for creating the next transaction in different states

  1. If the count of UTXOs is less than MIN_PREFERRED_UTXOS, the Wallet library will try to increase the number of UTXOs. It does so by using the minimal number of UTXOs with the highest value available.

    In addition, if the change is greater than MIN_PREFERRED_UTXO_COST * 2, the Wallet library adds an additional SendCweb for the change, to the transaction. These two change commands divides the change into two equal parts.

    For this strategy, if only a single UTXO is used to fund the transaction, the number of UTXOs will increase by 1.

  2. If the count of UTXOs is in the range MIN_PREFERRED_UTXOS..MAX_PREFERRED_UTXOS, the Wallet library will not try to increase the number of UTXOs. In this case, the Wallet library uses the minimal number of UTXOs with the highest value available to fund the transaction but creates only a single SendCweb command for the change.

  3. If the count of UTXOs is greater than MAX_PREFERRED_UTXOS, the Wallet library will try to reduce the number of UTXOs. It does so by using the maximum number of UTXOs with the smallest value available. The Wallet library creates a single SendCweb command for the change.

Configurable Parameters

  1. MIN_PREFERRED_UTXOS (default ~ 10) - see user UTXOs state p.1
  2. MAX_PREFERRED_UTXOS (default ~ 50) - see user UTXOs state p.3
  3. MIN_PREFERRED_UTXO_COST (default ~ 1+E18) - The minimal reasonable cost of a created UTXO. The best solution is to set it to the minimal UserOperation transaction fee.