@@ -1336,19 +1336,12 @@ bool CBlock::AcceptBlock()
13361336 if (!AddToBlockIndex (nFile, nBlockPos))
13371337 return error (" AcceptBlock() : AddToBlockIndex failed" );
13381338
1339- // Don't relay old inventory during initial block download.
1340- // Please keep this number updated to a few thousand below current block count.
1341- if (hashBestChain == hash && nBestHeight > 55000 )
1342- RelayInventory (CInv (MSG_BLOCK , hash));
1343-
1344- // // Add atoms to user reviews for coins created
1345- // vector<unsigned char> vchPubKey;
1346- // if (ExtractPubKey(vtx[0].vout[0].scriptPubKey, false, vchPubKey))
1347- // {
1348- // unsigned short nAtom = GetRand(USHRT_MAX - 100) + 100;
1349- // vector<unsigned short> vAtoms(1, nAtom);
1350- // AddAtomsAndPropagate(Hash(vchPubKey.begin(), vchPubKey.end()), vAtoms, true);
1351- // }
1339+ // Relay inventory, but don't relay old inventory during initial block download
1340+ if (hashBestChain == hash)
1341+ CRITICAL_BLOCK (cs_vNodes)
1342+ foreach (CNode* pnode, vNodes)
1343+ if (nBestHeight > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : 55000 ))
1344+ pnode->PushInventory (CInv (MSG_BLOCK , hash));
13521345
13531346 return true ;
13541347}
@@ -1721,19 +1714,21 @@ bool ProcessMessages(CNode* pfrom)
17211714 // (4) message start
17221715 // (12) command
17231716 // (4) size
1717+ // (4) checksum
17241718 // (x) data
17251719 //
17261720
17271721 loop
17281722 {
17291723 // Scan for message start
17301724 CDataStream::iterator pstart = search (vRecv.begin (), vRecv.end (), BEGIN (pchMessageStart), END (pchMessageStart));
1731- if (vRecv.end () - pstart < sizeof (CMessageHeader))
1725+ int nHeaderSize = vRecv.GetSerializeSize (CMessageHeader ());
1726+ if (vRecv.end () - pstart < nHeaderSize)
17321727 {
1733- if (vRecv.size () > sizeof (CMessageHeader) )
1728+ if (vRecv.size () > nHeaderSize )
17341729 {
17351730 printf (" \n\n PROCESSMESSAGE MESSAGESTART NOT FOUND\n\n " );
1736- vRecv.erase (vRecv.begin (), vRecv.end () - sizeof (CMessageHeader) );
1731+ vRecv.erase (vRecv.begin (), vRecv.end () - nHeaderSize );
17371732 }
17381733 break ;
17391734 }
@@ -1742,6 +1737,7 @@ bool ProcessMessages(CNode* pfrom)
17421737 vRecv.erase (vRecv.begin (), pstart);
17431738
17441739 // Read header
1740+ vector<char > vHeaderSave (vRecv.begin (), vRecv.begin () + nHeaderSize);
17451741 CMessageHeader hdr;
17461742 vRecv >> hdr;
17471743 if (!hdr.IsValid ())
@@ -1757,17 +1753,30 @@ bool ProcessMessages(CNode* pfrom)
17571753 {
17581754 // Rewind and wait for rest of message
17591755 // /// need a mechanism to give up waiting for overlong message size error
1760- // if (fDebug)
1761- // printf("message-break\n");
1762- vRecv.insert (vRecv.begin (), BEGIN (hdr), END (hdr));
1763- Sleep (100 );
1756+ if (fDebug )
1757+ printf (" message-break\n " );
1758+ vRecv.insert (vRecv.begin (), vHeaderSave.begin (), vHeaderSave.end ());
17641759 break ;
17651760 }
17661761
17671762 // Copy message to its own buffer
17681763 CDataStream vMsg (vRecv.begin (), vRecv.begin () + nMessageSize, vRecv.nType , vRecv.nVersion );
17691764 vRecv.ignore (nMessageSize);
17701765
1766+ // Checksum
1767+ if (vRecv.GetVersion () >= 209 )
1768+ {
1769+ uint256 hash = Hash (vMsg.begin (), vMsg.end ());
1770+ unsigned int nChecksum = 0 ;
1771+ memcpy (&nChecksum, &hash, sizeof (nChecksum));
1772+ if (nChecksum != hdr.nChecksum )
1773+ {
1774+ printf (" ProcessMessage(%s, %d bytes) : CHECKSUM ERROR nChecksum=%08x hdr.nChecksum=%08x\n " ,
1775+ strCommand.c_str (), nMessageSize, nChecksum, hdr.nChecksum );
1776+ continue ;
1777+ }
1778+ }
1779+
17711780 // Process message
17721781 bool fRet = false ;
17731782 try
@@ -1844,6 +1853,9 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
18441853 vRecv >> addrFrom >> nNonce;
18451854 if (pfrom->nVersion >= 106 && !vRecv.empty ())
18461855 vRecv >> strSubVer;
1856+ if (pfrom->nVersion >= 209 && !vRecv.empty ())
1857+ vRecv >> pfrom->nStartingHeight ;
1858+
18471859 if (pfrom->nVersion == 0 )
18481860 return false ;
18491861
@@ -1854,9 +1866,6 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
18541866 return true ;
18551867 }
18561868
1857- pfrom->vSend .SetVersion (min (pfrom->nVersion , VERSION ));
1858- pfrom->vRecv .SetVersion (min (pfrom->nVersion , VERSION ));
1859-
18601869 pfrom->fClient = !(pfrom->nServices & NODE_NETWORK );
18611870 if (pfrom->fClient )
18621871 {
@@ -1866,6 +1875,13 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
18661875
18671876 AddTimeData (pfrom->addr .ip , nTime);
18681877
1878+ // Change version
1879+ if (pfrom->nVersion >= 209 )
1880+ pfrom->PushMessage (" verack" );
1881+ pfrom->vSend .SetVersion (min (pfrom->nVersion , VERSION ));
1882+ if (pfrom->nVersion < 209 )
1883+ pfrom->vRecv .SetVersion (min (pfrom->nVersion , VERSION ));
1884+
18691885 // Ask the first connected node for block updates
18701886 static bool fAskedForBlocks ;
18711887 if (!fAskedForBlocks && !pfrom->fClient )
@@ -1876,7 +1892,7 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
18761892
18771893 pfrom->fSuccessfullyConnected = true ;
18781894
1879- printf (" version message: version %d\n " , pfrom->nVersion );
1895+ printf (" version message: version %d, blocks=%d \n " , pfrom->nVersion , pfrom-> nStartingHeight );
18801896 }
18811897
18821898
@@ -1887,6 +1903,12 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
18871903 }
18881904
18891905
1906+ else if (strCommand == " verack" )
1907+ {
1908+ pfrom->vRecv .SetVersion (min (pfrom->nVersion , VERSION ));
1909+ }
1910+
1911+
18901912 else if (strCommand == " addr" )
18911913 {
18921914 vector<CAddress> vAddr;
@@ -2101,9 +2123,8 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
21012123 vRecv >> *pblock;
21022124
21032125 // // debug print
2104- // printf("received block:\n");
2105- // pblock->print();
21062126 printf (" received block %s\n " , pblock->GetHash ().ToString ().substr (0 ,16 ).c_str ());
2127+ // pblock->print();
21072128
21082129 CInv inv (MSG_BLOCK , pblock->GetHash ());
21092130 pfrom->AddInventoryKnown (inv);
@@ -2388,8 +2409,11 @@ void GenerateBitcoins(bool fGenerate)
23882409 int nAddThreads = nProcessors - vnThreadsRunning[3 ];
23892410 printf (" Starting %d BitcoinMiner threads\n " , nAddThreads);
23902411 for (int i = 0 ; i < nAddThreads; i++)
2412+ {
23912413 if (!CreateThread (ThreadBitcoinMiner, NULL ))
23922414 printf (" Error: CreateThread(ThreadBitcoinMiner) failed\n " );
2415+ Sleep (10 );
2416+ }
23932417 }
23942418}
23952419
0 commit comments