Browse Source

Merge remote-tracking branch 'up/develop' into deploydialog

cl-refactor
yann300 10 years ago
parent
commit
5b6ed24503
  1. 5
      CMakeLists.txt
  2. 6
      alethzero/Main.ui
  3. 40
      alethzero/MainWin.cpp
  4. 1
      alethzero/MainWin.h
  5. 19
      evmjit/CMakeLists.txt
  6. 2
      libethash-cl/CMakeLists.txt
  7. 24
      libethash-cl/ethash_cl_miner.cpp
  8. 1
      libethcore/BlockInfo.h
  9. 12
      libethcore/Common.h
  10. 1
      libethcore/Exceptions.h
  11. 19
      libethereum/BlockChain.cpp
  12. 37
      libethereum/BlockChain.h
  13. 2
      libethereum/BlockQueue.cpp
  14. 2
      libethereum/CanonBlockChain.cpp
  15. 10
      test/libethereum/blockchain.cpp

5
CMakeLists.txt

@ -1,7 +1,7 @@
# cmake global
cmake_minimum_required(VERSION 2.8.12)
set(PROJECT_VERSION "0.9.37")
set(PROJECT_VERSION "0.9.38")
if (${CMAKE_VERSION} VERSION_GREATER 3.0)
cmake_policy(SET CMP0048 NEW) # allow VERSION argument in project()
project(ethereum VERSION ${PROJECT_VERSION})
@ -57,7 +57,7 @@ set(D_PARANOID OFF)
set(D_PROFILING OFF)
set(D_ROCKSDB OFF)
set(D_NOBOOST OFF)
set(D_FRONTIER OFF)
set(D_FRONTIER ON)
set(D_MINER ON)
set(D_ETHKEY ON)
@ -139,7 +139,6 @@ elseif (BUNDLE STREQUAL "release") # release builds
set(D_EVMJIT ON)
set(D_JSCONSOLE ON)
set(D_JSONRPC ON)
set(D_FRONTIER ON)
set(D_CMAKE_BUILD_TYPE "Release")
endif ()

6
alethzero/Main.ui

@ -223,6 +223,7 @@
<addaction name="debugCurrent"/>
<addaction name="debugDumpState"/>
<addaction name="debugDumpStatePre"/>
<addaction name="dumpBlockState"/>
</widget>
<widget class="QMenu" name="menu_Config">
<property name="title">
@ -1819,6 +1820,11 @@ font-size: 14pt</string>
<string>&amp;Hermit Mode</string>
</property>
</action>
<action name="dumpBlockState">
<property name="text">
<string>Dump &amp;Block State as JSON...</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>

40
alethzero/MainWin.cpp

