Author

Topic: RPC getrawtransaction for all transactions in a block (Read 169 times)

legendary
Activity: 3472
Merit: 10611
OMG; that is what I needed,
thanks a million!!! This goes many times faster now.

Still odd that it takes longer when I give the hash.

your welcome.
the longer time is probably due to the overhead of multiple individual RPC calls (one per tx) and the client having to find a transaction in its database by only having its hash.
newbie
Activity: 6
Merit: 4
OMG; that is what I needed,
thanks a million!!! This goes many times faster now.

Still odd that it takes longer when I give the hash.
legendary
Activity: 3472
Merit: 10611
you don't need to call getrawtransaction command for each transaction in a block. since you want "all" transactions in a specific block the same getblock command can return what you need if you set the other optional integer variable called "verbosity".
https://bitcoin.org/en/developer-reference#getblock
0 -> returns the whole block in hexadecimal format
1 -> returns deserialized JSON but the tx array only contains the tx IDs
2 -> returns deserialized JSON and each tx is also deserialized as a JSON object. this also has a new JSON key called "hex" per tx that includes the raw tx hex in it.
newbie
Activity: 6
Merit: 4
I wrote a little page to do a speed test on a large block,
I only ran it three times, but it is consistent,
Code:
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
import time
rpc_user = "NotMyRealUsername"
rpc_password = "NotMyRealPassword"
rpc_connection = AuthServiceProxy("http://%s:%[email protected]:8332"%(rpc_user, rpc_password))
h = "000000000000000000036f0cfb2dadd069060c8ba36d63f2e11cb02e85ef7ed2"

alldata = rpc_connection.getblock(h)
start = time.time()
for txid in alldata['tx']:
    rawtx = rpc_connection.getrawtransaction(txid,1)
stop = time.time()
print(stop-start)
start = time.time()
for txid in alldata['tx']:
    rawtx = rpc_connection.getrawtransaction(txid,1,h)
stop = time.time()
print(stop-start)
first without hash is 9 seconds, with hash is 149 seconds
My bitcoin node is live, but only has 20 peers, and little traffic.  It is version 0.17 (newest I can install on pfSense), the database is on a dedicated SSD, core 2 quad,
Memory: 221M Active, 290M Free  4G real memory.  bitcoind is the only thing that uses any real CPU.

to test my code, open your bitcoin config file to set rpcuser, rpcpassword, rpcallowip, and set txindex=1 (this will require re-indexing... sit back for a week on HDD with my CPU!!!) 
If you have an indexed full node, and python, pip install python-bitcoinrpc, and set the proper user/password/ip in the above code.
newbie
Activity: 6
Merit: 4
I have an indexed full node on my home router, and I run a python script on my desktop to grab all the transactions for a full block.  I did run it two ways:
Code:
rpc_connection.getrawtransaction(transactionID,1)
and
rpc_connection.getrawtransaction(transactionID,1,hash)
I also tried batch, but that would time out if I had a big block I wanted to look at.
first way thrashes the HD, second way hardly uses the HD at all, about 70% of one core, and runs slower than the first way.  can someone verify getrawtransaction takes longer to execute if you tell it which hash it's in?
Jump to: