From fc14f46a63df93301aa76825a34ee72010c7860c Mon Sep 17 00:00:00 2001 From: subtly Date: Thu, 16 Oct 2014 15:10:54 +0200 Subject: [PATCH 1/7] add headers to cmake --- alethzero/CMakeLists.txt | 5 +++-- eth/CMakeLists.txt | 3 ++- libdevcore/CMakeLists.txt | 7 +++---- libdevcrypto/CMakeLists.txt | 8 +++----- libethcore/CMakeLists.txt | 8 +++----- libethereum/CMakeLists.txt | 8 +++----- libevm/CMakeLists.txt | 8 +++----- libevmface/CMakeLists.txt | 8 +++----- liblll/CMakeLists.txt | 8 +++----- libp2p/CMakeLists.txt | 8 +++----- libqethereum/CMakeLists.txt | 5 +++-- libserpent/CMakeLists.txt | 8 +++----- libwebthree/CMakeLists.txt | 8 +++----- libwhisper/CMakeLists.txt | 8 +++----- test/CMakeLists.txt | 3 ++- third/CMakeLists.txt | 5 +++-- 16 files changed, 46 insertions(+), 62 deletions(-) diff --git a/alethzero/CMakeLists.txt b/alethzero/CMakeLists.txt index c5d1aa0be..4ad06f7a6 100644 --- a/alethzero/CMakeLists.txt +++ b/alethzero/CMakeLists.txt @@ -25,6 +25,7 @@ find_package(Qt5WebKitWidgets REQUIRED) qt5_wrap_ui(ui_Main.h Main.ui) # Set name of binary and add_executable() +file(GLOB HEADERS "*.h") if (APPLE) set(EXECUTEABLE AlethZero) set(BIN_INSTALL_DIR ".") @@ -41,14 +42,14 @@ if (APPLE) set(MACOSX_BUNDLE_ICON_FILE alethzero) include(BundleUtilities) - add_executable(${EXECUTEABLE} MACOSX_BUNDLE alethzero.icns Main.ui ${SRC_LIST}) + add_executable(${EXECUTEABLE} MACOSX_BUNDLE alethzero.icns Main.ui ${SRC_LIST} ${HEADERS}) set_target_properties(${EXECUTEABLE} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/EthereumMacOSXBundleInfo.plist.in") SET_SOURCE_FILES_PROPERTIES(${EXECUTEABLE} PROPERTIES MACOSX_PACKAGE_LOCATION MacOS) SET_SOURCE_FILES_PROPERTIES(${MACOSX_BUNDLE_ICON_FILE}.icns PROPERTIES MACOSX_PACKAGE_LOCATION "Resources") else () set(EXECUTEABLE alethzero) - add_executable(${EXECUTEABLE} Main.ui ${SRC_LIST}) + add_executable(${EXECUTEABLE} Main.ui ${SRC_LIST} ${HEADERS}) endif () qt5_use_modules(${EXECUTEABLE} Core)# Gui Widgets Network WebKit WebKitWidgets) diff --git a/eth/CMakeLists.txt b/eth/CMakeLists.txt index eee1d258b..087c5314a 100644 --- a/eth/CMakeLists.txt +++ b/eth/CMakeLists.txt @@ -8,7 +8,8 @@ link_directories(../libwebthree) set(EXECUTABLE eth) -add_executable(${EXECUTABLE} ${SRC_LIST}) +file(GLOB HEADERS "*.h") +add_executable(${EXECUTABLE} ${SRC_LIST} ${HEADERS}) target_link_libraries(${EXECUTABLE} webthree) target_link_libraries(${EXECUTABLE} secp256k1) diff --git a/libdevcore/CMakeLists.txt b/libdevcore/CMakeLists.txt index 3f3ecb619..81e210cad 100644 --- a/libdevcore/CMakeLists.txt +++ b/libdevcore/CMakeLists.txt @@ -10,13 +10,12 @@ aux_source_directory(. SRC_LIST) set(EXECUTABLE devcore) -# set(CMAKE_INSTALL_PREFIX ../lib) +file(GLOB HEADERS "*.h") if(ETH_STATIC) - add_library(${EXECUTABLE} STATIC ${SRC_LIST}) + add_library(${EXECUTABLE} STATIC ${SRC_LIST} ${HEADERS}) else() - add_library(${EXECUTABLE} SHARED ${SRC_LIST}) + add_library(${EXECUTABLE} SHARED ${SRC_LIST} ${HEADERS}) endif() -file(GLOB HEADERS "*.h") include_directories(..) diff --git a/libdevcrypto/CMakeLists.txt b/libdevcrypto/CMakeLists.txt index e7f112f95..cee7d130d 100644 --- a/libdevcrypto/CMakeLists.txt +++ b/libdevcrypto/CMakeLists.txt @@ -4,15 +4,13 @@ aux_source_directory(. SRC_LIST) set(EXECUTABLE devcrypto) -# set(CMAKE_INSTALL_PREFIX ../lib) +file(GLOB HEADERS "*.h") if(ETH_STATIC) - add_library(${EXECUTABLE} STATIC ${SRC_LIST}) + add_library(${EXECUTABLE} STATIC ${SRC_LIST} ${HEADERS}) else() - add_library(${EXECUTABLE} SHARED ${SRC_LIST}) + add_library(${EXECUTABLE} SHARED ${SRC_LIST} ${HEADERS}) endif() -file(GLOB HEADERS "*.h") - include_directories(..) target_link_libraries(${EXECUTABLE} devcore) diff --git a/libethcore/CMakeLists.txt b/libethcore/CMakeLists.txt index 6aba644f1..f5cf00b57 100644 --- a/libethcore/CMakeLists.txt +++ b/libethcore/CMakeLists.txt @@ -4,15 +4,13 @@ aux_source_directory(. SRC_LIST) set(EXECUTABLE ethcore) -# set(CMAKE_INSTALL_PREFIX ../lib) +file(GLOB HEADERS "*.h") if(ETH_STATIC) - add_library(${EXECUTABLE} STATIC ${SRC_LIST}) + add_library(${EXECUTABLE} STATIC ${SRC_LIST} ${HEADERS}) else() - add_library(${EXECUTABLE} SHARED ${SRC_LIST}) + add_library(${EXECUTABLE} SHARED ${SRC_LIST} ${HEADERS}) endif() -file(GLOB HEADERS "*.h") - include_directories(..) target_link_libraries(${EXECUTABLE} devcrypto) diff --git a/libethereum/CMakeLists.txt b/libethereum/CMakeLists.txt index 128dd5999..cb2049886 100644 --- a/libethereum/CMakeLists.txt +++ b/libethereum/CMakeLists.txt @@ -6,15 +6,13 @@ aux_source_directory(. SRC_LIST) set(EXECUTABLE ethereum) -# set(CMAKE_INSTALL_PREFIX ../lib) +file(GLOB HEADERS "*.h") if(ETH_STATIC) - add_library(${EXECUTABLE} STATIC ${SRC_LIST}) + add_library(${EXECUTABLE} STATIC ${SRC_LIST} ${HEADERS}) else() - add_library(${EXECUTABLE} SHARED ${SRC_LIST}) + add_library(${EXECUTABLE} SHARED ${SRC_LIST} ${HEADERS}) endif() -file(GLOB HEADERS "*.h") - include_directories(..) target_link_libraries(${EXECUTABLE} evm) diff --git a/libevm/CMakeLists.txt b/libevm/CMakeLists.txt index f19119f83..0c31a9fc3 100644 --- a/libevm/CMakeLists.txt +++ b/libevm/CMakeLists.txt @@ -6,15 +6,13 @@ aux_source_directory(. SRC_LIST) set(EXECUTABLE evm) -# set(CMAKE_INSTALL_PREFIX ../lib) +file(GLOB HEADERS "*.h") if(ETH_STATIC) - add_library(${EXECUTABLE} STATIC ${SRC_LIST}) + add_library(${EXECUTABLE} STATIC ${SRC_LIST} ${HEADERS}) else() - add_library(${EXECUTABLE} SHARED ${SRC_LIST}) + add_library(${EXECUTABLE} SHARED ${SRC_LIST} ${HEADERS}) endif() -file(GLOB HEADERS "*.h") - include_directories(..) target_link_libraries(${EXECUTABLE} ethcore) diff --git a/libevmface/CMakeLists.txt b/libevmface/CMakeLists.txt index 212ce825d..874b9e397 100644 --- a/libevmface/CMakeLists.txt +++ b/libevmface/CMakeLists.txt @@ -6,15 +6,13 @@ aux_source_directory(. SRC_LIST) set(EXECUTABLE evmface) -# set(CMAKE_INSTALL_PREFIX ../lib) +file(GLOB HEADERS "*.h") if(ETH_STATIC) - add_library(${EXECUTABLE} STATIC ${SRC_LIST}) + add_library(${EXECUTABLE} STATIC ${SRC_LIST} ${HEADERS}) else() - add_library(${EXECUTABLE} SHARED ${SRC_LIST}) + add_library(${EXECUTABLE} SHARED ${SRC_LIST} ${HEADERS}) endif() -file(GLOB HEADERS "*.h") - include_directories(..) target_link_libraries(${EXECUTABLE} devcore) diff --git a/liblll/CMakeLists.txt b/liblll/CMakeLists.txt index 7746613ec..cb50cc36e 100644 --- a/liblll/CMakeLists.txt +++ b/liblll/CMakeLists.txt @@ -6,15 +6,13 @@ aux_source_directory(. SRC_LIST) set(EXECUTABLE lll) -# set(CMAKE_INSTALL_PREFIX ../lib) +file(GLOB HEADERS "*.h") if(ETH_STATIC) - add_library(${EXECUTABLE} STATIC ${SRC_LIST}) + add_library(${EXECUTABLE} STATIC ${SRC_LIST} ${HEADERS}) else() - add_library(${EXECUTABLE} SHARED ${SRC_LIST}) + add_library(${EXECUTABLE} SHARED ${SRC_LIST} ${HEADERS}) endif() -file(GLOB HEADERS "*.h") - include_directories(..) target_link_libraries(${EXECUTABLE} evmface) diff --git a/libp2p/CMakeLists.txt b/libp2p/CMakeLists.txt index c3cdc70b9..9e20fd99f 100644 --- a/libp2p/CMakeLists.txt +++ b/libp2p/CMakeLists.txt @@ -6,15 +6,13 @@ aux_source_directory(. SRC_LIST) set(EXECUTABLE p2p) -# set(CMAKE_INSTALL_PREFIX ../lib) +file(GLOB HEADERS "*.h") if(ETH_STATIC) - add_library(${EXECUTABLE} STATIC ${SRC_LIST}) + add_library(${EXECUTABLE} STATIC ${SRC_LIST} ${HEADERS}) else() - add_library(${EXECUTABLE} SHARED ${SRC_LIST}) + add_library(${EXECUTABLE} SHARED ${SRC_LIST} ${HEADERS}) endif() -file(GLOB HEADERS "*.h") - include_directories(..) target_link_libraries(${EXECUTABLE} devcrypto) diff --git a/libqethereum/CMakeLists.txt b/libqethereum/CMakeLists.txt index 68ee1bb9d..4fb7d1a21 100644 --- a/libqethereum/CMakeLists.txt +++ b/libqethereum/CMakeLists.txt @@ -51,10 +51,11 @@ if (APPLE) include(BundleUtilities) endif () +file(GLOB HEADERS "*.h") if(ETH_STATIC) - add_library(${EXECUTABLE} STATIC ${RESOURCE_ADDED} ${SRC_LIST}) + add_library(${EXECUTABLE} STATIC ${RESOURCE_ADDED} ${SRC_LIST} ${HEADERS}) else() - add_library(${EXECUTABLE} SHARED ${RESOURCE_ADDED} ${SRC_LIST}) + add_library(${EXECUTABLE} SHARED ${RESOURCE_ADDED} ${SRC_LIST} ${HEADERS}) endif() include_directories(/) diff --git a/libserpent/CMakeLists.txt b/libserpent/CMakeLists.txt index 0d66393b2..0090b5dc3 100644 --- a/libserpent/CMakeLists.txt +++ b/libserpent/CMakeLists.txt @@ -6,15 +6,13 @@ aux_source_directory(. SRC_LIST) set(EXECUTABLE serpent) -# set(CMAKE_INSTALL_PREFIX ../lib) +file(GLOB HEADERS "*.h") if(ETH_STATIC) - add_library(${EXECUTABLE} STATIC ${SRC_LIST}) + add_library(${EXECUTABLE} STATIC ${SRC_LIST} ${HEADERS}) else() - add_library(${EXECUTABLE} SHARED ${SRC_LIST}) + add_library(${EXECUTABLE} SHARED ${SRC_LIST} ${HEADERS}) endif() -file(GLOB HEADERS "*.h") - include_directories(..) target_link_libraries(${EXECUTABLE} lll) diff --git a/libwebthree/CMakeLists.txt b/libwebthree/CMakeLists.txt index d3332d8b0..cc1b290f5 100644 --- a/libwebthree/CMakeLists.txt +++ b/libwebthree/CMakeLists.txt @@ -6,15 +6,13 @@ aux_source_directory(. SRC_LIST) set(EXECUTABLE webthree) -# set(CMAKE_INSTALL_PREFIX ../lib) +file(GLOB HEADERS "*.h") if(ETH_STATIC) - add_library(${EXECUTABLE} STATIC ${SRC_LIST}) + add_library(${EXECUTABLE} STATIC ${SRC_LIST} ${HEADERS}) else() - add_library(${EXECUTABLE} SHARED ${SRC_LIST}) + add_library(${EXECUTABLE} SHARED ${SRC_LIST} ${HEADERS}) endif() -file(GLOB HEADERS "*.h") - include_directories(..) target_link_libraries(${EXECUTABLE} ethereum) diff --git a/libwhisper/CMakeLists.txt b/libwhisper/CMakeLists.txt index 49857d16a..364d9759a 100644 --- a/libwhisper/CMakeLists.txt +++ b/libwhisper/CMakeLists.txt @@ -6,15 +6,13 @@ aux_source_directory(. SRC_LIST) set(EXECUTABLE whisper) -# set(CMAKE_INSTALL_PREFIX ../lib) +file(GLOB HEADERS "*.h") if(ETH_STATIC) - add_library(${EXECUTABLE} STATIC ${SRC_LIST}) + add_library(${EXECUTABLE} STATIC ${SRC_LIST} ${HEADERS}) else() - add_library(${EXECUTABLE} SHARED ${SRC_LIST}) + add_library(${EXECUTABLE} SHARED ${SRC_LIST} ${HEADERS}) endif() -file(GLOB HEADERS "*.h") - include_directories(..) target_link_libraries(${EXECUTABLE} ethcore) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6936addb3..2e5366079 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -6,7 +6,8 @@ include_directories(..) link_directories(../libethcore) link_directories(../libethereum) -add_executable(testeth ${SRC_LIST}) +file(GLOB HEADERS "*.h") +add_executable(testeth ${SRC_LIST} ${HEADERS}) target_link_libraries(testeth ethereum) target_link_libraries(testeth ethcore) diff --git a/third/CMakeLists.txt b/third/CMakeLists.txt index 77b2bb496..9221ad045 100644 --- a/third/CMakeLists.txt +++ b/third/CMakeLists.txt @@ -25,6 +25,7 @@ find_package(Qt5WebKitWidgets REQUIRED) qt5_wrap_ui(ui_Main.h Main.ui) # Set name of binary and add_executable() +file(GLOB HEADERS "*.h") if (APPLE) set(EXECUTEABLE Third) set(BIN_INSTALL_DIR ".") @@ -41,14 +42,14 @@ if (APPLE) set(MACOSX_BUNDLE_ICON_FILE third) include(BundleUtilities) - add_executable(${EXECUTEABLE} MACOSX_BUNDLE third.icns Main.ui ${SRC_LIST}) + add_executable(${EXECUTEABLE} MACOSX_BUNDLE third.icns Main.ui ${SRC_LIST} ${HEADERS}) set_target_properties(${EXECUTEABLE} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/EthereumMacOSXBundleInfo.plist.in") SET_SOURCE_FILES_PROPERTIES(${EXECUTEABLE} PROPERTIES MACOSX_PACKAGE_LOCATION MacOS) SET_SOURCE_FILES_PROPERTIES(${MACOSX_BUNDLE_ICON_FILE}.icns PROPERTIES MACOSX_PACKAGE_LOCATION "Resources") else () set(EXECUTEABLE third) - add_executable(${EXECUTEABLE} Main.ui ${SRC_LIST}) + add_executable(${EXECUTEABLE} Main.ui ${SRC_LIST} ${HEADERS}) endif () qt5_use_modules(${EXECUTEABLE} Core)# Gui Widgets Network WebKit WebKitWidgets) From 1d6255d96da5d5afb4920ffbe3dd97433e9d6f38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 16 Oct 2014 18:19:58 +0200 Subject: [PATCH 2/7] test/rlp bugfix: expectedText can be empty --- test/rlp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/rlp.cpp b/test/rlp.cpp index 95d40ada7..69360ad66 100644 --- a/test/rlp.cpp +++ b/test/rlp.cpp @@ -79,7 +79,7 @@ namespace dev if ( v.type() == js::str_type ) { const std::string& expectedText = v.get_str(); - if ( expectedText.front() == '#' ) + if ( !expectedText.empty() && expectedText.front() == '#' ) { // Deal with bigint instead of a raw string std::string bigIntStr = expectedText.substr(1,expectedText.length()-1); From efaa2977595f49d1928f048194c23457902cd21d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 16 Oct 2014 18:20:49 +0200 Subject: [PATCH 3/7] Prepare VM test engine for running JIT-ed tests --- test/vm.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/vm.cpp b/test/vm.cpp index cc87866df..d77906731 100644 --- a/test/vm.cpp +++ b/test/vm.cpp @@ -493,7 +493,6 @@ void doTests(json_spirit::mValue& v, bool _fillin) BOOST_REQUIRE(o.count("pre") > 0); BOOST_REQUIRE(o.count("exec") > 0); - VM vm; dev::test::FakeExtVM fev; fev.importEnv(o["env"].get_obj()); fev.importState(o["pre"].get_obj()); @@ -508,11 +507,13 @@ void doTests(json_spirit::mValue& v, bool _fillin) fev.code = &fev.thisTxCode; } - vm.reset(fev.gas); bytes output; + u256 gas; try { - output = vm.go(fev).toBytes(); + VM vm(fev.gas); + output = vm.go(fev).toVector(); + gas = vm.gas(); // Get the remaining gas } catch (Exception const& _e) { @@ -549,7 +550,7 @@ void doTests(json_spirit::mValue& v, bool _fillin) o["post"] = mValue(fev.exportState()); o["callcreates"] = fev.exportCallCreates(); o["out"] = "0x" + toHex(output); - fev.push(o, "gas", vm.gas()); + fev.push(o, "gas", gas); } else { @@ -573,7 +574,7 @@ void doTests(json_spirit::mValue& v, bool _fillin) else BOOST_CHECK(output == fromHex(o["out"].get_str())); - BOOST_CHECK(test.toInt(o["gas"]) == vm.gas()); + BOOST_CHECK(test.toInt(o["gas"]) == gas); BOOST_CHECK(test.addresses == fev.addresses); BOOST_CHECK(test.callcreates == fev.callcreates); } From c7634c27b07d91341d928a045e74dbd75250d466 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 16 Oct 2014 19:43:48 +0300 Subject: [PATCH 4/7] Correct namespace for a few things in devcrypto. Added lower_bound to TrieDB. Added nextActiveAddress to State. --- alethzero/MainWin.cpp | 2 +- eth/main.cpp | 2 +- exp/main.cpp | 15 +-- libdevcrypto/Common.cpp | 5 +- libdevcrypto/MemoryDB.cpp | 4 - libdevcrypto/MemoryDB.h | 3 - libdevcrypto/OverlayDB.cpp | 4 - libdevcrypto/OverlayDB.h | 3 - libdevcrypto/SHA3.cpp | 4 - libdevcrypto/SHA3.h | 3 - libdevcrypto/TrieCommon.cpp | 3 - libdevcrypto/TrieCommon.h | 22 ++++- libdevcrypto/TrieDB.cpp | 3 +- libdevcrypto/TrieDB.h | 168 +++++++++++++++++++++++++++++++--- libethcore/BlockInfo.cpp | 2 +- libethcore/CommonEth.cpp | 2 +- libethereum/BlockChain.h | 4 +- libethereum/CommonNet.h | 5 +- libethereum/MessageFilter.cpp | 2 +- libethereum/State.cpp | 15 ++- libethereum/State.h | 5 +- libethereum/Transaction.cpp | 2 +- libethereum/Transaction.h | 4 +- libqethereum/QEthereum.cpp | 8 +- libwhisper/Common.h | 2 + libwhisper/Interface.cpp | 13 +-- libwhisper/Interface.h | 19 +++- libwhisper/Message.h | 8 +- libwhisper/WhisperHost.h | 2 +- neth/main.cpp | 2 +- test/MemTrie.cpp | 4 +- test/crypto.cpp | 2 +- test/hexPrefix.cpp | 1 - test/trie.cpp | 46 +++++++++- 34 files changed, 297 insertions(+), 92 deletions(-) diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index 8d69727f8..762f2f681 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -1327,7 +1327,7 @@ void Main::on_contracts_currentItemChanged() s << "

