Browse Source

Merge remote-tracking branch 'upstream/develop' into develop

cl-refactor
Christoph Jentzsch 10 years ago
parent
commit
da4d393a28
  1. 70
      alethzero/Main.ui
  2. 55
      alethzero/MainWin.cpp
  3. 2
      alethzero/MainWin.h
  4. 2
      libdevcore/Common.cpp
  5. 2
      libethcore/Exceptions.h
  6. 12
      libethereum/BlockChain.cpp
  7. 2
      libethereum/DownloadMan.cpp
  8. 11
      libethereum/DownloadMan.h
  9. 4
      libethereum/EthereumHost.cpp
  10. 10
      libethereum/EthereumPeer.cpp
  11. 7
      libethereum/State.cpp
  12. 2
      libevm/VM.h
  13. 1
      libp2p/Common.h
  14. 4
      libp2p/Session.cpp
  15. 2
      test/TestHelper.cpp
  16. 2
      test/rlp.cpp

70
alethzero/Main.ui

@ -130,6 +130,8 @@
<property name="title">
<string>&amp;Network</string>
</property>
<addaction name="go"/>
<addaction name="separator"/>
<addaction name="upnp"/>
<addaction name="usePast"/>
<addaction name="localNetworking"/>
@ -141,15 +143,12 @@
<string>T&amp;ools</string>
</property>
<addaction name="mine"/>
<addaction name="preview"/>
<addaction name="separator"/>
<addaction name="create"/>
<addaction name="importKey"/>
<addaction name="importKeyFile"/>
<addaction name="exportKey"/>
<addaction name="separator"/>
<addaction name="showAll"/>
<addaction name="showAllAccounts"/>
<addaction name="separator"/>
<addaction name="loadJS"/>
</widget>
<widget class="QMenu" name="menu_Help">
@ -162,7 +161,32 @@
<property name="title">
<string>Deb&amp;ug</string>
</property>
<widget class="QMenu" name="menuDump_Trace">
<addaction name="debugDumpState"/>
<addaction name="debugDumpStatePre"/>
<addaction name="separator"/>
<addaction name="paranoia"/>
<addaction name="killBlockchain"/>
<addaction name="inject"/>
<addaction name="forceMining"/>
<addaction name="turboMining"/>
<addaction name="enableOptimizer"/>
<addaction name="separator"/>
<addaction name="usePrivate"/>
</widget>
<widget class="QMenu" name="menu_View">
<property name="title">
<string>&amp;View</string>
</property>
<addaction name="showAll"/>
<addaction name="showAllAccounts"/>
<addaction name="separator"/>
<addaction name="preview"/>
</widget>
<widget class="QMenu" name="menuDebugger">
<property name="title">
<string>D&amp;ebugger</string>
</property>
<widget class="QMenu" name="menu_Dump_Trace">
<property name="title">
<string>&amp;Dump Trace</string>
</property>
@ -170,9 +194,13 @@
<addaction name="dumpTraceStorage"/>
<addaction name="dumpTracePretty"/>
</widget>
<widget class="QMenu" name="menuType_Here">
<property name="title">
<string>Type Here</string>
</property>
</widget>
<addaction name="debugCurrent"/>
<addaction name="debugDumpState"/>
<addaction name="debugDumpStatePre"/>
<addaction name="menu_Dump_Trace"/>
<addaction name="separator"/>
<addaction name="debugStep"/>
<addaction name="debugStepInto"/>
@ -180,20 +208,13 @@
<addaction name="debugStepBack"/>
<addaction name="debugStepBackInto"/>
<addaction name="debugStepBackOut"/>
<addaction name="menuDump_Trace"/>
<addaction name="separator"/>
<addaction name="paranoia"/>
<addaction name="killBlockchain"/>
<addaction name="inject"/>
<addaction name="forceMining"/>
<addaction name="turboMining"/>
<addaction name="enableOptimizer"/>
<addaction name="separator"/>
<addaction name="usePrivate"/>
<addaction name="menuType_Here"/>
</widget>
<addaction name="menu_File"/>
<addaction name="menu_View"/>
<addaction name="menu_Network"/>
<addaction name="menu_Tools"/>
<addaction name="menuDebugger"/>
<addaction name="menu_Debug"/>
<addaction name="menu_Help"/>
</widget>
@ -507,8 +528,7 @@
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="net"/>
<addaction name="connect"/>
<addaction name="go"/>
<addaction name="preview"/>
<addaction name="mine"/>
<addaction name="refresh"/>
@ -1521,7 +1541,7 @@ font-size: 14pt</string>
<bool>true</bool>
</property>
<property name="text">
<string>&amp;Preview</string>
<string>&amp;Preview Pending Transactions</string>
</property>
</action>
<action name="debugStep">
@ -1740,6 +1760,16 @@ font-size: 14pt</string>
<string>Enable Local Addresses</string>
</property>
</action>
<action name="importKeyFile">
<property name="text">
<string>Import Key &amp;File...</string>
</property>
</action>
<action name="go">
<property name="text">
<string>Go!</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>

55
alethzero/MainWin.cpp

@ -28,6 +28,7 @@
#include <QtGui/QClipboard>
#include <QtCore/QtCore>
#include <boost/algorithm/string.hpp>
#include <test/JsonSpiritHeaders.h>
#include <libserpent/funcs.h>
#include <libserpent/util.h>
#include <libdevcrypto/FileSystem.h>
@ -49,6 +50,7 @@ using namespace std;
using namespace dev;
using namespace dev::p2p;
using namespace dev::eth;
namespace js = json_spirit;
static void initUnits(QComboBox* _b)
{
@ -570,6 +572,47 @@ void Main::on_importKey_triggered()
QMessageBox::warning(this, "Invalid Entry", "Could not import the secret key; invalid key entered. Make sure it is 64 hex characters (0-9 or A-F).");
}
void Main::on_importKeyFile_triggered()
{
QString s = QFileDialog::getOpenFileName(this, "Import Account", QDir::homePath(), "JSON Files (*.json);;All Files (*)");
try
{
js::mValue val;
json_spirit::read_string(asString(contents(s.toStdString())), val);
js::mObject obj = val.get_obj();
KeyPair k;
if (obj["encseed"].type() == js::str_type)
{
string encseedstr = obj["encseed"].get_str();
bytes encseed = fromHex(encseedstr);
Secret sec = sha3(encseed);
k = KeyPair(sec);
if (obj["ethaddr"].type() == js::str_type)
{
Address a(obj["ethaddr"].get_str());
Address b = k.address();
if (a != b && QMessageBox::warning(this, "Key File Invalid", "Could not import the secret key: it doesn't agree with the given address.\nWould you like to attempt to import anyway?", QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
return;
}
}
else
throw 0;
if (std::find(m_myKeys.begin(), m_myKeys.end(), k) == m_myKeys.end())
{
m_myKeys.append(k);
m_keysChanged = true;
update();
}
else
QMessageBox::warning(this, "Already Have Key", "Could not import the secret key: we already own this account.");
}
catch (...)
{
QMessageBox::warning(this, "Key File Invalid", "Could not find secret key definition. This is probably not an Ethereum key file.");
}
}
void Main::on_exportKey_triggered()
{
if (ui->ourAccounts->currentRow() >= 0 && ui->ourAccounts->currentRow() < m_myKeys.size())
@ -691,7 +734,7 @@ void Main::refreshNetwork()
ui->peerCount->setText(QString::fromStdString(toString(ps.size())) + " peer(s)");
ui->peers->clear();
for (PeerInfo const& i: ps)
ui->peers->addItem(QString("%3 ms - %1:%2 - %4 %5").arg(i.host.c_str()).arg(i.port).arg(chrono::duration_cast<chrono::milliseconds>(i.lastPing).count()).arg(i.clientVersion.c_str()).arg(QString::fromStdString(toString(i.caps))));
ui->peers->addItem(QString("[%6] %3 ms - %1:%2 - %4 %5").arg(i.host.c_str()).arg(i.port).arg(chrono::duration_cast<chrono::milliseconds>(i.lastPing).count()).arg(i.clientVersion.c_str()).arg(QString::fromStdString(toString(i.caps))).arg(i.socket));
}
void Main::refreshAll()
@ -1695,6 +1738,16 @@ void Main::on_dumpTraceStorage_triggered()
}
}
void Main::on_go_triggered()
{
if (!ui->net->isChecked())
{
ui->net->setChecked(true);
on_net_triggered();
}
web3()->connect(Host::pocHost());
}
void Main::on_callStack_currentItemChanged()
{
updateDebugger();

2
alethzero/MainWin.h

@ -147,6 +147,8 @@ private slots:
void on_usePrivate_triggered();
void on_enableOptimizer_triggered();
void on_turboMining_triggered();
void on_go_triggered();
void on_importKeyFile_triggered();
signals:
void poll();

2
libdevcore/Common.cpp

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

2
libethcore/Exceptions.h

@ -25,7 +25,7 @@ class InvalidBlockHeaderFormat: public dev::Exception { public: InvalidBlockHead
class InvalidUnclesHash: public dev::Exception {};
class InvalidUncle: public dev::Exception {};
class UncleTooOld: public dev::Exception {};
class UncleInChain: public dev::Exception {};
class UncleInChain: public dev::Exception { public: UncleInChain(h256Set _uncles, h256 _block): m_uncles(_uncles), m_block(_block) {} h256Set m_uncles; h256 m_block; virtual std::string description() const { return "Uncle in block already mentioned: Uncles " + toString(m_uncles) + " (" + m_block.abridged() + ")"; } };
class DuplicateUncleNonce: public dev::Exception {};
class InvalidStateRoot: public dev::Exception {};
class InvalidTransactionsHash: public dev::Exception { public: InvalidTransactionsHash(h256 _head, h256 _real): m_head(_head), m_real(_real) {} h256 m_head; h256 m_real; virtual std::string description() const { return "Invalid transactions hash: header says: " + toHex(m_head.ref()) + " block is:" + toHex(m_real.ref()); } };

12
libethereum/BlockChain.cpp

@ -276,7 +276,10 @@ h256s BlockChain::import(bytes const& _block, OverlayDB const& _db)
auto pd = details(bi.parentHash);
if (!pd)
{
cwarn << "Odd: details is returning false despite block known:" << RLP(pd.rlp());
cwarn << "Block:" << RLP(block(bi.parentHash));
}
// Check it's not crazy
if (bi.timestamp > (u256)time(0))
@ -479,13 +482,16 @@ bytes BlockChain::block(h256 _hash) const
string d;
m_db->Get(m_readOptions, ldb::Slice((char const*)&_hash, 32), &d);
if (!d.size())
{
cwarn << "Couldn't find requested block:" << _hash.abridged();
return bytes();
}
WriteGuard l(x_cache);
m_cache[_hash].resize(d.size());
memcpy(m_cache[_hash].data(), d.data(), d.size());
if (!d.size())
cwarn << "Couldn't find requested block:" << _hash.abridged();
return m_cache[_hash];
}

2
libethereum/DownloadMan.cpp

@ -50,7 +50,7 @@ h256Set DownloadSub::nextFetch(unsigned _n)
m_indices.clear();
m_remaining.clear();
if (!m_man)
if (!m_man || m_man->chain().empty())
return h256Set();
m_asked = (~(m_man->taken() + m_attempted)).lowest(_n);

11
libethereum/DownloadMan.h

@ -101,6 +101,17 @@ public:
m_blocksGot = RangeMask<unsigned>(0, m_chain.size());
}
void reset()
{
{
ReadGuard l(x_subs);
for (auto i: m_subs)
i->resetFetch();
}
m_chain.clear();
m_blocksGot.clear();
}
RangeMask<unsigned> taken(bool _desperate = false) const
{
auto ret = m_blocksGot;

4
libethereum/EthereumHost.cpp

@ -149,6 +149,7 @@ void EthereumHost::noteDoneBlocks(EthereumPeer* _who)
// Done our chain-get.
clog(NetNote) << "Chain download complete.";
updateGrabbing(Grabbing::Nothing);
m_man.reset();
}
if (_who->m_grabbing == Grabbing::Chain)
{
@ -156,6 +157,7 @@ void EthereumHost::noteDoneBlocks(EthereumPeer* _who)
clog(NetNote) << "Chain download failed. Peer with blocks didn't have them all. This peer is bad and should be punished.";
// TODO: note that peer is BADBADBAD!
updateGrabbing(Grabbing::Nothing);
m_man.reset();
}
}
@ -263,6 +265,8 @@ void EthereumHost::maintainBlocks(BlockQueue& _bq, h256 _currentHash)
++c;
}
clog(NetMessageSummary) << "Sending" << c << "new blocks (current is" << _currentHash << ", was" << m_latestBlockSent << ")";
if (c > 1000)
cwarn << "Gaa sending an awful lot of new blocks. Sure this is right?";
ts.appendList(1 + c).append(BlocksPacket).appendRaw(bs, c);
bytes b;
ts.swapOut(b);

