bitcoin core – Optimising blockchain parsing with rpc + python

on

|

views

and

comments


I’ve a python app to trace and retailer utxo in a easy/flat construction that appears like this…

from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException 

# monitor the utxo
trackUtxoList = []

# rpc name 1
rpc_connection = AuthServiceProxy("http://%s:%s@127.0.0.1:8332"%(rpc_user, rpc_password))

for b in vary(blockStart, blockLimit): 

    # rpc name 2 (per block)
    blockhash = rpc_connection.getblockhash(b)

    # rpc name 3 (per block)
    block = rpc_connection.getblock(blockhash)

    for txid in block['tx']:
        
        # rpc name 4 (per tx)
        raw_tx = rpc_connection.getrawtransaction(txid,False,blockhash) 

        # rpc name 5 (per tx)
        decoded_tx = rpc_connection.decoderawtransaction(raw_tx)

        for output in decoded_tx['vout']:

            # rpc name 6 (per vout)
            for l in rpc_connection.deriveaddresses(output['scriptPubKey']['desc']):
                trackUtxoList.append({'deal with':str(l),'worth':output['value'],'block':b, 'txid':txid,'isUtxo':True})

        for output in decoded_tx['vin']:

            vinSearch = record(filter(lambda merchandise: merchandise['t'] == output['txid'], trackUtxoList))
            vinSearch[output['vout']]['isUtxo'] = False

The issue is that it runs very slowly for two causes that relate to my 2 questions…

  1. My blocks listing is on an exterior laborious drive as a result of it is too massive for my laptop computer – fairly positive this may impression read-speeds and so I am questioning if it is attainable to someway cut up the blocks listing in order that for instance, I may pull 100k blocks onto my laptop computer, course of that, then delete and replica the subsequent 100k blocks onto my laptop computer and many others. I’ve already cut up the blocks listing (on exterior hdd) from the remainder of the information listing (on my laptop computer) however cannot discover any examples of individuals briefly splitting the blocks listing itself.

  2. I am making 2 rpc calls per block, 2 per transaction and 1 per vout. To my eye it seems like calls 5 + 6 (as commented in my code instance) do not actually need to make use of my rpc_connection since they’re manipulations on information already pulled from the blockchain? Whereas the others are necessities/unavoidable? If that is right, are there any python libraries which are usually used to decode transactions and derive addresses with out utilizing an rpc name? I performed a bit of with Buterin’s https://pypi.org/venture/bitcoin/ however because it’s now not maintained I wasn’t positive whether or not it is my greatest guess.

Thanks for any ideas in any respect on the way to optimise my code to parse your entire blockchain

Share this
Tags

Must-read

Constructing the Torc Driverless Security Case

At Torc, we’ve structured our security case on three foundational pillars: Engineer It to Be Secure, Function It to Be Secure, and the...

What’s DL+S? Unlocking the Huge Information Required to Develop Autonomous Vans

Breakthroughs in AI for autonomous driving don't occur in isolation. They occur when information, simulation, machine studying, infrastructure, and car testing work as...

Why I can’t wait to get right into a driverless automotive | Self-driving automobiles

Adrian Chiles (Driverless automobiles are taking us on a street to nowhere, 10 September) needs to know who requested for driverless automobiles. I...

Recent articles

More like this

LEAVE A REPLY

Please enter your comment!
Please enter your name here