diff --git a/CMakeLists.txt b/CMakeLists.txt index 89d3c167a..1d35280e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -403,13 +403,13 @@ if (TOOLS) endif () if (JSONRPC AND GENERAL) - add_subdirectory(libweb3jsonrpc) +# add_subdirectory(libweb3jsonrpc) endif () if (JSCONSOLE) - add_subdirectory(libjsengine) - add_subdirectory(libjsconsole) - add_subdirectory(ethconsole) +# add_subdirectory(libjsengine) +# add_subdirectory(libjsconsole) +# add_subdirectory(ethconsole) endif () if (NOT WIN32) @@ -435,33 +435,33 @@ endif () add_subdirectory(libethcore) if (GENERAL) - add_subdirectory(libevm) - add_subdirectory(libethereum) - add_subdirectory(libwebthree) +# add_subdirectory(libevm) +# add_subdirectory(libethereum) +# add_subdirectory(libwebthree) endif () if (MINER OR TOOLS) - add_subdirectory(ethminer) +# add_subdirectory(ethminer) endif () if (ETHKEY OR TOOLS) - add_subdirectory(ethkey) +# add_subdirectory(ethkey) endif () if (TESTS) - add_subdirectory(libtestutils) - add_subdirectory(test) +# add_subdirectory(libtestutils) +# add_subdirectory(test) if (JSONRPC) - add_subdirectory(ethrpctest) +# add_subdirectory(ethrpctest) endif () endif () if (TOOLS) - add_subdirectory(rlp) - add_subdirectory(abi) - add_subdirectory(ethvm) - add_subdirectory(eth) +# add_subdirectory(rlp) +# add_subdirectory(abi) +# add_subdirectory(ethvm) +# add_subdirectory(eth) if("x${CMAKE_BUILD_TYPE}" STREQUAL "xDebug") add_subdirectory(exp) diff --git a/exp/CMakeLists.txt b/exp/CMakeLists.txt index 7a80023bf..30f4705f9 100644 --- a/exp/CMakeLists.txt +++ b/exp/CMakeLists.txt @@ -18,15 +18,21 @@ if (READLINE_FOUND) endif() if (JSONRPC) - target_link_libraries(${EXECUTABLE} web3jsonrpc) +# target_link_libraries(${EXECUTABLE} web3jsonrpc) endif() -target_link_libraries(${EXECUTABLE} webthree) -target_link_libraries(${EXECUTABLE} ethereum) -target_link_libraries(${EXECUTABLE} p2p) +#target_link_libraries(${EXECUTABLE} webthree) +#target_link_libraries(${EXECUTABLE} ethereum) +#target_link_libraries(${EXECUTABLE} p2p) if (ETHASHCL) - target_link_libraries(${EXECUTABLE} ethash-cl) - target_link_libraries(${EXECUTABLE} ethash) - target_link_libraries(${EXECUTABLE} ${OpenCL_LIBRARIES}) +# target_link_libraries(${EXECUTABLE} ethash-cl) +# target_link_libraries(${EXECUTABLE} ethash) +# target_link_libraries(${EXECUTABLE} ${OpenCL_LIBRARIES}) endif() +target_link_libraries(${EXECUTABLE} ethcore) install( TARGETS ${EXECUTABLE} DESTINATION bin) + + + + + diff --git a/exp/main.cpp b/exp/main.cpp index 07eee6a11..fa8603459 100644 --- a/exp/main.cpp +++ b/exp/main.cpp @@ -70,6 +70,7 @@ namespace fs = boost::filesystem; #include #include #include +#include using namespace std; using namespace dev; using namespace eth; @@ -80,24 +81,43 @@ using namespace eth; int main() { BlockInfo bi; + bi.difficulty = c_genesisDifficulty; + bi.gasLimit = c_genesisGasLimit; + bi.number = 1; + bi.parentHash = sha3("parentHash"); + bytes sealedData; - SealEngineFace* se = BasicAuthority::createSealEngine(); - cdebug << se->sealers(); - se->onSealGenerated([&](SealFace const* seal){ sealedData = seal->sealedHeader(bi); }); - se->generateSeal(bi); { + KeyPair kp(sha3("test")); + SealEngineFace* se = BasicAuthority::createSealEngine(); + se->setOption("authority", rlp(kp.secret())); + se->setOption("authorities", rlpList(kp.address())); + cdebug << se->sealers(); + bool done = false; + se->onSealGenerated([&](SealFace const* seal){ + sealedData = seal->sealedHeader(bi); + done = true; + }); + se->generateSeal(bi); + while (!done) + this_thread::sleep_for(chrono::milliseconds(50)); BasicAuthority::BlockHeader sealed = BasicAuthority::BlockHeader::fromHeader(sealedData, CheckEverything); cdebug << sealed.sig(); } - SealEngineFace* se = Ethash::createSealEngine(); - cdebug << se->sealers(); - se->onSealGenerated([&](SealFace const* seal){ sealedData = seal->sealedHeader(bi); done = true; }); - se->generateSeal(bi); - while (!done) - this_thread::sleep_for(chrono::milliseconds(50)); { + SealEngineFace* se = Ethash::createSealEngine(); + cdebug << se->sealers(); + bool done = false; + se->setSealer("cpu"); + se->onSealGenerated([&](SealFace const* seal){ + sealedData = seal->sealedHeader(bi); + done = true; + }); + se->generateSeal(bi); + while (!done) + this_thread::sleep_for(chrono::milliseconds(50)); Ethash::BlockHeader sealed = Ethash::BlockHeader::fromHeader(sealedData, CheckEverything); cdebug << sealed.nonce(); } diff --git a/libdevcore/Common.h b/libdevcore/Common.h index 303512e57..612b7c685 100644 --- a/libdevcore/Common.h +++ b/libdevcore/Common.h @@ -65,6 +65,7 @@ using byte = uint8_t; #define DEV_IGNORE_EXCEPTIONS(X) try { X; } catch (...) {} #define DEV_IF_NO_ELSE(X) if(!(X)){}else +#define DEV_IF_THROWS(X) try{X;}catch(...) namespace dev { diff --git a/libethcore/BasicAuthority.cpp b/libethcore/BasicAuthority.cpp index bbf4e3f2a..7006107e1 100644 --- a/libethcore/BasicAuthority.cpp +++ b/libethcore/BasicAuthority.cpp @@ -26,11 +26,11 @@ using namespace std; using namespace dev; using namespace eth; -const Address BasicAuthority::Authority = Address("1234567890123456789012345678901234567890"); +AddressHash BasicAuthority::s_authorities; bool BasicAuthority::BlockHeaderRaw::verify() const { - return toAddress(recover(m_sig, hashWithout())) == Authority; + return s_authorities.count(toAddress(recover(m_sig, hashWithout()))); } bool BasicAuthority::BlockHeaderRaw::preVerify() const @@ -94,11 +94,23 @@ public: MiningProgress miningProgress() const { return MiningProgress(); } private: + virtual bool onOptionChanging(std::string const& _name, bytes const& _value) + { + RLP rlp(_value); + if (_name == "authorities") + BasicAuthority::s_authorities = rlp.toUnorderedSet
(); + else if (_name == "authority") + m_secret = rlp.toHash(); + else + return false; + return true; + } + Secret m_secret; std::function m_onSealGenerated; }; -SealEngineFace* createSealEngine() +SealEngineFace* BasicAuthority::createSealEngine() { return new BasicAuthoritySealEngine; } diff --git a/libethcore/BasicAuthority.h b/libethcore/BasicAuthority.h index 616c18340..9127c1d53 100644 --- a/libethcore/BasicAuthority.h +++ b/libethcore/BasicAuthority.h @@ -30,6 +30,7 @@ #include "Sealer.h" class BasicAuthoritySeal; +class BasicAuthoritySealEngine; namespace dev { @@ -48,6 +49,8 @@ namespace eth */ class BasicAuthority { + friend class ::BasicAuthoritySealEngine; + public: // TODO: remove struct Result {}; @@ -70,6 +73,7 @@ public: Signature sig() const { return m_sig; } protected: + BlockHeaderRaw() = default; BlockHeaderRaw(BlockInfo const& _bi): BlockInfo(_bi) {} static const unsigned SealFields = 1; @@ -84,7 +88,8 @@ public: }; using BlockHeader = BlockHeaderPolished; - static const Address Authority; +private: + static AddressHash s_authorities; }; } diff --git a/libethcore/BlockInfo.h b/libethcore/BlockInfo.h index cd55bc1f6..710279cb2 100644 --- a/libethcore/BlockInfo.h +++ b/libethcore/BlockInfo.h @@ -158,7 +158,7 @@ public: explicit BlockHeaderPolished(bytesConstRef _block, Strictness _s = IgnoreNonce, h256 const& _h = h256()) { populate(_block, _s, _h); } static BlockHeaderPolished fromHeader(bytes const& _header, Strictness _s = IgnoreNonce, h256 const& _h = h256()) { return fromHeader(bytesConstRef(&_header), _s, _h); } - static BlockHeaderPolished fromHeader(bytesConstRef _header, Strictness _s = IgnoreNonce, h256 const& _h = h256()) { BlockHeaderPolished ret; ret.populateFromHeader(_header, _s, _h); return ret; } + static BlockHeaderPolished fromHeader(bytesConstRef _header, Strictness _s = IgnoreNonce, h256 const& _h = h256()) { BlockHeaderPolished ret; ret.populateFromHeader(RLP(_header), _s, _h); return ret; } void populate(bytesConstRef _block, Strictness _s, h256 const& _h = h256()) { populateFromHeader(BlockInfo::extractHeader(_block), _s, _h); } diff --git a/libethcore/Ethash.cpp b/libethcore/Ethash.cpp index c3f19e723..d385163be 100644 --- a/libethcore/Ethash.cpp +++ b/libethcore/Ethash.cpp @@ -119,7 +119,7 @@ bool Ethash::BlockHeaderRaw::verify() const } #endif - auto result = EthashAux::eval(*this); + auto result = EthashAux::eval(seedHash(), hashWithout(), m_nonce); bool slow = result.value <= boundary() && result.mixHash == m_mixHash; // cdebug << (slow ? "VERIFY" : "VERYBAD"); @@ -281,6 +281,7 @@ public: { m_farm.onSolutionFound([=](Ethash::Solution const& sol) { + cdebug << m_farm.work().seedHash << m_farm.work().headerHash << sol.nonce << EthashAux::eval(m_farm.work().seedHash, m_farm.work().headerHash, sol.nonce).value; EthashSeal s(sol.mixHash, sol.nonce); _f(&s); return true; diff --git a/libethcore/Ethash.h b/libethcore/Ethash.h index eee0e3881..99baa8a05 100644 --- a/libethcore/Ethash.h +++ b/libethcore/Ethash.h @@ -94,6 +94,7 @@ public: h256 const& mixHash() const { return m_mixHash; } protected: + BlockHeaderRaw() = default; BlockHeaderRaw(BlockInfo const& _bi): BlockInfo(_bi) {} static const unsigned SealFields = 2; diff --git a/libethcore/EthashAux.cpp b/libethcore/EthashAux.cpp index 42a3cf6fb..00537c21a 100644 --- a/libethcore/EthashAux.cpp +++ b/libethcore/EthashAux.cpp @@ -200,18 +200,6 @@ EthashAux::FullType EthashAux::full(h256 const& _seedHash, bool _createIfMissing return ret; } -Ethash::Result EthashAux::eval(BlockInfo const& _header) -{ -#if ETH_USING_ETHASH - return eval(_header, _header.proof.nonce); -#else - (void)_header; - return Ethash::Result(); -#endif -} - -#define DEV_IF_THROWS(X) try { X; } catch (...) - unsigned EthashAux::computeFull(h256 const& _seedHash, bool _createIfMissing) { Guard l(get()->x_fulls); @@ -260,17 +248,6 @@ Ethash::Result EthashAux::LightAllocation::compute(h256 const& _headerHash, Nonc return Ethash::Result{h256((uint8_t*)&r.result, h256::ConstructFromPointer), h256((uint8_t*)&r.mix_hash, h256::ConstructFromPointer)}; } -Ethash::Result EthashAux::eval(BlockInfo const& _header, Nonce const& _nonce) -{ -#if ETH_USING_ETHASH - return eval(_header.proofCache(), _header.headerHash(WithoutProof), _nonce); -#else - (void)_header; - (void)_nonce; - return Ethash::Result(); -#endif -} - Ethash::Result EthashAux::eval(h256 const& _seedHash, h256 const& _headerHash, Nonce const& _nonce) { DEV_GUARDED(get()->x_fulls) diff --git a/libethcore/EthashAux.h b/libethcore/EthashAux.h index 5ae24898d..132b9b436 100644 --- a/libethcore/EthashAux.h +++ b/libethcore/EthashAux.h @@ -79,8 +79,6 @@ public: /// Kicks off generation of DAG for @a _blocknumber and blocks until ready; @returns result or empty pointer if not existing and _createIfMissing is false. static FullType full(h256 const& _seedHash, bool _createIfMissing = false, std::function const& _f = std::function()); - static Ethash::Result eval(BlockInfo const& _header); - static Ethash::Result eval(BlockInfo const& _header, Nonce const& _nonce); static Ethash::Result eval(h256 const& _seedHash, h256 const& _headerHash, Nonce const& _nonce); private: diff --git a/libethcore/Sealer.h b/libethcore/Sealer.h index f491240f3..28381444e 100644 --- a/libethcore/Sealer.h +++ b/libethcore/Sealer.h @@ -24,6 +24,7 @@ #pragma once #include +#include #include "Common.h" namespace dev @@ -43,6 +44,9 @@ public: class SealEngineFace { public: + bytes option(std::string const& _name) const { Guard l(x_options); return m_options.count(_name) ? m_options.at(_name) : bytes(); } + bool setOption(std::string const& _name, bytes const& _value) { Guard l(x_options); try { if (onOptionChanging(_name, _value)) { m_options[_name] = _value; return true; } } catch (...) {} return false; } + virtual strings sealers() const { return { "default" }; } virtual void setSealer(std::string const&) {} virtual void generateSeal(BlockInfo const& _bi) = 0; @@ -52,6 +56,14 @@ public: // TODO: rename & generalise virtual bool isMining() const { return false; } virtual MiningProgress miningProgress() const { return MiningProgress(); } + +protected: + virtual bool onOptionChanging(std::string const&, bytes const&) { return true; } + void injectOption(std::string const& _name, bytes const& _value) { Guard l(x_options); m_options[_name] = _value; } + +private: + mutable Mutex x_options; + std::unordered_map m_options; }; }