Backport Bitcoin PR#9260: Mrs Peacock in The Library with The Candlestick (killed main.{h,cpp}) (#1566)

* Remove orphan state wipe from UnloadBlockIndex.

As orphan state is now "network state", like in
d6ea737be1,

UnloadBlockIndex is only used during init if we end up reindexing
to clear our block state so that we can start over. However, at
that time no connections have been brought up as CConnman hasn't
been started yet, so all of the network processing state logic is
empty when its called.

* Move network-msg-processing code out of main to its own file

* Rename the remaining main.{h,cpp} to validation.{h,cpp}
This commit is contained in:
Oleg Girko 2017-08-09 01:19:06 +01:00 committed by UdjinM6
parent bcf5455bfd
commit df6d458b85
65 changed files with 2786 additions and 2713 deletions

View File

@ -7,7 +7,7 @@ define(_CLIENT_VERSION_BUILD, 0)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2017)
AC_INIT([Dash Core],[_CLIENT_VERSION_MAJOR._CLIENT_VERSION_MINOR._CLIENT_VERSION_REVISION],[https://github.com/dashpay/dash/issues],[dashcore])
AC_CONFIG_SRCDIR([src/main.cpp])
AC_CONFIG_SRCDIR([src/validation.cpp])
AC_CONFIG_HEADERS([src/config/dash-config.h])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([build-aux/m4])

View File

@ -127,7 +127,6 @@ BITCOIN_CORE_H = \
keystore.h \
dbwrapper.h \
limitedmap.h \
main.h \
masternode.h \
masternode-payments.h \
masternode-sync.h \
@ -138,6 +137,7 @@ BITCOIN_CORE_H = \
messagesigner.h \
miner.h \
net.h \
net_processing.h \
netbase.h \
netfulfilledman.h \
noui.h \
@ -183,6 +183,7 @@ BITCOIN_CORE_H = \
utilmoneystr.h \
utilstrencodings.h \
utiltime.h \
validation.h \
validationinterface.h \
version.h \
versionbits.h \
@ -223,12 +224,12 @@ libbitcoin_server_a_SOURCES = \
governance-validators.cpp \
governance-vote.cpp \
governance-votedb.cpp \
main.cpp \
merkleblock.cpp \
messagesigner.cpp \
miner.cpp \
net.cpp \
netfulfilledman.cpp \
net_processing.cpp \
noui.cpp \
policy/fees.cpp \
policy/policy.cpp \
@ -250,6 +251,7 @@ libbitcoin_server_a_SOURCES = \
torcontrol.cpp \
txdb.cpp \
txmempool.cpp \
validation.cpp \
validationinterface.cpp \
versionbits.cpp \
$(BITCOIN_CORE_H)

View File

@ -3,7 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "bench.h"
#include "main.h"
#include "validation.h"
#include "utiltime.h"
// Sanity test: this should loop ten times, and

View File

@ -5,7 +5,7 @@
#include "bench.h"
#include "key.h"
#include "main.h"
#include "validation.h"
#include "util.h"
int

View File

@ -7,7 +7,7 @@
#include "chain.h"
#include "chainparams.h"
#include "main.h"
#include "validation.h"
#include "uint256.h"
#include <stdint.h>

View File

@ -6,7 +6,7 @@
#ifndef DARKSEND_RELAY_H
#define DARKSEND_RELAY_H
#include "main.h"
#include "validation.h"
#include "activemasternode.h"
#include "masternodeman.h"

View File

@ -7,7 +7,7 @@
#include "core_io.h"
#include "governance-classes.h"
#include "init.h"
#include "main.h"
#include "validation.h"
#include "utilstrencodings.h"
#include <boost/algorithm/string.hpp>

View File

@ -5,7 +5,7 @@
#ifndef GOVERNANCE_MISC_H
#define GOVERNANCE_MISC_H
#include "main.h"
#include "validation.h"
#include "governance.h"
#include "init.h"

View File

@ -6,7 +6,7 @@
#include "governance-object.h"
#include "governance-vote.h"
#include "governance-classes.h"
#include "main.h"
#include "net_processing.h"
#include "masternode.h"
#include "masternode-sync.h"
#include "masternodeman.h"

View File

@ -20,10 +20,11 @@
#include "httpserver.h"
#include "httprpc.h"
#include "key.h"
#include "main.h"
#include "validation.h"
#include "miner.h"
#include "net.h"
#include "netfulfilledman.h"
#include "net_processing.h"
#include "policy/policy.h"
#include "rpc/server.h"
#include "script/standard.h"

View File

@ -5,7 +5,7 @@
#include "activemasternode.h"
#include "instantx.h"
#include "key.h"
#include "main.h"
#include "validation.h"
#include "masternode-sync.h"
#include "masternodeman.h"
#include "messagesigner.h"

View File

@ -8,8 +8,8 @@
#include "util.h"
#include "core_io.h"
#include "key.h"
#include "main.h"
#include "masternode.h"
#include "net_processing.h"
#include "utilstrencodings.h"
class CMasternodePayments;

View File

@ -5,7 +5,7 @@
#include "activemasternode.h"
#include "checkpoints.h"
#include "governance.h"
#include "main.h"
#include "validation.h"
#include "masternode.h"
#include "masternode-payments.h"
#include "masternode-sync.h"

View File

@ -6,7 +6,7 @@
#define MASTERNODE_H
#include "key.h"
#include "main.h"
#include "validation.h"
#include "net.h"
#include "spork.h"
#include "timedata.h"

View File

@ -4,7 +4,7 @@
#include "base58.h"
#include "hash.h"
#include "main.h" // For strMessageMagic
#include "validation.h" // For strMessageMagic
#include "messagesigner.h"
#include "tinyformat.h"
#include "utilstrencodings.h"

View File

@ -14,7 +14,7 @@
#include "consensus/merkle.h"
#include "consensus/validation.h"
#include "hash.h"
#include "main.h"
#include "validation.h"
#include "net.h"
#include "policy/policy.h"
#include "pow.h"

2655
src/net_processing.cpp Normal file

File diff suppressed because it is too large Load Diff

50
src/net_processing.h Normal file
View File

@ -0,0 +1,50 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2015 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_NET_PROCESSING_H
#define BITCOIN_NET_PROCESSING_H
#include "net.h"
#include "validationinterface.h"
/** Register with a network node to receive its signals */
void RegisterNodeSignals(CNodeSignals& nodeSignals);
/** Unregister a network node */
void UnregisterNodeSignals(CNodeSignals& nodeSignals);
class PeerLogicValidation : public CValidationInterface {
private:
CConnman* connman;
public:
PeerLogicValidation(CConnman* connmanIn);
virtual void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload);
virtual void BlockChecked(const CBlock& block, const CValidationState& state);
};
struct CNodeStateStats {
int nMisbehavior;
int nSyncHeight;
int nCommonHeight;
std::vector<int> vHeightInFlight;
};
/** Get statistics from node state */
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats);
/** Increase a node's misbehavior score. */
void Misbehaving(NodeId nodeid, int howmuch);
/** Process protocol messages received from a given node */
bool ProcessMessages(CNode* pfrom, CConnman& connman);
/**
* Send queued protocol messages to be sent to a give node.
*
* @param[in] pto The node which we are sending messages to.
* @param[in] connman The connection manager for that node.
*/
bool SendMessages(CNode* pto, CConnman& connman);
#endif // BITCOIN_NET_PROCESSING_H

