| 224 | } |
| 225 | |
| 226 | void BlockChainSync::syncPeer(std::shared_ptr<EthereumPeer> _peer, bool _force) |
| 227 | { |
| 228 | if (_peer->m_asking != Asking::Nothing) |
| 229 | { |
| 230 | clog(NetAllDetail) << "Can't sync with this peer - outstanding asks."; |
| 231 | return; |
| 232 | } |
| 233 | |
| 234 | if (m_state == SyncState::Waiting) |
| 235 | return; |
| 236 | |
| 237 | u256 td = host().chain().details().totalDifficulty; |
| 238 | if (host().bq().isActive()) |
| 239 | td += host().bq().difficulty(); |
| 240 | |
| 241 | u256 syncingDifficulty = std::max(m_syncingTotalDifficulty, td); |
| 242 | |
| 243 | if (_force || _peer->m_totalDifficulty > syncingDifficulty) |
| 244 | { |
| 245 | // start sync |
| 246 | m_syncingTotalDifficulty = _peer->m_totalDifficulty; |
| 247 | if (m_state == SyncState::Idle || m_state == SyncState::NotSynced) |
| 248 | m_state = SyncState::Blocks; |
| 249 | _peer->requestBlockHeaders(_peer->m_latestHash, 1, 0, false); |
| 250 | _peer->m_requireTransactions = true; |
| 251 | return; |
| 252 | } |
| 253 | |
| 254 | if (m_state == SyncState::Blocks) |
| 255 | { |
| 256 | requestBlocks(_peer); |
| 257 | return; |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | void BlockChainSync::continueSync() |
| 262 | { |
nothing calls this directly
no test coverage detected