Browse Source

Download view as will be.

Fixes.
cl-refactor
Gav Wood 11 years ago
parent
commit
b72d0717b4
  1. 40
      alethzero/DownloadView.cpp
  2. 49
      alethzero/DownloadView.h
  3. 39
      alethzero/Main.ui
  4. 2
      eth/main.cpp
  5. 17
      libethereum/EthereumHost.cpp
  6. 120
      libethereum/EthereumHost.h
  7. 4
      libethereum/EthereumPeer.cpp
  8. 1
      libethereum/Executive.cpp
  9. 1
      libevm/VM.h

40
alethzero/DownloadView.cpp

@ -0,0 +1,40 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file DownloadView.cpp
* @author Gav Wood <i@gavwood.com>
* @date 2014
*/
#include "DownloadView.h"
#include <QtWidgets>
#include <QtCore>
#include <libethereum/Client.h>
#include "Grapher.h"
using namespace std;
using namespace dev;
using namespace dev::eth;
DownloadView::DownloadView(QWidget* _p): QWidget(_p)
{
}
void DownloadView::paintEvent(QPaintEvent*)
{
QPainter p(this);
}

49
alethzero/DownloadView.h

@ -0,0 +1,49 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file DownloadView.h
* @author Gav Wood <i@gavwood.com>
* @date 2014
*/
#pragma once
#ifdef Q_MOC_RUN
#define BOOST_MPL_IF_HPP_INCLUDED
#endif
#include <list>
#include <QtWidgets/QWidget>
#ifndef Q_MOC_RUN
#include <libethereum/Client.h>
#endif
namespace dev { namespace eth {
struct MineInfo;
}}
class DownloadView: public QWidget
{
Q_OBJECT
public:
DownloadView(QWidget* _p = nullptr);
protected:
virtual void paintEvent(QPaintEvent*);
private:
};

39
alethzero/Main.ui

@ -1432,6 +1432,39 @@ font-size: 14pt</string>
</layout> </layout>
</widget> </widget>
</widget> </widget>
<widget class="QDockWidget" name="dockWidget_12">
<property name="features">
<set>QDockWidget::DockWidgetFeatureMask</set>
</property>
<property name="windowTitle">
<string>Blockchain Download</string>
</property>
<attribute name="dockWidgetArea">
<number>2</number>
</attribute>
<widget class="QWidget" name="dockWidgetContents_12">
<layout class="QHBoxLayout" name="horizontalLayout_8">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="DownloadView" name="downloadView" native="true"/>
</item>
</layout>
</widget>
</widget>
<action name="quit"> <action name="quit">
<property name="text"> <property name="text">
<string>&amp;Quit</string> <string>&amp;Quit</string>
@ -1712,6 +1745,12 @@ font-size: 14pt</string>
<header>MiningView.h</header> <header>MiningView.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
<customwidget>
<class>DownloadView</class>
<extends>QWidget</extends>
<header>DownloadView.h</header>
<container>1</container>
</customwidget>
</customwidgets> </customwidgets>
<tabstops> <tabstops>
<tabstop>destination</tabstop> <tabstop>destination</tabstop>

2
eth/main.cpp

@ -747,7 +747,7 @@ int main(int argc, char** argv)
c.startMining(); c.startMining();
while (true) while (true)
{ {
if (c.blockChain().details().number - n == mining) if (c.isMining() && c.blockChain().details().number - n == mining)
c.stopMining(); c.stopMining();
this_thread::sleep_for(chrono::milliseconds(100)); this_thread::sleep_for(chrono::milliseconds(100));
} }

17
libethereum/EthereumHost.cpp

