Giter Club home page Giter Club logo

rust-bitcoin-indexer's Introduction

Bitcoin Indexer

An experiment in creating a perfect Bitcoin Indexer, in Rust.

Query blocks using JsonRPC, dump them into Postgres in an append-only format, suitable for querying, as much as event-sourcing-like handling. After reaching chain-head, keep indexing in real-time and handle reorgs.

This started as an educational experiment, but is quite advanced already.

Goals:

  • simplicity and small code:
    • easy to fork and customize
  • versatile data model:
    • append-only log
    • support for event sourcing
    • support for efficient queries
    • correct by construction
    • always-coherent state view (i.e. atomic reorgs)
  • top-notch performance, especially during initial indexing

Read How to interact with a blockchain for knowledge sharing, discoveries and design-decisions.

Status:

  • The codebase is very simple, design quite clean and composable and performance really good.
  • Some tests are there and everything seems quite robust, but not tested in production so far.
  • Indexing the blockchain works
  • Indexing mempool works

Comparing to alternatives

Please take with a grain of salt, and submit PRs if any information is stale or wrong.

electrs uses an embedded key value store (RocksDB) to locally maintain addtitional indices. When needed it queries the fullnode itself for block/tx data. rust-bitcoin-indexer uses a normal relational database model, with decompressed data stored in a standalone Postgres instance that can run on a different host/cluster.

Embedded KV store approach has many advantages:

  • naturally good indexing performance and less disk space usage
  • all the data is always available as a raw block/tx data (while with rust-bitcoin-indexer one would have to modify the schema, and then extract and retro-fit it with a small piece of code).

Using relational database will allow you to execute ad-hoc queries and potentially share the db with other applications, without building a separate interface. You can add and remove indices according to your needs, etc.

rust-bitcoin-indexer was designed to have a good idempotent and reliable events streaming/subscription data model.

electrs is used for practical purposes, rust-bitcoin-indexer (at least right now) is just a neat experiment that gave good results and seems to be working quite well.

Looking back, I think electrs model is esier, faster, and more robust approach for most applications, and I haven't used it mostly because I was unware of all the aspects of problem at hand ¯\_(ツ)_/¯. However I am still very happy with results achived with rust-bitcoin-indexer. It's compact, relatively small (memory-usage & LoC-wise) and squizes every last drop of performance to make indexing to a general-purpose database practical. And running random SQL queries against Bitcoin's blockchain data is just very fun. rust-bitcoin-indexer can be also a good example how to quickly dump billions of rows worth of SQL data into Postgres.

Running

Install Rust with https://rustup.rs

Bitcoind node

Setup Bitcoind full node, with a config similiar to this:

# [core]
# Run in the background as a daemon and accept commands.
daemon=0

# [rpc]
# Accept command line and JSON-RPC commands.
server=1
# Username for JSON-RPC connections
rpcuser=user
# Password for JSON-RPC connections
rpcpassword=password

# [wallet]
# Do not load the wallet and disable wallet RPC calls.
disablewallet=1
walletbroadcast=0

The only important part here is being able to access JSON-RPC interface.

Postgresql

Setup Postgresql DB, with a db and user:pass that can access it. Example:

sudo su postgres
export PGPASSWORD=bitcoin-indexer
createuser bitcoin-indexer
createdb bitcoin-indexer bitcoin-indexer

.env file

Setup .env file with Postgresql and Bitcoin Core connection data. Example:

DATABASE_URL=postgres://bitcoin-indexer:bitcoin-indexer@localhost/bitcoin-indexer
NODE_RPC_URL=http://someuser:somepassword@localhost:18443

Optimize DB performance for massive amount of inserts!

This one is very important!!!

Indexing from scratch will dump huge amounts of data into the DB. If you don't want to wait for the initial indexing to complete for days or weeks, you should carefully review this section.

On software level pg.rs already implements the following optimizations:

  • inserts are made using multi-row value insert statements;
  • multiple multi-row insert statements are batched into one transaction;
  • initial sync starts with no indices and utxo set is cached in memory;
  • once restarted, missing UTXOs are fetched from the db, but new ones are still being cached in memory;
  • once restarted, only minimum indices are created (for UTXO fetching)
  • all indices are created only after reach the chain-head

