You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

net_processing.h 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright (c) 2009-2010 Satoshi Nakamoto
  2. // Copyright (c) 2009-2016 The Starwels developers
  3. // Distributed under the MIT software license, see the accompanying
  4. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  5. #ifndef STARWELS_NET_PROCESSING_H
  6. #define STARWELS_NET_PROCESSING_H
  7. #include "net.h"
  8. #include "validationinterface.h"
  9. #include "consensus/params.h"
  10. /** Default for -maxorphantx, maximum number of orphan transactions kept in memory */
  11. static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100;
  12. /** Expiration time for orphan transactions in seconds */
  13. static const int64_t ORPHAN_TX_EXPIRE_TIME = 20 * 60;
  14. /** Minimum time between orphan transactions expire time checks in seconds */
  15. static const int64_t ORPHAN_TX_EXPIRE_INTERVAL = 5 * 60;
  16. /** Default number of orphan+recently-replaced txn to keep around for block reconstruction */
  17. static const unsigned int DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN = 100;
  18. /** Headers download timeout expressed in microseconds
  19. * Timeout = base + per_header * (expected number of headers) */
  20. static constexpr int64_t HEADERS_DOWNLOAD_TIMEOUT_BASE = 15 * 60 * 1000000; // 15 minutes
  21. static constexpr int64_t HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER = 1000; // 1ms/header
  22. /** Protect at least this many outbound peers from disconnection due to slow/
  23. * behind headers chain.
  24. */
  25. static constexpr int32_t MAX_OUTBOUND_PEERS_TO_PROTECT_FROM_DISCONNECT = 4;
  26. /** Timeout for (unprotected) outbound peers to sync to our chainwork, in seconds */
  27. static constexpr int64_t CHAIN_SYNC_TIMEOUT = 20 * 60; // 20 minutes
  28. /** How frequently to check for stale tips, in seconds */
  29. static constexpr int64_t STALE_CHECK_INTERVAL = 10 * 60; // 10 minutes
  30. /** How frequently to check for extra outbound peers and disconnect, in seconds */
  31. static constexpr int64_t EXTRA_PEER_CHECK_INTERVAL = 45;
  32. /** Minimum time an outbound-peer-eviction candidate must be connected for, in order to evict, in seconds */
  33. static constexpr int64_t MINIMUM_CONNECT_TIME = 30;
  34. class PeerLogicValidation : public CValidationInterface, public NetEventsInterface {
  35. private:
  36. CConnman* const connman;
  37. public:
  38. explicit PeerLogicValidation(CConnman* connman, CScheduler &scheduler);
  39. void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexConnected, const std::vector<CTransactionRef>& vtxConflicted) override;
  40. void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override;
  41. void BlockChecked(const CBlock& block, const CValidationState& state) override;
  42. void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock) override;
  43. void InitializeNode(CNode* pnode) override;
  44. void FinalizeNode(NodeId nodeid, bool& fUpdateConnectionTime) override;
  45. /** Process protocol messages received from a given node */
  46. bool ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt) override;
  47. /**
  48. * Send queued protocol messages to be sent to a give node.
  49. *
  50. * @param[in] pto The node which we are sending messages to.
  51. * @param[in] interrupt Interrupt condition for processing threads
  52. * @return True if there is more work to be done
  53. */
  54. bool SendMessages(CNode* pto, std::atomic<bool>& interrupt) override;
  55. void ConsiderEviction(CNode *pto, int64_t time_in_seconds);
  56. void CheckForStaleTipAndEvictPeers(const Consensus::Params &consensusParams);
  57. void EvictExtraOutboundPeers(int64_t time_in_seconds);
  58. private:
  59. int64_t m_stale_tip_check_time; //! Next time to check for stale tip
  60. };
  61. struct CNodeStateStats {
  62. int nMisbehavior;
  63. int nSyncHeight;
  64. int nCommonHeight;
  65. std::vector<int> vHeightInFlight;
  66. };
  67. /** Get statistics from node state */
  68. bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats);
  69. /** Increase a node's misbehavior score. */
  70. void Misbehaving(NodeId nodeid, int howmuch);
  71. #endif // STARWELS_NET_PROCESSING_H