Fabcoin Core
0.16.2
P2P Digital Currency
|
Base BlockChain synchronization strategy class. More...
#include <BlockChainSync.h>
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... | |
EthereumHost & | host () |
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 | |
EthereumHost & | m_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, HeaderIdHash > | m_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)] |
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.
BlockChainSync::BlockChainSync | ( | EthereumHost & | _host | ) |
BlockChainSync::~BlockChainSync | ( | ) |
void BlockChainSync::abortSync | ( | ) |
Abort all sync activity.
Definition at line 193 of file BlockChainSync.cpp.
|
private |
|
private |
|
private |
Definition at line 569 of file BlockChainSync.cpp.
void BlockChainSync::completeSync | ( | ) |
Called after all blocks have been downloaded Public only for test mode.
Definition at line 777 of file BlockChainSync.cpp.
|
private |
Resume downloading after witing state.
Definition at line 261 of file BlockChainSync.cpp.
|
inlineprivate |
|
inlineprivate |
|
overrideprivatevirtual |
Reimplement to specify the invariants.
Implements dev::HasInvariants.
Definition at line 849 of file BlockChainSync.cpp.
bool BlockChainSync::isSyncing | ( | ) | const |
Definition at line 788 of file BlockChainSync.cpp.
|
private |
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.
void BlockChainSync::onPeerAborting | ( | ) |
Called by peer when it is disconnecting.
Definition at line 840 of file BlockChainSync.cpp.
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.
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.
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.
void BlockChainSync::onPeerNewHashes | ( | std::shared_ptr< EthereumPeer > | _peer, |
std::vector< std::pair< h256, u256 >> const & | _hashes | ||
) |
void BlockChainSync::onPeerStatus | ( | std::shared_ptr< EthereumPeer > | _peer | ) |
Called by peer to report status.
Definition at line 203 of file BlockChainSync.cpp.
|
private |
Enter waiting state.
Definition at line 783 of file BlockChainSync.cpp.
|
private |
Definition at line 270 of file BlockChainSync.cpp.
|
private |
void BlockChainSync::restartSync | ( | ) |
Restart sync.
Definition at line 765 of file BlockChainSync.cpp.
|
inlinestatic |
SyncStatus BlockChainSync::status | ( | ) | const |
Definition at line 740 of file BlockChainSync.cpp.
|
private |
Definition at line 226 of file BlockChainSync.cpp.
|
private |
Downloaded block bodies.
Definition at line 150 of file BlockChainSync.h.
|
private |
Peers to m_downloadingSubchain number map.
Definition at line 152 of file BlockChainSync.h.
|
private |
Triggered once block queue has space for more blocks.
Definition at line 141 of file BlockChainSync.h.
|
private |
Set of block header numbers being downloaded.
Definition at line 148 of file BlockChainSync.h.
|
private |
Set of block body numbers being downloaded.
Definition at line 147 of file BlockChainSync.h.
|
private |
True if common block for our and remote chain has been found.
Definition at line 154 of file BlockChainSync.h.
|
private |
Definition at line 153 of file BlockChainSync.h.
|
private |
Downloaded headers.
Definition at line 149 of file BlockChainSync.h.
|
private |
Peers to m_downloadingSubchain number map.
Definition at line 151 of file BlockChainSync.h.
|
private |
Highest block number seen.
Definition at line 146 of file BlockChainSync.h.
|
private |
Definition at line 140 of file BlockChainSync.h.
|
private |
New hashes we know about use for logging only.
Definition at line 144 of file BlockChainSync.h.
|
private |
Last imported block number.
Definition at line 155 of file BlockChainSync.h.
|
private |
Last imported block hash.
Definition at line 156 of file BlockChainSync.h.
|
private |
Last block number for the start of sync.
Definition at line 145 of file BlockChainSync.h.
|
private |
Current sync state.
Definition at line 143 of file BlockChainSync.h.
|
private |
Highest peer difficulty.
Definition at line 157 of file BlockChainSync.h.
|
staticprivate |
Definition at line 160 of file BlockChainSync.h.
|
mutableprivate |
Definition at line 142 of file BlockChainSync.h.