Bitcoin Forum
June 06, 2024, 03:22:12 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Where is the version field set for "getblocks" and "getheaders"?  (Read 980 times)
MatthewLM (OP)
Legendary
*
Offline Offline

Activity: 1190
Merit: 1004


View Profile
August 22, 2013, 04:33:22 PM
 #1

According to the protocol specification wiki page the "getblocks" and "getheaders" messages have a version field: https://en.bitcoin.it/wiki/Protocol_specification#getblocks

I cannot find where this is set in the bitcoin satoshi client source code. All I can see is the block locator object and stop hash being set. Can anyone enlighten me?
joshlang
Newbie
*
Offline Offline

Activity: 26
Merit: 0


View Profile
August 22, 2013, 05:15:29 PM
 #2

According to that link, it's the protocol version that you negotiated with the remote node.

Yours is hardcoded.  70001 for example.

You connect to another node and exchange "version" messages, but their version message says they're using protocol version 60001 instead.

So for the rest of the connection, you both have to use 60001.

...That being said, it makes no sense to me why protocol version would be included as part of a payload other than the "version" payload, since it's negotiated and known already.  So perhaps the spec is incomplete or not yet being used.  
joshlang
Newbie
*
Offline Offline

Activity: 26
Merit: 0


View Profile
August 22, 2013, 05:21:54 PM
 #3

!#%(&!@#)(!@&#%)!(@#%&!@#)(%&!@#)(%&!@#()%&!@#)(%&!@#)(%&!@)#(%&!)@(#%&!#@)(%&!@#)(%&!#@)(%&!@#)(%&!#)@(&%
Silly forum just deleted my follow-up post because I posted less than 6 minutes ago.  GRR.

Anyway - just a thought that struck me:

Perhaps getheaders and getblocks is intended one day to be passed between nodes?

For example:
You connect to node 1.  You send getheaders.
Node 1 says "wtf I dunno!" and passes it along to Node 2.
Node 2 needs to know your protocol version, because you're not connected to it.
Node 2 responds, and node 1 passes it back to you.

Who knows.  I'm newb Smiley.

But in getblocks, it's definitely OK to set it to your negotiated protocol version.  I do this, and I manage to download the entire blockchain every time with no problems.
MatthewLM (OP)
Legendary
*
Offline Offline

Activity: 1190
Merit: 1004


View Profile
August 22, 2013, 06:04:04 PM
 #4

Thank you for the response. The only concern I have is I can't find where the version is set in the source-code at all. "getblocks" is sent with PushGetBlocks which is:

Code:
void PushGetBlocks(CNode* pnode, CBlockIndex* pindexBegin, uint256 hashEnd)
{
    // Filter out duplicate requests
    if (pindexBegin == pnode->pindexLastGetBlocksBegin && hashEnd == pnode->hashLastGetBlocksEnd)
        return;
    pnode->pindexLastGetBlocksBegin = pindexBegin;
    pnode->hashLastGetBlocksEnd = hashEnd;

    pnode->PushMessage("getblocks", CBlockLocator(pindexBegin), hashEnd);
}

So it's pushing the message "getblocks", but only with the block locator and hashEnd. Where is the version? I can't find it set in BeginMessage() or EndMessage(). Nor is it found in the CBlockLocator...
joshlang
Newbie
*
Offline Offline

Activity: 26
Merit: 0


View Profile
August 22, 2013, 08:14:34 PM
 #5

Here it is:

Code:
class CBlockLocator
{
...
IMPLEMENT_SERIALIZE
    (
        if (!(nType & SER_GETHASH))
            READWRITE(nVersion);
        READWRITE(vHave);
    )
...
};

Funny - it's in there kinda just as a side-effect Smiley
MatthewLM (OP)
Legendary
*
Offline Offline

Activity: 1190
Merit: 1004


View Profile
August 22, 2013, 08:42:43 PM
 #6

Ah thank you. Trying to read through the source code can be a bit like going through a maze. Smiley I do not like macros being used to implement whole pieces of code. It appears by that code that sometimes a hash value of a CBlockLocator is wanted? No idea why that is.

Also I found that the CDataStream uses a version of MIN_PROTO_VERSION (See 237 of net.h) which would then be used in the "getblocks" messages.
joshlang
Newbie
*
Offline Offline

Activity: 26
Merit: 0


View Profile
August 22, 2013, 08:44:09 PM
 #7

A maze?

More like a meat grinder Smiley
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!