From 091e5d13dd950c67a675683fc0c382ea0ff77583 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 7 Jul 2015 10:32:16 -0700 Subject: [PATCH 1/5] Reorganise logs. --- libethereum/EthereumHost.cpp | 26 +++++++++++++++++--------- libethereum/EthereumHost.h | 2 ++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/libethereum/EthereumHost.cpp b/libethereum/EthereumHost.cpp index 186eb6fa8..f00ec7dc7 100644 --- a/libethereum/EthereumHost.cpp +++ b/libethereum/EthereumHost.cpp @@ -45,6 +45,12 @@ static unsigned const c_maxSendTransactions = 256; char const* const EthereumHost::s_stateNames[static_cast(SyncState::Size)] = {"Idle", "Waiting", "Hashes", "Blocks", "NewBlocks" }; +#ifdef _WIN32 +const char* EthereumHostTrace::name() { return EthPurple "^" EthGray " "; } +#else +const char* EthereumHostTrace::name() { return EthPurple "⧫" EthGray " "; } +#endif + EthereumHost::EthereumHost(BlockChain const& _ch, TransactionQueue& _tq, BlockQueue& _bq, u256 _networkId): HostCapability(), Worker ("ethsync"), @@ -67,7 +73,7 @@ bool EthereumHost::ensureInitialised() { // First time - just initialise. m_latestBlockSent = m_chain.currentHash(); - clog(NetNote) << "Initialising: latest=" << m_latestBlockSent; + clog(EthereumHostTrace) << "Initialising: latest=" << m_latestBlockSent; Guard l(x_transactions); m_transactionsSent = m_tq.knownTransactions(); @@ -150,7 +156,7 @@ void EthereumHost::maintainTransactions() RLPStream ts; _p->prep(ts, TransactionsPacket, n).appendRaw(b, n); _p->sealAndSend(ts); - cnote << "Sent" << n << "transactions to " << _p->session()->info().clientVersion; + clog(EthereumHostTrace) << "Sent" << n << "transactions to " << _p->session()->info().clientVersion; } _p->m_requireTransactions = false; return true; @@ -206,11 +212,15 @@ void EthereumHost::maintainBlocks(h256 const& _currentHash) if (diff(detailsFrom.number, detailsTo.number) < 20) { // don't be sending more than 20 "new" blocks. if there are any more we were probably waaaay behind. - clog(NetMessageSummary) << "Sending a new block (current is" << _currentHash << ", was" << m_latestBlockSent << ")"; + clog(EthereumHostTrace) << "Sending a new block (current is" << _currentHash << ", was" << m_latestBlockSent << ")"; h256s blocks = get<0>(m_chain.treeRoute(m_latestBlockSent, _currentHash, false, false, true)); - auto s = randomSelection(25, [&](EthereumPeer* p){ DEV_GUARDED(p->x_knownBlocks) return !p->m_knownBlocks.count(_currentHash); return false; }); + auto s = randomSelection(25, [&](EthereumPeer* p){ + DEV_GUARDED(p->x_knownBlocks) + return !p->m_knownBlocks.count(_currentHash); + return false; + }); for (shared_ptr const& p: get<0>(s)) for (auto const& b: blocks) { @@ -292,11 +302,11 @@ void EthereumHost::onPeerTransactions(std::shared_ptr _peer, RLP c { if (_peer->isCriticalSyncing()) { - clog(NetAllDetail) << "Ignoring transaction from peer we are syncing with"; + clog(EthereumHostTrace) << "Ignoring transaction from peer we are syncing with"; return; } unsigned itemCount = _r.itemCount(); - clog(NetAllDetail) << "Transactions (" << dec << itemCount << "entries)"; + clog(EthereumHostTrace) << "Transactions (" << dec << itemCount << "entries)"; m_tq.enqueue(_r, _peer->session()->id()); } @@ -351,10 +361,8 @@ void EthereumHost::onTransactionImported(ImportResult _ir, h256 const& _h, h512 break; case ImportResult::AlreadyKnown: // if we already had the transaction, then don't bother sending it on. - { - Guard l(x_transactions); + DEV_GUARDED(x_transactions) m_transactionsSent.insert(_h); - } peer->addRating(0); break; case ImportResult::Success: diff --git a/libethereum/EthereumHost.h b/libethereum/EthereumHost.h index b65ddb5d0..6cb82ebb4 100644 --- a/libethereum/EthereumHost.h +++ b/libethereum/EthereumHost.h @@ -49,6 +49,8 @@ class TransactionQueue; class BlockQueue; class BlockChainSync; +struct EthereumHostTrace: public LogChannel { static const char* name(); static const int verbosity = 6; }; + /** * @brief The EthereumHost class * @warning None of this is thread-safe. You have been warned. From 136a077625ee0b22efbcc24d35256c8bd58be053 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 7 Jul 2015 13:04:30 -0700 Subject: [PATCH 2/5] Undo hard fork. --- libethereum/State.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libethereum/State.cpp b/libethereum/State.cpp index 8ba3b438a..f50545d08 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -1212,7 +1212,6 @@ ExecutionResult State::execute(LastHashes const& _lh, Transaction const& _t, Per uncommitToMine(); // OK - transaction looks valid - execute. - u256 startGasUsed = gasUsed(); #if ETH_PARANOIA ctrace << "Executing" << e.t() << "on" << h; ctrace << toHex(e.t().rlp()); @@ -1262,7 +1261,7 @@ ExecutionResult State::execute(LastHashes const& _lh, Transaction const& _t, Per // Add to the user-originated transactions that we've executed. m_transactions.push_back(e.t()); - m_receipts.push_back(TransactionReceipt(rootHash(), startGasUsed + (m_currentBlock.number >= 830000 ? e.gasUsedNoRefunds() : e.gasUsed()), e.logs())); + m_receipts.push_back(TransactionReceipt(rootHash(), e.gasUsed(), e.logs())); m_transactionSet.insert(e.t().sha3()); } From f014438195be4a13c3e9601c5f337e69a6bdd376 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 7 Jul 2015 13:09:25 -0700 Subject: [PATCH 3/5] Don't use PRNG for key generation! --- libdevcrypto/Common.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/libdevcrypto/Common.cpp b/libdevcrypto/Common.cpp index 8bf95d02f..e45d1cfb6 100644 --- a/libdevcrypto/Common.cpp +++ b/libdevcrypto/Common.cpp @@ -262,16 +262,9 @@ bytes dev::scrypt(std::string const& _pass, bytes const& _salt, uint64_t _n, uin KeyPair KeyPair::create() { - static boost::thread_specific_ptr s_eng; - static unsigned s_id = 0; - if (!s_eng.get()) - s_eng.reset(new mt19937_64(time(0) + chrono::high_resolution_clock::now().time_since_epoch().count() + ++s_id)); - - uniform_int_distribution d(0, 255); - for (int i = 0; i < 100; ++i) { - KeyPair ret(FixedHash<32>::random(*s_eng.get())); + KeyPair ret(FixedHash<32>::random()); if (ret.address()) return ret; } From e9cff7f0212c92a1894bd929efe44e22f42d0b79 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 7 Jul 2015 13:11:16 -0700 Subject: [PATCH 4/5] Better casting. --- libdevcore/FixedHash.h | 2 +- libdevcrypto/Common.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libdevcore/FixedHash.h b/libdevcore/FixedHash.h index 09bc3393b..139c0d943 100644 --- a/libdevcore/FixedHash.h +++ b/libdevcore/FixedHash.h @@ -151,7 +151,7 @@ public: { FixedHash ret; for (auto& i: ret.m_data) - i = std::uniform_int_distribution(0, 255)(_eng); + i = std::uniform_int_distribution(0, 255)(_eng); return ret; } diff --git a/libdevcrypto/Common.cpp b/libdevcrypto/Common.cpp index e45d1cfb6..e75623799 100644 --- a/libdevcrypto/Common.cpp +++ b/libdevcrypto/Common.cpp @@ -344,9 +344,9 @@ void Nonce::initialiseIfNeeded() { // todo: replace w/entropy from user and system std::mt19937_64 s_eng(time(0) + chrono::high_resolution_clock::now().time_since_epoch().count()); - std::uniform_int_distribution d(0, 255); + std::uniform_int_distribution d(0, 255); for (unsigned i = 0; i < 32; ++i) - m_value[i] = byte(d(s_eng)); + m_value[i] = d(s_eng); } if (!m_value) BOOST_THROW_EXCEPTION(InvalidState()); From 98ad4c2454482a9198861d0de1e54d843442223b Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 7 Jul 2015 14:42:35 -0700 Subject: [PATCH 5/5] windows build fix. --- libdevcore/FixedHash.h | 1 + libdevcrypto/Common.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/libdevcore/FixedHash.h b/libdevcore/FixedHash.h index 139c0d943..5257ed333 100644 --- a/libdevcore/FixedHash.h +++ b/libdevcore/FixedHash.h @@ -24,6 +24,7 @@ #pragma once #include +#include #include #include #include "CommonData.h" diff --git a/libdevcrypto/Common.cpp b/libdevcrypto/Common.cpp index e75623799..6ff29988a 100644 --- a/libdevcrypto/Common.cpp +++ b/libdevcrypto/Common.cpp @@ -22,6 +22,7 @@ #include "Common.h" #include +#include #include #include #include