@@ -1336,19 +1336,12 @@ bool CBlock::AcceptBlock()
1336
1336
if (!AddToBlockIndex (nFile, nBlockPos))
1337
1337
return error (" AcceptBlock() : AddToBlockIndex failed" );
1338
1338
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));
1352
1345
1353
1346
return true ;
1354
1347
}
@@ -1721,19 +1714,21 @@ bool ProcessMessages(CNode* pfrom)
1721
1714
// (4) message start
1722
1715
// (12) command
1723
1716
// (4) size
1717
+ // (4) checksum
1724
1718
// (x) data
1725
1719
//
1726
1720
1727
1721
loop
1728
1722
{
1729
1723
// Scan for message start
1730
1724
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)
1732
1727
{
1733
- if (vRecv.size () > sizeof (CMessageHeader) )
1728
+ if (vRecv.size () > nHeaderSize )
1734
1729
{
1735
1730
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 );
1737
1732
}
1738
1733
break ;
1739
1734
}
@@ -1742,6 +1737,7 @@ bool ProcessMessages(CNode* pfrom)
1742
1737
vRecv.erase (vRecv.begin (), pstart);
1743
1738
1744
1739
// Read header
1740
+ vector<char > vHeaderSave (vRecv.begin (), vRecv.begin () + nHeaderSize);
1745
1741
CMessageHeader hdr;
1746
1742
vRecv >> hdr;
1747
1743
if (!hdr.IsValid ())
@@ -1757,17 +1753,30 @@ bool ProcessMessages(CNode* pfrom)
1757
1753
{
1758
1754
// Rewind and wait for rest of message
1759
1755
// /// 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 ());
1764
1759
break ;
1765
1760
}
1766
1761
1767
1762
// Copy message to its own buffer
1768
1763
CDataStream vMsg (vRecv.begin (), vRecv.begin () + nMessageSize, vRecv.nType , vRecv.nVersion );
1769
1764
vRecv.ignore (nMessageSize);
1770
1765
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
+
1771
1780
// Process message
1772
1781
bool fRet = false ;
1773
1782
try
@@ -1844,6 +1853,9 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
1844
1853
vRecv >> addrFrom >> nNonce;
1845
1854
if (pfrom->nVersion >= 106 && !vRecv.empty ())
1846
1855
vRecv >> strSubVer;
1856
+ if (pfrom->nVersion >= 209 && !vRecv.empty ())
1857
+ vRecv >> pfrom->nStartingHeight ;
1858
+
1847
1859
if (pfrom->nVersion == 0 )
1848
1860
return false ;
1849
1861
@@ -1854,9 +1866,6 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
1854
1866
return true ;
1855
1867
}
1856
1868
1857
- pfrom->vSend .SetVersion (min (pfrom->nVersion , VERSION));
1858
- pfrom->vRecv .SetVersion (min (pfrom->nVersion , VERSION));
1859
-
1860
1869
pfrom->fClient = !(pfrom->nServices & NODE_NETWORK);
1861
1870
if (pfrom->fClient )
1862
1871
{
@@ -1866,6 +1875,13 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
1866
1875
1867
1876
AddTimeData (pfrom->addr .ip , nTime);
1868
1877
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
+
1869
1885
// Ask the first connected node for block updates
1870
1886
static bool fAskedForBlocks ;
1871
1887
if (!fAskedForBlocks && !pfrom->fClient )
@@ -1876,7 +1892,7 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
1876
1892
1877
1893
pfrom->fSuccessfullyConnected = true ;
1878
1894
1879
- printf (" version message: version %d\n " , pfrom->nVersion );
1895
+ printf (" version message: version %d, blocks=%d \n " , pfrom->nVersion , pfrom-> nStartingHeight );
1880
1896
}
1881
1897
1882
1898
@@ -1887,6 +1903,12 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
1887
1903
}
1888
1904
1889
1905
1906
+ else if (strCommand == " verack" )
1907
+ {
1908
+ pfrom->vRecv .SetVersion (min (pfrom->nVersion , VERSION));
1909
+ }
1910
+
1911
+
1890
1912
else if (strCommand == " addr" )
1891
1913
{
1892
1914
vector<CAddress> vAddr;
@@ -2101,9 +2123,8 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
2101
2123
vRecv >> *pblock;
2102
2124
2103
2125
// // debug print
2104
- // printf("received block:\n");
2105
- // pblock->print();
2106
2126
printf (" received block %s\n " , pblock->GetHash ().ToString ().substr (0 ,16 ).c_str ());
2127
+ // pblock->print();
2107
2128
2108
2129
CInv inv (MSG_BLOCK, pblock->GetHash ());
2109
2130
pfrom->AddInventoryKnown (inv);
@@ -2388,8 +2409,11 @@ void GenerateBitcoins(bool fGenerate)
2388
2409
int nAddThreads = nProcessors - vnThreadsRunning[3 ];
2389
2410
printf (" Starting %d BitcoinMiner threads\n " , nAddThreads);
2390
2411
for (int i = 0 ; i < nAddThreads; i++)
2412
+ {
2391
2413
if (!CreateThread (ThreadBitcoinMiner, NULL ))
2392
2414
printf (" Error: CreateThread(ThreadBitcoinMiner) failed\n " );
2415
+ Sleep (10 );
2416
+ }
2393
2417
}
2394
2418
}
2395
2419
0 commit comments