@ -1851,6 +1851,46 @@ void Main::on_debugCurrent_triggered()
}
}
std::string minHex(h256 const& _h)
{
unsigned i = 0;
for (; i < 31 && !_h[i]; ++i) {}
return toHex(_h.ref().cropped(i));
}
void Main::on_dumpBlockState_triggered()
{
#if ETH_FATDB || !ETH_TRUE
if (auto item = ui->blocks->currentItem())
{
auto hba = item->data(Qt::UserRole).toByteArray();
assert(hba.size() == 32);
auto h = h256((byte const*)hba.data(), h256::ConstructFromPointer);
QString fn = QFileDialog::getSaveFileName(this, "Select file to output state dump");
ofstream f(fn.toStdString());
if (f.is_open())
{
js::mObject s;
State state = ethereum()->state(h);
for (pair<Address, u256> const& i: state.addresses())
{
js::mObject a;
a["balance"] = toString(i.second);
a["nonce"] = toString(state.transactionsFrom(i.first));
a["codeHash"] = state.codeHash(i.first).hex();
js::mObject st;
for (pair<u256, u256> const& j: state.storage(i.first))
st[minHex(j.first)] = st[minHex(j.second)];
a["storage"] = st;
s[i.first.hex()] = a;
}
js::mValue v(s);
js::write_stream(v, f, true);
}
}
#endif
}
void Main::debugDumpState(int _add)
{
if (auto item = ui->blocks->currentItem())

1
alethzero/MainWin.h

@ -193,6 +193,7 @@ private slots:
void on_debugCurrent_triggered();
void on_debugDumpState_triggered() { debugDumpState(1); }
void on_debugDumpStatePre_triggered() { debugDumpState(0); }
void on_dumpBlockState_triggered();
// Whisper
void on_newIdentity_triggered();

19
evmjit/CMakeLists.txt

@ -27,12 +27,25 @@ endif()
# LLVM
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND NOT LLVM_DIR)
# Workaround for Ubuntu broken LLVM package
message(STATUS "Using llvm-3.7-dev package from Ubuntu. If does not work, build LLVM and set -DLLVM_DIR=llvm-build/share/llvm/cmake")
execute_process(COMMAND llvm-config-3.7 --includedir OUTPUT_VARIABLE LLVM_INCLUDE_DIRS OUTPUT_STRIP_TRAILING_WHITESPACE)
find_program(LLVM3_7_CONFIG llvm-config-3.7)
find_program(LLVM3_8_CONFIG llvm-config-3.8)
if (LLVM3_7_CONFIG)
message(STATUS "Using llvm-3.7-dev package from Ubuntu. If does not work, build LLVM and set -DLLVM_DIR=llvm-build/share/llvm/cmake")
set(LLVM_CONFIG_EXEC llvm-config-3.7)
set(LLVM_LIB_DIR /usr/lib/llvm-3.7/lib)
elseif(LLVM3_8_CONFIG)
message(STATUS "Using llvm-3.8-dev package from Ubuntu. If does not work, build LLVM and set -DLLVM_DIR=llvm-build/share/llvm/cmake")
set(LLVM_CONFIG_EXEC llvm-config-3.8)
set(LLVM_LIB_DIR /usr/lib/llvm-3.8/lib)
else()
message(FATAL_ERROR "No LLVM package found!")
endif()
execute_process(COMMAND ${LLVM_CONFIG_EXEC} --includedir OUTPUT_VARIABLE LLVM_INCLUDE_DIRS OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "LLVM include dirs: ${LLVM_INCLUDE_DIRS}")
set(LLVM_LIBS "-lLLVMipo -lLLVMVectorize -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMX86Desc -lLLVMX86Info -lLLVMMCDisassembler -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMCodeGen -lLLVMScalarOpts -lLLVMProfileData -lLLVMInstCombine -lLLVMInstrumentation -lLLVMTransformUtils -lLLVMipa -lLLVMMCJIT -lLLVMExecutionEngine -lLLVMTarget -lLLVMAnalysis -lLLVMRuntimeDyld -lLLVMObject -lLLVMMCParser -lLLVMBitReader -lLLVMMC -lLLVMCore -lLLVMSupport -lz -lpthread -lffi -ltinfo -ldl -lm")
set(LLVM_DEFINITIONS "-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS")
link_directories(/usr/lib/llvm-3.7/lib)
link_directories(${LLVM_LIB_DIR})
else()
find_package(LLVM REQUIRED CONFIG)
if (${LLVM_VERSION} VERSION_LESS 3.7)

2
libethash-cl/CMakeLists.txt

@ -24,7 +24,7 @@ include_directories(${Boost_INCLUDE_DIRS})
include_directories(..)
add_library(${EXECUTABLE} ${SRC_LIST} ${HEADERS})
target_include_directories(${EXECUTABLE} PUBLIC ${OpenCL_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE} ${OpenCL_LIBRARIES} ethash ${Boost_RANDOM_LIBRARIES} ${Boost_SYSTEM_LIBRARIES})
target_link_libraries(${EXECUTABLE} ${OpenCL_LIBRARIES} ethash)
install( TARGETS ${EXECUTABLE} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib )
install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} )

24
libethash-cl/ethash_cl_miner.cpp

