Browse Source

UI tweaks.

Additional diagnostics.
cl-refactor
Gav Wood 11 years ago
parent
commit
a46f6894ad
  1. 38
      alethzero/Main.ui
  2. 8
      alethzero/MainWin.cpp
  3. 1
      alethzero/MainWin.h
  4. 29
      libethereum/BlockInfo.cpp
  5. 2
      libethereum/Common.cpp
  6. 3
      libethereum/Exceptions.h
  7. 19
      libethereum/PeerNetwork.cpp
  8. 2
      libethereum/PeerNetwork.h

38
alethzero/Main.ui

@ -190,11 +190,33 @@
</property>
<item>
<widget class="QListWidget" name="log">
<property name="font">
<font>
<family>Monospace</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="verbosity">
<property name="maximum">
<number>10</number>
</property>
<property name="value">
<number>4</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBothSides</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
@ -249,7 +271,7 @@
<property name="minimumSize">
<size>
<width>349</width>
<height>225</height>
<height>251</height>
</size>
</property>
<property name="features">
@ -279,7 +301,7 @@
</property>
</widget>
</item>
<item row="4" column="4">
<item row="5" column="4">
<widget class="QPushButton" name="send">
<property name="text">
<string>Send</string>
@ -322,9 +344,6 @@
</property>
</widget>
</item>
<item row="1" column="3" colspan="2">
<widget class="QComboBox" name="valueUnits"/>
</item>
<item row="2" column="2">
<widget class="QSpinBox" name="fee">
<property name="suffix">
@ -341,6 +360,9 @@
</property>
</widget>
</item>
<item row="1" column="3" colspan="2">
<widget class="QComboBox" name="valueUnits"/>
</item>
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="label5_3">
<property name="text">
@ -348,9 +370,6 @@
</property>
</widget>
</item>
<item row="3" column="2" colspan="3">
<widget class="QPlainTextEdit" name="data"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
@ -361,6 +380,9 @@
</property>
</widget>
</item>
<item row="4" column="0" colspan="5">
<widget class="QPlainTextEdit" name="data"/>
</item>
</layout>
</widget>
</widget>

8
alethzero/MainWin.cpp