View File

@ -7,7 +7,7 @@
#include "policy/policy.h"
#include "main.h"
#include "validation.h"
#include "tinyformat.h"
#include "util.h"
#include "utilstrencodings.h"

View File

@ -13,6 +13,7 @@
#include "chainparams.h"
#include "checkpoints.h"
#include "clientversion.h"
#include "validation.h"
#include "net.h"
#include "txmempool.h"
#include "ui_interface.h"

View File

@ -16,7 +16,7 @@
#include "coincontrol.h"
#include "init.h"
#include "main.h" // For minRelayTxFee
#include "validation.h" // For minRelayTxFee
#include "wallet/wallet.h"
#include "instantx.h"

View File

@ -12,7 +12,7 @@
#include "primitives/transaction.h"
#include "init.h"
#include "main.h" // For minRelayTxFee
#include "validation.h" // For minRelayTxFee
#include "protocol.h"
#include "script/script.h"
#include "script/standard.h"

View File

@ -13,7 +13,7 @@
#include "guiutil.h"
#include "optionsmodel.h"
#include "main.h" // for DEFAULT_SCRIPTCHECK_THREADS and MAX_SCRIPTCHECK_THREADS
#include "validation.h" // for DEFAULT_SCRIPTCHECK_THREADS and MAX_SCRIPTCHECK_THREADS
#include "netbase.h"
#include "txdb.h" // for -dbcache defaults

