Author

Topic: Where is the version field set for "getblocks" and "getheaders"? (Read 980 times)

newbie
Activity: 26
Merit: 0
A maze?

More like a meat grinder Smiley
legendary
Activity: 1190
Merit: 1004
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.
newbie
Activity: 26
Merit: 0
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
legendary
Activity: 1190
Merit: 1004
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...
newbie
Activity: 26
Merit: 0
!#%(&!@#)(!@&#%)!(@#%&!@#)(%&!@#)(%&!@#()%&!@#)(%&!@#)(%&!@)#(%&!)@(#%&!#@)(%&!@#)(%&!#@)(%&!@#)(%&!#)@(&%
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.
newbie
Activity: 26
Merit: 0
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.  
legendary
Activity: 1190
Merit: 1004
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?
Jump to: