Browse Source

Blockchain sync trivial fixes.

cl-refactor
Gav Wood 10 years ago
parent
commit
b26b38c466
  1. 8
      libethereum/BlockChainSync.cpp
  2. 20
      libethereum/BlockChainSync.h

8
libethereum/BlockChainSync.cpp

@ -94,7 +94,7 @@ void BlockChainSync::onPeerStatus(EthereumPeer* _peer)
DEV_INVARIANT_CHECK; DEV_INVARIANT_CHECK;
} }
unsigned BlockChainSync::estimateHashes() unsigned BlockChainSync::estimateHashes() const
{ {
BlockInfo block = host().chain().info(); BlockInfo block = host().chain().info();
time_t lastBlockTime = (block.hash() == host().chain().genesisHash()) ? 1428192000 : (time_t)block.timestamp; 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" : ""); 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); 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_latestHash = _latestHash;
_peer->m_totalDifficulty = _td; _peer->m_totalDifficulty = _td;
@ -707,7 +707,7 @@ void PV60Sync::onPeerNewHashes(EthereumPeer* _peer, h256s const& _hashes)
} }
unsigned knowns = 0; unsigned knowns = 0;
unsigned unknowns = 0; unsigned unknowns = 0;
for (auto h: _hashes) for (auto const& h: _hashes)
{ {
_peer->addRating(1); _peer->addRating(1);
DEV_GUARDED(_peer->x_knownBlocks) DEV_GUARDED(_peer->x_knownBlocks)

20
libethereum/BlockChainSync.h

@ -103,29 +103,29 @@ protected:
virtual void pauseSync() = 0; virtual void pauseSync() = 0;
/// Restart sync for given peer /// 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& host() { return m_host; }
EthereumHost const& host() const { return m_host; } EthereumHost const& host() const { return m_host; }
/// Estimates max number of hashes peers can give us. /// Estimates max number of hashes peers can give us.
unsigned estimateHashes(); unsigned estimateHashes() const;
/// Request blocks from peer if needed /// Request blocks from peer if needed
void requestBlocks(EthereumPeer* _peer); void requestBlocks(EthereumPeer* _peer);
private:
static char const* const s_stateNames[static_cast<int>(SyncState::Size)];
bool invariants() const override = 0;
EthereumHost& m_host;
HashDownloadMan m_hashMan;
protected: protected:
Handler m_bqRoomAvailable; Handler m_bqRoomAvailable;
mutable RecursiveMutex x_sync; mutable RecursiveMutex x_sync;
SyncState m_state = SyncState::Idle; ///< Current sync state SyncState m_state = SyncState::Idle; ///< Current sync state
SyncState m_lastActiveState = SyncState::Idle; ///< Saved state before entering waiting queue mode 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. 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<int>(SyncState::Size)];
bool invariants() const override = 0;
EthereumHost& m_host;
HashDownloadMan m_hashMan;
}; };
@ -159,7 +159,7 @@ public:
void restartSync() override; void restartSync() override;
void completeSync() override; void completeSync() override;
void pauseSync() 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: private:
/// Transition sync state in a particular direction. @param _peer Peer that is responsible for state tranfer /// 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); } void resetNeedsSyncing(EthereumPeer* _peer) { setNeedsSyncing(_peer, h256(), 0); }
/// Update peer syncing requirements state. /// 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? /// Do we presently need syncing with this peer?
bool needsSyncing(EthereumPeer* _peer) const; bool needsSyncing(EthereumPeer* _peer) const;

Loading…
Cancel
Save