Browse Source

filter out duplicate getblocks and don't relay inv messages during initial block download -- 0.2 rc2

git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@49 1a98c847-1fd6-4fd8-948a-caf3550aa51b
0.8 v0.2.0
s_nakamoto 15 years ago
parent
commit
e2c2648c14
  1. 25
      main.cpp
  2. 21
      net.cpp
  3. 7
      net.h
  4. 2
      serialize.h
  5. 2
      setup.nsi

25
main.cpp

@ -1274,7 +1274,7 @@ bool CBlock::AcceptBlock()
if (!AddToBlockIndex(nFile, nBlockPos)) if (!AddToBlockIndex(nFile, nBlockPos))
return error("AcceptBlock() : AddToBlockIndex failed"); return error("AcceptBlock() : AddToBlockIndex failed");
if (hashBestChain == hash) if (hashBestChain == hash && nBestHeight > 28000)
RelayInventory(CInv(MSG_BLOCK, hash)); RelayInventory(CInv(MSG_BLOCK, hash));
// // Add atoms to user reviews for coins created // // Add atoms to user reviews for coins created
@ -1314,7 +1314,7 @@ bool ProcessBlock(CNode* pfrom, CBlock* pblock)
// Ask this guy to fill in what we're missing // Ask this guy to fill in what we're missing
if (pfrom) if (pfrom)
pfrom->PushMessage("getblocks", CBlockLocator(pindexBest), GetOrphanRoot(pblock)); pfrom->PushGetBlocks(pindexBest, GetOrphanRoot(pblock));
return true; return true;
} }
@ -1816,7 +1816,7 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
if (!fAskedForBlocks && !pfrom->fClient) if (!fAskedForBlocks && !pfrom->fClient)
{ {
fAskedForBlocks = true; fAskedForBlocks = true;
pfrom->PushMessage("getblocks", CBlockLocator(pindexBest), uint256(0)); pfrom->PushGetBlocks(pindexBest, uint256(0));
} }
pfrom->fSuccessfullyConnected = true; pfrom->fSuccessfullyConnected = true;
@ -1836,6 +1836,8 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
{ {
vector<CAddress> vAddr; vector<CAddress> vAddr;
vRecv >> vAddr; vRecv >> vAddr;
if (vAddr.size() > 50000) // lower this to 1000 later
return error("message addr size() = %d", vAddr.size());
// Store the new addresses // Store the new addresses
CAddrDB addrdb; CAddrDB addrdb;
@ -1864,6 +1866,8 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
{ {
vector<CInv> vInv; vector<CInv> vInv;
vRecv >> vInv; vRecv >> vInv;
if (vInv.size() > 50000)
return error("message inv size() = %d", vInv.size());
CTxDB txdb("r"); CTxDB txdb("r");
foreach(const CInv& inv, vInv) foreach(const CInv& inv, vInv)
@ -1878,7 +1882,7 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
if (!fAlreadyHave) if (!fAlreadyHave)
pfrom->AskFor(inv); pfrom->AskFor(inv);
else if (inv.type == MSG_BLOCK && mapOrphanBlocks.count(inv.hash)) else if (inv.type == MSG_BLOCK && mapOrphanBlocks.count(inv.hash))
pfrom->PushMessage("getblocks", CBlockLocator(pindexBest), GetOrphanRoot(mapOrphanBlocks[inv.hash])); pfrom->PushGetBlocks(pindexBest, GetOrphanRoot(mapOrphanBlocks[inv.hash]));
// Track requests for our stuff // Track requests for our stuff
CRITICAL_BLOCK(cs_mapRequestCount) CRITICAL_BLOCK(cs_mapRequestCount)
@ -1895,6 +1899,8 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
{ {
vector<CInv> vInv; vector<CInv> vInv;
vRecv >> vInv; vRecv >> vInv;
if (vInv.size() > 50000)
return error("message getdata size() = %d", vInv.size());
foreach(const CInv& inv, vInv) foreach(const CInv& inv, vInv)
{ {
@ -2210,17 +2216,6 @@ bool SendMessages(CNode* pto)
} }
} }
// Clear inventory known periodically in case an inv message was missed,
// although usually they would just get it from another node.
static int64 nLastInventoryKnownClear;
if (GetTime() - nLastInventoryKnownClear > 2 * 60 * 60) // every 2 hours
{
nLastInventoryKnownClear = GetTime();
CRITICAL_BLOCK(cs_vNodes)
foreach(CNode* pnode, vNodes)
pnode->setInventoryKnown.clear();
}
// //
// Message: addr // Message: addr

21
net.cpp

@ -40,6 +40,23 @@ CAddress addrProxy("127.0.0.1:9050");
void CNode::PushGetBlocks(CBlockIndex* pindexBegin, uint256 hashEnd)
{
// Filter out duplicate requests
if (pindexBegin == pindexLastGetBlocksBegin && hashEnd == hashLastGetBlocksEnd)
return;
pindexLastGetBlocksBegin = pindexBegin;
hashLastGetBlocksEnd = hashEnd;
PushMessage("getblocks", CBlockLocator(pindexBegin), hashEnd);
}
bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet) bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet)
{ {
hSocketRet = INVALID_SOCKET; hSocketRet = INVALID_SOCKET;
@ -764,12 +781,12 @@ void ThreadSocketHandler2(void* parg)
printf("socket no message in first 60 seconds, %d %d\n", pnode->nLastRecv != 0, pnode->nLastSend != 0); printf("socket no message in first 60 seconds, %d %d\n", pnode->nLastRecv != 0, pnode->nLastSend != 0);
pnode->fDisconnect = true; pnode->fDisconnect = true;
} }
else if (GetTime() - pnode->nLastSend > 10 * 60 && GetTime() - pnode->nLastSendEmpty > 10 * 60) else if (GetTime() - pnode->nLastSend > 90*60 && GetTime() - pnode->nLastSendEmpty > 90*60)
{ {
printf("socket not sending\n"); printf("socket not sending\n");
pnode->fDisconnect = true; pnode->fDisconnect = true;
} }
else if (GetTime() - pnode->nLastRecv > (pnode->nVersion >= 107 ? 15*60 : 90*60)) else if (GetTime() - pnode->nLastRecv > 90*60)
{ {
printf("socket inactivity timeout\n"); printf("socket inactivity timeout\n");
pnode->fDisconnect = true; pnode->fDisconnect = true;

7
net.h

@ -7,6 +7,7 @@ class CAddress;
class CInv; class CInv;
class CRequestTracker; class CRequestTracker;
class CNode; class CNode;
class CBlockIndex;
@ -504,6 +505,8 @@ public:
map<uint256, CRequestTracker> mapRequests; map<uint256, CRequestTracker> mapRequests;
CCriticalSection cs_mapRequests; CCriticalSection cs_mapRequests;
uint256 hashContinue; uint256 hashContinue;
CBlockIndex* pindexLastGetBlocksBegin;
uint256 hashLastGetBlocksEnd;
// flood // flood
vector<CAddress> vAddrToSend; vector<CAddress> vAddrToSend;
@ -541,6 +544,8 @@ public:
nRefCount = 0; nRefCount = 0;
nReleaseTime = 0; nReleaseTime = 0;
hashContinue = 0; hashContinue = 0;
pindexLastGetBlocksBegin = 0;
hashLastGetBlocksEnd = 0;
fGetAddr = false; fGetAddr = false;
vfSubscribe.assign(256, false); vfSubscribe.assign(256, false);
@ -635,6 +640,7 @@ public:
} }
void BeginMessage(const char* pszCommand) void BeginMessage(const char* pszCommand)
{ {
cs_vSend.Enter(); cs_vSend.Enter();
@ -900,6 +906,7 @@ public:
void PushGetBlocks(CBlockIndex* pindexBegin, uint256 hashEnd);
bool IsSubscribed(unsigned int nChannel); bool IsSubscribed(unsigned int nChannel);
void Subscribe(unsigned int nChannel, unsigned int nHops=0); void Subscribe(unsigned int nChannel, unsigned int nHops=0);
void CancelSubscribe(unsigned int nChannel); void CancelSubscribe(unsigned int nChannel);

2
serialize.h

@ -20,7 +20,7 @@ class CDataStream;
class CAutoFile; class CAutoFile;
static const int VERSION = 200; static const int VERSION = 200;
static const char* pszSubVer = " rc1"; static const char* pszSubVer = " rc2";

2
setup.nsi

@ -42,7 +42,7 @@ Var StartMenuGroup
!insertmacro MUI_LANGUAGE English !insertmacro MUI_LANGUAGE English
# Installer attributes # Installer attributes
OutFile bitcoin-0.2.0-setup.exe OutFile bitcoin-0.2.0-win32-setup.exe
InstallDir $PROGRAMFILES\Bitcoin InstallDir $PROGRAMFILES\Bitcoin
CRCCheck on CRCCheck on
XPStyle on XPStyle on

Loading…
Cancel
Save