Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show All 24 Lines | |||||
#include <primitives/transaction.h> | #include <primitives/transaction.h> | ||||
#include <random.h> | #include <random.h> | ||||
#include <reverse_iterator.h> | #include <reverse_iterator.h> | ||||
#include <scheduler.h> | #include <scheduler.h> | ||||
#include <tinyformat.h> | #include <tinyformat.h> | ||||
#include <txmempool.h> | #include <txmempool.h> | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <util/validation.h> | |||||
#include <validation.h> | #include <validation.h> | ||||
#include <memory> | #include <memory> | ||||
#if defined(NDEBUG) | #if defined(NDEBUG) | ||||
#error "Bitcoin cannot be compiled without assertions." | #error "Bitcoin cannot be compiled without assertions." | ||||
#endif | #endif | ||||
▲ Show 20 Lines • Show All 1,623 Lines • ▼ Show 20 Lines | bool need_activate_chain = false; | ||||
need_activate_chain = true; | need_activate_chain = true; | ||||
} | } | ||||
} | } | ||||
} // release cs_main before calling ActivateBestChain | } // release cs_main before calling ActivateBestChain | ||||
if (need_activate_chain) { | if (need_activate_chain) { | ||||
BlockValidationState state; | BlockValidationState state; | ||||
if (!ActivateBestChain(config, state, a_recent_block)) { | if (!ActivateBestChain(config, state, a_recent_block)) { | ||||
LogPrint(BCLog::NET, "failed to activate chain (%s)\n", | LogPrint(BCLog::NET, "failed to activate chain (%s)\n", | ||||
FormatStateMessage(state)); | state.ToString()); | ||||
} | } | ||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
const CBlockIndex *pindex = LookupBlockIndex(hash); | const CBlockIndex *pindex = LookupBlockIndex(hash); | ||||
if (pindex) { | if (pindex) { | ||||
send = BlockRequestAllowed(pindex, consensusParams); | send = BlockRequestAllowed(pindex, consensusParams); | ||||
if (!send) { | if (!send) { | ||||
▲ Show 20 Lines • Show All 1,026 Lines • ▼ Show 20 Lines | if (strCommand == NetMsgType::GETBLOCKS) { | ||||
std::shared_ptr<const CBlock> a_recent_block; | std::shared_ptr<const CBlock> a_recent_block; | ||||
{ | { | ||||
LOCK(cs_most_recent_block); | LOCK(cs_most_recent_block); | ||||
a_recent_block = most_recent_block; | a_recent_block = most_recent_block; | ||||
} | } | ||||
BlockValidationState state; | BlockValidationState state; | ||||
if (!ActivateBestChain(config, state, a_recent_block)) { | if (!ActivateBestChain(config, state, a_recent_block)) { | ||||
LogPrint(BCLog::NET, "failed to activate chain (%s)\n", | LogPrint(BCLog::NET, "failed to activate chain (%s)\n", | ||||
FormatStateMessage(state)); | state.ToString()); | ||||
} | } | ||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
// Find the last block the caller has in the main chain | // Find the last block the caller has in the main chain | ||||
const CBlockIndex *pindex = | const CBlockIndex *pindex = | ||||
FindForkInGlobalIndex(::ChainActive(), locator); | FindForkInGlobalIndex(::ChainActive(), locator); | ||||
▲ Show 20 Lines • Show All 293 Lines • ▼ Show 20 Lines | if (strCommand == NetMsgType::TX) { | ||||
// nodes hidden behind it. | // nodes hidden behind it. | ||||
// | // | ||||
// Never relay transactions that might result in being | // Never relay transactions that might result in being | ||||
// disconnected (or banned). | // disconnected (or banned). | ||||
if (state.IsInvalid() && TxRelayMayResultInDisconnect(state)) { | if (state.IsInvalid() && TxRelayMayResultInDisconnect(state)) { | ||||
LogPrintf("Not relaying invalid transaction %s from " | LogPrintf("Not relaying invalid transaction %s from " | ||||
"whitelisted peer=%d (%s)\n", | "whitelisted peer=%d (%s)\n", | ||||
tx.GetId().ToString(), pfrom->GetId(), | tx.GetId().ToString(), pfrom->GetId(), | ||||
FormatStateMessage(state)); | state.ToString()); | ||||
} else { | } else { | ||||
LogPrintf("Force relaying tx %s from whitelisted peer=%d\n", | LogPrintf("Force relaying tx %s from whitelisted peer=%d\n", | ||||
tx.GetId().ToString(), pfrom->GetId()); | tx.GetId().ToString(), pfrom->GetId()); | ||||
RelayTransaction(tx.GetId(), *connman); | RelayTransaction(tx.GetId(), *connman); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
Show All 12 Lines | if (strCommand == NetMsgType::TX) { | ||||
// transactions, but any tx not accepted by the mempool, which may be | // transactions, but any tx not accepted by the mempool, which may be | ||||
// due to node policy (vs. consensus). So we can't blanket penalize a | // due to node policy (vs. consensus). So we can't blanket penalize a | ||||
// peer simply for relaying a tx that our recentRejects has caught, | // peer simply for relaying a tx that our recentRejects has caught, | ||||
// regardless of false positives. | // regardless of false positives. | ||||
if (state.IsInvalid()) { | if (state.IsInvalid()) { | ||||
LogPrint(BCLog::MEMPOOLREJ, | LogPrint(BCLog::MEMPOOLREJ, | ||||
"%s from peer=%d was not accepted: %s\n", | "%s from peer=%d was not accepted: %s\n", | ||||
tx.GetHash().ToString(), pfrom->GetId(), | tx.GetHash().ToString(), pfrom->GetId(), state.ToString()); | ||||
FormatStateMessage(state)); | |||||
MaybePunishNodeForTx(pfrom->GetId(), state); | MaybePunishNodeForTx(pfrom->GetId(), state); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
if (strCommand == NetMsgType::CMPCTBLOCK) { | if (strCommand == NetMsgType::CMPCTBLOCK) { | ||||
// Ignore cmpctblock received while importing | // Ignore cmpctblock received while importing | ||||
if (fImporting || fReindex) { | if (fImporting || fReindex) { | ||||
▲ Show 20 Lines • Show All 552 Lines • ▼ Show 20 Lines | if (strCommand == NetMsgType::AVARESPONSE && !fImporting && !fReindex && | ||||
UnparkBlock(pindex); | UnparkBlock(pindex); | ||||
} break; | } break; | ||||
} | } | ||||
} | } | ||||
BlockValidationState state; | BlockValidationState state; | ||||
if (!ActivateBestChain(config, state)) { | if (!ActivateBestChain(config, state)) { | ||||
LogPrint(BCLog::NET, "failed to activate chain (%s)\n", | LogPrint(BCLog::NET, "failed to activate chain (%s)\n", | ||||
FormatStateMessage(state)); | state.ToString()); | ||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
if (strCommand == NetMsgType::GETADDR) { | if (strCommand == NetMsgType::GETADDR) { | ||||
// This asymmetric behavior for inbound and outbound connections was | // This asymmetric behavior for inbound and outbound connections was | ||||
▲ Show 20 Lines • Show All 1,370 Lines • Show Last 20 Lines |