10
libethereum/EthereumPeer.cpp

@ -176,12 +176,12 @@ bool EthereumPeer::interpret(RLP const& _r)
unsigned limit = _r[2].toInt<unsigned>();
clogS(NetMessageSummary) << "GetBlockHashes (" << limit << "entries," << later.abridged() << ")";
unsigned c = min<unsigned>(max<unsigned>(1, host()->m_chain.number(later)) - 1, limit);
unsigned c = min<unsigned>(host()->m_chain.number(later), limit);
RLPStream s;
prep(s).appendList(1 + c).append(BlockHashesPacket);
h256 p = host()->m_chain.details(later).parent;
for (unsigned i = 0; i < c; ++i, p = host()->m_chain.details(p).parent)
for (unsigned i = 0; i < c && p; ++i, p = host()->m_chain.details(p).parent)
s << p;
sealAndSend(s);
break;
@ -203,7 +203,7 @@ bool EthereumPeer::interpret(RLP const& _r)
for (unsigned i = 1; i < _r.itemCount(); ++i)
{
auto h = _r[i].toHash<h256>();
if (host()->m_chain.details(h))
if (host()->m_chain.isKnown(h))
{
host()->noteHaveChain(this);
return true;
@ -246,6 +246,7 @@ bool EthereumPeer::interpret(RLP const& _r)
// Couldn't get any from last batch - probably got to this peer's latest block - just give up.
m_sub.doneFetch();
giveUpOnFetch();
break;
}
unsigned used = 0;
@ -263,7 +264,8 @@ bool EthereumPeer::interpret(RLP const& _r)
unsigned unknownParents = 0;
if (g_logVerbosity >= NetMessageSummary::verbosity)
{
for (unsigned i = 1; i < _r.itemCount(); ++i)
unsigned ic = _r.itemCount();
for (unsigned i = 1; i < ic; ++i)
{
auto h = BlockInfo::headerHash(_r[i].data());
BlockInfo bi(_r[i].data());

7
libethereum/State.cpp

@ -577,6 +577,9 @@ u256 State::enact(bytesConstRef _block, BlockChain const* _bc, bool _checkNonce)
set<h256> knownUncles = _bc ? _bc->allUnclesFrom(m_currentBlock.parentHash) : set<h256>();
for (auto const& i: RLP(_block)[2])
{
if (knownUncles.count(sha3(i.data())))
throw UncleInChain(knownUncles, sha3(i.data()));
BlockInfo uncle = BlockInfo::fromHeader(i.data());
if (nonces.count(uncle.nonce))
throw DuplicateUncleNonce();
@ -585,8 +588,6 @@ u256 State::enact(bytesConstRef _block, BlockChain const* _bc, bool _checkNonce)
BlockInfo uncleParent(_bc->block(uncle.parentHash));
if ((bigint)uncleParent.number < (bigint)m_currentBlock.number - 6)
throw UncleTooOld();
if (knownUncles.count(sha3(i.data())))
throw UncleInChain();
uncle.verifyParent(uncleParent);
}
@ -725,7 +726,7 @@ void State::commitToMine(BlockChain const& _bc)
auto us = _bc.details(p).children;
assert(us.size() >= 1); // must be at least 1 child of our grandparent - it's our own parent!
for (auto const& u: us)
if (!knownUncles.count(BlockInfo::headerHash(_bc.block(u)))) // ignore any uncles/mainline blocks that we know about. We use header-hash for this.
if (!knownUncles.count(u)) // ignore any uncles/mainline blocks that we know about.
{
BlockInfo ubi(_bc.block(u));
ubi.fillStream(unclesData, true);

2
libevm/VM.h

@ -634,7 +634,7 @@ template <class Ext> dev::bytesConstRef dev::eth::VM::go(Ext& _ext, OnOpFunc con
if (_ext.balance(_ext.myAddress) >= value)
{
_ext.subBalance(value);
m_stack.push_back(_ext.call(receiveAddress, value, bytesConstRef(m_temp.data() + inOff, inSize), &gas, bytesRef(m_temp.data() + outOff, outSize), _onOp, Address(), inst == Instruction::CALL ? receiveAddress : _ext.myAddress));
m_stack.push_back(_ext.call(inst == Instruction::CALL ? receiveAddress : _ext.myAddress, value, bytesConstRef(m_temp.data() + inOff, inSize), &gas, bytesRef(m_temp.data() + outOff, outSize), _onOp, Address(), receiveAddress));
}
else
m_stack.push_back(0);

1
libp2p/Common.h

@ -95,6 +95,7 @@ struct PeerInfo
unsigned short port;
std::chrono::steady_clock::duration lastPing;
std::set<std::string> caps;
unsigned socket;
};
}

4
libp2p/Session.cpp

@ -40,7 +40,7 @@ Session::Session(Host* _s, bi::tcp::socket _socket, bi::address _peerAddress, un
{
m_disconnect = std::chrono::steady_clock::time_point::max();
m_connect = std::chrono::steady_clock::now();
m_info = PeerInfo({"?", _peerAddress.to_string(), m_listenPort, std::chrono::steady_clock::duration(0)});
m_info = PeerInfo({"?", _peerAddress.to_string(), m_listenPort, std::chrono::steady_clock::duration(0), set<string>(), 0});
}
Session::~Session()
@ -102,7 +102,7 @@ bool Session::interpret(RLP const& _r)
return false;
}
try
{ m_info = PeerInfo({clientVersion, m_socket.remote_endpoint().address().to_string(), m_listenPort, std::chrono::steady_clock::duration(), _r[3].toSet<string>()}); }
{ m_info = PeerInfo({clientVersion, m_socket.remote_endpoint().address().to_string(), m_listenPort, std::chrono::steady_clock::duration(), _r[3].toSet<string>(), (unsigned)m_socket.native_handle()}); }
catch (...)
{
disconnect(BadProtocol);

2
test/TestHelper.cpp

@ -42,6 +42,8 @@ void mine(Client& c, int numBlocks)
void connectClients(Client& c1, Client& c2)
{
(void)c1;
(void)c2;
// TODO: Move to WebThree. eth::Client no longer handles networking.
#if 0
short c1Port = 20000;

2
test/rlp.cpp

@ -22,12 +22,12 @@
#include <fstream>
#include <sstream>
#include "JsonSpiritHeaders.h"
#include <libdevcore/Log.h>
#include <libdevcore/RLP.h>
#include <libdevcore/Common.h>
#include <boost/test/unit_test.hpp>
#include <algorithm>
#include "JsonSpiritHeaders.h"
using namespace std;
using namespace dev;

Loading…
Cancel
Save