Browse Source

Merge branch 'develop' into rpcfix

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
bc607cf79c
  1. 17
      exp/main.cpp
  2. 2
      libdevcore/Common.cpp
  3. 7
      libethcore/BlockInfo.cpp
  4. 4
      libethcore/BlockInfo.h
  5. 19
      libethcore/ProofOfWork.cpp
  6. 2
      libethereum/BlockChain.cpp
  7. 18
      libethereum/Client.cpp

17
exp/main.cpp

@ -19,10 +19,11 @@
* @date 2014
* Ethereum client.
*/
#if ETH_ETHASHCL
#define __CL_ENABLE_EXCEPTIONS
#define CL_USE_DEPRECATED_OPENCL_2_0_APIS
#include "libethash-cl/cl.hpp"
#endif
#include <functional>
#include <libdevcore/RangeMask.h>
#include <libdevcore/Log.h>
@ -108,22 +109,18 @@ int main()
#else
int main()
{
std::vector<cl::Platform> platforms;
cl::Platform::get(&platforms);
if (platforms.empty())
{
cdebug << "No OpenCL platforms found.";
return false;
}
#if ETH_ETHASHCL
EthashCL ecl;
BlockInfo genesis = CanonBlockChain::genesis();
TransientDirectory td;
genesis.difficulty = 1 << 18;
cdebug << (h256)u256((bigint(1) << 256) / genesis.difficulty);
std::pair<MineInfo, Ethash::Proof> r;
while (!r.first.completed)
r = ecl.mine(genesis, 1000);
cdebug << r.second.mixHash << r.second.nonce;
EthashCL::assignResult(r.second, genesis);
assert(EthashCPU::verify(genesis));
#endif
return 0;
}
#endif

2
libdevcore/Common.cpp

@ -27,7 +27,7 @@ using namespace dev;
namespace dev
{
char const* Version = "0.9.6";
char const* Version = "0.9.7";
}

7
libethcore/BlockInfo.cpp

@ -75,6 +75,13 @@ h256 const& BlockInfo::hash() const
return m_hash;
}
h256 const& BlockInfo::boundary() const
{
if (!m_boundary)
m_boundary = (h256)(u256)((bigint(1) << 256) / difficulty);
return m_boundary;
}
BlockInfo BlockInfo::fromHeader(bytesConstRef _header, Strictness _s, h256 const& _h)
{
BlockInfo ret;

4
libethcore/BlockInfo.h

@ -118,7 +118,7 @@ public:
void clear();
void noteDirty() const { m_hash = m_seedHash = h256(); }
void noteDirty() const { m_hash = m_seedHash = m_boundary = h256(); }
void populateFromHeader(RLP const& _header, Strictness _s = IgnoreNonce, h256 const& _h = h256());
void populate(bytesConstRef _block, Strictness _s = IgnoreNonce, h256 const& _h = h256());
@ -131,6 +131,7 @@ public:
u256 selectGasLimit(BlockInfo const& _parent) const;
h256 const& seedHash() const;
h256 const& hash() const;
h256 const& boundary() const;
/// sha3 of the header only.
h256 headerHash(IncludeNonce _n) const;
@ -139,6 +140,7 @@ public:
private:
mutable h256 m_seedHash;
mutable h256 m_hash; ///< SHA3 hash of the block header! Not serialised.
mutable h256 m_boundary; ///< 2^256 / difficulty
};
inline std::ostream& operator<<(std::ostream& _out, BlockInfo const& _bi)

19
libethcore/ProofOfWork.cpp