Tune your system for best performance too:

  • Consider tunning your PG instance for such workloads.;
  • Make sure your DB is on a performant file-system; generally COW filesystems perform poorly for databases, without providing any value; on btrfs you can disable COW per directory; eg. chattr -R +C /var/lib/postgresql/9.6/; On other FSes: disable barriers, align to SSD; you can mount your fs in more risky-mode for initial sync, and revert back to safe settings aftewards.
  • on my HDD ext4 sudo tune2fs -o journal_data_writeback /dev/<partition> some improvement, but ultimately SMR disk turned out to be too slow to keep up with inserting data into > 1B records table and updating indices.

Possibly ask an experienced db admin if anything more can be done. We're talking about inserting around billion records into 3 tables each.

For reference - on my system, I get around 30k txs indexed per second:

[2019-05-24T05:20:29Z INFO  bitcoin_indexer::db::pg] Block 194369H fully indexed and commited; 99block/s; 30231tx/s

which leads to around 5 hours initial blockchain indexing time (current block height is around 577k)... and then just 4 additional hours to build indices.

I suggest using tx/s metric to estimate completion.

Run

Now everything should be ready. Compile and run with:

cargo run --release --bin bitcoin-indexer

After the initial full sync, you can also start mempool indexer:

cargo run --release --bin mempool-indexer

in a directory containing the .env file.

More options

You can use --wipe-whole-db to wipe the db. (to be removed in the future)

For logging set env. var. RUST_LOG to bitcoin_indexer=info or refer to https://docs.rs/env_logger/0.6.0/env_logger/.

Some useful stuff that can be done already

Check current balance of an address:

bitcoin-indexer=> select * from address_balances where address = '14zV5ZCqYmgyCzoVEhRVsP7SpUDVsCBz5g';                                                                                                                                          
              address               |   value
------------------------------------+------------
 14zV5ZCqYmgyCzoVEhRVsP7SpUDVsCBz5g | 6138945213

Check balances at a given height:

bitcoin-indexer=> select * from address_balances_at_height WHERE address IN ('14zV5ZCqYmgyCzoVEhRVsP7SpUDVsCBz5g', '344tcgkKA97LpgzGtAprtqnNRDfo4VQQWT') AND height = 559834;
              address               | height |   value   
------------------------------------+--------+-----------
 14zV5ZCqYmgyCzoVEhRVsP7SpUDVsCBz5g | 559834 | 162209091
 344tcgkKA97LpgzGtAprtqnNRDfo4VQQWT | 559834 |         0

Check txes pending in the mempool:

bitcoin-indexer=> select * from tx_in_mempool order by (fee/weight) desc limit 5;
              hash_id               |             hash_rest              | size | weight |  fee   | locktime | coinbase |                                hash                                |             ts
------------------------------------+------------------------------------+------+--------+--------+----------+----------+--------------------------------------------------------------------+----------------------------
 \x5d094cc3e4d9a1ec2d280aa9204ff8e4 | \xf0e960ddfed324880dac6e8ab54544c6 |  191 |    764 | 562871 |   577816 | f        | \xc64445b58a6eac0d8824d3fedd60e9f0e4f84f20a90a282deca1d9e4c34c095d | 2019-05-26 05:31:08.658908
 \x5a8caef874d1cd657460f754a9ae6985 | \xcce821c1789f20b665fd6240717340b6 |  213 |    855 | 182000 |        0 | f        | \xb64073714062fd65b6209f78c121e8cc8569aea954f7607465cdd174f8ae8c5a | 2019-05-26 05:36:10.331908
 \xab60acf5b6c7d6103e7186a9d319210b | \xdb0baedb6c49cfe748411ea8de8425a8 |  371 |   1484 | 298600 |        0 | f        | \xa82584dea81e4148e7cf496cdbae0bdb0b2119d3a986713e10d6c7b6f5ac60ab | 2019-05-26 05:30:57.902214
 \x5b63601004575830ccde165a924b823e | \xd5085b0193da8a5c2d0d1bc579a77a06 |  339 |   1356 | 163953 |        0 | f        | \x067aa779c51b0d2d5c8ada93015b08d53e824b925a16decc305857041060635b | 2019-05-26 05:34:34.603281
 \xaf8ce41bd3c7db9dd44fa126b5d5d386 | \x1b0a8db2986f1124c2ebba3e9cbc9251 |  112 |    450 |  53788 |        0 | f        | \x5192bc9c3ebaebc224116f98b28d0a1b86d3d5b526a14fd49ddbc7d31be48caf | 2019-05-26 05:37:46.736696
