From fa476f188ed1200087ea4cca2e883c792836f845 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Fri, 5 Mar 2021 11:48:34 +0100 Subject: [PATCH] Use C++11 member initializer in CNodeState --- src/net_processing.cpp | 53 ++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 35 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index d19e11f7b1..638c39e6be 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -491,17 +491,17 @@ struct CNodeState { //! The peer's address const CService address; //! The best known block we know this peer has announced. - const CBlockIndex *pindexBestKnownBlock; + const CBlockIndex* pindexBestKnownBlock{nullptr}; //! The hash of the last unknown block this peer has announced. - uint256 hashLastUnknownBlock; + uint256 hashLastUnknownBlock{}; //! The last full block we both have. - const CBlockIndex *pindexLastCommonBlock; + const CBlockIndex* pindexLastCommonBlock{nullptr}; //! The best header we have sent our peer. - const CBlockIndex *pindexBestHeaderSent; + const CBlockIndex* pindexBestHeaderSent{nullptr}; //! Length of current-streak of unconnecting headers announcements - int nUnconnectingHeaders; + int nUnconnectingHeaders{0}; //! Whether we've started headers synchronization with this peer. - bool fSyncStarted; + bool fSyncStarted{false}; //! When to potentially disconnect peer for stalling headers download std::chrono::microseconds m_headers_sync_timeout{0us}; //! Since when we're stalling block download progress (in microseconds), or 0. @@ -509,29 +509,29 @@ struct CNodeState { std::list vBlocksInFlight; //! When the first entry in vBlocksInFlight started downloading. Don't care when vBlocksInFlight is empty. std::chrono::microseconds m_downloading_since{0us}; - int nBlocksInFlight; - int nBlocksInFlightValidHeaders; + int nBlocksInFlight{0}; + int nBlocksInFlightValidHeaders{0}; //! Whether we consider this a preferred download peer. - bool fPreferredDownload; + bool fPreferredDownload{false}; //! Whether this peer wants invs or headers (when possible) for block announcements. - bool fPreferHeaders; + bool fPreferHeaders{false}; //! Whether this peer wants invs or cmpctblocks (when possible) for block announcements. - bool fPreferHeaderAndIDs; + bool fPreferHeaderAndIDs{false}; /** * Whether this peer will send us cmpctblocks if we request them. * This is not used to gate request logic, as we really only care about fSupportsDesiredCmpctVersion, * but is used as a flag to "lock in" the version of compact blocks (fWantsCmpctWitness) we send. */ - bool fProvidesHeaderAndIDs; + bool fProvidesHeaderAndIDs{false}; //! Whether this peer can give us witnesses - bool fHaveWitness; + bool fHaveWitness{false}; //! Whether this peer wants witnesses in cmpctblocks/blocktxns - bool fWantsCmpctWitness; + bool fWantsCmpctWitness{false}; /** * If we've announced NODE_WITNESS to this peer: whether the peer sends witnesses in cmpctblocks/blocktxns, * otherwise: whether this peer sends non-witnesses in cmpctblocks/blocktxns. */ - bool fSupportsDesiredCmpctVersion; + bool fSupportsDesiredCmpctVersion{false}; /** State used to enforce CHAIN_SYNC_TIMEOUT and EXTRA_PEER_CHECK_INTERVAL logic. * @@ -568,13 +568,13 @@ struct CNodeState { bool m_protect; }; - ChainSyncTimeoutState m_chain_sync; + ChainSyncTimeoutState m_chain_sync{0, nullptr, false, false}; //! Time of last new block announcement - int64_t m_last_block_announcement; + int64_t m_last_block_announcement{0}; //! Whether this peer is an inbound connection - bool m_is_inbound; + const bool m_is_inbound; //! A rolling bloom filter of all announced tx CInvs to this peer. CRollingBloomFilter m_recently_announced_invs = CRollingBloomFilter{INVENTORY_MAX_RECENT_RELAY, 0.000001}; @@ -585,23 +585,6 @@ struct CNodeState { CNodeState(CAddress addrIn, bool is_inbound) : address(addrIn), m_is_inbound(is_inbound) { - pindexBestKnownBlock = nullptr; - hashLastUnknownBlock.SetNull(); - pindexLastCommonBlock = nullptr; - pindexBestHeaderSent = nullptr; - nUnconnectingHeaders = 0; - fSyncStarted = false; - nBlocksInFlight = 0; - nBlocksInFlightValidHeaders = 0; - fPreferredDownload = false; - fPreferHeaders = false; - fPreferHeaderAndIDs = false; - fProvidesHeaderAndIDs = false; - fHaveWitness = false; - fWantsCmpctWitness = false; - fSupportsDesiredCmpctVersion = false; - m_chain_sync = { 0, nullptr, false, false }; - m_last_block_announcement = 0; m_recently_announced_invs.reset(); } };