@ -130,6 +130,7 @@ struct EthashCLHook: public ethash_cl_miner::search_hook
{
if (m_aborted)
return;
cdebug << "Attempting to abort";
m_abort = true;
for (unsigned timeout = 0; timeout < 100 && !m_aborted; ++timeout)
std::this_thread::sleep_for(chrono::milliseconds(30));
@ -149,12 +150,14 @@ protected:
for (unsigned i = 0; i < _count; ++i)
m_found.push_back((Nonce)(u64)_nonces[i]);
m_aborted = true;
cdebug << "Found nonces: " << vector<uint64_t>(_nonces, _nonces + _count);
return true;
}
virtual bool searched(uint64_t _startNonce, uint32_t _count) override
{
Guard l(x_all);
cdebug << "Searched" << _count << "from" << _startNonce;
m_total += _count;
m_last = _startNonce + _count;
if (m_abort)
@ -195,14 +198,19 @@ std::pair<MineInfo, Ethash::Proof> EthashCL::mine(BlockInfo const& _header, unsi
if (m_miner)
m_hook->abort();
m_miner.reset(new ethash_cl_miner);
m_miner->init(Ethasher::params(_header), [&](void* d){ Ethasher::get()->readFull(_header, d); });
auto cb = [&](void* d) {
Ethasher::get()->readFull(_header, d);
};
m_miner->init(Ethasher::params(_header), cb);
}
if (m_lastHeader != _header)
{
m_hook->abort();
static std::random_device s_eng;
uint64_t tryNonce = (uint64_t)(u64)(m_last = Nonce::random(s_eng));
m_miner->search(_header.headerHash(WithoutNonce).data(), tryNonce, *m_hook);
auto hh = _header.headerHash(WithoutNonce);
cdebug << "Mining with headerhash" << hh << "from nonce" << m_last << "with boundary" << _header.boundary();
m_miner->search(hh.data(), tryNonce, *m_hook);
}
m_lastHeader = _header;
@ -210,10 +218,15 @@ std::pair<MineInfo, Ethash::Proof> EthashCL::mine(BlockInfo const& _header, unsi
auto found = m_hook->fetchFound();
if (!found.empty())
{
Nonce n = (Nonce)(u64)found[0];
for (auto const& n: found)
{
auto result = Ethasher::eval(_header, n);
cdebug << "Got nonce " << n << "gives result" << result.value;
if (result.value < _header.boundary())
return std::make_pair(MineInfo(true), EthashCL::Proof{n, result.mixHash});
}
assert(false);
}
return std::make_pair(MineInfo(false), EthashCL::Proof());
}

2
libethereum/BlockChain.cpp

@ -601,7 +601,7 @@ pair<h256s, h256> BlockChain::import(bytes const& _block, OverlayDB const& _db,
m_extrasDB->Put(m_writeOptions, toSlice(h, ExtraTransactionAddress), (ldb::Slice)dev::ref(m_transactionAddresses[h].rlp()));
}
clog(BlockChainNote) << " Imported and best" << td << ". Has" << (details(bi.parentHash).children.size() - 1) << "siblings. Route:" << toString(route);
clog(BlockChainNote) << " Imported and best" << td << " (#" << bi.number << "). Has" << (details(bi.parentHash).children.size() - 1) << "siblings. Route:" << toString(route);
noteCanonChanged();
StructuredLogger::chainNewHead(

18
libethereum/Client.cpp

@ -259,16 +259,28 @@ void Client::clearPending()
noteChanged(changeds);
}
template <class T>
static string filtersToString(T const& _fs)
{
stringstream ret;
ret << "{";
bool i = false;
for (h256 const& f: _fs)
ret << (i++ ? ", " : "") << (f == PendingChangedFilter ? "pending" : f == ChainChangedFilter ? "chain" : f.abridged());
ret << "}";
return ret.str();
}
void Client::noteChanged(h256Set const& _filters)
{
Guard l(x_filtersWatches);
if (_filters.size())
cnote << "noteChanged(" << _filters << ")";
cnote << "noteChanged(" << filtersToString(_filters) << ")";
// accrue all changes left in each filter into the watches.
for (auto& w: m_watches)
if (_filters.count(w.second.id))
{
cwatch << "!!!" << w.first << w.second.id;
cwatch << "!!!" << w.first << (m_filters.count(w.second.id) ? w.second.id.abridged() : w.second.id == PendingChangedFilter ? "pending" : w.second.id == ChainChangedFilter ? "chain" : "???");
if (m_filters.count(w.second.id)) // Normal filtering watch
w.second.changes += m_filters.at(w.second.id).changes;
else // Special ('pending'/'latest') watch
@ -523,7 +535,7 @@ void Client::doWork()
clog(ClientChat) << "Live block:" << h.abridged();
for (auto const& th: m_bc.transactionHashes(h))
{
clog(ClientNote) << "Safely dropping transaction " << th;
clog(ClientNote) << "Safely dropping transaction " << th.abridged();
m_tq.drop(th);
}
}

Loading…
Cancel
Save