(5 rows)

and many more. Refer to ./src/db/pg/*.sql files for good overview of the schema and utilities.

Support

If you like and/or use this project, you can pay for it by sending Bitcoin to 33A9SwFHWEnwmFfgRfHu1GvSfCeDcABx93.

rust-bitcoin-indexer's People

Contributors

dpc avatar vorot93 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rust-bitcoin-indexer's Issues

Crash: Send should not fail: SendError(..)

After syncing for a while I get the following crash:

$ cargo run --release --bin bitcoin-indexer
....
Block 148000H: 15fab4fea3bc1ce8e2b3bde4196c5b93a7005ab6de92a07347231df11693c975
Block 149000H: 63764d310fa13832501d5b0f1bd330b848d39775d70863528b42322f44f84348
Block 150000H: a3713b98f2d05246f2c1f022fc68e1f41eca08145be6ec3a64b74a671b54e5bd
Block 151000H: 0cb9ffcce95652e5751cdd4b62bfde13a2032792cdf89d7bcbcd9a797a61ac5f
thread 'main' panicked at 'Send should not fail: "SendError(..)"', src/db/pg.rs:1338:14
thread 'main' panicked at 'Couldn't join on thread: Any { .. }', src/db/pg.rs:1109:18
stack backtrace:
0: 0x559869c919a0 - std::backtrace_rs::backtrace::libunwind::trace::ha0ad43e8a952bfe7
at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
1: 0x559869c919a0 - std::backtrace_rs::backtrace::trace_unsynchronized::h6830419c0c4130dc
at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
2: 0x559869c919a0 - std::sys_common::backtrace::_print_fmt::h8f3516631ffa1ef5
at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/sys_common/backtrace.rs:67:5
3: 0x559869c919a0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he1640d5f0d93f618
at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/sys_common/backtrace.rs:46:22
4: 0x559869cb353c - core::fmt::write::h88012e1f01caeebf
at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/fmt/mod.rs:1115:17
5: 0x559869c8cff5 - std::io::Write::write_fmt::h360fa85b30182555
at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/io/mod.rs:1665:15
6: 0x559869c93a5b - std::sys_common::backtrace::_print::ha1f00492f406a015
at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/sys_common/backtrace.rs:49:5
7: 0x559869c93a5b - std::sys_common::backtrace::print::hd54561b13feb6af3
at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/sys_common/backtrace.rs:36:9
8: 0x559869c93a5b - std::panicking::default_hook::{{closure}}::h84fe124cd0864662
at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:208:50
9: 0x559869c93531 - std::panicking::default_hook::h5a8e74a76ce290a7
at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:225:9
10: 0x559869c94124 - std::panicking::rust_panic_with_hook::h67c812a4fe9d4c91
at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:622:17
11: 0x559869c93c07 - std::panicking::begin_panic_handler::{{closure}}::h33f9c1b96af300d7
at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:519:13
12: 0x559869c91e9c - std::sys_common::backtrace::__rust_end_short_backtrace::h51bae64be5921f0e
at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/sys_common/backtrace.rs:141:18
13: 0x559869c93b69 - rust_begin_unwind
at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:515:5
14: 0x559869a1e241 - core::panicking::panic_fmt::h12a3a3c256485fca
at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/panicking.rs:92:14
15: 0x559869a1e333 - core::result::unwrap_failed::h2d8d0952e3250de9
at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/result.rs:1599:5
16: 0x559869ad5d68 - <bitcoin_indexer::db::pg::AsyncBlockInsertWorker as core::ops::drop::Drop>::drop::h728e549bf3a75c3a
17: 0x559869ad0b1c - core::ptr::drop_in_place<core::option::Option<bitcoin_indexer::db::pg::AsyncBlockInsertWorker>>::h057563b2348cd0db
18: 0x559869ad728b - bitcoin_indexer::db::pg::IndexerStore::stop_workers::h59577b2b32e0e5d4
19: 0x559869a2ad5e - core::ptr::drop_in_place<bitcoin_indexer::db::pg::IndexerStore>::h7e6791489810616f
20: 0x559869a2a4b3 - core::ptr::drop_in_place<bitcoin_indexer::Indexer>::h480fc1fcd6d63aed
21: 0x559869a2d823 - bitcoin_indexer::main::h2e9aa7182fd27883
22: 0x559869a4ca33 - std::sys_common::backtrace::__rust_begin_short_backtrace::ha533a456d10dd549
23: 0x559869a4cae9 - std::rt::lang_start::{{closure}}::h970b6bd182e7c5ce
24: 0x559869c9472a - core::ops::function::impls::<impl core::ops::function::FnOnce for &F>::call_once::ha9408abe89f69dc4
at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/ops/function.rs:259:13
25: 0x559869c9472a - std::panicking::try::do_call::h5b0cc9e9102acb65
at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:401:40
26: 0x559869c9472a - std::panicking::try::hddc7f8229138b3ba
at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:365:19
27: 0x559869c9472a - std::panic::catch_unwind::hfa401ff8bab2986e
at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panic.rs:434:14
28: 0x559869c9472a - std::rt::lang_start_internal::{{closure}}::h8163422320d11405
at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/rt.rs:45:48
29: 0x559869c9472a - std::panicking::try::do_call::hc742cc7bb4f0fb20
at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:401:40
30: 0x559869c9472a - std::panicking::try::ha37d8d2dd1acf7d3
at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:365:19
31: 0x559869c9472a - std::panic::catch_unwind::h8a5381d5ecf437bc
at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panic.rs:434:14
32: 0x559869c9472a - std::rt::lang_start_internal::h7e2cee8c90d4a4d3
at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/rt.rs:45:20
33: 0x559869a2d852 - main
34: 0x7f3fa84e113a - __libc_start_main
35: 0x559869a1ea1a - _start
36: 0x0 -
thread panicked while panicking. aborting.
Illegal instruction

$ cargo --version
cargo 1.55.0 (32da73ab1 2021-08-23)

$ rustc -V
rustc 1.55.0 (c8dfcfe04 2021-09-06)

Error: JSON-RPC error: JSON decode error: invalid type: map, expected a sequence

Howdy! Just found your project. Looking forward to using it.

I set up bitcoind, and it's running. The following curl command works:

$ curl --user user --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblockchaininfo", "params": [] }'  -H 'content-type: text/plain;' http://127.0.0.1:8332/
Enter host password for user 'user':
{"result":{"chain":"main","blocks":618983,"headers":618983,"bestblockhash":"0000000000000000000a9aae670c69c9874d6006065edf73a2c26af7c878602b","difficulty":15486913440292.87,"mediantime":1582661642,"verificationprogress":0.9999986054933675,"initialblockdownload":false,"chainwork":"00000000000000000000000000000000000000000d076aae823919dd1c7f5b68","size_on_disk":300418549537,"pruned":false,"softforks":{"bip34":{"type":"buried","active":true,"height":227931},"bip66":{"type":"buried","active":true,"height":363725},"bip65":{"type":"buried","active":true,"height":388381},"csv":{"type":"buried","active":true,"height":419328},"segwit":{"type":"buried","active":true,"height":481824}},"warnings":""},"error":null,"id":"curltest"}

My .env looks like this:

DATABASE_URL=postgres://jkugler:PASS@localhost/bitcoin-indexer
NODE_RPC_URL=http://user:PASS@localhost:8332

But when I run cargo run --release --bin bitcoin-indexer it fails with:

    Finished release [optimized] target(s) in 0.13s
     Running `target/release/bitcoin-indexer`
Error: JSON-RPC error: JSON decode error: invalid type: map, expected a sequence

Any suggestions?

I am using bitcoin-core 0.19.0.1. What version was used with this project? I'm really looking forward to using this...just trying to get it up and running.

Add `fee` on `txs`

sum(outputs.value) - sum(inputs.value). It's much better to have it on the txs, than trying to calculate it on fly, when needed.

Perf log

Using UNLOGGED:

[2019-05-06T01:37:57Z INFO  bitcoin_indexer::db::pg] Creating initial db schema  
...
[2019-05-06T05:38:18Z INFO  bitcoin_indexer::db::pg] Entering normal mode: all indices
...
[2019-05-06T05:38:25Z INFO  bitcoin_indexer::db::pg] Adjusting schema to mode: normal
...
[2019-05-06T11:32:00Z INFO  bitcoin_indexer::db::pg] Block 574771H fully indexed and commited; 0block/s; 0tx/s

Without bother with UNLOGGED:

[2019-05-06T19:55:05Z INFO  bitcoin_indexer::db::pg] Creating initial db schema
...

[2019-05-07T00:45:09Z INFO  bitcoin_indexer::db::pg] Entering normal mode: all indices
...
[2019-05-07T00:45:16Z INFO  bitcoin_indexer::db::pg] Adjusting schema to mode: normal                                                              
...                                                                  
[2019-05-07T03:03:43Z INFO  bitcoin_indexer::db::pg] Block 574883H fully indexed and commited; 0block/s; 0tx/s     

Significant performance penalty when interrupting and restarting indexing

I've experienced a significant performance penalty when restarting indexing (~12k tx/s -> ~3k tx/s), probably due to old UTXOs being queried from the DB as described in the README. To avoid that the in-memory UTXO set probably had to be rebuilt when restarting. I wonder if that's feasible?

I don't think it has a high priority, just to keep it in mind.

Database error while running indexer

I got past the error in #8 by downgrading to bitcoin core 0.18, but have hit another issue:

    Finished dev [unoptimized + debuginfo] target(s) in 0.17s
     Running `target/debug/bitcoin-indexer`
Error: database error: ERROR: syntax error at or near "NOT"

I am running postgresql 9.2 (CentOS 7). I'm going to try upgrading and see where I get.

Document required disk space

First of all, this project looks really cool! I hope I will be able to play with it at some point. :) Maybe even package it into my deb repo at some point.

I'd like to know the system requirements, especially disk space and I think it'd be useful to have it in the README.

Segfault soon after run start

Soon after startup got this:

$ cargo run --release --bin bitcoin-indexer
    Finished release [optimized] target(s) in 0.42s
     Running `target/release/bitcoin-indexer`
Block 0H: 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
Block 1000H: 00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09
Block 2000H: 00000000dfd5d65c9d8561b4b8f60a63018fe3933ecb131fb37f905f87da951a
Block 3000H: 000000004a81b9aa469b11649996ecb0a452c16d1181e72f9f980850a1c5ecce
...
Block 70000H: 00000000002b8cd0faa58444df3ba2a22af2b5838c7e4a5b687444f913a575c2
Block 71000H: 00000000003eea76022498376477294a921cfabeee70f0630ce0fd45dc22179b
Block 72000H: 0000000000eb357d4c6fef6ad9a6fade126985ad36042a99cf215a4454545977
thread '<unnamed>' panicked at 'attempted to leave type `nodrop::NoDrop<(epoch::Epoch, garbage::Bag)>` uninitialized, which is invalid', /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/core/src/mem/mod.rs:659:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Segmentation fault (core dumped)

Running plain vanilla Ubuntu 20.04 with latest stable rust 1.49.0:

$ uname -a
Linux ip-172-31-36-91 5.4.0-1029-aws #30-Ubuntu SMP Tue Oct 20 10:06:38 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

$ rustup show
Default host: x86_64-unknown-linux-gnu
rustup home:  /home/ubuntu/snap/rustup/common/rustup

stable-x86_64-unknown-linux-gnu (default)
rustc 1.49.0 (e1884a8e3 2020-12-29)

Might be similar to openethereum/openethereum#157 ?

Stuck at Block 10000H

Hi there
Not sure how to debug this it just stops at block 10000H.
I had a look at database tables and they are empty too

[2022-02-17T18:34:52Z INFO  bitcoin_indexer::db::pg] Creating initial db schema
[2022-02-17T18:34:52Z INFO  bitcoin_indexer::db::pg] Entering fresh mode: no indices
[2022-02-17T18:34:52Z INFO  bitcoin_indexer::db::pg] Adjusting schema to mode: fresh-bulk
[2022-02-17T18:34:52Z INFO  bitcoin_indexer::db::pg] Entering fresh mode: minimum indices
[2022-02-17T18:34:52Z INFO  bitcoin_indexer::db::pg] Adjusting schema to mode: bulk
[2022-02-17T18:34:52Z INFO  bitcoin_indexer::db::pg] Entering normal mode: all indices
[2022-02-17T18:34:52Z INFO  bitcoin_indexer::db::pg] Adjusting schema to mode: normal
[2022-02-17T18:34:52Z INFO  bitcoin_indexer::db::pg] Entering fresh mode: minimum indices
[2022-02-17T18:34:52Z INFO  bitcoin_indexer::db::pg] Adjusting schema to mode: bulk
[2022-02-17T18:34:52Z INFO  bitcoin_indexer::db::pg] Entering fresh mode: no indices
[2022-02-17T18:34:52Z INFO  bitcoin_indexer::db::pg] Adjusting schema to mode: fresh-bulk
[2022-02-17T18:34:52Z INFO  bitcoin_indexer::db::pg] Adjusting schema to mode: fresh-bulk
[2022-02-17T18:34:52Z INFO  bitcoin_indexer] Node chain-head at 146362H
[2022-02-17T18:34:52Z INFO  bitcoin_indexer::node::prefetcher] Starting block fetcher starting at genesis block

Block 0H: ceac4f4dc5aa01eb7fe5b36410cd7a1cb0f89856c76401a69d1b30fb8bc0e3bf
Block 1000H: 19c1b92ac5ac4457ca873a7d1e40a675913d7cbe102f208b72407984721c44ba
Block 2000H: 4dd81876e67fe947c2088ef002bb1dd3d9f64add4339af736b9948d9fa7ebd1f
Block 3000H: 4315a14679fe131c94404784fc5f7012e9ab951cbc0e464bb105a4f0e555ce39
Block 4000H: ee39880e4fbc5b1f4a0f4310a8410d491e3c5833c03c5d7027217da4328efcd3
Block 5000H: 955c292a31ef8e472736f983e9205c38510fdc8f96a4641f1cf0832e3971c77e
Block 6000H: 8fc3873307839882d2f5ac58b6849ee66c58286cb518baf646528de3116e70d4
Block 7000H: d38dee425335979c5047dd761692502459cc1e12736ec7ff2d53b718569f984e
Block 8000H: 370780d486dfe5354fc8937e48dd46c3172dc30dd43f7e1f915524e47ec6856b
Block 9000H: 9182dccdc36aaf4aaa8ade8e25a9ffe955216572ce07414a42157699014a2dfc
Block 10000H: 404abb998428aa89a7bb75baa8a1a6f463e8f28b9e909616ad1c71143b0f3df6

Lower `SQL_HASH_ID_SIZE`?

SQL_HASH_ID_SIZE defines how many first bytes of a txid are we using as an ID. Since ID is used in all other tables, referencing a tx, which is a central to everything, every byte we shave from it, saves many gigabytes and some performance elsewhere.

Can't connect with DO managed postgres

I've been trying to run the the rust-bitcoin-indexer, it runs perfectly in my locally but while using DO managed postgres, it give error ' it runs perfectly in my locally'. I think this is related to the following LOC, looking forward to your suggestion/edit.

match pg::Connection::connect(url, pg::TlsMode::None) {

Incorrect comparison in readme

Embedded KV store can be potentially more compact and faster, but electrs stores the actual block data, while rust-bitcoin-indexer extracts only the data it needs and throws everything else away.

I'm not sure this is correct. As far as I understand it electrs only maintains a very minimal TX output, TX input and TXID => block height index.

All the actual data queries are passed through to bitcoind.

https://github.com/romanz/electrs/blob/0f3aaa6671e3839fc2dcdc54a36f0e8dd674f398/doc/schema.md

Cursor-based API

Each downstream consumer would maintain a cursor, and ask for next blocks using it. The response would contain new cursor. This way multiple unrelated consumers can follow the ledger, without API having to keep track of them.

Canceling protocol should be used, so we will need code converting truncating protocol in the db into canceling one. Should be easy.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.