Fabcoin Core  0.16.2
P2P Digital Currency
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
dev::eth::BlockChainSync Class Reference

Base BlockChain synchronization strategy class. More...

#include <BlockChainSync.h>

Inheritance diagram for dev::eth::BlockChainSync:
[legend]
Collaboration diagram for dev::eth::BlockChainSync:
[legend]

Classes

struct  Header
 
struct  HeaderId
 Used to identify header by transactions and uncles hashes. More...
 
struct  HeaderIdHash
 

Public Member Functions

 BlockChainSync (EthereumHost &_host)
 
 ~BlockChainSync ()
 
void abortSync ()
 Abort all sync activity. More...
 
bool isSyncing () const
 
void restartSync ()
 Restart sync. More...
 
void completeSync ()
 Called after all blocks have been downloaded Public only for test mode. More...
 
void onPeerStatus (std::shared_ptr< EthereumPeer > _peer)
 Called by peer to report status. More...
 
void onPeerBlockHeaders (std::shared_ptr< EthereumPeer > _peer, RLP const &_r)
 Called by peer once it has new block headers during sync. More...
 
void onPeerBlockBodies (std::shared_ptr< EthereumPeer > _peer, RLP const &_r)
 Called by peer once it has new block bodies. More...
 
void onPeerNewBlock (std::shared_ptr< EthereumPeer > _peer, RLP const &_r)
 Called by peer once it has new block bodies. More...
 
void onPeerNewHashes (std::shared_ptr< EthereumPeer > _peer, std::vector< std::pair< h256, u256 >> const &_hashes)
 
void onPeerAborting ()
 Called by peer when it is disconnecting. More...
 
void onBlockImported (BlockHeader const &_info)
 Called when a blockchain has imported a new block onto the DB. More...
 
SyncStatus status () const
 

Static Public Member Functions

static char const * stateName (SyncState _s)
 

Private Member Functions

void continueSync ()
 Resume downloading after witing state. More...
 
void pauseSync ()
 Enter waiting state. More...
 
EthereumHosthost ()
 
EthereumHost const & host () const
 
void resetSync ()
 
void syncPeer (std::shared_ptr< EthereumPeer > _peer, bool _force)
 
void requestBlocks (std::shared_ptr< EthereumPeer > _peer)
 
void clearPeerDownload (std::shared_ptr< EthereumPeer > _peer)
 
void clearPeerDownload ()
 
void collectBlocks ()
 
bool invariants () const override
 Reimplement to specify the invariants. More...
 
void logNewBlock (h256 const &_h)
 

Private Attributes

EthereumHostm_host
 
Handler m_bqRoomAvailable
 Triggered once block queue has space for more blocks. More...
 
RecursiveMutex x_sync
 
SyncState m_state = SyncState::Idle
 Current sync state. More...
 
h256Hash m_knownNewHashes
 New hashes we know about use for logging only. More...
 
unsigned m_startingBlock = 0
 Last block number for the start of sync. More...
 
unsigned m_highestBlock = 0
 Highest block number seen. More...
 
std::unordered_set< unsigned > m_downloadingHeaders
 Set of block body numbers being downloaded. More...
 
std::unordered_set< unsigned > m_downloadingBodies
 Set of block header numbers being downloaded. More...
 
std::map< unsigned, std::vector< Header > > m_headers
 Downloaded headers. More...
 
std::map< unsigned, std::vector< bytes > > m_bodies
 Downloaded block bodies. More...
 
std::map< std::weak_ptr< EthereumPeer >, std::vector< unsigned >, std::owner_less< std::weak_ptr< EthereumPeer > > > m_headerSyncPeers
 Peers to m_downloadingSubchain number map. More...
 
std::map< std::weak_ptr< EthereumPeer >, std::vector< unsigned >, std::owner_less< std::weak_ptr< EthereumPeer > > > m_bodySyncPeers
 Peers to m_downloadingSubchain number map. More...
 
std::unordered_map< HeaderId, unsigned, HeaderIdHashm_headerIdToNumber
 
bool m_haveCommonHeader = false
 True if common block for our and remote chain has been found. More...
 
unsigned m_lastImportedBlock = 0
 Last imported block number. More...
 
h256 m_lastImportedBlockHash
 Last imported block hash. More...
 
u256 m_syncingTotalDifficulty
 Highest peer difficulty. More...
 

