Skip to content

Commit e175ca9

Browse files
committed
Merge #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
2 parents 461f0c7 + fa476f1 commit e175ca9

File tree

1 file changed

+18
-35
lines changed

1 file changed

+18
-35
lines changed

src/net_processing.cpp

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -491,47 +491,47 @@ struct CNodeState {
491491
//! The peer's address
492492
const CService address;
493493
//! The best known block we know this peer has announced.
494-
const CBlockIndex *pindexBestKnownBlock;
494+
const CBlockIndex* pindexBestKnownBlock{nullptr};
495495
//! The hash of the last unknown block this peer has announced.
496-
uint256 hashLastUnknownBlock;
496+
uint256 hashLastUnknownBlock{};
497497
//! The last full block we both have.
498-
const CBlockIndex *pindexLastCommonBlock;
498+
const CBlockIndex* pindexLastCommonBlock{nullptr};
499499
//! The best header we have sent our peer.
500-
const CBlockIndex *pindexBestHeaderSent;
500+
const CBlockIndex* pindexBestHeaderSent{nullptr};
501501
//! Length of current-streak of unconnecting headers announcements
502-
int nUnconnectingHeaders;
502+
int nUnconnectingHeaders{0};
503503
//! Whether we've started headers synchronization with this peer.
504-
bool fSyncStarted;
504+
bool fSyncStarted{false};
505505
//! When to potentially disconnect peer for stalling headers download
506506
std::chrono::microseconds m_headers_sync_timeout{0us};
507507
//! Since when we're stalling block download progress (in microseconds), or 0.
508508
std::chrono::microseconds m_stalling_since{0us};
509509
std::list<QueuedBlock> vBlocksInFlight;
510510
//! When the first entry in vBlocksInFlight started downloading. Don't care when vBlocksInFlight is empty.
511511
std::chrono::microseconds m_downloading_since{0us};
512-
int nBlocksInFlight;
513-
int nBlocksInFlightValidHeaders;
512+
int nBlocksInFlight{0};
513+
int nBlocksInFlightValidHeaders{0};
514514
//! Whether we consider this a preferred download peer.
515-
bool fPreferredDownload;
515+
bool fPreferredDownload{false};
516516
//! Whether this peer wants invs or headers (when possible) for block announcements.
517-
bool fPreferHeaders;
517+
bool fPreferHeaders{false};
518518
//! Whether this peer wants invs or cmpctblocks (when possible) for block announcements.
519-
bool fPreferHeaderAndIDs;
519+
bool fPreferHeaderAndIDs{false};
520520
/**
521521
* Whether this peer will send us cmpctblocks if we request them.
522522
* This is not used to gate request logic, as we really only care about fSupportsDesiredCmpctVersion,
523523
* but is used as a flag to "lock in" the version of compact blocks (fWantsCmpctWitness) we send.
524524
*/
525-
bool fProvidesHeaderAndIDs;
525+
bool fProvidesHeaderAndIDs{false};
526526
//! Whether this peer can give us witnesses
527-
bool fHaveWitness;
527+
bool fHaveWitness{false};
528528
//! Whether this peer wants witnesses in cmpctblocks/blocktxns
529-
bool fWantsCmpctWitness;
529+
bool fWantsCmpctWitness{false};
530530
/**
531531
* If we've announced NODE_WITNESS to this peer: whether the peer sends witnesses in cmpctblocks/blocktxns,
532532
* otherwise: whether this peer sends non-witnesses in cmpctblocks/blocktxns.
533533
*/
534-
bool fSupportsDesiredCmpctVersion;
534+
bool fSupportsDesiredCmpctVersion{false};
535535

536536
/** State used to enforce CHAIN_SYNC_TIMEOUT and EXTRA_PEER_CHECK_INTERVAL logic.
537537
*
@@ -568,13 +568,13 @@ struct CNodeState {
568568
bool m_protect;
569569
};
570570

571-
ChainSyncTimeoutState m_chain_sync;
571+
ChainSyncTimeoutState m_chain_sync{0, nullptr, false, false};
572572

573573
//! Time of last new block announcement
574-
int64_t m_last_block_announcement;
574+
int64_t m_last_block_announcement{0};
575575

576576
//! Whether this peer is an inbound connection
577-
bool m_is_inbound;
577+
const bool m_is_inbound;
578578

579579
//! A rolling bloom filter of all announced tx CInvs to this peer.
580580
CRollingBloomFilter m_recently_announced_invs = CRollingBloomFilter{INVENTORY_MAX_RECENT_RELAY, 0.000001};
@@ -585,23 +585,6 @@ struct CNodeState {
585585
CNodeState(CAddress addrIn, bool is_inbound)
586586
: address(addrIn), m_is_inbound(is_inbound)
587587
{
588-
pindexBestKnownBlock = nullptr;
589-
hashLastUnknownBlock.SetNull();
590-
pindexLastCommonBlock = nullptr;
591-
pindexBestHeaderSent = nullptr;
592-
nUnconnectingHeaders = 0;
593-
fSyncStarted = false;
594-
nBlocksInFlight = 0;
595-
nBlocksInFlightValidHeaders = 0;
596-
fPreferredDownload = false;
597-
fPreferHeaders = false;
598-
fPreferHeaderAndIDs = false;
599-
fProvidesHeaderAndIDs = false;
600-
fHaveWitness = false;
601-
fWantsCmpctWitness = false;
602-
fSupportsDesiredCmpctVersion = false;
603-
m_chain_sync = { 0, nullptr, false, false };
604-
m_last_block_announcement = 0;
605588
m_recently_announced_invs.reset();
606589
}
607590
};

0 commit comments

Comments
 (0)