@ -31,8 +31,9 @@
#include <queue>
#include <vector>
#include <random>
#include <boost/random/random_device.hpp>
#include <boost/random/uniform_int_distribution.hpp>
#include <random>
#include <atomic>
#include <sstream>
#include <libethash/util.h>
#include <libethash/ethash.h>
#include <libethash/internal.h>
@ -57,7 +58,22 @@ unsigned const ethash_cl_miner::c_defaultGlobalWorkSizeMultiplier = 4096; // * C
unsigned const ethash_cl_miner::c_defaultMSPerBatch = 0;
// TODO: If at any point we can use libdevcore in here then we should switch to using a LogChannel
#if defined(_WIN32)
extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char* lpOutputString);
static std::atomic_flag s_logSpin = ATOMIC_FLAG_INIT;
#define ETHCL_LOG(_contents) \
do \
{ \
std::stringstream ss; \
ss << _contents; \
while (s_logSpin.test_and_set(std::memory_order_acquire)) {} \
OutputDebugStringA(ss.str().c_str()); \
cerr << ss.str() << endl << flush; \
s_logSpin.clear(std::memory_order_release); \
} while (false)
#else
#define ETHCL_LOG(_contents) cout << "[OPENCL]:" << _contents << endl
#endif
// Types of OpenCL devices we are interested in
#define ETHCL_QUERIED_DEVICE_TYPES (CL_DEVICE_TYPE_GPU | CL_DEVICE_TYPE_ACCELERATOR)
@ -472,8 +488,8 @@ void ethash_cl_miner::search(uint8_t const* header, uint64_t target, search_hook
m_searchKernel.setArg(argPos + 2, ~0u);
unsigned buf = 0;
boost::random_device engine;
uint64_t start_nonce = boost::random::uniform_int_distribution<uint64_t>()(engine);
random_device engine;
uint64_t start_nonce = uniform_int_distribution<uint64_t>()(engine);
for (;; start_nonce += m_globalWorkSize)
{
auto t = chrono::high_resolution_clock::now();

1
libethcore/BlockInfo.h

@ -41,6 +41,7 @@ enum IncludeProof
enum Strictness
{
CheckEverything,
JustSeal,
QuickNonce,
IgnoreSeal,
CheckNothing

12
libethcore/Common.h

@ -127,15 +127,17 @@ struct ImportRequirements
enum
{
ValidSeal = 1, ///< Validate seal
DontHave = 2, ///< Avoid old blocks
UncleBasic = 4, ///< Check the basic structure of the uncles.
TransactionBasic = 8, ///< Check the basic structure of the transactions.
UncleSeals = 16, ///< Check the basic structure of the uncles.
TransactionSignatures = 32, ///< Check the basic structure of the transactions.
Parent = 64, ///< Check parent block header
CheckUncles = UncleBasic | UncleSeals, ///< Check uncle seals
CheckTransactions = TransactionBasic | TransactionSignatures, ///< Check transaction signatures
Everything = ValidSeal | DontHave | CheckUncles | CheckTransactions | Parent,
Parent = 64, ///< Check parent block header.
UncleParent = 128, ///< Check uncle parent block header.
CheckUncles = UncleBasic | UncleSeals, ///< Check uncle seals.
CheckTransactions = TransactionBasic | TransactionSignatures, ///< Check transaction signatures.
OutOfOrderChecks = ValidSeal | CheckUncles | CheckTransactions, ///< Do all checks that can be done independently of prior blocks having been imported.
InOrderChecks = Parent | UncleParent, ///< Do all checks that cannot be done independently of prior blocks having been imported.
Everything = ValidSeal | CheckUncles | CheckTransactions | Parent | UncleParent,
None = 0
};
};

1
libethcore/Exceptions.h

@ -70,6 +70,7 @@ DEV_SIMPLE_EXCEPTION(InvalidNonce);
DEV_SIMPLE_EXCEPTION(InvalidBlockHeaderItemCount);
DEV_SIMPLE_EXCEPTION(InvalidBlockNonce);
DEV_SIMPLE_EXCEPTION(InvalidParentHash);
DEV_SIMPLE_EXCEPTION(InvalidUncleParentHash);
DEV_SIMPLE_EXCEPTION(InvalidNumber);
DEV_SIMPLE_EXCEPTION(BlockNotFound);

19
libethereum/BlockChain.cpp

@ -427,11 +427,11 @@ tuple<ImportRoute, bool, unsigned> BlockChain::sync(BlockQueue& _bq, OverlayDB c
return make_tuple(ImportRoute{dead, fresh, goodTransactions}, _bq.doneDrain(badBlocks), count);
}
pair<ImportResult, ImportRoute> BlockChain::attemptImport(bytes const& _block, OverlayDB const& _stateDB, ImportRequirements::value _ir) noexcept
pair<ImportResult, ImportRoute> BlockChain::attemptImport(bytes const& _block, OverlayDB const& _stateDB, bool _mustBeNew) noexcept
{
try
{
return make_pair(ImportResult::Success, import(verifyBlock(&_block, m_onBad, _ir), _stateDB, _ir | ImportRequirements::TransactionBasic));
return make_pair(ImportResult::Success, import(verifyBlock(&_block, m_onBad, ImportRequirements::OutOfOrderChecks), _stateDB, _mustBeNew));
}
catch (UnknownParent&)
{
@ -453,7 +453,7 @@ pair<ImportResult, ImportRoute> BlockChain::attemptImport(bytes const& _block, O
}
}
ImportRoute BlockChain::import(bytes const& _block, OverlayDB const& _db, ImportRequirements::value _ir)
ImportRoute BlockChain::import(bytes const& _block, OverlayDB const& _db, bool _mustBeNew)
{
// VERIFY: populates from the block and checks the block is internally coherent.
VerifiedBlockRef block;
@ -462,7 +462,7 @@ ImportRoute BlockChain::import(bytes const& _block, OverlayDB const& _db, Import
try
#endif
{
block = verifyBlock(&_block, m_onBad, _ir | ImportRequirements::TransactionBasic);
block = verifyBlock(&_block, m_onBad, ImportRequirements::OutOfOrderChecks);
}
#if ETH_CATCH
catch (Exception& ex)
@ -474,10 +474,10 @@ ImportRoute BlockChain::import(bytes const& _block, OverlayDB const& _db, Import
}
#endif
return import(block, _db, _ir);
return import(block, _db, _mustBeNew);
}
ImportRoute BlockChain::import(VerifiedBlockRef const& _block, OverlayDB const& _db, ImportRequirements::value _ir)
ImportRoute BlockChain::import(VerifiedBlockRef const& _block, OverlayDB const& _db, bool _mustBeNew)
{
//@tidy This is a behemoth of a method - could do to be split into a few smaller ones.
@ -492,7 +492,7 @@ ImportRoute BlockChain::import(VerifiedBlockRef const& _block, OverlayDB const&
#endif
// Check block doesn't already exist first!
if (isKnown(_block.info.hash()) && (_ir & ImportRequirements::DontHave))
if (isKnown(_block.info.hash()) && _mustBeNew)
{
clog(BlockChainNote) << _block.info.hash() << ": Not new.";
BOOST_THROW_EXCEPTION(AlreadyHaveBlock());
@ -528,6 +528,9 @@ ImportRoute BlockChain::import(VerifiedBlockRef const& _block, OverlayDB const&
BOOST_THROW_EXCEPTION(FutureTime());
}
// Verify parent-critical parts
verifyBlock(_block.block, m_onBad, ImportRequirements::InOrderChecks);
clog(BlockChainChat) << "Attempting import of " << _block.info.hash() << "...";
#if ETH_TIMED_IMPORTS
@ -758,7 +761,7 @@ ImportRoute BlockChain::import(VerifiedBlockRef const& _block, OverlayDB const&
try
{
State canary(_db, BaseState::Empty);
canary.populateFromChain(*this, _block.info.hash(), ImportRequirements::DontHave);
canary.populateFromChain(*this, _block.info.hash());
}
catch (...)
{

37
libethereum/BlockChain.h

@ -122,12 +122,12 @@ public:
/// Attempt to import the given block directly into the CanonBlockChain and sync with the state DB.
/// @returns the block hashes of any blocks that came into/went out of the canonical block chain.
std::pair<ImportResult, ImportRoute> attemptImport(bytes const& _block, OverlayDB const& _stateDB, ImportRequirements::value _ir = ImportRequirements::Everything) noexcept;
std::pair<ImportResult, ImportRoute> attemptImport(bytes const& _block, OverlayDB const& _stateDB, bool _mutBeNew = true) noexcept;
/// Import block into disk-backed DB
/// @returns the block hashes of any blocks that came into/went out of the canonical block chain.
ImportRoute import(bytes const& _block, OverlayDB const& _stateDB, ImportRequirements::value _ir = ImportRequirements::Everything);
ImportRoute import(VerifiedBlockRef const& _block, OverlayDB const& _db, ImportRequirements::value _ir = ImportRequirements::Everything);
ImportRoute import(bytes const& _block, OverlayDB const& _stateDB, bool _mustBeNew = true);
ImportRoute import(VerifiedBlockRef const& _block, OverlayDB const& _db, bool _mustBeNew = true);
/// Returns true if the given block is known (though not necessarily a part of the canon chain).
bool isKnown(h256 const& _hash) const;
@ -289,7 +289,7 @@ public:
State genesisState(OverlayDB const& _db);
/// Verify block and prepare it for enactment
virtual VerifiedBlockRef verifyBlock(bytesConstRef _block, std::function<void(Exception&)> const& _onBad, ImportRequirements::value _ir) const = 0;
virtual VerifiedBlockRef verifyBlock(bytesConstRef _block, std::function<void(Exception&)> const& _onBad, ImportRequirements::value _ir = ImportRequirements::OutOfOrderChecks) const = 0;
protected:
static h256 chunkId(unsigned _level, unsigned _index) { return h256(_index * 0xff + _level); }
@ -410,7 +410,7 @@ public:
typename Sealer::BlockHeader header(h256 const& _hash) const { return typename Sealer::BlockHeader(headerData(_hash), IgnoreSeal, _hash, HeaderData); }
typename Sealer::BlockHeader header() const { return header(currentHash()); }
virtual VerifiedBlockRef verifyBlock(bytesConstRef _block, std::function<void(Exception&)> const& _onBad, ImportRequirements::value _ir) const override
virtual VerifiedBlockRef verifyBlock(bytesConstRef _block, std::function<void(Exception&)> const& _onBad, ImportRequirements::value _ir = ImportRequirements::OutOfOrderChecks) const override
{
VerifiedBlockRef res;
BlockHeader h;
@ -418,11 +418,11 @@ public:
{
h = BlockHeader(_block, (_ir & ImportRequirements::ValidSeal) ? Strictness::CheckEverything : Strictness::QuickNonce);
h.verifyInternals(_block);
if ((_ir & ImportRequirements::Parent) != 0)
if (!!(_ir & ImportRequirements::Parent))
{
bytes parentHeader(headerData(h.parentHash()));
if (parentHeader.empty())
BOOST_THROW_EXCEPTION(InvalidParentHash());
BOOST_THROW_EXCEPTION(InvalidParentHash() << errinfo_required_h256(h.parentHash()) << errinfo_currentNumber(h.number()));
h.verifyParent(typename Sealer::BlockHeader(parentHeader, IgnoreSeal, h.parentHash(), HeaderData));
}
res.info = static_cast<BlockInfo&>(h);
@ -443,17 +443,20 @@ public:
RLP r(_block);
unsigned i = 0;
if (_ir && ImportRequirements::UncleBasic)
if (_ir && (ImportRequirements::UncleBasic | ImportRequirements::UncleParent | ImportRequirements::UncleSeals))
for (auto const& uncle: r[2])
{
BlockHeader h;
BlockHeader uh;
try
{
h.populateFromHeader(RLP(uncle.data()), (_ir & ImportRequirements::UncleSeals) ? Strictness::CheckEverything : Strictness::IgnoreSeal);
bytes parentHeader(headerData(h.parentHash()));
if (parentHeader.empty())
BOOST_THROW_EXCEPTION(InvalidParentHash());
h.verifyParent(typename Sealer::BlockHeader(parentHeader, IgnoreSeal, h.parentHash(), HeaderData));
uh.populateFromHeader(RLP(uncle.data()), (_ir & ImportRequirements::UncleSeals) ? Strictness::CheckEverything : Strictness::IgnoreSeal);
if (!!(_ir & ImportRequirements::UncleParent))
{
bytes parentHeader(headerData(uh.parentHash()));
if (parentHeader.empty())
BOOST_THROW_EXCEPTION(InvalidUncleParentHash() << errinfo_required_h256(uh.parentHash()) << errinfo_currentNumber(h.number()) << errinfo_uncleNumber(uh.number()));
uh.verifyParent(typename Sealer::BlockHeader(parentHeader, IgnoreSeal, uh.parentHash(), HeaderData));
}
}
catch (Exception& ex)
{
@ -463,8 +466,8 @@ public:
ex << errinfo_block(_block.toBytes());
// only populate extraData if we actually managed to extract it. otherwise,
// we might be clobbering the existing one.
if (!h.extraData().empty())
ex << errinfo_extraData(h.extraData());
if (!uh.extraData().empty())
ex << errinfo_extraData(uh.extraData());
if (_onBad)
_onBad(ex);
throw;
@ -472,7 +475,7 @@ public:
++i;
}
i = 0;
if (_ir && ImportRequirements::TransactionBasic)
if (_ir && (ImportRequirements::TransactionBasic | ImportRequirements::TransactionSignatures))
for (RLP const& tr: r[1])
{
bytesConstRef d = tr.data();

2
libethereum/BlockQueue.cpp

@ -111,7 +111,7 @@ void BlockQueue::verifierBody()
swap(work.block, res.blockData);
try
{
res.verified = m_bc->verifyBlock(&res.blockData, m_onBad, ImportRequirements::Everything & ~ImportRequirements::Parent);
res.verified = m_bc->verifyBlock(&res.blockData, m_onBad, ImportRequirements::OutOfOrderChecks);
}
catch (...)
{

2
libethereum/CanonBlockChain.cpp

@ -111,7 +111,7 @@ unordered_map<Address, Account> CanonBlockChain<Ethash>::createGenesisState()
if (s_ret.empty())
{
js::mValue val;
json_spirit::read_string(s_genesisStateJSON.empty() ? c_genesisInfo : s_genesisStateJSON, val);
js::read_string(s_genesisStateJSON.empty() ? c_genesisInfo : s_genesisStateJSON, val);
for (auto account: val.get_obj()["alloc"].get_obj())
{
u256 balance;

10
test/libethereum/blockchain.cpp

@ -838,11 +838,11 @@ BOOST_AUTO_TEST_CASE(bcGasPricerTest)
dev::test::executeTests("bcGasPricerTest", "/BlockchainTests",dev::test::getFolder(__FILE__) + "/BlockchainTestsFiller", dev::test::doBlockchainTests);
}
BOOST_AUTO_TEST_CASE(bcBruncleTest)
{
if (c_network != Network::Frontier)
dev::test::executeTests("bcBruncleTest", "/BlockchainTests",dev::test::getFolder(__FILE__) + "/BlockchainTestsFiller", dev::test::doBlockchainTests);
}
//BOOST_AUTO_TEST_CASE(bcBruncleTest)
//{
// if (c_network != Network::Frontier)
// dev::test::executeTests("bcBruncleTest", "/BlockchainTests",dev::test::getFolder(__FILE__) + "/BlockchainTestsFiller", dev::test::doBlockchainTests);
//}
BOOST_AUTO_TEST_CASE(bcBlockGasLimitTest)
{

Loading…
Cancel
Save