View File

@ -14,7 +14,7 @@
#include "amount.h"
#include "init.h"
#include "main.h" // For DEFAULT_SCRIPTCHECK_THREADS
#include "validation.h" // For DEFAULT_SCRIPTCHECK_THREADS
#include "net.h"
#include "txdb.h" // for -dbcache defaults

View File

@ -11,7 +11,7 @@
#include "base58.h"
#include "chainparams.h"
#include "main.h" // For minRelayTxFee
#include "validation.h" // For minRelayTxFee
#include "ui_interface.h"
#include "util.h"
#include "wallet/wallet.h"

View File

@ -8,6 +8,7 @@
#include "guiconstants.h"
#include "guiutil.h"
#include "validation.h" // for cs_main
#include "sync.h"
#include <QDebug>

View File

@ -5,7 +5,7 @@
#ifndef BITCOIN_QT_PEERTABLEMODEL_H
#define BITCOIN_QT_PEERTABLEMODEL_H
#include "main.h" // For CNodeStateStats
#include "net_processing.h" // For CNodeStateStats
#include "net.h"
#include <QAbstractTableModel>

View File

@ -18,7 +18,7 @@
#include "base58.h"
#include "coincontrol.h"
#include "main.h" // mempool and minRelayTxFee
#include "validation.h" // mempool and minRelayTxFee
#include "ui_interface.h"
#include "txmempool.h"
#include "wallet/wallet.h"

View File

@ -13,7 +13,7 @@
#include "base58.h"
#include "init.h"
#include "main.h" // For strMessageMagic
#include "validation.h" // For strMessageMagic
#include "wallet/wallet.h"
#include <string>

View File

@ -12,7 +12,7 @@
#include "base58.h"
#include "consensus/consensus.h"
#include "main.h"
#include "validation.h"
#include "script/script.h"
#include "timedata.h"
#include "util.h"

View File

@ -7,7 +7,7 @@
#include "base58.h"
#include "consensus/consensus.h"
#include "main.h"
#include "validation.h"
#include "timedata.h"
#include "wallet/wallet.h"

View File

@ -14,7 +14,7 @@
#include "walletmodel.h"
#include "core_io.h"
#include "main.h"
#include "validation.h"
#include "sync.h"
#include "uint256.h"
#include "util.h"

View File

@ -14,9 +14,11 @@
#include "base58.h"
#include "keystore.h"
#include "main.h"
#include "validation.h"
#include "net.h" // for g_connman
#include "sync.h"
#include "ui_interface.h"
#include "util.h" // for GetBoolArg
#include "wallet/wallet.h"
#include "wallet/walletdb.h" // for BackupWallet

View File

@ -7,7 +7,7 @@
#include "chainparams.h"
#include "primitives/block.h"
#include "primitives/transaction.h"
#include "main.h"
#include "validation.h"
#include "httpserver.h"
#include "rpc/server.h"
#include "streams.h"

View File

@ -10,7 +10,7 @@
#include "checkpoints.h"
#include "coins.h"
#include "consensus/validation.h"
#include "main.h"
#include "validation.h"
#include "policy/policy.h"
#include "primitives/transaction.h"
#include "rpc/server.h"

View File

@ -10,7 +10,7 @@
#include "governance-classes.h"
#include "governance-validators.h"
#include "init.h"
#include "main.h"
#include "validation.h"
#include "masternode.h"
#include "masternode-sync.h"
#include "masternodeconfig.h"

View File

@ -4,7 +4,7 @@
#include "activemasternode.h"
#include "init.h"
#include "main.h"
#include "validation.h"
#include "masternode-payments.h"
#include "masternode-sync.h"
#include "masternodeconfig.h"

View File

@ -13,7 +13,7 @@
#include "consensus/validation.h"
#include "core_io.h"
#include "init.h"
#include "main.h"
#include "validation.h"
#include "miner.h"
#include "net.h"
#include "pow.h"

