diff --git a/alethzero/Main.ui b/alethzero/Main.ui
index f9e734c8b..3723e1e23 100644
--- a/alethzero/Main.ui
+++ b/alethzero/Main.ui
@@ -190,11 +190,33 @@
-
+
+
+ Monospace
+ 12
+
+
QFrame::NoFrame
+ -
+
+
+ 10
+
+
+ 4
+
+
+ Qt::Vertical
+
+
+ QSlider::TicksBothSides
+
+
+
@@ -249,7 +271,7 @@
349
- 225
+ 251
@@ -279,7 +301,7 @@
- -
+
-
Send
@@ -322,9 +344,6 @@
- -
-
-
-
@@ -341,6 +360,9 @@
+ -
+
+
-
@@ -348,9 +370,6 @@
- -
-
-
-
@@ -361,6 +380,9 @@
+ -
+
+
diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp
index d4949e74b..d3064f4d0 100644
--- a/alethzero/MainWin.cpp
+++ b/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())
diff --git a/alethzero/MainWin.h b/alethzero/MainWin.h
index 23a78c835..e3231609b 100644
--- a/alethzero/MainWin.h
+++ b/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(); }
diff --git a/libethereum/BlockInfo.cpp b/libethereum/BlockInfo.cpp
index fd4d6fb2b..700f72ffe 100644
--- a/libethereum/BlockInfo.cpp
+++ b/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();
- sha3Uncles = header[1].toHash();
- coinbaseAddress = header[2].toHash();
- stateRoot = header[3].toHash();
- sha3Transactions = header[4].toHash();
- difficulty = header[5].toInt();
- timestamp = header[6].toInt();
- extraData = header[7].toBytes();
- nonce = header[8].toInt();
+ parentHash = header[field = 0].toHash();
+ sha3Uncles = header[field = 1].toHash();
+ coinbaseAddress = header[field = 2].toHash();
+ stateRoot = header[field = 3].toHash();
+ sha3Transactions = header[field = 4].toHash();
+ difficulty = header[field = 5].toInt();
+ timestamp = header[field = 6].toInt();
+ extraData = header[field = 7].toBytes();
+ nonce = header[field = 8].toInt();
}
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();
diff --git a/libethereum/Common.cpp b/libethereum/Common.cpp
index c05662ef8..aa140d065 100644
--- a/libethereum/Common.cpp
+++ b/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 eth::g_logOverride;
thread_local std::string eth::t_logThreadName = "???";
static std::string g_mainThreadName = (eth::t_logThreadName = "main");
diff --git a/libethereum/Exceptions.h b/libethereum/Exceptions.h
index ee6ef8e5d..865e42d9d 100644
--- a/libethereum/Exceptions.h
+++ b/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 {};
diff --git a/libethereum/PeerNetwork.cpp b/libethereum/PeerNetwork.cpp
index 6336235b5..ecc2e6f72 100644
--- a/libethereum/PeerNetwork.cpp
+++ b/libethereum/PeerNetwork.cpp
@@ -40,7 +40,7 @@
using namespace std;
using namespace eth;
-#define clogS(X) eth::LogOutputStream(false) << " | " << std::setw(2) << m_socket.native_handle() << " ] "
+#define clogS(X) eth::LogOutputStream(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() : 0x07;
m_listenPort = _r.itemCount() > 5 ? _r[5].toInt() : 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 buffer = std::make_shared();
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 buffer = std::make_shared(_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(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();
}
diff --git a/libethereum/PeerNetwork.h b/libethereum/PeerNetwork.h
index f2a5bc84a..66d05e02a 100644
--- a/libethereum/PeerNetwork.h
+++ b/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: