Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
| Show First 20 Lines • Show All 898 Lines • ▼ Show 20 Lines | private: | ||||
| */ | */ | ||||
| void MaybePunishNodeForBlock(NodeId nodeid, | void MaybePunishNodeForBlock(NodeId nodeid, | ||||
| const BlockValidationState &state, | const BlockValidationState &state, | ||||
| bool via_compact_block, | bool via_compact_block, | ||||
| const std::string &message = "") | const std::string &message = "") | ||||
| EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); | EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); | ||||
| /** | /** | ||||
| * Potentially disconnect and discourage a node based on the contents of a | |||||
| * TxValidationState object | |||||
| */ | |||||
| void MaybePunishNodeForTx(NodeId nodeid, const TxValidationState &state, | |||||
| const std::string &message = "") | |||||
| EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); | |||||
| /** | |||||
| * Maybe disconnect a peer and discourage future connections from its | * Maybe disconnect a peer and discourage future connections from its | ||||
| * address. | * address. | ||||
| * | * | ||||
| * @param[in] pnode The node to check. | * @param[in] pnode The node to check. | ||||
| * @param[in] peer The peer object to check. | * @param[in] peer The peer object to check. | ||||
| * @return True if the peer was marked for disconnection in | * @return True if the peer was marked for disconnection in | ||||
| * this function | * this function | ||||
| */ | */ | ||||
| ▲ Show 20 Lines • Show All 1,827 Lines • ▼ Show 20 Lines | switch (state.GetResult()) { | ||||
| case BlockValidationResult::BLOCK_TIME_FUTURE: | case BlockValidationResult::BLOCK_TIME_FUTURE: | ||||
| break; | break; | ||||
| } | } | ||||
| if (message != "") { | if (message != "") { | ||||
| LogPrint(BCLog::NET, "peer=%d: %s\n", nodeid, message); | LogPrint(BCLog::NET, "peer=%d: %s\n", nodeid, message); | ||||
| } | } | ||||
| } | } | ||||
| void PeerManagerImpl::MaybePunishNodeForTx(NodeId nodeid, | |||||
| const TxValidationState &state, | |||||
| const std::string &message) { | |||||
| PeerRef peer{GetPeerRef(nodeid)}; | |||||
| switch (state.GetResult()) { | |||||
| case TxValidationResult::TX_RESULT_UNSET: | |||||
| break; | |||||
| // The node is providing invalid data: | |||||
| case TxValidationResult::TX_CONSENSUS: | |||||
| if (peer) { | |||||
| Misbehaving(*peer, message); | |||||
| } | |||||
| return; | |||||
| // Conflicting (but not necessarily invalid) data or different policy: | |||||
| case TxValidationResult::TX_INPUTS_NOT_STANDARD: | |||||
| case TxValidationResult::TX_NOT_STANDARD: | |||||
| case TxValidationResult::TX_MISSING_INPUTS: | |||||
| case TxValidationResult::TX_PREMATURE_SPEND: | |||||
| case TxValidationResult::TX_DUPLICATE: | |||||
| case TxValidationResult::TX_CONFLICT: | |||||
| case TxValidationResult::TX_CHILD_BEFORE_PARENT: | |||||
| case TxValidationResult::TX_MEMPOOL_POLICY: | |||||
| case TxValidationResult::TX_NO_MEMPOOL: | |||||
| case TxValidationResult::TX_PACKAGE_RECONSIDERABLE: | |||||
| case TxValidationResult::TX_AVALANCHE_RECONSIDERABLE: | |||||
| case TxValidationResult::TX_UNKNOWN: | |||||
| break; | |||||
| } | |||||
| if (message != "") { | |||||
| LogPrint(BCLog::NET, "peer=%d: %s\n", nodeid, message); | |||||
| } | |||||
| } | |||||
| bool PeerManagerImpl::BlockRequestAllowed(const CBlockIndex *pindex) { | bool PeerManagerImpl::BlockRequestAllowed(const CBlockIndex *pindex) { | ||||
| AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
| if (m_chainman.ActiveChain().Contains(pindex)) { | if (m_chainman.ActiveChain().Contains(pindex)) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| return pindex->IsValid(BlockValidity::SCRIPTS) && | return pindex->IsValid(BlockValidity::SCRIPTS) && | ||||
| (m_chainman.m_best_header != nullptr) && | (m_chainman.m_best_header != nullptr) && | ||||
| (m_chainman.m_best_header->GetBlockTime() - pindex->GetBlockTime() < | (m_chainman.m_best_header->GetBlockTime() - pindex->GetBlockTime() < | ||||
| ▲ Show 20 Lines • Show All 1,515 Lines • ▼ Show 20 Lines | if (state.GetResult() == TxValidationResult::TX_PACKAGE_RECONSIDERABLE) { | ||||
| m_recent_rejects.insert(txid); | m_recent_rejects.insert(txid); | ||||
| } | } | ||||
| m_txrequest.ForgetInvId(txid); | m_txrequest.ForgetInvId(txid); | ||||
| if (maybe_add_extra_compact_tx && RecursiveDynamicUsage(*ptx) < 100000) { | if (maybe_add_extra_compact_tx && RecursiveDynamicUsage(*ptx) < 100000) { | ||||
| AddToCompactExtraTransactions(ptx); | AddToCompactExtraTransactions(ptx); | ||||
| } | } | ||||
| MaybePunishNodeForTx(nodeid, state); | |||||
| // If the tx failed in ProcessOrphanTx, it should be removed from the | // If the tx failed in ProcessOrphanTx, it should be removed from the | ||||
| // orphanage unless the tx was still missing inputs. If the tx was not in | // orphanage unless the tx was still missing inputs. If the tx was not in | ||||
| // the orphanage, EraseTx does nothing and returns 0. | // the orphanage, EraseTx does nothing and returns 0. | ||||
| if (m_mempool.withOrphanage([&txid](TxOrphanage &orphanage) { | if (m_mempool.withOrphanage([&txid](TxOrphanage &orphanage) { | ||||
| return orphanage.EraseTx(txid); | return orphanage.EraseTx(txid); | ||||
| }) > 0) { | }) > 0) { | ||||
| LogPrint(BCLog::TXPACKAGES, " removed orphan tx %s\n", | LogPrint(BCLog::TXPACKAGES, " removed orphan tx %s\n", | ||||
| txid.ToString()); | txid.ToString()); | ||||
| ▲ Show 20 Lines • Show All 5,136 Lines • Show Last 20 Lines | |||||