View File

@ -7,7 +7,7 @@
#include "base58.h"
#include "clientversion.h"
#include "init.h"
#include "main.h"
#include "validation.h"
#include "net.h"
#include "netbase.h"
#include "rpc/server.h"

View File

@ -7,8 +7,9 @@
#include "chainparams.h"
#include "clientversion.h"
#include "main.h"
#include "validation.h"
#include "net.h"
#include "net_processing.h"
#include "netbase.h"
#include "protocol.h"
#include "sync.h"

View File

@ -11,7 +11,7 @@
#include "core_io.h"
#include "init.h"
#include "keystore.h"
#include "main.h"
#include "validation.h"
#include "merkleblock.h"
#include "net.h"
#include "policy/policy.h"

View File

@ -3,8 +3,9 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "chainparams.h"
#include "main.h"
#include "validation.h"
#include "messagesigner.h"
#include "net_processing.h"
#include "spork.h"
#include <boost/lexical_cast.hpp>

View File

@ -6,8 +6,8 @@
#include "chainparams.h"
#include "keystore.h"
#include "main.h"
#include "net.h"
#include "net_processing.h"
#include "pow.h"
#include "script/sign.h"
#include "serialize.h"

View File

@ -9,7 +9,6 @@
#include "chainparams.h"
#include "clientversion.h"
#include "data/alertTests.raw.h"
#include "main.h" // For PartitionCheck
#include "serialize.h"
#include "streams.h"
#include "util.h"

View File

@ -4,7 +4,7 @@
#include "clientversion.h"
#include "consensus/validation.h"
#include "main.h" // For CheckBlock
#include "validation.h" // For CheckBlock
#include "primitives/block.h"
#include "test/test_dash.h"
#include "utiltime.h"

View File

@ -6,7 +6,7 @@
#include "random.h"
#include "uint256.h"
#include "test/test_dash.h"
#include "main.h"
#include "validation.h"
#include "consensus/validation.h"
#include <vector>

View File

@ -4,7 +4,8 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "chainparams.h"
#include "main.h"
#include "validation.h"
#include "net.h"
#include "test/test_dash.h"

View File

@ -7,7 +7,7 @@
#include "consensus/consensus.h"
#include "consensus/merkle.h"
#include "consensus/validation.h"
#include "main.h"
#include "validation.h"
#include "masternode-payments.h"
#include "miner.h"
#include "pubkey.h"

View File

@ -6,7 +6,7 @@
#include "rpc/client.h"
#include "base58.h"
#include "main.h"
#include "validation.h"
#include "wallet/wallet.h"
#include "test/test_dash.h"

View File

@ -4,7 +4,7 @@
#include "key.h"
#include "keystore.h"
#include "main.h"
#include "validation.h"
#include "policy/policy.h"
#include "script/script.h"
#include "script/script_error.h"

View File

@ -5,7 +5,7 @@
#include "consensus/validation.h"
#include "data/sighash.json.h"
#include "hash.h"
#include "main.h" // For CheckTransaction
#include "validation.h" // For CheckTransaction
#include "random.h"
#include "script/interpreter.h"
#include "script/script.h"

View File

@ -10,8 +10,9 @@
#include "consensus/consensus.h"
#include "consensus/validation.h"
#include "key.h"
#include "main.h"
#include "validation.h"
#include "miner.h"
#include "net_processing.h"
#include "pubkey.h"
#include "random.h"
#include "txdb.h"

View File

@ -11,7 +11,7 @@
#include "core_io.h"
#include "key.h"
#include "keystore.h"
#include "main.h" // For CheckTransaction
#include "validation.h" // For CheckTransaction
#include "policy/policy.h"
#include "script/script.h"
#include "script/script_error.h"

View File

@ -4,7 +4,7 @@
#include "consensus/validation.h"
#include "key.h"
#include "main.h"
#include "validation.h"
#include "miner.h"
#include "pubkey.h"
#include "txmempool.h"

View File

@ -7,7 +7,7 @@
#include "versionbits.h"
#include "test/test_dash.h"
#include "chainparams.h"
#include "main.h"
#include "validation.h"
#include "consensus/params.h"
#include <boost/test/unit_test.hpp>

View File

