Bitcoin Forum
August 22, 2024, 05:22:13 AM *
News: All versions of Windows are affected by a critical security bug; make sure you update.
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: What is the difference between getblockCOUNT and getblockNUMBER ???  (Read 1871 times)
gigabytecoin (OP)
Sr. Member
****
Offline Offline

Activity: 280
Merit: 252


View Profile
June 28, 2011, 02:00:10 AM
 #1

When interacting with the bitcoin client, you have the option of passing two (different?) commands to it that seemingly always return the exact same result.

getblockcount === getblocknumber

Or does it?

And why?
JoelKatz
Legendary
*
Offline Offline

Activity: 1596
Merit: 1012


Democracy is vulnerable to a 51% attack.


View Profile WWW
June 28, 2011, 02:15:09 AM
 #2

Their code is identical in the client, other than the slight difference in the help text. One says it "[r]eturns the number of blocks in the longest block chain" the other says it "[r]eturns the block number of the latest block in the longest block chain".

Value getblockcount(const Array& params, bool fHelp)
{
    if (fHelp || params.size() != 0)
        throw runtime_error(
            "getblockcount\n"
            "Returns the number of blocks in the longest block chain.");

    return nBestHeight;
}

Value getblocknumber(const Array& params, bool fHelp)
{
    if (fHelp || params.size() != 0)
        throw runtime_error(
            "getblocknumber\n"
            "Returns the block number of the latest block in the longest block chain.");

    return nBestHeight;
}

I am an employee of Ripple. Follow me on Twitter @JoelKatz
1Joe1Katzci1rFcsr9HH7SLuHVnDy2aihZ BM-NBM3FRExVJSJJamV9ccgyWvQfratUHgN
theymos
Administrator
Legendary
*
Offline Offline

Activity: 5292
Merit: 13207


View Profile
June 28, 2011, 02:50:59 AM
 #3

They are the same. getblocknumber is obsolete.

It used to be that getblocknumber would return the highest block number, while getblockcount would return the total number of blocks. Confusingly, this behavior was switched when getblocknumber was made obsolete, so getblockcount now actually gives the highest block number.

The total number of blocks is different from the highest block number because the genesis block is block #0.

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
gigabytecoin (OP)
Sr. Member
****
Offline Offline

Activity: 280
Merit: 252


View Profile
June 28, 2011, 03:33:02 AM
 #4

Thanks for those explanations everyone.
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!