1

As some people have mentioned (eg. here), the only way to get the balance of an address in bitcoin core was to import it as a watch-only address and rescan the blockchain. Starting with bitcoin core v0.17, we can use the scantxoutset command, however this is quite slow:

> time bitcoin-cli scantxoutset "start" "[\"addr(17Pu3CEx34YX8bpGATq45PfL2fGBCPcr2u)\"]"
{
  "success": true,
  "searched_items": 64162818,
  "unspents": [
    {
      "txid": "9796cee98fa88efcb9fdb954188d276b73d6e76719af6b5470ad23a2f744ecca",
      "vout": 1,
      "scriptPubKey": "76a91446255848182640edff4d178f365d7824513bc28d88ac",
      "desc": "addr(17Pu3CEx34YX8bpGATq45PfL2fGBCPcr2u)#x2q6xgrk",
      "amount": 0.02155141,
      "height": 607852
    }
  ],
  "total_amount": 0.02155141
}

real    0m42.419s
user    0m0.007s
sys 0m0.003s 

42 seconds is quite slow, I would like to get something comparable to block explorers (less than 2 seconds). Is it possible to achieve faster results with some advanced bitcoin core configuration?

Or, is there any open-source project I could use to index the UTXO set by address? Not sure if libbitcoin, bitcoinj, bitcoinJS, etc. are able to do this faster. Some tool block explorers might use to provide this service would be what I am looking for.

1 Answer 1

3

There is no way to enable faster querying for arbitrary addresses than scantxoutset in bitcoind.

Explorers provide this functionality by maintaining a separate database of all addresses and transactions which is optimized for that kind of query. Bitcoin Core, on the other hand, is optimized for consensus related queries, which are largely a hashset lookup for a given input for a transaction.

You could try running something such as ElectrumX, which backs the electrum wallet, or Bitcore, which backs many of Bitpay's wallet and explorer services.

7
  • Thanks. Any chance of bitcore or electrumX using bitcoin core's data folder to avoid storing ~300 GB twice?
    – Pedro
    Commented Dec 15, 2019 at 22:46
  • You can read the data from an existing installation, but any indexing program will have to duplicate it into its own database to actually be able to efficiently answer your queries. Commented Dec 15, 2019 at 23:15
  • Yes, I read eletrumX's DB has ~30GB and can (and should) read the data from a bitcoin core full node. Checking now whether this is also de case for bitcore.
    – Pedro
    Commented Dec 15, 2019 at 23:18
  • These are all solutions that operate on top of bitcoind, as that is still the source of truth - they simply add some indexing capabilities that extend the kind of queries you can perform. Your space usage will not really double, as bitcoind's stoage format is somewhat inefficient in favour of fast lookups for specific tx outputs. Traditional databases will do a more efficient job in a lot of cases Commented Dec 15, 2019 at 23:20
  • Hi @Pedro Were you able to get this to work? I'm curious to know since I'm looking to do something similar.
    – kdas
    Commented Nov 17, 2021 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.