@ -8,7 +8,7 @@
#include "chain.h"
#include "chainparams.h"
#include "hash.h"
#include "main.h"
#include "validation.h"
#include "pow.h"
#include "uint256.h"

View File

@ -8,8 +8,9 @@
#include "clientversion.h"
#include "consensus/consensus.h"
#include "consensus/validation.h"
#include "main.h"
#include "validation.h"
#include "policy/fees.h"
#include "random.h"
#include "streams.h"
#include "timedata.h"
#include "util.h"

File diff suppressed because it is too large Load Diff

View File

@ -4,8 +4,8 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_MAIN_H
#define BITCOIN_MAIN_H
#ifndef BITCOIN_VALIDATION_H
#define BITCOIN_VALIDATION_H
#if defined(HAVE_CONFIG_H)
#include "config/dash-config.h"
@ -14,10 +14,9 @@
#include "amount.h"
#include "chain.h"
#include "coins.h"
#include "net.h"
#include "protocol.h" // For CMessageHeader::MessageStartChars
#include "script/script_error.h"
#include "sync.h"
#include "validationinterface.h"
#include "versionbits.h"
#include "spentindex.h"
@ -30,7 +29,10 @@
#include <utility>
#include <vector>
#include <atomic>
#include <boost/unordered_map.hpp>
#include <boost/filesystem/path.hpp>
class CBlockIndex;
class CBlockTreeDB;
@ -855,45 +857,4 @@ static const unsigned int REJECT_ALREADY_KNOWN = 0x101;
/** Transaction conflicts with a transaction already known */
static const unsigned int REJECT_CONFLICT = 0x102;
// The following things handle network-processing logic
// (and should be moved to a separate file)
/** Register with a network node to receive its signals */
void RegisterNodeSignals(CNodeSignals& nodeSignals);
/** Unregister a network node */
void UnregisterNodeSignals(CNodeSignals& nodeSignals);
class PeerLogicValidation : public CValidationInterface {
private:
CConnman* connman;
public:
PeerLogicValidation(CConnman* connmanIn);
virtual void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload);
virtual void BlockChecked(const CBlock& block, const CValidationState& state);
};
struct CNodeStateStats {
int nMisbehavior;
int nSyncHeight;
int nCommonHeight;
std::vector<int> vHeightInFlight;
};
/** Get statistics from node state */
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats);
/** Increase a node's misbehavior score. */
void Misbehaving(NodeId nodeid, int howmuch);
/** Process protocol messages received from a given node */
bool ProcessMessages(CNode* pfrom, CConnman& connman);
/**
* Send queued protocol messages to be sent to a give node.
*
* @param[in] pto The node which we are sending messages to.
* @param[in] connman The connection manager for that node.
*/
bool SendMessages(CNode* pto, CConnman& connman);
#endif // BITCOIN_MAIN_H
#endif // BITCOIN_VALIDATION_H

View File

@ -7,7 +7,7 @@
#include "chain.h"
#include "rpc/server.h"
#include "init.h"
#include "main.h"
#include "validation.h"
#include "script/script.h"
#include "script/standard.h"
#include "sync.h"

View File

@ -9,7 +9,7 @@
#include "chain.h"
#include "core_io.h"
#include "init.h"
#include "main.h"
#include "validation.h"
#include "net.h"
#include "netbase.h"
#include "policy/rbf.h"

View File

@ -14,7 +14,7 @@
#include "consensus/validation.h"
#include "key.h"
#include "keystore.h"
#include "main.h"
#include "validation.h"
#include "net.h"
#include "policy/policy.h"
#include "primitives/block.h"

View File

@ -8,7 +8,7 @@
#include "base58.h"
#include "consensus/validation.h"
#include "main.h" // For CheckTransaction
#include "validation.h" // For CheckTransaction
#include "protocol.h"
#include "serialize.h"
#include "sync.h"

View File

@ -6,7 +6,7 @@
#include "zmqpublishnotifier.h"
#include "version.h"
#include "main.h"
#include "validation.h"
#include "streams.h"
#include "util.h"

View File

@ -3,8 +3,9 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "chainparams.h"
#include "streams.h"
#include "zmqpublishnotifier.h"
#include "main.h"
#include "validation.h"
#include "util.h"
static std::multimap<std::string, CZMQAbstractPublishNotifier*> mapPublishNotifiers;