Author

Topic: Determining "Up-To-Date-Ness" via RPC commands (Read 185 times)

staff
Activity: 3458
Merit: 6793
Just writing some code
I would much rather do it that simpler way. However when I run `getblockchaininfo`, the key 'initialblockdownload' is always blank. All the other keys have values but that one does not

Code:
            [chain] => main
            [blocks] => 637966
            [headers] => 637967
            [difficulty] => 15784217546288
            [mediantime] => 1594035307
            [verificationprogress] => 0.99999916914354
            [initialblockdownload] =>
            [size_on_disk] => 1911635625
            [pruned] => 1
            [pruneheight] => 636460
            [automatic_pruning] => 1
            [prune_target_size] => 1999634432
The JSON-RPC interface won't return a blank value for something in a JSON object, that's not allowed. It's probably returning false and your software is interpreting that to be blank or null.
newbie
Activity: 6
Merit: 0
We would have to see your code. You are probably missing something in the JSON object constructions.

There's an easier way to check this. Bitcoin Core has an internal check called IsInitialBlockDownload. The boolean result of this is output in getblockchaininfo as the initialblockdownload field. When that becomes false, you can be reasonably sure that the node is fully synced. So you can just poll the getblockchaininfo RPC and wait for initialblockdownload to become false.

I would much rather do it that simpler way. However when I run `getblockchaininfo`, the key 'initialblockdownload' is always blank. All the other keys have values but that one does not

Code:
            [chain] => main
            [blocks] => 637966
            [headers] => 637967
            [difficulty] => 15784217546288
            [mediantime] => 1594035307
            [verificationprogress] => 0.99999916914354
            [initialblockdownload] =>
            [size_on_disk] => 1911635625
            [pruned] => 1
            [pruneheight] => 636460
            [automatic_pruning] => 1
            [prune_target_size] => 1999634432


sr. member
Activity: 310
Merit: 727
---------> 1231006505
I'm doing the exact same thing as you describe for my custom parser. This is in python:

Code:

endBlock =rpc_connection.getblockcount()
number_to_process = (endBlock - startBlock) + 1

print "===================================================================="
print "Starting from : " + str(startBlock)
print "Ending at     : " + str(endBlock)
print "===================================================================="

progress = 0
with progressbar.ProgressBar(max_value=number_to_process) as bar:
        for height in range(startBlock, endBlock+1):
                block_hash = rpc_connection.getblockhash(height)

                block= rpc_connection.getblock(block_hash)
                transactions_in_block = block["nTx"]

                #fill variables based on json response
                height     = block["height"]            #integer
                version    = block["version"]           #integer
                difficulty = block["difficulty"]        #integer
                time       = block["time"]              #integer
                txs        = transactions_in_block      #integer
                nonce      = block["nonce"]             #integer
                bits       = block["bits"]              #string
                size       = block["size"]              #integer
                weight     = block["weight"]            #integer
                blockhash  = block["hash"]              #string
                merkleroot = block["merkleroot"]        #string
This works like a charm so I guess you are doing something wrong. Hard to tell what since you didn't share any code.
staff
Activity: 3458
Merit: 6793
Just writing some code
We would have to see your code. You are probably missing something in the JSON object constructions.

There's an easier way to check this. Bitcoin Core has an internal check called IsInitialBlockDownload. The boolean result of this is output in getblockchaininfo as the initialblockdownload field. When that becomes false, you can be reasonably sure that the node is fully synced. So you can just poll the getblockchaininfo RPC and wait for initialblockdownload to become false.
newbie
Activity: 6
Merit: 0
After doing some reading on the topic, it looks like the only way to determine if a wallet is up to date, and this is apparently what the wallets do, is just see how old the newest block is. With bitcoin, if the newest block is less than 90 minutes old, you are considered up to date.

I'm trying to recreate this in my own web dashboard using RPC commands. So I do the following....
First I run this
Code:
getblockcount
To get the number of the newest block.

Then I run this
Code:
getblockhash {number from previous step}
to get the hash of that block

Then I run this to look up all the info on this block and ultimately get it's ['time'] attribute:
Code:
getblock {hash from previous step}

But this is where things go awry. This returns an error:
Code:
             {code} => -32700
            {message} => Parse error

This is inside a php shell script using the built in curl module. I also tried running this command using `curl` directly from the command line.
Code:
curl --user *username* --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblock", "params": ["08eea4f5d6dfac07937095695aea67ba1548c64b64bae99b2f4f20a34e08aea0"] }' -H 'content-type: text/plain;' http://*lanIP*:*port#*/
Using that, I repeatedly get "Connection Refused" errors. Which is different than a parse error. So I have no idea what's actually going on here?

Any thoughts? Is the `getblock` command broken? Or is there something I'm doing wrong in my code?
Jump to: