Bitcoin Forum
May 07, 2024, 04:10:51 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Determining "Up-To-Date-Ness" via RPC commands  (Read 171 times)
l008com II (OP)
Newbie
*
Offline Offline

Activity: 6
Merit: 0


View Profile
July 02, 2020, 01:55:15 PM
 #1

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?
1715098251
Hero Member
*
Offline Offline

Posts: 1715098251

View Profile Personal Message (Offline)

Ignore
1715098251
Reply with quote  #2

1715098251
Report to moderator
Remember that Bitcoin is still beta software. Don't put all of your money into BTC!
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715098251
Hero Member
*
Offline Offline

Posts: 1715098251

View Profile Personal Message (Offline)

Ignore
1715098251
Reply with quote  #2

1715098251
Report to moderator
1715098251
Hero Member
*
Offline Offline

Posts: 1715098251

View Profile Personal Message (Offline)

Ignore
1715098251
Reply with quote  #2

1715098251
Report to moderator
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6631


Just writing some code


View Profile WWW
July 02, 2020, 02:35:06 PM
 #2

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.

TheArchaeologist
Sr. Member
****
Offline Offline

Activity: 310
Merit: 727


---------> 1231006505


View Profile WWW
July 03, 2020, 03:43:52 PM
 #3

I'm doing the exact same thing as you describe for my custom parser. This is in python:

Code:
<snip>
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.

Sooner or later you're going to realize, just as I did, that there's a difference between knowing the path and walking the path
l008com II (OP)
Newbie
*
Offline Offline

Activity: 6
Merit: 0


View Profile
July 06, 2020, 12:29:25 PM
 #4

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


achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6631


Just writing some code


View Profile WWW
July 06, 2020, 03:20:14 PM
 #5

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.

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!