From aefcb7b70c923ccd341329a2d5e22238dc14ac3b Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 4 Oct 2016 13:36:11 -0400 Subject: Move net-processing logic definitions together in main.h --- src/main.h | 56 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 26 deletions(-) (limited to 'src/main.h') diff --git a/src/main.h b/src/main.h index 2646d8f86b..3c587569f6 100644 --- a/src/main.h +++ b/src/main.h @@ -41,7 +41,6 @@ class CValidationInterface; class CValidationState; struct PrecomputedTransactionData; -struct CNodeStateStats; struct LockPoints; /** Default for DEFAULT_WHITELISTRELAY. */ @@ -206,11 +205,6 @@ static const unsigned int DEFAULT_CHECKLEVEL = 3; // Setting the target to > than 550MB will make it likely we can respect the target. static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024; -/** Register with a network node to receive its signals */ -void RegisterNodeSignals(CNodeSignals& nodeSignals); -/** Unregister a network node */ -void UnregisterNodeSignals(CNodeSignals& nodeSignals); - /** * Process an incoming block. This only returns after the best known valid * block is made active. Note that it does not, however, guarantee that the @@ -240,15 +234,6 @@ bool InitBlockIndex(const CChainParams& chainparams); bool LoadBlockIndex(); /** Unload database information */ void UnloadBlockIndex(); -/** 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); /** Run an instance of the script checking thread */ void ThreadScriptCheck(); /** Check whether we are doing an initial block download (synchronizing from disk or network) */ @@ -291,10 +276,6 @@ void UnlinkPrunedFiles(std::set& setFilesToPrune); /** Create a new block index entry for a given block hash */ CBlockIndex * InsertBlockIndex(uint256 hash); -/** Get statistics from node state */ -bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats); -/** Increase a node's misbehavior score. */ -void Misbehaving(NodeId nodeid, int howmuch); /** Flush all state, indexes and buffers to disk. */ void FlushStateToDisk(); /** Prune block files and flush state to disk. */ @@ -310,13 +291,6 @@ std::string FormatStateMessage(const CValidationState &state); /** Get the BIP9 state for a given deployment at the current tip. */ ThresholdState VersionBitsTipState(const Consensus::Params& params, Consensus::DeploymentPos pos); -struct CNodeStateStats { - int nMisbehavior; - int nSyncHeight; - int nCommonHeight; - std::vector vHeightInFlight; -}; - /** @@ -545,4 +519,34 @@ 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); + +struct CNodeStateStats { + int nMisbehavior; + int nSyncHeight; + int nCommonHeight; + std::vector 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 -- cgit v1.2.3 From fef1010199b70026fd6d56ebac5c277552757307 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 4 Oct 2016 13:49:44 -0400 Subject: Use CValidationInterface from chain logic to notify peer logic This adds a new CValidationInterface subclass, defined in main.h, to receive notifications of UpdatedBlockTip and use that to push blocks to peers, instead of doing it directly from ActivateBestChain. --- src/main.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/main.h') diff --git a/src/main.h b/src/main.h index 3c587569f6..bb5e26b0b2 100644 --- a/src/main.h +++ b/src/main.h @@ -16,6 +16,7 @@ #include "net.h" #include "script/script_error.h" #include "sync.h" +#include "validationinterface.h" #include "versionbits.h" #include @@ -527,6 +528,16 @@ void RegisterNodeSignals(CNodeSignals& nodeSignals); /** Unregister a network node */ void UnregisterNodeSignals(CNodeSignals& nodeSignals); +class PeerLogicValidation : public CValidationInterface { +private: + CConnman* connman; + +public: + PeerLogicValidation(CConnman* connmanIn) : connman(connmanIn) {} + + virtual void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload); +}; + struct CNodeStateStats { int nMisbehavior; int nSyncHeight; -- cgit v1.2.3 From f5efa283931ce1d52c59234b58988a221d42ecb4 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 30 Sep 2016 18:38:05 -0400 Subject: Remove CConnman parameter from ProcessNewBlock/ActivateBestChain --- src/main.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main.h') diff --git a/src/main.h b/src/main.h index bb5e26b0b2..77179b25b9 100644 --- a/src/main.h +++ b/src/main.h @@ -218,7 +218,7 @@ static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024; * @param[out] dbp The already known disk position of pblock, or NULL if not yet stored. * @return True if state.IsValid() */ -bool ProcessNewBlock(CValidationState& state, const CChainParams& chainparams, CNode* pfrom, const CBlock* pblock, bool fForceProcessing, const CDiskBlockPos* dbp, CConnman* connman); +bool ProcessNewBlock(CValidationState& state, const CChainParams& chainparams, CNode* pfrom, const CBlock* pblock, bool fForceProcessing, const CDiskBlockPos* dbp); /** Check whether enough disk space is available for an incoming block */ bool CheckDiskSpace(uint64_t nAdditionalBytes = 0); /** Open a block file (blk?????.dat) */ @@ -250,7 +250,7 @@ std::string GetWarnings(const std::string& strFor); /** Retrieve a transaction (from memory pool, or from disk, if possible) */ bool GetTransaction(const uint256 &hash, CTransaction &tx, const Consensus::Params& params, uint256 &hashBlock, bool fAllowSlow = false); /** Find the best known block, and make it the tip of the block chain */ -bool ActivateBestChain(CValidationState& state, const CChainParams& chainparams, const CBlock* pblock = NULL, CConnman* connman = NULL); +bool ActivateBestChain(CValidationState& state, const CChainParams& chainparams, const CBlock* pblock = NULL); CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams); /** -- cgit v1.2.3 From a9aec5c24d8c4efe9e1ede54e8b8039b4b3f0835 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 4 Oct 2016 13:54:29 -0400 Subject: Use BlockChecked signal to send reject messages from mapBlockSource --- src/main.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/main.h') diff --git a/src/main.h b/src/main.h index 77179b25b9..889b6a2da1 100644 --- a/src/main.h +++ b/src/main.h @@ -536,6 +536,7 @@ public: PeerLogicValidation(CConnman* connmanIn) : connman(connmanIn) {} virtual void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload); + virtual void BlockChecked(const CBlock& block, const CValidationState& state); }; struct CNodeStateStats { -- cgit v1.2.3