Today, it is possible to fetch a block’s spent prevouts in order to build an external index by using the /rest/block/BLOCKHASH.json
endpoint. However, its performance is low due to JSON serialization overhead.
We can significantly optimize it by adding a new REST API endpoint, using a binary response format (returning a collection of spent txout lists, one per each block transaction):
0$ BLOCKHASH=00000000000000000002a7c4c1e48d76c5a37902165a270156b7a8d72728a054
1
2$ ab -k -c 1 -n 100 http://localhost:8332/rest/block/$BLOCKHASH.json
3Document Length: 13278152 bytes
4Requests per second: 3.53 [#/sec] (mean)
5Time per request: 283.569 [ms] (mean)
6
7$ ab -k -c 1 -n 10000 http://localhost:8332/rest/spenttxouts/$BLOCKHASH.bin
8Document Length: 195591 bytes
9Requests per second: 254.47 [#/sec] (mean)
10Time per request: 3.930 [ms] (mean)
Currently, this PR is being used and tested by Bindex1.
This PR would allow to improve the performance of external indexers such as electrs2, ElectrumX3, Fulcrum4 and Blockbook5.