Commit 170977be authored by Ashot's avatar Ashot

Merge branch 'revert-sync-optimization' into 'Current-dev'

Revert back sync optimization

See merge request !165
parents c8834bf7 4e1ff11c
Pipeline #814 passed with stage
in 18 minutes and 28 seconds
......@@ -168,12 +168,6 @@ namespace {
/** Dirty block file entries. */
set<int> setDirtyFileInfo;
/** Map which holds received headers auxpow **/
std::map<uint256, CAuxPow> mapAuxPow;
/** Indicator to start/stop headers sync **/
bool g_headerSyncStopped = false;
} // anon namespace
//////////////////////////////////////////////////////////////////////////////
......@@ -3621,9 +3615,6 @@ bool static LoadBlockIndexDB()
return true;
chainActive.SetTip(it->second);
// This function calls after relaunch so download headers again
pindexBestHeader = chainActive.Tip();
PruneBlockIndexCandidates();
LogPrintf("LoadBlockIndexDB(): hashBestChain=%s height=%d date=%s progress=%f\n",
......@@ -4228,12 +4219,7 @@ void static ProcessGetData(CNode* pfrom)
if (!ReadBlockFromDisk(block, (*mi).second))
assert(!"cannot load block from disk");
if (inv.type == MSG_BLOCK)
{
// Don't send auxpow information with block
block.auxpow.reset();
block.readWriteAuxPow = false;
pfrom->PushMessage("block", block);
}
else // MSG_FILTERED_BLOCK)
{
LOCK(pfrom->cs_filter);
......@@ -5015,22 +5001,11 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
return error(strError.c_str());
}
}
else
{
if (header.nVersion.IsAuxpow())
{
// If block header is accepted successfully keep auxpow to use for blocks
mapAuxPow.insert(std::pair<uint256, CAuxPow>(header.GetHash(), *(header.auxpow)));
}
}
}
if (pindexLast)
UpdateBlockAvailability(pfrom->GetId(), pindexLast->GetBlockHash());
// Don't let headers sync to go further more than 50.000 blocks
if (pindexBestHeader->nHeight - chainActive.Tip()->nHeight < MAX_HEADERS_IN_MEMORY)
{
if (nCount == MAX_HEADERS_RESULTS && pindexLast && hasNewHeaders) {
// Headers message had its maximum size; the peer may have more headers.
// TODO: optimize: if pindexLast is an ancestor of chainActive.Tip or pindexBestHeader, continue
......@@ -5038,11 +5013,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
LogPrint("net", "more getheaders (%d) to end to peer=%d (startheight:%d)\n", pindexLast->nHeight, pfrom->id, pfrom->nStartingHeight);
pfrom->PushMessage("getheaders", chainActive.GetLocator(pindexLast), uint256());
}
}
else
{
g_headerSyncStopped = true;
}
CheckBlockIndex();
}
......@@ -5050,47 +5020,24 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
else if (strCommand == "block" && !fImporting && !fReindex) // Ignore blocks received while importing
{
CBlock block;
// Auxpow should be received with headers so no need to get it with blocks
if (pfrom->nVersion > AUXPOW_SEND_VERSION)
{
block.readWriteAuxPow = false;
}
vRecv >> block;
bool processBlock = true;
if (block.nVersion.IsAuxpow() && pfrom->nVersion > AUXPOW_SEND_VERSION)
{
std::map<uint256, CAuxPow>::iterator auxIt = mapAuxPow.find(block.GetHash());
if (auxIt != mapAuxPow.end())
{
block.auxpow.reset(new CAuxPow(auxIt->second));
mapAuxPow.erase(block.GetHash());
} else {
LogPrintf("Couldn't find auxpow for block: %s, at height: %d\n", block.GetHash().ToString(), chainActive.Tip()->nHeight);
processBlock = false;
}
}
CInv inv(MSG_BLOCK, block.GetHash());
LogPrint("net", "received block %s peer=%d\n", inv.hash.ToString(), pfrom->id);
if (processBlock)
{
CInv inv(MSG_BLOCK, block.GetHash());
LogPrint("net", "received block %s peer=%d\n", inv.hash.ToString(), pfrom->id);
pfrom->AddInventoryKnown(inv);
pfrom->AddInventoryKnown(inv);
CValidationState state;
ProcessNewBlock(state, pfrom, &block);
int nDoS;
if (state.IsInvalid(nDoS)) {
pfrom->PushMessage("reject", strCommand, state.GetRejectCode(),
state.GetRejectReason().substr(0, MAX_REJECT_MESSAGE_LENGTH), inv.hash);
if (nDoS > 0) {
TRY_LOCK(cs_main, lockMain);
if(lockMain) Misbehaving(pfrom->GetId(), nDoS);
}
CValidationState state;
ProcessNewBlock(state, pfrom, &block);
int nDoS;
if (state.IsInvalid(nDoS)) {
pfrom->PushMessage("reject", strCommand, state.GetRejectCode(),
state.GetRejectReason().substr(0, MAX_REJECT_MESSAGE_LENGTH), inv.hash);
if (nDoS > 0) {
TRY_LOCK(cs_main, lockMain);
if(lockMain) Misbehaving(pfrom->GetId(), nDoS);
}
}
}
......@@ -5574,14 +5521,6 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
}
}
// Restart headers sync if synced blocks coint is 10% behinde from headers
const int restartLimit = (MAX_HEADERS_IN_MEMORY * 10) / 100;
if (g_headerSyncStopped && (pindexBestHeader->nHeight - chainActive.Tip()->nHeight < restartLimit))
{
g_headerSyncStopped = false;
pto->PushMessage("getheaders", chainActive.GetLocator(pindexBestHeader), uint256());
}
// Resend wallet transactions that haven't gotten in a block yet
// Except during reindex, importing and IBD, when old wallet
// transactions become unconfirmed and spams other nodes.
......
......@@ -100,8 +100,6 @@ static const unsigned int DATABASE_WRITE_INTERVAL = 60 * 60;
static const unsigned int DATABASE_FLUSH_INTERVAL = 24 * 60 * 60;
/** Maximum length of reject messages. */
static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111;
/** Maximum number headers in memory */
static const int MAX_HEADERS_IN_MEMORY = 50000;
/** "reject" message codes */
static const unsigned char REJECT_MALFORMED = 0x01;
......
......@@ -13,7 +13,6 @@
#include "uint256.h"
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
/** The maximum allowed size for a serialized block, in bytes (network rule) */
static const unsigned int MAX_BLOCK_SIZE = 1000000;
......@@ -31,7 +30,6 @@ public:
// auxpow (if this is a merge-minded block)
boost::shared_ptr<CAuxPow> auxpow;
bool readWriteAuxPow;
CBlockHeader()
{
......@@ -46,13 +44,10 @@ public:
nVersion = this->nVersion.GetBaseVersion();
if (this->nVersion.IsAuxpow())
{
if (readWriteAuxPow)
{
if (ser_action.ForRead())
auxpow = boost::make_shared<CAuxPow>();
assert(auxpow);
READWRITE(*auxpow);
}
if (ser_action.ForRead())
auxpow.reset (new CAuxPow());
assert(auxpow);
READWRITE(*auxpow);
} else if (ser_action.ForRead())
auxpow.reset();
}
......@@ -66,7 +61,6 @@ public:
nTime = 0;
nBits = 0;
nNonce = 0;
readWriteAuxPow = true;
}
bool IsNull() const
......
......@@ -53,7 +53,4 @@ static const int BIP0031_VERSION = 60000;
//! "mempool" command, enhanced "getdata" behavior starts with this version
static const int MEMPOOL_GD_VERSION = 60002;
//! Nodes above this version won't send AuxPow information with blocks
static const int AUXPOW_SEND_VERSION = 70053;
#endif // BITCOIN_VERSION_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment