25 #include <unordered_map> 30 #include <libp2p/Common.h> 40 class EthereumCapability;
98 EthereumCapability
const& host()
const {
return m_host; }
101 void syncPeer(
NodeID const& _peerID,
bool _force);
102 void requestBlocks(
NodeID const& _peerID);
103 void clearPeerDownload(
NodeID const& _peerID);
104 void clearPeerDownload();
105 void collectBlocks();
106 bool requestDaoForkBlockHeader(
NodeID const& _peerID);
107 bool verifyDaoChallengeResponse(RLP
const& _r);
108 void logImported(
unsigned _success,
unsigned _future,
unsigned _got,
unsigned _unknown);
121 h256 transactionsRoot;
124 bool operator==(HeaderId
const& _other)
const 126 return transactionsRoot == _other.transactionsRoot && uncles == _other.uncles;
132 std::size_t operator()(
const HeaderId& _k)
const 136 boost::hash_combine(seed, hasher(_k.transactionsRoot));
137 boost::hash_combine(seed, hasher(_k.uncles));
142 EthereumCapability& m_host;
143 Handler<> m_bqRoomAvailable;
146 std::set<NodeID> m_daoChallengedPeers;
149 unsigned m_chainStartBlock = 0;
150 unsigned m_startingBlock = 0;
151 unsigned m_highestBlock = 0;
152 std::unordered_set<unsigned> m_downloadingHeaders;
153 std::unordered_set<unsigned> m_downloadingBodies;
154 std::map<unsigned, std::vector<Header>> m_headers;
155 std::map<unsigned, std::vector<bytes>> m_bodies;
156 std::map<NodeID, std::vector<unsigned>> m_headerSyncPeers;
159 std::map<NodeID, std::vector<unsigned>> m_bodySyncPeers;
160 std::unordered_map<HeaderId, unsigned, HeaderIdHash> m_headerIdToNumber;
161 bool m_haveCommonHeader =
false;
162 unsigned m_lastImportedBlock = 0;
163 h256 m_lastImportedBlockHash;
164 u256 m_syncingTotalDifficulty;
171 static char const*
const s_stateNames[static_cast<int>(
SyncState::Size)];
172 bool invariants()
const override;
173 void logNewBlock(
h256 const& _h);
176 std::ostream&
operator<<(std::ostream& _out, SyncStatus
const& _sync);
void onPeerBlockHeaders(NodeID const &_peerID, RLP const &_r)
Called by peer once it has new block headers during sync.
Inheritable for classes that have invariants.
void restartSync()
Restart sync.
void onPeerNewHashes(NodeID const &_peerID, std::vector< std::pair< h256, u256 >> const &_hashes)
void abortSync()
Abort all sync activity.
std::ostream & operator<<(std::ostream &_out, BlockHeader const &_bi)
The EthereumCapability class.
Initial chain sync complete. Waiting for new packets.
std::recursive_mutex RecursiveMutex
void onPeerBlockBodies(NodeID const &_peerID, RLP const &_r)
Called by peer once it has new block bodies.
Logger createLogger(int _severity, std::string const &_channel)
std::vector< byte > bytes
SyncStatus status() const
static char const * stateName(SyncState _s)
void onPeerAborting()
Called by peer when it is disconnecting.
Base BlockChain synchronization strategy class. Syncs to peers and keeps up to date....
void onPeerStatus(EthereumPeer const &_peer)
Called by peer to report status.
BlockChainSync(EthereumCapability &_host)
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void > > u256
std::unordered_set< h256 > h256Hash
void onBlockImported(BlockHeader const &_info)
Called when a blockchain has imported a new block onto the DB.
boost::log::sources::severity_channel_logger<> Logger
void onPeerNewBlock(NodeID const &_peerID, RLP const &_r)
Called by peer once it has new block bodies.