|
|
@ -3016,7 +3016,7 @@ static void NotifyHeaderTip() { |
|
|
|
* or an activated best chain. pblock is either NULL or a pointer to a block |
|
|
|
* or an activated best chain. pblock is either NULL or a pointer to a block |
|
|
|
* that is already loaded (to avoid loading it again from disk). |
|
|
|
* that is already loaded (to avoid loading it again from disk). |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams, const CBlock *pblock) { |
|
|
|
bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams, const CBlock *pblock, CConnman* connman) { |
|
|
|
CBlockIndex *pindexMostWork = NULL; |
|
|
|
CBlockIndex *pindexMostWork = NULL; |
|
|
|
CBlockIndex *pindexNewTip = NULL; |
|
|
|
CBlockIndex *pindexNewTip = NULL; |
|
|
|
do { |
|
|
|
do { |
|
|
@ -3731,7 +3731,7 @@ static bool AcceptBlock(const CBlock& block, CValidationState& state, const CCha |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool ProcessNewBlock(CValidationState& state, const CChainParams& chainparams, CNode* pfrom, const CBlock* pblock, bool fForceProcessing, const CDiskBlockPos* dbp) |
|
|
|
bool ProcessNewBlock(CValidationState& state, const CChainParams& chainparams, CNode* pfrom, const CBlock* pblock, bool fForceProcessing, const CDiskBlockPos* dbp, CConnman* connman) |
|
|
|
{ |
|
|
|
{ |
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK(cs_main); |
|
|
|
LOCK(cs_main); |
|
|
@ -3753,7 +3753,7 @@ bool ProcessNewBlock(CValidationState& state, const CChainParams& chainparams, C |
|
|
|
|
|
|
|
|
|
|
|
NotifyHeaderTip(); |
|
|
|
NotifyHeaderTip(); |
|
|
|
|
|
|
|
|
|
|
|
if (!ActivateBestChain(state, chainparams, pblock)) |
|
|
|
if (!ActivateBestChain(state, chainparams, pblock, connman)) |
|
|
|
return error("%s: ActivateBestChain failed", __func__); |
|
|
|
return error("%s: ActivateBestChain failed", __func__); |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -4891,7 +4891,7 @@ uint32_t GetFetchFlags(CNode* pfrom, CBlockIndex* pprev, const Consensus::Params |
|
|
|
return nFetchFlags; |
|
|
|
return nFetchFlags; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, int64_t nTimeReceived, const CChainParams& chainparams) |
|
|
|
bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, int64_t nTimeReceived, const CChainParams& chainparams, CConnman& connman) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint("net", "received: %s (%u bytes) peer=%d\n", SanitizeString(strCommand), vRecv.size(), pfrom->id); |
|
|
|
LogPrint("net", "received: %s (%u bytes) peer=%d\n", SanitizeString(strCommand), vRecv.size(), pfrom->id); |
|
|
|
if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0) |
|
|
|
if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0) |
|
|
@ -5680,7 +5680,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, |
|
|
|
txn.blockhash = cmpctblock.header.GetHash(); |
|
|
|
txn.blockhash = cmpctblock.header.GetHash(); |
|
|
|
CDataStream blockTxnMsg(SER_NETWORK, PROTOCOL_VERSION); |
|
|
|
CDataStream blockTxnMsg(SER_NETWORK, PROTOCOL_VERSION); |
|
|
|
blockTxnMsg << txn; |
|
|
|
blockTxnMsg << txn; |
|
|
|
return ProcessMessage(pfrom, NetMsgType::BLOCKTXN, blockTxnMsg, nTimeReceived, chainparams); |
|
|
|
return ProcessMessage(pfrom, NetMsgType::BLOCKTXN, blockTxnMsg, nTimeReceived, chainparams, connman); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
req.blockhash = pindex->GetBlockHash(); |
|
|
|
req.blockhash = pindex->GetBlockHash(); |
|
|
|
pfrom->PushMessage(NetMsgType::GETBLOCKTXN, req); |
|
|
|
pfrom->PushMessage(NetMsgType::GETBLOCKTXN, req); |
|
|
@ -5701,7 +5701,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, |
|
|
|
headers.push_back(cmpctblock.header); |
|
|
|
headers.push_back(cmpctblock.header); |
|
|
|
CDataStream vHeadersMsg(SER_NETWORK, PROTOCOL_VERSION); |
|
|
|
CDataStream vHeadersMsg(SER_NETWORK, PROTOCOL_VERSION); |
|
|
|
vHeadersMsg << headers; |
|
|
|
vHeadersMsg << headers; |
|
|
|
return ProcessMessage(pfrom, NetMsgType::HEADERS, vHeadersMsg, nTimeReceived, chainparams); |
|
|
|
return ProcessMessage(pfrom, NetMsgType::HEADERS, vHeadersMsg, nTimeReceived, chainparams, connman); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -5737,7 +5737,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, |
|
|
|
pfrom->PushMessage(NetMsgType::GETDATA, invs); |
|
|
|
pfrom->PushMessage(NetMsgType::GETDATA, invs); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
CValidationState state; |
|
|
|
CValidationState state; |
|
|
|
ProcessNewBlock(state, chainparams, pfrom, &block, false, NULL); |
|
|
|
ProcessNewBlock(state, chainparams, pfrom, &block, false, NULL, &connman); |
|
|
|
int nDoS; |
|
|
|
int nDoS; |
|
|
|
if (state.IsInvalid(nDoS)) { |
|
|
|
if (state.IsInvalid(nDoS)) { |
|
|
|
assert (state.GetRejectCode() < REJECT_INTERNAL); // Blocks are never rejected with internal reject codes
|
|
|
|
assert (state.GetRejectCode() < REJECT_INTERNAL); // Blocks are never rejected with internal reject codes
|
|
|
@ -5913,7 +5913,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, |
|
|
|
// Such an unrequested block may still be processed, subject to the
|
|
|
|
// Such an unrequested block may still be processed, subject to the
|
|
|
|
// conditions in AcceptBlock().
|
|
|
|
// conditions in AcceptBlock().
|
|
|
|
bool forceProcessing = pfrom->fWhitelisted && !IsInitialBlockDownload(); |
|
|
|
bool forceProcessing = pfrom->fWhitelisted && !IsInitialBlockDownload(); |
|
|
|
ProcessNewBlock(state, chainparams, pfrom, &block, forceProcessing, NULL); |
|
|
|
ProcessNewBlock(state, chainparams, pfrom, &block, forceProcessing, NULL, &connman); |
|
|
|
int nDoS; |
|
|
|
int nDoS; |
|
|
|
if (state.IsInvalid(nDoS)) { |
|
|
|
if (state.IsInvalid(nDoS)) { |
|
|
|
assert (state.GetRejectCode() < REJECT_INTERNAL); // Blocks are never rejected with internal reject codes
|
|
|
|
assert (state.GetRejectCode() < REJECT_INTERNAL); // Blocks are never rejected with internal reject codes
|
|
|
@ -6163,7 +6163,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// requires LOCK(cs_vRecvMsg)
|
|
|
|
// requires LOCK(cs_vRecvMsg)
|
|
|
|
bool ProcessMessages(CNode* pfrom) |
|
|
|
bool ProcessMessages(CNode* pfrom, CConnman& connman) |
|
|
|
{ |
|
|
|
{ |
|
|
|
const CChainParams& chainparams = Params(); |
|
|
|
const CChainParams& chainparams = Params(); |
|
|
|
//if (fDebug)
|
|
|
|
//if (fDebug)
|
|
|
@ -6240,7 +6240,7 @@ bool ProcessMessages(CNode* pfrom) |
|
|
|
bool fRet = false; |
|
|
|
bool fRet = false; |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
fRet = ProcessMessage(pfrom, strCommand, vRecv, msg.nTime, chainparams); |
|
|
|
fRet = ProcessMessage(pfrom, strCommand, vRecv, msg.nTime, chainparams, connman); |
|
|
|
boost::this_thread::interruption_point(); |
|
|
|
boost::this_thread::interruption_point(); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (const std::ios_base::failure& e) |
|
|
|
catch (const std::ios_base::failure& e) |
|
|
@ -6305,7 +6305,7 @@ public: |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
bool SendMessages(CNode* pto) |
|
|
|
bool SendMessages(CNode* pto, CConnman& connman) |
|
|
|
{ |
|
|
|
{ |
|
|
|
const Consensus::Params& consensusParams = Params().GetConsensus(); |
|
|
|
const Consensus::Params& consensusParams = Params().GetConsensus(); |
|
|
|
{ |
|
|
|
{ |
|
|
|