@ -188,7 +188,10 @@ void Main::on_net_triggered()
void Main::on_connect_triggered()
{
if (!ui->net->isChecked())
{
ui->net->setChecked(true);
on_net_triggered();
}
bool ok = false;
QString s = QInputDialog::getItem(this, "Connect to a Network Peer", "Enter a peer to which a connection may be made:", m_servers, m_servers.count() ? rand() % m_servers.count() : 0, true, &ok);
if (ok && s.contains(":"))
@ -199,6 +202,11 @@ void Main::on_connect_triggered()
}
}
void Main::on_verbosity_sliderMoved()
{
g_logVerbosity = ui->verbosity->value();
}
void Main::on_mine_triggered()
{
if (ui->mine->isChecked())

1
alethzero/MainWin.h

@ -29,6 +29,7 @@ private slots:
void on_send_clicked();
void on_create_triggered();
void on_net_triggered();
void on_verbosity_sliderMoved();
void on_ourAccounts_doubleClicked();
void on_accounts_doubleClicked();
void on_quit_triggered() { close(); }

29
libethereum/BlockInfo.cpp

@ -82,25 +82,32 @@ void BlockInfo::populateGenesis()
void BlockInfo::populate(bytesConstRef _block)
{
RLP root(_block);
int field = 0;
RLP header = root[0];
if (!header.isList())
throw InvalidBlockFormat(0, header.data());
try
{
RLP header = root[0];
hash = eth::sha3(_block);
parentHash = header[0].toHash<h256>();
sha3Uncles = header[1].toHash<h256>();
coinbaseAddress = header[2].toHash<Address>();
stateRoot = header[3].toHash<h256>();
sha3Transactions = header[4].toHash<h256>();
difficulty = header[5].toInt<u256>();
timestamp = header[6].toInt<u256>();
extraData = header[7].toBytes();
nonce = header[8].toInt<u256>();
parentHash = header[field = 0].toHash<h256>();
sha3Uncles = header[field = 1].toHash<h256>();
coinbaseAddress = header[field = 2].toHash<Address>();
stateRoot = header[field = 3].toHash<h256>();
sha3Transactions = header[field = 4].toHash<h256>();
difficulty = header[field = 5].toInt<u256>();
timestamp = header[field = 6].toInt<u256>();
extraData = header[field = 7].toBytes();
nonce = header[field = 8].toInt<u256>();
}
catch (RLP::BadCast)
{
throw InvalidBlockFormat();
throw InvalidBlockHeaderFormat(field, header[field].data());
}
if (!root[1].isList())
throw InvalidBlockFormat(1, root[1].data());
if (!root[2].isList())
throw InvalidBlockFormat(2, root[2].data());
// check it hashes according to proof of work or that it's the genesis block.
if (parentHash && !Dagger::verify(headerHashWithoutNonce(), nonce, difficulty))
throw InvalidNonce();

2
libethereum/Common.cpp

@ -39,7 +39,7 @@ using namespace std;
using namespace eth;
// Logging
int eth::g_logVerbosity = 6;
int eth::g_logVerbosity = 8;
map<type_info const*, bool> eth::g_logOverride;
thread_local std::string eth::t_logThreadName = "???";
static std::string g_mainThreadName = (eth::t_logThreadName = "main");

3
libethereum/Exceptions.h

@ -24,7 +24,8 @@ class ContractAddressCollision: public Exception {};
class FeeTooSmall: public Exception {};
class InvalidSignature: public Exception {};
class InvalidTransactionFormat: public Exception {};
class InvalidBlockFormat: public Exception { public: virtual std::string description() const { return "Invalid block format"; } };
class InvalidBlockFormat: public Exception { public: InvalidBlockFormat(int _f, bytesConstRef _d): m_f(_f), m_d(_d.toBytes()) {} int m_f; bytes m_d; virtual std::string description() const { return "Invalid block format: Bad field " + toString(m_f) + " (" + asHex(m_d) + ")"; } };
class InvalidBlockHeaderFormat: public Exception { public: InvalidBlockHeaderFormat(int _f, bytesConstRef _d): m_f(_f), m_d(_d.toBytes()) {} int m_f; bytes m_d; virtual std::string description() const { return "Invalid block header format: Bad field " + toString(m_f) + " (" + asHex(m_d) + ")"; } };
class InvalidUnclesHash: public Exception {};
class InvalidUncle: public Exception {};
class InvalidStateRoot: public Exception {};

19
libethereum/PeerNetwork.cpp

@ -40,7 +40,7 @@
using namespace std;
using namespace eth;
#define clogS(X) eth::LogOutputStream<X, true>(false) << " | " << std::setw(2) << m_socket.native_handle() << " ] "
#define clogS(X) eth::LogOutputStream<X, true>(false) << "| " << std::setw(2) << m_socket.native_handle() << "] "
static const eth::uint c_maxHashes = 256; ///< Maximum number of hashes GetChain will ever send.
static const eth::uint c_maxBlocks = 128; ///< Maximum number of blocks Blocks will ever send. BUG: if this gets too big (e.g. 2048) stuff starts going wrong.
@ -97,7 +97,7 @@ bool PeerSession::interpret(RLP const& _r)
m_caps = _r.itemCount() > 4 ? _r[4].toInt<uint>() : 0x07;
m_listenPort = _r.itemCount() > 5 ? _r[5].toInt<short>() : 0;
clogS(NetMessageSummary) << "Hello: " << clientVersion << " " << showbase << hex << m_caps << dec << " " << m_listenPort;
clogS(NetMessageSummary) << "Hello: " << clientVersion << "V[" << m_protocolVersion << "/" << m_networkId << "]" << showbase << hex << m_caps << dec << m_listenPort;
if (m_protocolVersion != 1 || m_networkId != m_reqNetworkId)
{
@ -356,7 +356,6 @@ RLPStream& PeerSession::prep(RLPStream& _s)
void PeerServer::seal(bytes& _b)
{
clogS(NetLeft) << RLP(bytesConstRef(&_b).cropped(8));
_b[0] = 0x22;
_b[1] = 0x40;
_b[2] = 0x08;
@ -378,6 +377,7 @@ void PeerSession::sealAndSend(RLPStream& _s)
void PeerSession::sendDestroy(bytes& _msg)
{
clogS(NetLeft) << RLP(bytesConstRef(&_msg).cropped(8));
std::shared_ptr<bytes> buffer = std::make_shared<bytes>();
swap(*buffer, _msg);
assert((*buffer)[0] == 0x22);
@ -391,6 +391,7 @@ void PeerSession::sendDestroy(bytes& _msg)
void PeerSession::send(bytesConstRef _msg)
{
clogS(NetLeft) << RLP(_msg.cropped(8));
std::shared_ptr<bytes> buffer = std::make_shared<bytes>(_msg.toBytes());
assert((*buffer)[0] == 0x22);
ba::async_write(m_socket, ba::buffer(*buffer), [=](boost::system::error_code ec, std::size_t length)
@ -445,7 +446,7 @@ void PeerSession::start()
{
RLPStream s;
prep(s);
s.appendList(m_server->m_public.port() ? 6 : 5) << HelloPacket << (uint)0 << (uint)0 << m_server->m_clientVersion << (m_server->m_mode == NodeMode::Full ? 0x07 : m_server->m_mode == NodeMode::PeerServer ? 0x01 : 0);
s.appendList(m_server->m_public.port() ? 6 : 5) << HelloPacket << (uint)1 << (uint)m_server->m_requiredNetworkId << m_server->m_clientVersion << (m_server->m_mode == NodeMode::Full ? 0x07 : m_server->m_mode == NodeMode::PeerServer ? 0x01 : 0);
if (m_server->m_public.port())
s << m_server->m_public.port();
sealAndSend(s);
@ -479,11 +480,11 @@ void PeerSession::doRead()
else
{
uint32_t len = fromBigEndian<uint32_t>(bytesConstRef(m_incoming.data() + 4, 4));
// cdebug << "Received packet of " << len << " bytes";
if (m_incoming.size() - 8 < len)
break;
// enough has come in.
// cerr << "Received " << len << ": " << asHex(bytesConstRef(m_incoming.data() + 8, len)) << endl;
RLP r(bytesConstRef(m_incoming.data() + 8, len));
if (!interpret(r))
// error
@ -494,6 +495,11 @@ void PeerSession::doRead()
}
doRead();
}
catch (Exception const& _e)
{
clogS(NetWarn) << "ERROR: " << _e.description();
dropped();
}
catch (std::exception const& _e)
{
clogS(NetWarn) << "ERROR: " << _e.what();
@ -862,7 +868,8 @@ bool PeerServer::process(BlockChain& _bc, TransactionQueue& _tq, Overlay& _o)
seal(b);
for (auto const& i: m_peers)
if (auto p = i.lock())
p->send(&b);
if (p->isOpen())
p->send(&b);
m_lastPeersRequest = chrono::steady_clock::now();
}

2
libethereum/PeerNetwork.h

@ -83,6 +83,8 @@ public:
void ping();
bool isOpen() const { return m_socket.is_open(); }
bi::tcp::endpoint endpoint() const; ///< for other peers to connect to.
private:

Loading…
Cancel
Save