From b26b38c466f6edc2e742409be62b9eaa0e8a4b35 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 19 Jun 2015 10:53:13 +0800 Subject: [PATCH] Blockchain sync trivial fixes. --- libethereum/BlockChainSync.cpp | 8 ++++---- libethereum/BlockChainSync.h | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/libethereum/BlockChainSync.cpp b/libethereum/BlockChainSync.cpp index eb4514731..d7fd2c5ea 100644 --- a/libethereum/BlockChainSync.cpp +++ b/libethereum/BlockChainSync.cpp @@ -94,7 +94,7 @@ void BlockChainSync::onPeerStatus(EthereumPeer* _peer) DEV_INVARIANT_CHECK; } -unsigned BlockChainSync::estimateHashes() +unsigned BlockChainSync::estimateHashes() const { BlockInfo block = host().chain().info(); time_t lastBlockTime = (block.hash() == host().chain().genesisHash()) ? 1428192000 : (time_t)block.timestamp; @@ -478,12 +478,12 @@ void PV60Sync::transition(EthereumPeer* _peer, SyncState _s, bool _force, bool _ clog(NetWarn) << "Invalid state transition:" << EthereumHost::stateName(_s) << "from" << EthereumHost::stateName(m_state) << ", " << (isSyncing(_peer) ? "syncing" : "holding") << (needsSyncing(_peer) ? "& needed" : ""); } -void PV60Sync::resetSyncFor(EthereumPeer* _peer, h256 _latestHash, u256 _td) +void PV60Sync::resetSyncFor(EthereumPeer* _peer, h256 const& _latestHash, u256 const& _td) { setNeedsSyncing(_peer, _latestHash, _td); } -void PV60Sync::setNeedsSyncing(EthereumPeer* _peer, h256 _latestHash, u256 _td) +void PV60Sync::setNeedsSyncing(EthereumPeer* _peer, h256 const& _latestHash, u256 const& _td) { _peer->m_latestHash = _latestHash; _peer->m_totalDifficulty = _td; @@ -707,7 +707,7 @@ void PV60Sync::onPeerNewHashes(EthereumPeer* _peer, h256s const& _hashes) } unsigned knowns = 0; unsigned unknowns = 0; - for (auto h: _hashes) + for (auto const& h: _hashes) { _peer->addRating(1); DEV_GUARDED(_peer->x_knownBlocks) diff --git a/libethereum/BlockChainSync.h b/libethereum/BlockChainSync.h index e981a344e..7042c5a48 100644 --- a/libethereum/BlockChainSync.h +++ b/libethereum/BlockChainSync.h @@ -103,29 +103,29 @@ protected: virtual void pauseSync() = 0; /// Restart sync for given peer - virtual void resetSyncFor(EthereumPeer* _peer, h256 _latestHash, u256 _td) = 0; + virtual void resetSyncFor(EthereumPeer* _peer, h256 const& _latestHash, u256 const& _td) = 0; EthereumHost& host() { return m_host; } EthereumHost const& host() const { return m_host; } /// Estimates max number of hashes peers can give us. - unsigned estimateHashes(); + unsigned estimateHashes() const; /// Request blocks from peer if needed void requestBlocks(EthereumPeer* _peer); -private: - static char const* const s_stateNames[static_cast(SyncState::Size)]; - bool invariants() const override = 0; - EthereumHost& m_host; - HashDownloadMan m_hashMan; - protected: Handler m_bqRoomAvailable; mutable RecursiveMutex x_sync; SyncState m_state = SyncState::Idle; ///< Current sync state SyncState m_lastActiveState = SyncState::Idle; ///< Saved state before entering waiting queue mode unsigned m_estimatedHashes = 0; ///< Number of estimated hashes for the last peer over PV60. Used for status reporting only. + +private: + static char const* const s_stateNames[static_cast(SyncState::Size)]; + bool invariants() const override = 0; + EthereumHost& m_host; + HashDownloadMan m_hashMan; }; @@ -159,7 +159,7 @@ public: void restartSync() override; void completeSync() override; void pauseSync() override; - void resetSyncFor(EthereumPeer* _peer, h256 _latestHash, u256 _td) override; + void resetSyncFor(EthereumPeer* _peer, h256 const& _latestHash, u256 const& _td) override; private: /// Transition sync state in a particular direction. @param _peer Peer that is responsible for state tranfer @@ -169,7 +169,7 @@ private: void resetNeedsSyncing(EthereumPeer* _peer) { setNeedsSyncing(_peer, h256(), 0); } /// Update peer syncing requirements state. - void setNeedsSyncing(EthereumPeer* _peer, h256 _latestHash, u256 _td); + void setNeedsSyncing(EthereumPeer* _peer, h256 const& _latestHash, u256 const& _td); /// Do we presently need syncing with this peer? bool needsSyncing(EthereumPeer* _peer) const;