Browse Source

Remove asOf redundancy.

Minor mix typo fix.
cl-refactor
Gav Wood 10 years ago
parent
commit
fc5b6de495
  1. 21
      libethereum/Client.cpp
  2. 4
      libethereum/Client.h
  3. 23
      libethereum/ClientBase.cpp
  4. 19
      libethereum/ClientBase.h
  5. 23
      mix/MixClient.cpp
  6. 6
      mix/MixClient.h

21
libethereum/Client.cpp

@ -246,7 +246,7 @@ void Client::clearPending()
void Client::noteChanged(h256Set const& _filters)
{
Guard l(m_filterLock);
Guard l(x_filtersWatches);
if (_filters.size())
cnote << "noteChanged(" << _filters << ")";
// accrue all changes left in each filter into the watches.
@ -266,7 +266,7 @@ void Client::noteChanged(h256Set const& _filters)
void Client::appendFromNewPending(TransactionReceipt const& _receipt, h256Set& io_changed, h256 _transactionHash)
{
Guard l(m_filterLock);
Guard l(x_filtersWatches);
for (pair<h256 const, InstalledFilter>& i: m_filters)
if (i.second.filter.envelops(RelativeBlock::Pending, m_bc.number() + 1))
{
@ -288,7 +288,7 @@ void Client::appendFromNewBlock(h256 const& _block, h256Set& io_changed)
auto d = m_bc.info(_block);
auto br = m_bc.receipts(_block);
Guard l(m_filterLock);
Guard l(x_filtersWatches);
for (pair<h256 const, InstalledFilter>& i: m_filters)
if (i.second.filter.envelops(RelativeBlock::Latest, d.number) && i.second.filter.matches(d.logBloom))
// acceptable number & looks like block may contain a matching log entry.
@ -535,7 +535,7 @@ void Client::doWork()
// watches garbage collection
vector<unsigned> toUninstall;
{
Guard l(m_filterLock);
Guard l(x_filtersWatches);
for (auto key: keysOf(m_watches))
if (m_watches[key].lastPoll != chrono::system_clock::time_point::max() && chrono::system_clock::now() - m_watches[key].lastPoll > chrono::seconds(20))
{
@ -553,18 +553,7 @@ void Client::doWork()
}
}
State Client::asOf(BlockNumber _h) const
{
ReadGuard l(x_stateDB);
if (_h == PendingBlock)
return m_postMine;
else if (_h == LatestBlock)
return m_preMine;
return State(m_stateDB, bc(), bc().numberHash(_h));
}
State Client::asOf(h256 _block) const
State Client::asOf(h256 const& _block) const
{
ReadGuard l(x_stateDB);
return State(m_stateDB, bc(), _block);

4
libethereum/Client.h

@ -254,8 +254,8 @@ protected:
/// Returns the state object for the full block (i.e. the terminal state) for index _h.
/// Works properly with LatestBlock and PendingBlock.
virtual State asOf(BlockNumber _h) const override;
virtual State asOf(h256 _block) const override;
using ClientBase::asOf;
virtual State asOf(h256 const& _block) const override;
virtual State preMine() const override { ReadGuard l(x_stateDB); return m_preMine; }
virtual State postMine() const override { ReadGuard l(x_stateDB); return m_postMine; }
virtual void prepareForTransaction() override;

23
libethereum/ClientBase.cpp

@ -29,6 +29,15 @@ using namespace std;
using namespace dev;
using namespace dev::eth;
State ClientBase::asOf(BlockNumber _h) const
{
if (_h == PendingBlock)
return postMine();
else if (_h == LatestBlock)
return preMine();
return asOf(bc().numberHash(_h));
}
void ClientBase::submitTransaction(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice)
{
prepareForTransaction();
@ -123,7 +132,7 @@ LocalisedLogEntries ClientBase::logs(unsigned _watchId) const
LogFilter f;
try
{
Guard l(m_filterLock);
Guard l(x_filtersWatches);
f = m_filters.at(m_watches.at(_watchId).id).filter;
}
catch (...)
@ -196,7 +205,7 @@ unsigned ClientBase::installWatch(LogFilter const& _f, Reaping _r)
{
h256 h = _f.sha3();
{
Guard l(m_filterLock);
Guard l(x_filtersWatches);
if (!m_filters.count(h))
{
cwatch << "FFF" << _f << h.abridged();
@ -210,7 +219,7 @@ unsigned ClientBase::installWatch(h256 _h, Reaping _r)
{
unsigned ret;
{
Guard l(m_filterLock);
Guard l(x_filtersWatches);
ret = m_watches.size() ? m_watches.rbegin()->first + 1 : 0;
m_watches[ret] = ClientWatch(_h, _r);
cwatch << "+++" << ret << _h.abridged();
@ -219,7 +228,7 @@ unsigned ClientBase::installWatch(h256 _h, Reaping _r)
if (ch.empty())
ch.push_back(InitialChange);
{
Guard l(m_filterLock);
Guard l(x_filtersWatches);
swap(m_watches[ret].changes, ch);
}
return ret;
@ -229,7 +238,7 @@ bool ClientBase::uninstallWatch(unsigned _i)
{
cwatch << "XXX" << _i;
Guard l(m_filterLock);
Guard l(x_filtersWatches);
auto it = m_watches.find(_i);
if (it == m_watches.end())
@ -249,7 +258,7 @@ bool ClientBase::uninstallWatch(unsigned _i)
LocalisedLogEntries ClientBase::peekWatch(unsigned _watchId) const
{
Guard l(m_filterLock);
Guard l(x_filtersWatches);
cwatch << "peekWatch" << _watchId;
auto& w = m_watches.at(_watchId);
@ -260,7 +269,7 @@ LocalisedLogEntries ClientBase::peekWatch(unsigned _watchId) const
LocalisedLogEntries ClientBase::checkWatch(unsigned _watchId)
{
Guard l(m_filterLock);
Guard l(x_filtersWatches);
LocalisedLogEntries ret;
cwatch << "checkWatch" << _watchId;

19
libethereum/ClientBase.h

@ -126,7 +126,7 @@ public:
virtual Addresses addresses(BlockNumber _block) const override;
virtual u256 gasLimitRemaining() const override;
// Set the coinbase address
/// Set the coinbase address
virtual void setAddress(Address _us) override;
/// Get the coinbase address
@ -143,21 +143,24 @@ public:
virtual std::pair<h256, u256> getWork() override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("dev::eth::ClientBase::getWork")); }
virtual bool submitWork(eth::ProofOfWork::Proof const&) override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("dev::eth::ClientBase::submitWork")); }
protected:
State asOf(BlockNumber _h) const;
protected:
/// The interface that must be implemented in any class deriving this.
/// {
virtual BlockChain const& bc() const = 0;
virtual State asOf(BlockNumber _h) const = 0;
virtual State asOf(h256 _h) const = 0;
virtual State asOf(h256 const& _h) const = 0;
virtual State preMine() const = 0;
virtual State postMine() const = 0;
virtual void prepareForTransaction() = 0;
/// }
TransactionQueue m_tq; ///< Maintains a list of incoming transactions not yet in a block on the blockchain.
TransactionQueue m_tq; ///< Maintains a list of incoming transactions not yet in a block on the blockchain.
// filters
mutable Mutex m_filterLock;
std::map<h256, InstalledFilter> m_filters;
std::map<unsigned, ClientWatch> m_watches;
mutable Mutex x_filtersWatches; ///< Our lock.
std::map<h256, InstalledFilter> m_filters; ///< The dictionary of filters that are active.
std::map<unsigned, ClientWatch> m_watches; ///< Each and every watch - these reference a filter.
};

23
mix/MixClient.cpp

@ -58,7 +58,7 @@ bytes MixBlockChain::createGenesisBlock(h256 _stateRoot)
}
MixClient::MixClient(std::string const& _dbPath):
m_dbPath(_dbPath), m_minigThreads(0)
m_dbPath(_dbPath), m_miningThreads(0)
{
std::map<Secret, u256> account;
account.insert(std::make_pair(c_defaultUserAccountSecret, 1000000 * ether));
@ -72,7 +72,7 @@ MixClient::~MixClient()
void MixClient::resetState(std::map<Secret, u256> _accounts)
{
WriteGuard l(x_state);
Guard fl(m_filterLock);
Guard fl(x_filtersWatches);
m_filters.clear();
m_watches.clear();
@ -188,7 +188,7 @@ void MixClient::executeTransaction(Transaction const& _t, State& _state, bool _c
BOOST_THROW_EXCEPTION(OutOfGas() << errinfo_comment("Not enough gas for contract deployment"));
// collect watches
h256Set changed;
Guard l(m_filterLock);
Guard l(x_filtersWatches);
for (std::pair<h256 const, eth::InstalledFilter>& i: m_filters)
if ((unsigned)i.second.filter.latest() > bc().number())
{
@ -234,18 +234,7 @@ ExecutionResult MixClient::execution(unsigned _index) const
return m_executions.at(_index);
}
State MixClient::asOf(BlockNumber _block) const
{
ReadGuard l(x_state);
if (_block == PendingBlock)
return m_state;
else if (_block == LatestBlock)
return m_startState;
return State(m_stateDB, bc(), bc().numberHash(_block));
}
State MixClient::asOf(h256 _block) const
State MixClient::asOf(h256 const& _block) const
{
ReadGuard l(x_state);
return State(m_stateDB, bc(), _block);
@ -325,12 +314,12 @@ void MixClient::setAddress(Address _us)
void MixClient::setMiningThreads(unsigned _threads)
{
m_minigThreads = _threads;
m_miningThreads = _threads;
}
unsigned MixClient::miningThreads() const
{
return m_minigThreads;
return m_miningThreads;
}
void MixClient::startMining()

6
mix/MixClient.h

@ -78,8 +78,8 @@ protected:
virtual dev::eth::BlockChain& bc() { return *m_bc; }
/// InterfaceStub methods
virtual dev::eth::State asOf(eth::BlockNumber _block) const override;
virtual dev::eth::State asOf(h256 _block) const override;
virtual dev::eth::State asOf(h256 const& _block) const override;
using ClientBase::asOf;
virtual dev::eth::BlockChain const& bc() const override { return *m_bc; }
virtual dev::eth::State preMine() const override { ReadGuard l(x_state); return m_startState; }
virtual dev::eth::State postMine() const override { ReadGuard l(x_state); return m_state; }
@ -98,7 +98,7 @@ private:
mutable boost::shared_mutex x_executions;
ExecutionResults m_executions;
std::string m_dbPath;
unsigned m_minigThreads;
unsigned m_miningThreads;
};
}

Loading…
Cancel
Save