Skip to content

Commit 1a07e04

Browse files
fanquakePastaPastaPasta
authored andcommitted
Merge bitcoin#21370: Use C++11 member initializer in CNodeState
fa476f1 Use C++11 member initializer in CNodeState (MarcoFalke) Pull request description: This removes a bunch of boilerplate, makes the code easier to read. Also, C++11 member initialization avoids accidental uninitialized members. ACKs for top commit: practicalswift: cr ACK fa476f1 hebasto: cr ACK fa476f1 jnewbery: utACK fa476f1 Tree-SHA512: 5c876717d30ded975e29bfbc77804012179588a13f950f0b2ec93fa9dbd5cf6b52fe86414fd5d1cce021db2ec77e271d533b0f7a8d6eeaac0feb9e6dbaec9ff2
1 parent 6423f6b commit 1a07e04

File tree

1 file changed

+17
-33
lines changed

1 file changed

+17
-33
lines changed

src/net_processing.cpp

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -702,41 +702,41 @@ namespace {
702702
*/
703703
struct CNodeState {
704704
//! The best known block we know this peer has announced.
705-
const CBlockIndex *pindexBestKnownBlock;
705+
const CBlockIndex* pindexBestKnownBlock{nullptr};
706706
//! The hash of the last unknown block this peer has announced.
707-
uint256 hashLastUnknownBlock;
707+
uint256 hashLastUnknownBlock{};
708708
//! The last full block we both have.
709-
const CBlockIndex *pindexLastCommonBlock;
709+
const CBlockIndex* pindexLastCommonBlock{nullptr};
710710
//! The best header we have sent our peer.
711-
const CBlockIndex *pindexBestHeaderSent;
711+
const CBlockIndex* pindexBestHeaderSent{nullptr};
712712
//! Length of current-streak of unconnecting headers announcements
713-
int nUnconnectingHeaders;
713+
int nUnconnectingHeaders{0};
714714
//! Whether we've started headers synchronization with this peer.
715-
bool fSyncStarted;
715+
bool fSyncStarted{false};
716716
//! When to potentially disconnect peer for stalling headers download
717717
std::chrono::microseconds m_headers_sync_timeout{0us};
718718
//! Since when we're stalling block download progress (in microseconds), or 0.
719719
std::chrono::microseconds m_stalling_since{0us};
720720
std::list<QueuedBlock> vBlocksInFlight;
721721
//! When the first entry in vBlocksInFlight started downloading. Don't care when vBlocksInFlight is empty.
722722
std::chrono::microseconds m_downloading_since{0us};
723-
int nBlocksInFlight;
724-
int nBlocksInFlightValidHeaders;
723+
int nBlocksInFlight{0};
724+
int nBlocksInFlightValidHeaders{0};
725725
//! Whether we consider this a preferred download peer.
726-
bool fPreferredDownload;
726+
bool fPreferredDownload{false};
727727
//! Whether this peer wants invs or headers (when possible) for block announcements.
728-
bool fPreferHeaders;
728+
bool fPreferHeaders{false};
729729
//! Whether this peer wants invs or compressed headers (when possible) for block announcements.
730-
bool fPreferHeadersCompressed;
730+
bool fPreferHeadersCompressed{false};
731731
//! Whether this peer wants invs or cmpctblocks (when possible) for block announcements.
732-
bool fPreferHeaderAndIDs;
732+
bool fPreferHeaderAndIDs{false};
733733
//! Whether this peer will send us cmpctblocks if we request them
734-
bool fProvidesHeaderAndIDs;
734+
bool fProvidesHeaderAndIDs{false};
735735
/**
736736
* If we've announced last version to this peer: whether the peer sends last version in cmpctblocks/blocktxns,
737737
* otherwise: whether this peer sends non-last version in cmpctblocks/blocktxns.
738738
*/
739-
bool fSupportsDesiredCmpctVersion;
739+
bool fSupportsDesiredCmpctVersion{false};
740740

741741
/** State used to enforce CHAIN_SYNC_TIMEOUT and EXTRA_PEER_CHECK_INTERVAL logic.
742742
*
@@ -773,10 +773,10 @@ struct CNodeState {
773773
bool m_protect{false};
774774
};
775775

776-
ChainSyncTimeoutState m_chain_sync;
776+
ChainSyncTimeoutState m_chain_sync{0, nullptr, false, false};
777777

778778
//! Time of last new block announcement
779-
int64_t m_last_block_announcement;
779+
int64_t m_last_block_announcement{0};
780780

781781
/*
782782
* State associated with objects download.
@@ -842,30 +842,14 @@ struct CNodeState {
842842
ObjectDownloadState m_object_download;
843843

844844
//! Whether this peer is an inbound connection
845-
bool m_is_inbound;
845+
const bool m_is_inbound;
846846

847847
//! A rolling bloom filter of all announced tx CInvs to this peer.
848848
CRollingBloomFilter m_recently_announced_invs = CRollingBloomFilter{INVENTORY_MAX_RECENT_RELAY, 0.000001};
849849

850850
CNodeState(bool is_inbound) :
851851
m_is_inbound(is_inbound)
852852
{
853-
pindexBestKnownBlock = nullptr;
854-
hashLastUnknownBlock.SetNull();
855-
pindexLastCommonBlock = nullptr;
856-
pindexBestHeaderSent = nullptr;
857-
nUnconnectingHeaders = 0;
858-
fSyncStarted = false;
859-
nBlocksInFlight = 0;
860-
nBlocksInFlightValidHeaders = 0;
861-
fPreferredDownload = false;
862-
fPreferHeaders = false;
863-
fPreferHeadersCompressed = false;
864-
fPreferHeaderAndIDs = false;
865-
fProvidesHeaderAndIDs = false;
866-
fSupportsDesiredCmpctVersion = false;
867-
m_chain_sync = { 0, nullptr, false, false };
868-
m_last_block_announcement = 0;
869853
m_recently_announced_invs.reset();
870854
}
871855
};

0 commit comments

Comments
 (0)