@ -97,7 +97,6 @@ bool EthereumHost::ensureInitialised(TransactionQueue& _tq)
void EthereumHost::noteDoneBlocks() void EthereumHost::noteDoneBlocks()
{ {
clog(NetNote) << "Peer given up on blocks fetch.";
if (m_blocksOnWay.empty()) if (m_blocksOnWay.empty())
{ {
// Done our chain-get. // Done our chain-get.
@ -135,13 +134,15 @@ void EthereumHost::doWork()
void EthereumHost::maintainTransactions(TransactionQueue& _tq, h256 _currentHash) void EthereumHost::maintainTransactions(TransactionQueue& _tq, h256 _currentHash)
{ {
bool resendAll = (_currentHash != m_latestBlockSent); bool resendAll = (_currentHash != m_latestBlockSent);
{
for (auto it = m_incomingTransactions.begin(); it != m_incomingTransactions.end(); ++it) lock_guard<recursive_mutex> l(m_incomingLock);
if (_tq.import(&*it)) for (auto it = m_incomingTransactions.begin(); it != m_incomingTransactions.end(); ++it)
{}//ret = true; // just putting a transaction in the queue isn't enough to change the state - it might have an invalid nonce... if (_tq.import(&*it))
else {}//ret = true; // just putting a transaction in the queue isn't enough to change the state - it might have an invalid nonce...
m_transactionsSent.insert(sha3(*it)); // if we already had the transaction, then don't bother sending it on. else
m_incomingTransactions.clear(); m_transactionsSent.insert(sha3(*it)); // if we already had the transaction, then don't bother sending it on.
m_incomingTransactions.clear();
}
// Send any new transactions. // Send any new transactions.
for (auto const& p: peers()) for (auto const& p: peers())

120
libethereum/EthereumHost.h

@ -46,6 +46,126 @@ namespace eth
class TransactionQueue; class TransactionQueue;
class BlockQueue; class BlockQueue;
using UnsignedRange = std::pair<unsigned, unsigned>;
using UnsignedRanges = std::vector<UnsignedRange>;
class RangeMask
{
public:
RangeMask() {}
RangeMask(unsigned _begin, unsigned _end): m_ranges({{_begin, _end}}) {}
RangeMask& operator+=(RangeMask const& _m)
{
for (auto const& i: _m.m_ranges)
operator+=(i);
return *this;
}
RangeMask& operator+=(UnsignedRange const& _m)
{
for (auto i = _m.first; i < _m.second;)
{
// for each number, we find the element equal or next lower. this must contain the value.
auto it = m_ranges.lower_bound(i);
auto uit = m_ranges.upper_bound(i + 1);
if (it == m_ranges.end() || it->second < i)
// lower range is too low to merge.
// if the next higher range is too high.
if (uit == m_ranges.end() || uit->first > _m.second)
{
// just create a new range
m_ranges[i] = _m.second;
break;
}
else
{
if (uit->first == i)
// move i to end of range
i = uit->second;
else
{
// merge with the next higher range
// move i to end of range
i = m_ranges[i] = uit->second;
i = uit->second;
m_ranges.erase(uit);
}
}
else if (it->second == i)
{
// if the next higher range is too high.
if (uit == m_ranges.end() || uit->first > _m.second)
{
// merge with the next lower range
m_ranges[it->first] = _m.second;
break;
}
else
{
// merge with both next lower & next higher.
i = m_ranges[it->first] = uit->second;
m_ranges.erase(uit);
}
}
else
i = it->second;
}
return *this;
}
RangeMask& operator+=(unsigned _i)
{
return operator+=(UnsignedRange(_i, _i + 1));
}
bool contains(unsigned _i) const
{
auto it = m_ranges.lower_bound(_i);
return it != m_ranges.end() && it->first <= _i && it->second > _i;
}
private:
std::map<unsigned, unsigned> m_ranges;
};
#if 0
class DownloadSub
{
friend class DownloadMan;
public:
h256s nextFetch();
void noteBlock(h256 _hash, bytesConstRef _data);
private:
void resetFetch(); // Called by DownloadMan when we need to reset the download.
DownloadMan* m_man;
Mutex m_fetch;
h256s m_fetching;
h256s m_activeGet;
bool m_killFetch;
RangeMask m_attempted;
};
class DownloadMan
{
friend class DownloadSub;
public:
void resetToChain(h256s const& _chain);
private:
void cancelFetch(DownloadSub* );
void noteBlock(h256 _hash, bytesConstRef _data);
h256s m_chain;
RangeMask m_complete;
std::map<DownloadSub*, UnsignedRange> m_fetching;
};
#endif
/** /**
* @brief The EthereumHost class * @brief The EthereumHost class
* @warning None of this is thread-safe. You have been warned. * @warning None of this is thread-safe. You have been warned.

4
libethereum/EthereumPeer.cpp

@ -148,14 +148,17 @@ bool EthereumPeer::interpret(RLP const& _r)
break; break;
} }
case TransactionsPacket: case TransactionsPacket:
{
clogS(NetMessageSummary) << "Transactions (" << dec << (_r.itemCount() - 1) << "entries)"; clogS(NetMessageSummary) << "Transactions (" << dec << (_r.itemCount() - 1) << "entries)";
addRating(_r.itemCount() - 1); addRating(_r.itemCount() - 1);
lock_guard<recursive_mutex> l(host()->m_incomingLock);
for (unsigned i = 1; i < _r.itemCount(); ++i) for (unsigned i = 1; i < _r.itemCount(); ++i)
{ {
host()->m_incomingTransactions.push_back(_r[i].data().toBytes()); host()->m_incomingTransactions.push_back(_r[i].data().toBytes());
m_knownTransactions.insert(sha3(_r[i].data())); m_knownTransactions.insert(sha3(_r[i].data()));
} }
break; break;
}
case GetBlockHashesPacket: case GetBlockHashesPacket:
{ {
h256 later = _r[1].toHash<h256>(); h256 later = _r[1].toHash<h256>();
@ -306,6 +309,7 @@ void EthereumPeer::continueGettingChain()
} }
else else
{ {
if (m_failedBlocks.size())
clogS(NetMessageSummary) << "No blocks left to get. Peer doesn't seem to have" << m_failedBlocks.size() << "of our needed blocks."; clogS(NetMessageSummary) << "No blocks left to get. Peer doesn't seem to have" << m_failedBlocks.size() << "of our needed blocks.";
host()->noteDoneBlocks(); host()->noteDoneBlocks();
} }

1
libethereum/Executive.cpp

@ -187,6 +187,7 @@ bool Executive::go(OnOpFunc const& _onOp)
catch (VMException const& _e) catch (VMException const& _e)
{ {
clog(StateChat) << "VM Exception: " << _e.description(); clog(StateChat) << "VM Exception: " << _e.description();
m_endGas = m_vm->gas();
} }
catch (Exception const& _e) catch (Exception const& _e)
{ {

1
libevm/VM.h

@ -41,7 +41,6 @@ class BreakPointHit: public VMException {};
class BadInstruction: public VMException {}; class BadInstruction: public VMException {};
class OutOfGas: public VMException {}; class OutOfGas: public VMException {};
class StackTooSmall: public VMException { public: StackTooSmall(u256 _req, u256 _got): req(_req), got(_got) {} u256 req; u256 got; }; class StackTooSmall: public VMException { public: StackTooSmall(u256 _req, u256 _got): req(_req), got(_got) {} u256 req; u256 got; };
class OperandOutOfRange: public VMException { public: OperandOutOfRange(u256 _min, u256 _max, u256 _got): mn(_min), mx(_max), got(_got) {} u256 mn; u256 mx; u256 got; };
// Convert from a 256-bit integer stack/memory entry into a 160-bit Address hash. // Convert from a 256-bit integer stack/memory entry into a 160-bit Address hash.
// Currently we just pull out the right (low-order in BE) 160-bits. // Currently we just pull out the right (low-order in BE) 160-bits.

Loading…
Cancel
Save