|
| 1 | +--- |
| 2 | +title: 'Field Report: Consolidation of 4 Million UTXOs at Xapo' |
| 3 | +permalink: /en/xapo-utxo-consolidation/ |
| 4 | +name: 2018-07-30-xapo-utxo-consolidation |
| 5 | +type: posts |
| 6 | +layout: post |
| 7 | +lang: en |
| 8 | +version: 1 |
| 9 | +--- |
| 10 | + |
| 11 | +{:.post-meta} |
| 12 | +*by [Anthony Towns](https://twitter.com/ajtowns)<br>Developer on Bitcoin Core |
| 13 | +at [Xapo][]* |
| 14 | + |
| 15 | +As mentioned in [newsletter #3][newsletter 3], the past few months of low |
| 16 | +transaction fees makes it a great time to do UTXO consolidation! |
| 17 | +Consolidation has been one of a variety of activities [Xapo][Xapo] has been |
| 18 | +undertaking to be prepared for the next time fees spike like they did in the |
| 19 | +last few months of 2017. |
| 20 | + |
| 21 | +{% assign img1_label = "Plot of total Bitcoin UXTOs, January - July 2018" %} |
| 22 | + |
| 23 | +{:.center} |
| 24 | +<br> |
| 25 | +*{{img1_label}}, |
| 26 | +source: [Statoshi](https://statoshi.info/dashboard/db/unspent-transaction-output-set?panelId=6&fullscreen&from=1514759562608&to=1532039707168)* |
| 27 | + |
| 28 | +[newsletter 3]: https://bitcoinops.org/en/newsletters/2018/07/10/#dashboard-items |
| 29 | +[Xapo]: https://www.xapo.com/ |
| 30 | + |
| 31 | +The idea behind UTXO consolidation is essentially this: when your average |
| 32 | +outgoing payment is larger than your average incoming payment (or when they’re |
| 33 | +the same, but you’re batching outgoing payments), you’ll often have to combine |
| 34 | +many UTXOs in order to fund an outgoing transaction, which increases the size |
| 35 | +of your transactions and hence the fees you pay. By consolidating UTXOs in |
| 36 | +advance, you can combine inputs ahead of time, giving you more |
| 37 | +control over when most of those costs are incurred. If you can do it when |
| 38 | +fees are low, that lets you reduce those costs pretty substantially. |
| 39 | + |
| 40 | +For example, if you would have spent a dozen 2-of-3 multisig inputs at 100 s/B |
| 41 | +(satoshis per byte), that would cost around 360,000 satoshis; while if you |
| 42 | +consolidated those inputs beforehand at 2 s/B, and then spent the single |
| 43 | +consolidated input later at 100 s/B, your total cost for the two transactions |
| 44 | +is only about 41,000 satoshis: i.e. 87% less paid in fees. And if fees don’t |
| 45 | +rise the risk isn’t huge: if fees just sat at 2 s/B, you’d be spending 7,900 |
| 46 | +satoshis across two transactions if you consolidated, rather than spending |
| 47 | +7,200 satoshis in a single transaction if you did nothing. |
| 48 | + |
| 49 | +Consolidation also gives an opportunity to update the addresses you use for |
| 50 | +your UTXOs, for example to roll keys over, switch to multisig, or switch to |
| 51 | +segwit or bech32 addresses. And reducing the number of UTXOs makes it easier to |
| 52 | +run a full node too, marginally improving Bitcoin’s decentralisation and |
| 53 | +overall security, which is always nice. |
| 54 | + |
| 55 | +Of course, one thing you really don’t want to have happen is for your |
| 56 | +consolidation transactions to somehow fill up the blockchain and cause fees to |
| 57 | +immediately start rising! There are two metrics to watch to avoid this risk: |
| 58 | +one is whether the [mempool][mempool] is full (which causes the minimum |
| 59 | +acceptable fee to rise), and the other is how much empty space there has been |
| 60 | +in recent blocks (which gives an indication of whether miners will accept more |
| 61 | +transactions at the minimum fee). Both these metrics have been very promising |
| 62 | +most of the time over the past few months: the mempool has regularly been close |
| 63 | +to empty, meaning the transactions paying as little as 1 s/B have been |
| 64 | +propagated to miners; and many blocks have not been full, meaning cheap |
| 65 | +consolidation transactions will get mined reasonably quickly rather than |
| 66 | +creating a backlog that will cause fees to rise. |
| 67 | + |
| 68 | +[mempool]: https://statoshi.info/dashboard/db/memory-pool?panelId=1&fullscreen&from=1509458400000&to=1531813659334&theme=dark |
| 69 | + |
| 70 | +The approach we took to actually doing the consolidation was to have a script |
| 71 | +that would select groups of small UTXOs and create a consolidation transaction |
| 72 | +spending them to a single pool address at a fee rate of 1.01 satoshis per byte. |
| 73 | +The script gradually feeds consolidation transactions into the network, so it |
| 74 | +doesn’t cause too large a spike in the mempool, and perhaps more importantly so |
| 75 | +we don’t risk having our transactions get dropped because they have low fees |
| 76 | +and the mempool has filled up. We triggered this manually when we were |
| 77 | +comfortable it wouldn't interfere with our operations, and when there didn’t seem |
| 78 | +to be much load on the Bitcoin network in general. |
| 79 | + |
| 80 | +All in all, this has worked out pretty well; we’ve reduced our UTXO count by |
| 81 | +something like [4 million UTXOs][4 million UTXOs] this year, and aside from |
| 82 | +some [concerned][redditors1] [redditors][redditors2], the cost to the network |
| 83 | +as a whole has been minimal, as has the cost to us. |
| 84 | + |
| 85 | +[4 million UTXOs]: https://www.oxt.me/entity/Xapo |
| 86 | +[redditors1]: https://www.reddit.com/r/BitcoinDiscussion/comments/8ocyc9/massive_consolidation_currently_underway/ |
| 87 | +[redditors2]: https://www.reddit.com/r/Bitcoin/comments/8p3y5b/does_xapo_spamming_the_blockchain/ |
| 88 | + |
| 89 | +## Additional resources |
| 90 | + |
| 91 | +- [Techniques to reduce transaction fees: consolidation](https://en.bitcoin.it/wiki/Techniques_to_reduce_transaction_fees#Consolidation) - Bitcoin Wiki |
| 92 | +- [How to cheaply consolidate coins to reduce miner fees](https://en.bitcoin.it/wiki/How_to_cheaply_consolidate_coins_to_reduce_miner_fees) - Bitcoin Wiki |
| 93 | +- [What are some best practices regarding the usage of consolidations and fanouts?](https://bitgo.freshdesk.com/support/solutions/articles/27000044185-what-are-some-best-practices-regarding-the-usage-of-consolidations-and-fanouts-) - BitGo |
0 commit comments