Static Private Attributes

static char const *const s_stateNames [static_cast< int >(SyncState::Size)]
 

Detailed Description

Base BlockChain synchronization strategy class.

Syncs to peers and keeps up to date. Base class handles blocks downloading but does not contain any details on state transfer logic.

Definition at line 49 of file BlockChainSync.h.

Constructor & Destructor Documentation

BlockChainSync::BlockChainSync ( EthereumHost _host)

Definition at line 160 of file BlockChainSync.cpp.

Here is the call graph for this function:

BlockChainSync::~BlockChainSync ( )

Definition at line 174 of file BlockChainSync.cpp.

Here is the call graph for this function:

Member Function Documentation

void BlockChainSync::abortSync ( )

Abort all sync activity.

Definition at line 193 of file BlockChainSync.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void BlockChainSync::clearPeerDownload ( std::shared_ptr< EthereumPeer _peer)
private

Definition at line 367 of file BlockChainSync.cpp.

Here is the call graph for this function:

void BlockChainSync::clearPeerDownload ( )
private

Definition at line 385 of file BlockChainSync.cpp.

Here is the caller graph for this function:

void BlockChainSync::collectBlocks ( )
private

Definition at line 569 of file BlockChainSync.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void BlockChainSync::completeSync ( )

Called after all blocks have been downloaded Public only for test mode.

Definition at line 777 of file BlockChainSync.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void BlockChainSync::continueSync ( )
private

Resume downloading after witing state.

Definition at line 261 of file BlockChainSync.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

EthereumHost& dev::eth::BlockChainSync::host ( )
inlineprivate

Definition at line 98 of file BlockChainSync.h.

Here is the caller graph for this function:

EthereumHost const& dev::eth::BlockChainSync::host ( ) const
inlineprivate

Definition at line 99 of file BlockChainSync.h.

Here is the call graph for this function:

bool BlockChainSync::invariants ( ) const
overrideprivatevirtual

Reimplement to specify the invariants.

Implements dev::HasInvariants.

Definition at line 849 of file BlockChainSync.cpp.

Here is the call graph for this function:

bool BlockChainSync::isSyncing ( ) const
Returns
true is Sync is in progress

Definition at line 788 of file BlockChainSync.cpp.

Here is the caller graph for this function:

void BlockChainSync::logNewBlock ( h256 const &  _h)
private

Definition at line 411 of file BlockChainSync.cpp.

Here is the caller graph for this function:

void BlockChainSync::onBlockImported ( BlockHeader const &  _info)

Called when a blockchain has imported a new block onto the DB.

Definition at line 180 of file BlockChainSync.cpp.

Here is the call graph for this function:

void BlockChainSync::onPeerAborting ( )

Called by peer when it is disconnecting.

Definition at line 840 of file BlockChainSync.cpp.

Here is the call graph for this function:

void BlockChainSync::onPeerBlockBodies ( std::shared_ptr< EthereumPeer _peer,
RLP const &  _r 
)

Called by peer once it has new block bodies.

Definition at line 521 of file BlockChainSync.cpp.

Here is the call graph for this function:

void BlockChainSync::onPeerBlockHeaders ( std::shared_ptr< EthereumPeer _peer,
RLP const &  _r 
)

Called by peer once it has new block headers during sync.

Definition at line 418 of file BlockChainSync.cpp.

Here is the call graph for this function:

void BlockChainSync::onPeerNewBlock ( std::shared_ptr< EthereumPeer _peer,
RLP const &  _r 
)

Called by peer once it has new block bodies.

Definition at line 658 of file BlockChainSync.cpp.

Here is the call graph for this function:

void BlockChainSync::onPeerNewHashes ( std::shared_ptr< EthereumPeer _peer,
std::vector< std::pair< h256, u256 >> const &  _hashes 
)

Definition at line 793 of file BlockChainSync.cpp.

Here is the call graph for this function:

void BlockChainSync::onPeerStatus ( std::shared_ptr< EthereumPeer _peer)

Called by peer to report status.

Definition at line 203 of file BlockChainSync.cpp.

Here is the call graph for this function:

void BlockChainSync::pauseSync ( )
private

Enter waiting state.

Definition at line 783 of file BlockChainSync.cpp.

Here is the caller graph for this function:

