Bitcoin Forum
May 07, 2024, 12:49:42 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: RPC getrawtransaction for all transactions in a block  (Read 146 times)
lapidary (OP)
Newbie
*
Offline Offline

Activity: 6
Merit: 4


View Profile
December 22, 2019, 12:53:09 PM
 #1

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?
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
lapidary (OP)
Newbie
*
Offline Offline

Activity: 6
Merit: 4


View Profile
December 23, 2019, 03:05:56 AM
 #2

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:%s@192.168.000.000: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.
pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10555



View Profile
December 23, 2019, 04:56:54 AM
Merited by HCP (2), ABCbits (1)
 #3

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.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
lapidary (OP)
Newbie
*
Offline Offline

Activity: 6
Merit: 4


View Profile
December 25, 2019, 09:34:41 PM
 #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.
pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10555



View Profile
December 26, 2019, 04:45:56 AM
 #5

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.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!