Body Code

" << disassemble(ethereum()->codeAt(address)); ui->contractInfo->appendHtml(QString::fromStdString(s.str())); } - catch (dev::eth::InvalidTrie) + catch (dev::InvalidTrie) { ui->contractInfo->appendHtml("Corrupted trie."); } diff --git a/eth/main.cpp b/eth/main.cpp index b5e8eb736..caf5afa99 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -700,7 +700,7 @@ int main(int argc, char** argv) cnote << "Saved" << rechex << "to" << outFile; } - catch (dev::eth::InvalidTrie) + catch (dev::InvalidTrie) { cwarn << "Corrupted trie."; } diff --git a/exp/main.cpp b/exp/main.cpp index 59c622b6e..9ee26644c 100644 --- a/exp/main.cpp +++ b/exp/main.cpp @@ -29,12 +29,14 @@ #include #include #include +#include using namespace std; using namespace dev; using namespace dev::eth; using namespace dev::p2p; using namespace dev::shh; +#if 0 int main() { DownloadMan man; @@ -69,8 +71,8 @@ int main() cnote << i;*/ return 0; } +#endif -/* int main(int argc, char** argv) { g_logVerbosity = 20; @@ -102,15 +104,16 @@ int main(int argc, char** argv) ph.connect(remoteHost, remotePort); /// Only interested in the packet if the lowest bit is 1 - auto w = wh->installWatch(MessageFilter(std::vector >({{fromHex("0000000000000000000000000000000000000000000000000000000000000001"), fromHex("0000000000000000000000000000000000000000000000000000000000000001")}}))); - + auto w = wh->installWatch(MessageFilter(TopicMasks({{Topic("0000000000000000000000000000000000000000000000000000000000000001"), Topic("0000000000000000000000000000000000000000000000000000000000000001")}}))); for (int i = 0; ; ++i) { - wh->sendRaw(h256(u256(i * i)).asBytes(), h256(u256(i)).asBytes(), 1000); + wh->sendRaw(RLPStream().append(i * i).out(), Topic(u256(i)), 1000); for (auto i: wh->checkWatch(w)) - cnote << "New message:" << (u256)h256(wh->message(i).payload); + { + auto p = wh->message(i).payload; + cnote << "New message:" << RLP(p).toInt(); + } } return 0; } -*/ diff --git a/libdevcrypto/Common.cpp b/libdevcrypto/Common.cpp index 8863352a4..a9fff83c4 100644 --- a/libdevcrypto/Common.cpp +++ b/libdevcrypto/Common.cpp @@ -25,7 +25,6 @@ #include "SHA3.h" using namespace std; using namespace dev; -using namespace dev::eth; //#define ETH_ADDRESS_DEBUG 1 @@ -46,7 +45,7 @@ Address dev::toAddress(Secret _private) ok = secp256k1_ecdsa_pubkey_verify(pubkey, 65); if (!ok) return Address(); - auto ret = right160(dev::eth::sha3(bytesConstRef(&(pubkey[1]), 64))); + auto ret = right160(dev::sha3(bytesConstRef(&(pubkey[1]), 64))); #if ETH_ADDRESS_DEBUG cout << "---- ADDRESS -------------------------------" << endl; cout << "SEC: " << _private << endl; @@ -94,7 +93,7 @@ KeyPair::KeyPair(h256 _sec): m_secret = m_secret; memcpy(m_public.data(), &(pubkey[1]), 64); - m_address = right160(dev::eth::sha3(bytesConstRef(&(pubkey[1]), 64))); + m_address = right160(dev::sha3(bytesConstRef(&(pubkey[1]), 64))); #if ETH_ADDRESS_DEBUG cout << "---- ADDRESS -------------------------------" << endl; diff --git a/libdevcrypto/MemoryDB.cpp b/libdevcrypto/MemoryDB.cpp index 4480417fc..4fc4ed9ad 100644 --- a/libdevcrypto/MemoryDB.cpp +++ b/libdevcrypto/MemoryDB.cpp @@ -23,12 +23,9 @@ #include "MemoryDB.h" using namespace std; using namespace dev; -using namespace dev::eth; namespace dev { -namespace eth -{ std::map MemoryDB::get() const { @@ -116,4 +113,3 @@ set MemoryDB::keys() const } } -} diff --git a/libdevcrypto/MemoryDB.h b/libdevcrypto/MemoryDB.h index 446a947ec..4b8d3b3a2 100644 --- a/libdevcrypto/MemoryDB.h +++ b/libdevcrypto/MemoryDB.h @@ -29,8 +29,6 @@ namespace dev { -namespace eth -{ struct DBChannel: public LogChannel { static const char* name() { return "TDB"; } static const int verbosity = 18; }; @@ -85,4 +83,3 @@ inline std::ostream& operator<<(std::ostream& _out, MemoryDB const& _m) } } -} diff --git a/libdevcrypto/OverlayDB.cpp b/libdevcrypto/OverlayDB.cpp index 460609fb3..8ccae6606 100644 --- a/libdevcrypto/OverlayDB.cpp +++ b/libdevcrypto/OverlayDB.cpp @@ -23,12 +23,9 @@ #include "OverlayDB.h" using namespace std; using namespace dev; -using namespace dev::eth; namespace dev { -namespace eth -{ OverlayDB::~OverlayDB() { @@ -100,4 +97,3 @@ void OverlayDB::kill(h256 _h) } } -} diff --git a/libdevcrypto/OverlayDB.h b/libdevcrypto/OverlayDB.h index 9db4eaed6..777d1e7df 100644 --- a/libdevcrypto/OverlayDB.h +++ b/libdevcrypto/OverlayDB.h @@ -34,8 +34,6 @@ namespace ldb = leveldb; namespace dev { -namespace eth -{ class OverlayDB: public MemoryDB { @@ -63,4 +61,3 @@ private: }; } -} diff --git a/libdevcrypto/SHA3.cpp b/libdevcrypto/SHA3.cpp index 58d5329ef..d72f5bbd4 100644 --- a/libdevcrypto/SHA3.cpp +++ b/libdevcrypto/SHA3.cpp @@ -24,12 +24,9 @@ using namespace std; using namespace dev; -using namespace dev::eth; namespace dev { -namespace eth -{ h256 EmptySHA3 = sha3(bytesConstRef()); @@ -118,4 +115,3 @@ bytes aesDecrypt(bytesConstRef _ivCipher, std::string const& _password, unsigned } } -} diff --git a/libdevcrypto/SHA3.h b/libdevcrypto/SHA3.h index caadfeaf9..fc2cfcfc3 100644 --- a/libdevcrypto/SHA3.h +++ b/libdevcrypto/SHA3.h @@ -29,8 +29,6 @@ namespace dev { -namespace eth -{ // SHA-3 convenience routines. @@ -69,4 +67,3 @@ void sha256(bytesConstRef _input, bytesRef _output); void ripemd160(bytesConstRef _input, bytesRef _output); } -} diff --git a/libdevcrypto/TrieCommon.cpp b/libdevcrypto/TrieCommon.cpp index bad29059e..ff44906b1 100644 --- a/libdevcrypto/TrieCommon.cpp +++ b/libdevcrypto/TrieCommon.cpp @@ -23,8 +23,6 @@ namespace dev { -namespace eth -{ /* * Hex-prefix Notation. First nibble has flags: oddness = 2^0 & termination = 2^1 @@ -127,4 +125,3 @@ byte uniqueInUse(RLP const& _orig, byte except) } } -} diff --git a/libdevcrypto/TrieCommon.h b/libdevcrypto/TrieCommon.h index ecfb4de67..8d6be8ebd 100644 --- a/libdevcrypto/TrieCommon.h +++ b/libdevcrypto/TrieCommon.h @@ -26,8 +26,6 @@ namespace dev { -namespace eth -{ inline byte nibble(bytesConstRef _data, unsigned _i) { @@ -49,10 +47,29 @@ struct NibbleSlice NibbleSlice(bytesConstRef _d = bytesConstRef(), unsigned _o = 0): data(_d), offset(_o) {} byte operator[](unsigned _index) const { return nibble(data, offset + _index); } unsigned size() const { return data.size() * 2 - offset; } + bool empty() const { return !size(); } NibbleSlice mid(unsigned _index) const { return NibbleSlice(data, offset + _index); } + void clear() { data.reset(); offset = 0; } bool contains(NibbleSlice _k) const { return shared(_k) == _k.size(); } unsigned shared(NibbleSlice _k) const { return sharedNibbles(data, offset, offset + size(), _k.data, _k.offset, _k.offset + _k.size()); } + /** + * @brief Determine if we, a full key, are situated prior to a particular key-prefix. + * @param _k The prefix. + * @return true if we are strictly prior to the prefix. + */ + bool isEarlierThan(NibbleSlice _k) const + { + unsigned i; + for (i = 0; i < _k.size() && i < size(); ++i) + if (operator[](i) < _k[i]) // Byte is lower - we're earlier.. + return true; + else if (operator[](i) > _k[i]) // Byte is higher - we're not earlier. + return false; + if (i >= _k.size()) // Ran past the end of the prefix - we're == for the entire prefix - we're not earlier. + return false; + return true; // Ran out before the prefix had finished - we're earlier. + } bool operator==(NibbleSlice _k) const { return _k.size() == size() && shared(_k) == _k.size(); } bool operator!=(NibbleSlice _s) const { return !operator==(_s); } }; @@ -102,4 +119,3 @@ inline std::string hexPrefixEncode(NibbleSlice _s1, NibbleSlice _s2, bool _leaf) } } -} diff --git a/libdevcrypto/TrieDB.cpp b/libdevcrypto/TrieDB.cpp index 3c551d2b4..168b2fdf7 100644 --- a/libdevcrypto/TrieDB.cpp +++ b/libdevcrypto/TrieDB.cpp @@ -23,10 +23,9 @@ #include "TrieDB.h" using namespace std; using namespace dev; -using namespace dev::eth; #if !ETH_LANGUAGES -const h256 dev::eth::c_shaNull = sha3(rlp("")); +const h256 dev::c_shaNull = sha3(rlp("")); #endif diff --git a/libdevcrypto/TrieDB.h b/libdevcrypto/TrieDB.h index 3dd76899a..1fca92294 100644 --- a/libdevcrypto/TrieDB.h +++ b/libdevcrypto/TrieDB.h @@ -39,8 +39,6 @@ namespace ldb = leveldb; namespace dev { -namespace eth -{ struct TrieDBChannel: public LogChannel { static const char* name() { return "-T-"; } static const int verbosity = 17; }; #define tdebug clog(TrieDBChannel) @@ -171,6 +169,7 @@ public: iterator() {} iterator(GenericTrieDB const* _db); + iterator(GenericTrieDB const* _db, bytesConstRef _key); iterator& operator++() { next(); return *this; } @@ -184,13 +183,17 @@ public: private: void next(); + void next(NibbleSlice _key); struct Node { std::string rlp; std::string key; // as hexPrefixEncoding. - byte child; // 255 -> entering + byte child; // 255 -> entering, 16 -> actually at the node, 17 -> exiting, 0-15 -> actual children. + + // 255 -> 16 -> 0 -> 1 -> ... -> 15 -> 17 + void setChild(unsigned _i) { child = _i; } void setFirstChild() { child = 16; } void incrementChild() { child = child == 16 ? 0 : child == 15 ? 17 : (child + 1); } @@ -205,6 +208,8 @@ public: iterator begin() const { return this; } iterator end() const { return iterator(); } + iterator lower_bound(bytesConstRef _key) const { return iterator(this, _key); } + private: RLPStream& streamNode(RLPStream& _s, bytes const& _b); @@ -298,6 +303,7 @@ public: iterator() {} iterator(TrieDB const* _db): Super(_db) {} + iterator(TrieDB const* _db, bytesConstRef _k): Super(_db, _k) {} value_type operator*() const { return at(); } value_type operator->() const { return at(); } @@ -307,6 +313,7 @@ public: iterator begin() const { return this; } iterator end() const { return iterator(); } + iterator lower_bound(KeyType _k) const { return iterator(this, bytesConstRef((byte const*)&_k, sizeof(KeyType))); } }; template @@ -317,14 +324,11 @@ std::ostream& operator<<(std::ostream& _out, TrieDB const& _db) return _out; } -} } // Template implementations... namespace dev { -namespace eth -{ template GenericTrieDB::iterator::iterator(GenericTrieDB const* _db) { @@ -333,6 +337,13 @@ template GenericTrieDB::iterator::iterator(GenericTrieDB const* _ next(); } +template GenericTrieDB::iterator::iterator(GenericTrieDB const* _db, bytesConstRef _fullKey) +{ + m_that = _db; + m_trail.push_back({_db->node(_db->m_root), std::string(1, '\0'), 255}); // one null byte is the HPE for the empty key. + next(_fullKey); +} + template typename GenericTrieDB::iterator::value_type GenericTrieDB::iterator::at() const { assert(m_trail.size()); @@ -341,10 +352,145 @@ template typename GenericTrieDB::iterator::value_type GenericTrie assert(!(b.key[0] & 0x10)); // should be an integer number of bytes (i.e. not an odd number of nibbles). RLP rlp(b.rlp); - if (rlp.itemCount() == 2) - return std::make_pair(bytesConstRef(b.key).cropped(1), rlp[1].payload()); - else - return std::make_pair(bytesConstRef(b.key).cropped(1), rlp[16].payload()); + return std::make_pair(bytesConstRef(b.key).cropped(1), rlp[rlp.itemCount() == 2 ? 1 : 16].payload()); +} + +template void GenericTrieDB::iterator::next(NibbleSlice _key) +{ + NibbleSlice k = _key; + while (true) + { + if (m_trail.empty()) + { + m_that = nullptr; + return; + } + + Node const& b = m_trail.back(); + RLP rlp(b.rlp); + + if (m_trail.back().child == 255) + { + // Entering. Look for first... + if (rlp.isEmpty()) + { + // Kill our search as soon as we hit an empty node. + k.clear(); + m_trail.pop_back(); + continue; + } + if (!rlp.isList() || (rlp.itemCount() != 2 && rlp.itemCount() != 17)) + { +#if ETH_PARANOIA + cwarn << "BIG FAT ERROR. STATE TRIE CORRUPTED!!!!!"; + cwarn << b.rlp.size() << toHex(b.rlp); + cwarn << rlp; + auto c = rlp.itemCount(); + cwarn << c; + BOOST_THROW_EXCEPTION(InvalidTrie()); +#else + m_that = nullptr; + return; +#endif + } + if (rlp.itemCount() == 2) + { + // Just turn it into a valid Branch + auto keyOfRLP = keyOf(rlp); + + // TODO: do something different depending on how keyOfRLP compares to k.mid(0, std::min(k.size(), keyOfRLP.size())); + // if == all is good - continue descent. + // if > discard key and continue descent. + // if < discard key and skip node. + + if (!k.contains(keyOfRLP)) + { + if (!k.isEarlierThan(keyOfRLP)) + { + k.clear(); + m_trail.pop_back(); + continue; + } + k.clear(); + } + + k = k.mid(std::min(k.size(), keyOfRLP.size())); + m_trail.back().key = hexPrefixEncode(keyOf(m_trail.back().key), keyOfRLP, false); + if (isLeaf(rlp)) + { + // leaf - exit now. + if (k.empty()) + { + m_trail.back().child = 0; + return; + } + // Still data in key we're supposed to be looking for when we're at a leaf. Go for next one. + k.clear(); + m_trail.pop_back(); + continue; + } + + // enter child. + m_trail.back().rlp = m_that->deref(rlp[1]); + // no need to set .child as 255 - it's already done. + continue; + } + else + { + // Already a branch - look for first valid. + if (k.size()) + { + m_trail.back().setChild(k[0]); + k = k.mid(1); + } + else + m_trail.back().setChild(16); + // run through to... + } + } + else + { + // Continuing/exiting. Look for next... + if (!(rlp.isList() && rlp.itemCount() == 17)) + { + k.clear(); + m_trail.pop_back(); + continue; + } + // else run through to... + m_trail.back().incrementChild(); + } + + // ...here. should only get here if we're a list. + assert(rlp.isList() && rlp.itemCount() == 17); + for (;; m_trail.back().incrementChild()) + if (m_trail.back().child == 17) + { + // finished here. + k.clear(); + m_trail.pop_back(); + break; + } + else if (!rlp[m_trail.back().child].isEmpty()) + { + if (m_trail.back().child == 16) + return; // have a value at this node - exit now. + else + { + // lead-on to another node - enter child. + // fixed so that Node passed into push_back is constructed *before* m_trail is potentially resized (which invalidates back and rlp) + Node const& back = m_trail.back(); + m_trail.push_back(Node{ + m_that->deref(rlp[back.child]), + hexPrefixEncode(keyOf(back.key), NibbleSlice(bytesConstRef(&back.child, 1), 1), false), + 255 + }); + break; + } + } + else + k.clear(); + } } template void GenericTrieDB::iterator::next() @@ -923,5 +1069,3 @@ template bytes GenericTrieDB::branch(RLP const& _orig) } } -} - diff --git a/libethcore/BlockInfo.cpp b/libethcore/BlockInfo.cpp index 536f684f2..6060ac032 100644 --- a/libethcore/BlockInfo.cpp +++ b/libethcore/BlockInfo.cpp @@ -72,7 +72,7 @@ h256 BlockInfo::headerHash(bytesConstRef _block) void BlockInfo::populateFromHeader(RLP const& _header, bool _checkNonce) { - hash = dev::eth::sha3(_header.data()); + hash = dev::sha3(_header.data()); int field = 0; try diff --git a/libethcore/CommonEth.cpp b/libethcore/CommonEth.cpp index 40a86dba4..54656173b 100644 --- a/libethcore/CommonEth.cpp +++ b/libethcore/CommonEth.cpp @@ -100,7 +100,7 @@ Address toAddress(Secret _private) ok = secp256k1_ecdsa_pubkey_verify(pubkey, 65); if (!ok) return Address(); - auto ret = right160(dev::eth::sha3(bytesConstRef(&(pubkey[1]), 64))); + auto ret = right160(dev::sha3(bytesConstRef(&(pubkey[1]), 64))); #if ETH_ADDRESS_DEBUG cout << "---- ADDRESS -------------------------------" << endl; cout << "SEC: " << _private << endl; diff --git a/libethereum/BlockChain.h b/libethereum/BlockChain.h index b723ed38d..6c96082a5 100644 --- a/libethereum/BlockChain.h +++ b/libethereum/BlockChain.h @@ -39,13 +39,15 @@ namespace ldb = leveldb; namespace dev { + +class OverlayDB; + namespace eth { static const h256s NullH256s; class State; -class OverlayDB; struct AlreadyHaveBlock: virtual Exception {}; struct UnknownParent: virtual Exception {}; diff --git a/libethereum/CommonNet.h b/libethereum/CommonNet.h index 7e4821bb4..4192c861e 100644 --- a/libethereum/CommonNet.h +++ b/libethereum/CommonNet.h @@ -30,6 +30,9 @@ namespace dev { + +class OverlayDB; + namespace eth { @@ -44,7 +47,7 @@ static const unsigned c_maxHashesAsk = 256; ///< Maximum number of hashes GetBl static const unsigned c_maxBlocks = 128; ///< Maximum number of blocks Blocks will ever send. static const unsigned c_maxBlocksAsk = 128; ///< Maximum number of blocks we ask to receive in Blocks (when using GetChain). #endif -class OverlayDB; + class BlockChain; class TransactionQueue; class EthereumHost; diff --git a/libethereum/MessageFilter.cpp b/libethereum/MessageFilter.cpp index d88bc8a9b..951bfec98 100644 --- a/libethereum/MessageFilter.cpp +++ b/libethereum/MessageFilter.cpp @@ -36,7 +36,7 @@ h256 MessageFilter::sha3() const { RLPStream s; fillStream(s); - return dev::eth::sha3(s.out()); + return dev::sha3(s.out()); } bool MessageFilter::matches(h256 _bloom) const diff --git a/libethereum/State.cpp b/libethereum/State.cpp index 8f2794c12..931ee2cf6 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -58,7 +58,7 @@ void ecrecoverCode(bytesConstRef _in, bytesRef _out) int pubkeylen = 65; secp256k1_start(); if (secp256k1_ecdsa_recover_compact(in.hash.data(), 32, in.r.data(), pubkey, &pubkeylen, 0, (int)(u256)in.v - 27)) - ret = dev::eth::sha3(bytesConstRef(&(pubkey[1]), 64)); + ret = dev::sha3(bytesConstRef(&(pubkey[1]), 64)); memcpy(_out.data(), &ret, min(_out.size(), sizeof(ret))); } @@ -207,6 +207,19 @@ State::~State() { } +Address State::nextActiveAddress(Address _a) const +{ + auto it = m_state.lower_bound(_a); + if ((*it).first == _a) + ++it; + if (it == m_state.end()) + // exchange comments if we want to wraparound +// it = m_state.begin(); + return Address(); + return (*it).first; +} + +// TODO: repot struct CachedAddressState { CachedAddressState(std::string const& _rlp, AddressState const* _s, OverlayDB const* _o): rS(_rlp), r(rS), s(_s), o(_o) {} diff --git a/libethereum/State.h b/libethereum/State.h index 5552ba454..dd6043c73 100644 --- a/libethereum/State.h +++ b/libethereum/State.h @@ -40,7 +40,8 @@ namespace dev { -namespace test{ class FakeExtVM; class FakeState;} + +namespace test { class FakeExtVM; class FakeState; } namespace eth { @@ -116,6 +117,8 @@ public: /// @returns the set containing all addresses currently in use in Ethereum. std::map addresses() const; + Address nextActiveAddress(Address _a) const; + BlockInfo const& info() const { return m_currentBlock; } /// @brief Checks that mining the current object will result in a valid block. diff --git a/libethereum/Transaction.cpp b/libethereum/Transaction.cpp index 70dae3557..bc8423bb1 100644 --- a/libethereum/Transaction.cpp +++ b/libethereum/Transaction.cpp @@ -81,7 +81,7 @@ Address Transaction::sender() const BOOST_THROW_EXCEPTION(InvalidSignature()); // TODO: check right160 is correct and shouldn't be left160. - m_sender = right160(dev::eth::sha3(bytesConstRef(&(pubkey[1]), 64))); + m_sender = right160(dev::sha3(bytesConstRef(&(pubkey[1]), 64))); #if ETH_ADDRESS_DEBUG cout << "---- RECOVER -------------------------------" << endl; diff --git a/libethereum/Transaction.h b/libethereum/Transaction.h index 5b327d96b..ecfbe24f0 100644 --- a/libethereum/Transaction.h +++ b/libethereum/Transaction.h @@ -67,8 +67,8 @@ struct Transaction void fillStream(RLPStream& _s, bool _sig = true) const; bytes rlp(bool _sig = true) const { RLPStream s; fillStream(s, _sig); return s.out(); } std::string rlpString(bool _sig = true) const { return asString(rlp(_sig)); } - h256 sha3(bool _sig = true) const { RLPStream s; fillStream(s, _sig); return dev::eth::sha3(s.out()); } - bytes sha3Bytes(bool _sig = true) const { RLPStream s; fillStream(s, _sig); return dev::eth::sha3Bytes(s.out()); } + h256 sha3(bool _sig = true) const { RLPStream s; fillStream(s, _sig); return dev::sha3(s.out()); } + bytes sha3Bytes(bool _sig = true) const { RLPStream s; fillStream(s, _sig); return dev::sha3Bytes(s.out()); } private: mutable Address m_sender; diff --git a/libqethereum/QEthereum.cpp b/libqethereum/QEthereum.cpp index e85d381f8..d55b17ea6 100644 --- a/libqethereum/QEthereum.cpp +++ b/libqethereum/QEthereum.cpp @@ -98,22 +98,22 @@ QString QEthereum::lll(QString _s) const QString QEthereum::sha3(QString _s) const { - return toQJS(dev::eth::sha3(toBytes(_s))); + return toQJS(dev::sha3(toBytes(_s))); } QString QEthereum::sha3(QString _s1, QString _s2) const { - return toQJS(dev::eth::sha3(asBytes(padded(_s1, 32)) + asBytes(padded(_s2, 32)))); + return toQJS(dev::sha3(asBytes(padded(_s1, 32)) + asBytes(padded(_s2, 32)))); } QString QEthereum::sha3(QString _s1, QString _s2, QString _s3) const { - return toQJS(dev::eth::sha3(asBytes(padded(_s1, 32)) + asBytes(padded(_s2, 32)) + asBytes(padded(_s3, 32)))); + return toQJS(dev::sha3(asBytes(padded(_s1, 32)) + asBytes(padded(_s2, 32)) + asBytes(padded(_s3, 32)))); } QString QEthereum::sha3old(QString _s) const { - return toQJS(dev::eth::sha3(asBytes(_s))); + return toQJS(dev::sha3(asBytes(_s))); } QString QEthereum::offset(QString _s, int _i) const diff --git a/libwhisper/Common.h b/libwhisper/Common.h index 26e8b9da8..49405f00b 100644 --- a/libwhisper/Common.h +++ b/libwhisper/Common.h @@ -57,5 +57,7 @@ enum WhisperPacket PacketCount }; +using Topic = h256; + } } diff --git a/libwhisper/Interface.cpp b/libwhisper/Interface.cpp index e5f5cd268..beab00f3c 100644 --- a/libwhisper/Interface.cpp +++ b/libwhisper/Interface.cpp @@ -36,15 +36,8 @@ using namespace dev::shh; bool MessageFilter::matches(Message const& _m) const { - for (auto const& t: m_topicMasks) - { - if (t.first.size() != t.second.size() || _m.topic.size() < t.first.size()) - continue; - for (unsigned i = 0; i < t.first.size(); ++i) - if (((t.first[i] ^ _m.topic[i]) & t.second[i]) != 0) - goto NEXT; - return true; - NEXT:; - } + for (TopicMask const& t: m_topicMasks) + if (((t.first ^ _m.topic) & t.second) == 0) + return true; return false; } diff --git a/libwhisper/Interface.h b/libwhisper/Interface.h index e9b822cba..6bed02977 100644 --- a/libwhisper/Interface.h +++ b/libwhisper/Interface.h @@ -37,20 +37,29 @@ namespace dev namespace shh { +/*struct TopicMask +{ + Topic data; + Topic mask; +};*/ + +using TopicMask = std::pair; +using TopicMasks = std::vector; + class MessageFilter { public: MessageFilter() {} - MessageFilter(std::vector > const& _m): m_topicMasks(_m) {} - MessageFilter(RLP const& _r): m_topicMasks((std::vector>)_r) {} + MessageFilter(TopicMasks const& _m): m_topicMasks(_m) {} + MessageFilter(RLP const& _r): m_topicMasks((TopicMasks)_r) {} void fillStream(RLPStream& _s) const { _s << m_topicMasks; } - h256 sha3() const { RLPStream s; fillStream(s); return dev::eth::sha3(s.out()); } + h256 sha3() const { RLPStream s; fillStream(s); return dev::sha3(s.out()); } bool matches(Message const& _m) const; private: - std::vector > m_topicMasks; + TopicMasks m_topicMasks; }; struct InstalledFilter @@ -85,7 +94,7 @@ public: virtual Message message(h256 _m) const = 0; - virtual void sendRaw(bytes const& _payload, bytes const& _topic, unsigned _ttl) = 0; + virtual void sendRaw(bytes const& _payload, h256 _topic, unsigned _ttl) = 0; }; struct WatshhChannel: public dev::LogChannel { static const char* name() { return "shh"; } static const int verbosity = 1; }; diff --git a/libwhisper/Message.h b/libwhisper/Message.h index 952238a9b..9bc36c6a2 100644 --- a/libwhisper/Message.h +++ b/libwhisper/Message.h @@ -40,23 +40,23 @@ struct Message { unsigned expiry = 0; unsigned ttl = 0; - bytes topic; // TODO: change to h256 + Topic topic; // TODO: change to h256 bytes payload; Message() {} - Message(unsigned _exp, unsigned _ttl, bytes const& _topic, bytes const& _payload): expiry(_exp), ttl(_ttl), topic(_topic), payload(_payload) {} + Message(unsigned _exp, unsigned _ttl, Topic const& _topic, bytes const& _payload): expiry(_exp), ttl(_ttl), topic(_topic), payload(_payload) {} Message(RLP const& _m) { expiry = _m[0].toInt(); ttl = _m[1].toInt(); - topic = _m[2].toBytes(); + topic = (Topic)_m[2]; payload = _m[3].toBytes(); } operator bool () const { return !!expiry; } void streamOut(RLPStream& _s) const { _s.appendList(4) << expiry << ttl << topic << payload; } - h256 sha3() const { RLPStream s; streamOut(s); return dev::eth::sha3(s.out()); } + h256 sha3() const { RLPStream s; streamOut(s); return dev::sha3(s.out()); } }; } diff --git a/libwhisper/WhisperHost.h b/libwhisper/WhisperHost.h index 285cc1b43..081be20a1 100644 --- a/libwhisper/WhisperHost.h +++ b/libwhisper/WhisperHost.h @@ -58,7 +58,7 @@ public: virtual Message message(h256 _m) const { try { dev::ReadGuard l(x_messages); return m_messages.at(_m); } catch (...) { return Message(); } } - virtual void sendRaw(bytes const& _payload, bytes const& _topic, unsigned _ttl) { inject(Message(time(0) + _ttl, _ttl, _topic, _payload)); } + virtual void sendRaw(bytes const& _payload, Topic _topic, unsigned _ttl) { inject(Message(time(0) + _ttl, _ttl, _topic, _payload)); } private: void streamMessage(h256 _m, RLPStream& _s) const; diff --git a/neth/main.cpp b/neth/main.cpp index cac19727c..bd66743e5 100644 --- a/neth/main.cpp +++ b/neth/main.cpp @@ -805,7 +805,7 @@ int main(int argc, char** argv) cnote << "Saved" << rechex << "to" << outFile; } - catch (dev::eth::InvalidTrie const& _e) + catch (dev::InvalidTrie const& _e) { cwarn << "Corrupted trie.\n" << diagnostic_information(_e); } diff --git a/test/MemTrie.cpp b/test/MemTrie.cpp index d654179f3..4879f2674 100644 --- a/test/MemTrie.cpp +++ b/test/MemTrie.cpp @@ -55,7 +55,7 @@ public: #endif /// 256-bit hash of the node - this is a SHA-3/256 hash of the RLP of the node. - h256 hash256() const { RLPStream s; makeRLP(s); return dev::eth::sha3(s.out()); } + h256 hash256() const { RLPStream s; makeRLP(s); return dev::sha3(s.out()); } bytes rlp() const { RLPStream s; makeRLP(s); return s.out(); } void mark() { m_hash256 = h256(); } @@ -200,7 +200,7 @@ void MemTrieNode::putRLP(RLPStream& _parentStream) const if (s.out().size() < 32) _parentStream.APPEND_CHILD(s.out()); else - _parentStream << dev::eth::sha3(s.out()); + _parentStream << dev::sha3(s.out()); } void TrieBranchNode::makeRLP(RLPStream& _intoStream) const diff --git a/test/crypto.cpp b/test/crypto.cpp index 55feb1a54..ebe3f81aa 100644 --- a/test/crypto.cpp +++ b/test/crypto.cpp @@ -150,7 +150,7 @@ int cryptoTest() int ret = secp256k1_ecdsa_recover_compact((byte const*)hmsg.data(), (int)hmsg.size(), (byte const*)sig64.data(), pubkey.data(), &pubkeylen, 0, (int)t.vrs.v - 27); pubkey.resize(pubkeylen); cout << "RECPUB: " << dec << ret << " " << pubkeylen << " " << toHex(pubkey) << endl; - cout << "SENDER: " << hex << toAddress(dev::eth::sha3(bytesConstRef(&pubkey).cropped(1))) << dec << endl; + cout << "SENDER: " << hex << toAddress(dev::sha3(bytesConstRef(&pubkey).cropped(1))) << dec << endl; } #endif return 0; diff --git a/test/hexPrefix.cpp b/test/hexPrefix.cpp index 6ced839dd..fb2fbc826 100644 --- a/test/hexPrefix.cpp +++ b/test/hexPrefix.cpp @@ -29,7 +29,6 @@ using namespace std; using namespace dev; -using namespace dev::eth; namespace js = json_spirit; BOOST_AUTO_TEST_CASE(hexPrefix_test) diff --git a/test/trie.cpp b/test/trie.cpp index fb74ebe20..899eb1f60 100644 --- a/test/trie.cpp +++ b/test/trie.cpp @@ -31,7 +31,6 @@ using namespace std; using namespace dev; -using namespace dev::eth; namespace js = json_spirit; @@ -236,6 +235,51 @@ BOOST_AUTO_TEST_CASE(moreTrieTests) } } +BOOST_AUTO_TEST_CASE(trieLowerBound) +{ + cnote << "Stress-testing Trie.lower_bound..."; + { + MemoryDB dm; + EnforceRefs e(dm, true); + GenericTrieDB d(&dm); + d.init(); // initialise as empty tree. + for (int a = 0; a < 20; ++a) + { + StringMap m; + for (int i = 0; i < 50; ++i) + { + auto k = randomWord(); + auto v = toString(i); + m[k] = v; + d.insert(k, v); + } + + for (auto i: d) + { + auto it = d.lower_bound(i.first); + for (auto iit = d.begin(); iit != d.end(); ++iit) + if ((*iit).first.toString() >= i.first.toString()) + { + BOOST_REQUIRE(it == iit); + break; + } + } + for (unsigned i = 0; i < 100; ++i) + { + auto k = randomWord(); + auto it = d.lower_bound(k); + for (auto iit = d.begin(); iit != d.end(); ++iit) + if ((*iit).first.toString() >= k) + { + BOOST_REQUIRE(it == iit); + break; + } + } + + } + } +} + BOOST_AUTO_TEST_CASE(trieStess) { cnote << "Stress-testing Trie..."; From d88eba1fcd629cdf9845c988cba1ad57cecdd44c Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 16 Oct 2014 20:03:04 +0300 Subject: [PATCH 5/7] Add QtCreator code style. Fix warnings. Bad boy, Alex! --- libdevcrypto/CryptoHeaders.h | 2 ++ qtcreator-style.xml | 39 ++++++++++++++++++++++++++++++++++++ test/TestHelperCrypto.h | 11 ++++++++++ 3 files changed, 52 insertions(+) create mode 100644 qtcreator-style.xml diff --git a/libdevcrypto/CryptoHeaders.h b/libdevcrypto/CryptoHeaders.h index 0361091e8..333c03a2f 100644 --- a/libdevcrypto/CryptoHeaders.h +++ b/libdevcrypto/CryptoHeaders.h @@ -29,6 +29,8 @@ #pragma GCC diagnostic ignored "-Wconversion" #pragma GCC diagnostic ignored "-Wunused-parameter" #pragma GCC diagnostic ignored "-Wunused-variable" +#pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor" +#pragma GCC diagnostic ignored "-Wextra" #include #include #include diff --git a/qtcreator-style.xml b/qtcreator-style.xml new file mode 100644 index 000000000..5a540f49d --- /dev/null +++ b/qtcreator-style.xml @@ -0,0 +1,39 @@ + + + + + + CodeStyleData + + false + false + true + false + false + false + true + false + true + false + false + false + true + true + false + true + false + false + false + 4 + true + false + 2 + false + 4 + + + + DisplayName + Gav + + diff --git a/test/TestHelperCrypto.h b/test/TestHelperCrypto.h index 6feeeb97f..cdc22ec31 100644 --- a/test/TestHelperCrypto.h +++ b/test/TestHelperCrypto.h @@ -22,11 +22,22 @@ #pragma once //#include + +#pragma warning(push) +#pragma warning(disable:4100 4244) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Wunused-variable" +#pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor" +#pragma GCC diagnostic ignored "-Wextra" #include #include #include #include #include +#pragma warning(pop) +#pragma GCC diagnostic pop using namespace std; using namespace CryptoPP; From 64aa05fcff85c7d76a9aed49d0b17c81a103c2f1 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 16 Oct 2014 21:18:36 +0300 Subject: [PATCH 6/7] eth and shh JS objects should only be created if the protocols are extant. --- libqethereum/QEthereum.h | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/libqethereum/QEthereum.h b/libqethereum/QEthereum.h index 94519e040..fc2d2b8b5 100644 --- a/libqethereum/QEthereum.h +++ b/libqethereum/QEthereum.h @@ -251,22 +251,29 @@ private: std::vector m_watches; }; +// TODO: add p2p object #define QETH_INSTALL_JS_NAMESPACE(frame, eth, shh, env) [frame, eth, shh, env]() \ { \ frame->disconnect(); \ frame->addToJavaScriptWindowObject("env", env, QWebFrame::QtOwnership); \ - frame->addToJavaScriptWindowObject("eth", eth, QWebFrame::ScriptOwnership); \ - frame->addToJavaScriptWindowObject("shh", eth, QWebFrame::ScriptOwnership); \ - frame->evaluateJavaScript("eth.makeWatch = function(a) { var ww = eth.newWatch(a); var ret = { w: ww }; ret.uninstall = function() { eth.killWatch(w); }; ret.changed = function(f) { eth.watchChanged.connect(function(nw) { if (nw == ww) f() }); }; ret.messages = function() { return JSON.parse(eth.watchMessages(this.w)) }; return ret; }"); \ - frame->evaluateJavaScript("eth.watch = function(a) { return eth.makeWatch(JSON.stringify(a)) }"); \ - frame->evaluateJavaScript("eth.transact = function(a, f) { var r = eth.doTransact(JSON.stringify(a)); if (f) f(r); }"); \ - frame->evaluateJavaScript("eth.call = function(a, f) { var ret = eth.doCallJson(JSON.stringify(a)); if (f) f(ret); return ret; }"); \ - frame->evaluateJavaScript("eth.messages = function(a) { return JSON.parse(eth.getMessages(JSON.stringify(a))); }"); \ - frame->evaluateJavaScript("eth.block = function(a) { return JSON.parse(eth.getBlock(a)); }"); \ - frame->evaluateJavaScript("eth.transaction = function(a) { return JSON.parse(eth.getTransaction(a)); }"); \ - frame->evaluateJavaScript("eth.uncle = function(a) { return JSON.parse(eth.getUncle(a)); }"); \ - frame->evaluateJavaScript("shh.makeWatch = function(a) { var ww = shh.newWatch(a); var ret = { w: ww }; ret.uninstall = function() { shh.killWatch(w); }; ret.changed = function(f) { shh.watchChanged.connect(function(nw) { if (nw == ww) f() }); }; ret.messages = function() { return JSON.parse(shh.watchMessages(this.w)) }; return ret; }"); \ - frame->evaluateJavaScript("shh.watch = function(a) { return shh.makeWatch(JSON.stringify(a)) }"); \ + if (eth) \ + { \ + frame->addToJavaScriptWindowObject("eth", eth, QWebFrame::ScriptOwnership); \ + frame->evaluateJavaScript("eth.makeWatch = function(a) { var ww = eth.newWatch(a); var ret = { w: ww }; ret.uninstall = function() { eth.killWatch(w); }; ret.changed = function(f) { eth.watchChanged.connect(function(nw) { if (nw == ww) f() }); }; ret.messages = function() { return JSON.parse(eth.watchMessages(this.w)) }; return ret; }"); \ + frame->evaluateJavaScript("eth.watch = function(a) { return eth.makeWatch(JSON.stringify(a)) }"); \ + frame->evaluateJavaScript("eth.transact = function(a, f) { var r = eth.doTransact(JSON.stringify(a)); if (f) f(r); }"); \ + frame->evaluateJavaScript("eth.call = function(a, f) { var ret = eth.doCallJson(JSON.stringify(a)); if (f) f(ret); return ret; }"); \ + frame->evaluateJavaScript("eth.messages = function(a) { return JSON.parse(eth.getMessages(JSON.stringify(a))); }"); \ + frame->evaluateJavaScript("eth.block = function(a) { return JSON.parse(eth.getBlock(a)); }"); \ + frame->evaluateJavaScript("eth.transaction = function(a) { return JSON.parse(eth.getTransaction(a)); }"); \ + frame->evaluateJavaScript("eth.uncle = function(a) { return JSON.parse(eth.getUncle(a)); }"); \ + } \ + if (shh) \ + { \ + frame->addToJavaScriptWindowObject("shh", shh, QWebFrame::ScriptOwnership); \ + frame->evaluateJavaScript("shh.makeWatch = function(a) { var ww = shh.newWatch(a); var ret = { w: ww }; ret.uninstall = function() { shh.killWatch(w); }; ret.changed = function(f) { shh.watchChanged.connect(function(nw) { if (nw == ww) f() }); }; ret.messages = function() { return JSON.parse(shh.watchMessages(this.w)) }; return ret; }"); \ + frame->evaluateJavaScript("shh.watch = function(a) { return shh.makeWatch(JSON.stringify(a)) }"); \ + } \ } template inline boost::multiprecision::number> toInt(QString const& _s) From bd6ed746dd8e988e450a79b132dbb29b52fe2d4f Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 16 Oct 2014 23:06:21 +0300 Subject: [PATCH 7/7] Fix display for ints > 2^160 < 2^200. --- alethzero/MainWin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index 762f2f681..ac2ed7358 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -1864,7 +1864,7 @@ QString Main::prettyU256(dev::u256 _n) const s << "" << (uint64_t)_n << " (0x" << hex << (uint64_t)_n << ")"; else if (!~(_n >> 64)) s << "" << (int64_t)_n << " (0x" << hex << (int64_t)_n << ")"; - else if ((_n >> 200) == 0) + else if ((_n >> 160) == 0) { Address a = right160(_n); QString n = pretty(a);