void BlockChainSync::requestBlocks ( std::shared_ptr< EthereumPeer _peer)
private

Definition at line 270 of file BlockChainSync.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void BlockChainSync::resetSync ( )
private

Definition at line 752 of file BlockChainSync.cpp.

Here is the caller graph for this function:

void BlockChainSync::restartSync ( )

Restart sync.

Definition at line 765 of file BlockChainSync.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

static char const* dev::eth::BlockChainSync::stateName ( SyncState  _s)
inlinestatic

Definition at line 89 of file BlockChainSync.h.

Here is the call graph for this function:

SyncStatus BlockChainSync::status ( ) const
Returns
Synchonization status

Definition at line 740 of file BlockChainSync.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void BlockChainSync::syncPeer ( std::shared_ptr< EthereumPeer _peer,
bool  _force 
)
private

Definition at line 226 of file BlockChainSync.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

std::map<unsigned, std::vector<bytes> > dev::eth::BlockChainSync::m_bodies
private

Downloaded block bodies.

Definition at line 150 of file BlockChainSync.h.

std::map<std::weak_ptr<EthereumPeer>, std::vector<unsigned>, std::owner_less<std::weak_ptr<EthereumPeer> > > dev::eth::BlockChainSync::m_bodySyncPeers
private

Peers to m_downloadingSubchain number map.

Definition at line 152 of file BlockChainSync.h.

Handler dev::eth::BlockChainSync::m_bqRoomAvailable
private

Triggered once block queue has space for more blocks.

Definition at line 141 of file BlockChainSync.h.

std::unordered_set<unsigned> dev::eth::BlockChainSync::m_downloadingBodies
private

Set of block header numbers being downloaded.

Definition at line 148 of file BlockChainSync.h.

std::unordered_set<unsigned> dev::eth::BlockChainSync::m_downloadingHeaders
private

Set of block body numbers being downloaded.

Definition at line 147 of file BlockChainSync.h.

bool dev::eth::BlockChainSync::m_haveCommonHeader = false
private

True if common block for our and remote chain has been found.

Definition at line 154 of file BlockChainSync.h.

std::unordered_map<HeaderId, unsigned, HeaderIdHash> dev::eth::BlockChainSync::m_headerIdToNumber
private

Definition at line 153 of file BlockChainSync.h.

std::map<unsigned, std::vector<Header> > dev::eth::BlockChainSync::m_headers
private

Downloaded headers.

Definition at line 149 of file BlockChainSync.h.

std::map<std::weak_ptr<EthereumPeer>, std::vector<unsigned>, std::owner_less<std::weak_ptr<EthereumPeer> > > dev::eth::BlockChainSync::m_headerSyncPeers
private

Peers to m_downloadingSubchain number map.

Definition at line 151 of file BlockChainSync.h.

unsigned dev::eth::BlockChainSync::m_highestBlock = 0
private

Highest block number seen.

Definition at line 146 of file BlockChainSync.h.

EthereumHost& dev::eth::BlockChainSync::m_host
private

Definition at line 140 of file BlockChainSync.h.

h256Hash dev::eth::BlockChainSync::m_knownNewHashes
private

New hashes we know about use for logging only.

Definition at line 144 of file BlockChainSync.h.

unsigned dev::eth::BlockChainSync::m_lastImportedBlock = 0
private

Last imported block number.

Definition at line 155 of file BlockChainSync.h.

h256 dev::eth::BlockChainSync::m_lastImportedBlockHash
private

Last imported block hash.

Definition at line 156 of file BlockChainSync.h.

unsigned dev::eth::BlockChainSync::m_startingBlock = 0
private

Last block number for the start of sync.

Definition at line 145 of file BlockChainSync.h.

SyncState dev::eth::BlockChainSync::m_state = SyncState::Idle
private

Current sync state.

Definition at line 143 of file BlockChainSync.h.

u256 dev::eth::BlockChainSync::m_syncingTotalDifficulty
private

Highest peer difficulty.

Definition at line 157 of file BlockChainSync.h.

char const* const dev::eth::BlockChainSync::s_stateNames[static_cast< int >(SyncState::Size)]
staticprivate

Definition at line 160 of file BlockChainSync.h.

RecursiveMutex dev::eth::BlockChainSync::x_sync
mutableprivate

Definition at line 142 of file BlockChainSync.h.


The documentation for this class was generated from the following files: