Browse Source

Merge branch 'develop' into rpc_txReceipt2

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
f0893e71de
  1. 5
      alethzero/CMakeLists.txt
  2. 198
      alethzero/DownloadView.cpp
  3. 14
      alethzero/DownloadView.h
  4. 18
      alethzero/ExportState.cpp
  5. 14
      alethzero/Main.ui
  6. 21
      alethzero/MainWin.cpp
  7. 1
      alethzero/MainWin.h
  8. 3
      cmake/EthCompilerSettings.cmake
  9. 25
      eth/main.cpp
  10. 2
      exp/main.cpp
  11. 43
      libdevcore/Base64.cpp
  12. 2
      libdevcore/Common.cpp
  13. 6
      libdevcore/FixedHash.h
  14. 14
      libdevcore/RangeMask.h
  15. 162
      libdevcore/TrieDB.h
  16. 12
      libdevcrypto/Common.cpp
  17. 2
      libethash-cl/ethash_cl_miner.h
  18. 4
      libethcore/Ethash.cpp
  19. 62
      libethereum/BlockChain.cpp
  20. 3
      libethereum/BlockChain.h
  21. 15
      libethereum/BlockChainSync.cpp
  22. 6
      libethereum/BlockChainSync.h
  23. 4
      libethereum/BlockDetails.h
  24. 4
      libethereum/BlockQueue.cpp
  25. 2
      libethereum/Client.cpp
  26. 2
      libethereum/Client.h
  27. 4
      libethereum/ClientBase.cpp
  28. 2
      libethereum/ClientBase.h
  29. 10
      libethereum/DownloadMan.cpp
  30. 33
      libethereum/DownloadMan.h
  31. 51
      libethereum/EthereumHost.cpp
  32. 3
      libethereum/EthereumHost.h
  33. 20
      libethereum/ExtVM.cpp
  34. 3
      libethereum/Interface.cpp
  35. 2
      libethereum/Interface.h
  36. 32
      libethereum/State.cpp
  37. 21
      libethereum/TransactionQueue.cpp
  38. 63
      libethereum/TransactionQueue.h
  39. 4
      libweb3jsonrpc/AccountHolder.cpp
  40. 4
      libwhisper/BloomFilter.h
  41. 4
      libwhisper/Message.cpp
  42. 1
      libwhisper/Message.h
  43. 5
      mix/CMakeLists.txt
  44. 3
      mix/ClientModel.cpp
  45. 2
      mix/ClientModel.h
  46. 7
      mix/MixClient.cpp
  47. 7
      mix/MixClient.h
  48. 8
      neth/main.cpp
  49. 133
      test/fuzzTesting/fuzzHelper.cpp
  50. 40
      test/libdevcore/FixedHash.cpp
  51. 41
      test/libdevcore/core.cpp
  52. 2
      test/libdevcrypto/AES.cpp
  53. 277
      test/libethereum/BlockchainTestsFiller/bcBlockGasLimitTestFiller.json
  54. 5
      test/libethereum/blockchain.cpp

5
alethzero/CMakeLists.txt

@ -7,6 +7,11 @@ if (${CMAKE_MAJOR_VERSION} GREATER 2)
cmake_policy(SET CMP0043 OLD)
endif()
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
# Supress warnings for qt headers for clang+ccache
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-inconsistent-missing-override")
endif ()
set(CMAKE_INCLUDE_CURRENT_DIR ON)
aux_source_directory(. SRC_LIST)

198
alethzero/DownloadView.cpp

@ -30,56 +30,176 @@ using namespace std;
using namespace dev;
using namespace dev::eth;
DownloadView::DownloadView(QWidget* _p): QWidget(_p)
SyncView::SyncView(QWidget* _p): QWidget(_p)
{
}
void DownloadView::paintEvent(QPaintEvent*)
void SyncView::paintEvent(QPaintEvent*)
{
QPainter p(this);
QPainter painter(this);
painter.fillRect(rect(), Qt::white);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setRenderHint(QPainter::HighQualityAntialiasing, true);
p.fillRect(rect(), Qt::white);
if (!m_man || m_man->chainEmpty() || !m_man->subCount())
if (!m_client || !isVisible() || !rect().width() || !rect().height())
return;
double ratio = (double)rect().width() / rect().height();
if (ratio < 1)
ratio = 1 / ratio;
double n = min(16.0, min(rect().width(), rect().height()) / ceil(sqrt(m_man->chainSize() / ratio)));
DownloadMan const* man = m_client->downloadMan();
BlockQueueStatus bqs = m_client->blockQueueStatus();
SyncStatus sync = m_client->syncStatus();
// QSizeF area(rect().width() / floor(rect().width() / n), rect().height() / floor(rect().height() / n));
QSizeF area(n, n);
QPointF pos(0, 0);
unsigned syncFrom = m_client->numberFromHash(PendingBlockHash);
unsigned syncImported = syncFrom;
unsigned syncImporting = syncImported + bqs.importing;
unsigned syncVerified = syncImporting + bqs.verified;
unsigned syncVerifying = syncVerified + bqs.verifying;
unsigned syncUnverified = syncVerifying + bqs.unverified;
unsigned syncCount = syncUnverified + bqs.unknown - syncFrom;
auto bg = m_man->blocksGot();
unsigned subCount = m_man->subCount();
if (subCount == 0)
return;
unsigned dh = 360 / subCount;
for (unsigned i = bg.all().first, ei = bg.all().second; i < ei; ++i)
// best effort guess. assumes there's no forks.
unsigned downloadFrom = sync.state == SyncState::Idle ? m_lastSyncFrom : m_client->numberFromHash(m_client->isKnown(man->firstBlock()) ? man->firstBlock() : PendingBlockHash);
unsigned downloadCount = sync.state == SyncState::Idle ? m_lastSyncCount : sync.blocksTotal;
unsigned downloadDone = downloadFrom + (sync.state == SyncState::Idle ? m_lastSyncCount : sync.blocksReceived);
unsigned downloadPoint = downloadFrom + (sync.state == SyncState::Idle ? m_lastSyncCount : man->overview().lastComplete);
unsigned hashFrom = sync.state == SyncState::Hashes ? m_client->numberFromHash(PendingBlockHash) : downloadFrom;
unsigned hashCount = sync.state == SyncState::Hashes ? sync.hashesTotal : downloadCount;
unsigned hashDone = hashFrom + (sync.state == SyncState::Hashes ? sync.hashesReceived : hashCount);
QString labelText = QString("PV%1").arg(sync.protocolVersion);
QColor labelBack = QColor::fromHsv(sync.protocolVersion == 60 ? 30 : sync.protocolVersion == 61 ? 120 : 240, 25, 200);
QColor labelFore = labelBack.darker();
switch (sync.state)
{
int s = -2;
if (bg.contains(i))
s = -1;
else
case SyncState::Hashes:
if (!syncCount || !sync.hashesEstimated)
{
m_lastSyncFrom = min(hashFrom, m_lastSyncFrom);
m_lastSyncCount = max(hashFrom + hashCount, m_lastSyncFrom + m_lastSyncCount) - m_lastSyncFrom;
m_wasEstimate = sync.hashesEstimated;
}
break;
case SyncState::Blocks:
if (m_wasEstimate)
{
m_lastSyncFrom = downloadFrom;
m_lastSyncCount = downloadCount;
m_wasEstimate = false;
}
break;
case SyncState::Idle:
if (!syncCount)
{
unsigned h = 0;
m_man->foreachSub([&](DownloadSub const& sub)
{
if (sub.askedContains(i))
s = h;
h++;
});
m_lastSyncFrom = (unsigned)-1;
m_lastSyncCount = 0;
labelBack = QColor::fromHsv(0, 0, 200);
labelFore = Qt::white;
labelText = "Idle";
}
if (s == -2)
p.fillRect(QRectF(QPointF(pos) + QPointF(3 * area.width() / 8, 3 * area.height() / 8), area / 4), Qt::black);
else if (s == -1)
p.fillRect(QRectF(QPointF(pos) + QPointF(1 * area.width() / 8, 1 * area.height() / 8), area * 3 / 4), Qt::black);
else
p.fillRect(QRectF(QPointF(pos) + QPointF(1 * area.width() / 8, 1 * area.height() / 8), area * 3 / 4), QColor::fromHsv(s * dh, 64, 128));
pos.setX(pos.x() + n);
if (pos.x() >= rect().width() - n)
pos = QPoint(0, pos.y() + n);
default: break;
}
unsigned from = min(min(hashFrom, downloadFrom), min(syncFrom, m_lastSyncFrom));
unsigned count = max(max(hashFrom + hashCount, downloadFrom + downloadCount), max(syncFrom + syncCount, m_lastSyncFrom + m_lastSyncCount)) - from;
/* cnote << "Range " << from << "-" << (from + count) << "(" << hashFrom << "+" << hashCount << "," << downloadFrom << "+" << downloadCount << "," << syncFrom << "+" << syncCount << ")";
auto r = [&](unsigned u) {
return toString((u - from) * 100 / count) + "%";
};
if (count)
{
cnote << "Hashes:" << r(hashDone) << " Blocks:" << r(downloadFlank) << r(downloadDone) << r(downloadPoint);
cnote << "Importing:" << r(syncFrom) << r(syncImported) << r(syncImporting) << r(syncVerified) << r(syncVerifying) << r(syncUnverified);
}
*/
float const squareSize = min(rect().width(), rect().height());
auto middleRect = [&](float w, float h) {
return QRectF(rect().width() / 2 - w / 2, rect().height() / 2 - h / 2, w, h);
};
auto middle = [&](float x) {
return middleRect(squareSize * x, squareSize * x);
};
auto pieProgress = [&](unsigned h, unsigned s, unsigned v, float row, float thickness, unsigned nfrom, unsigned ncount) {
auto arcLen = [&](unsigned x) {
return x * -5760.f / count;
};
auto arcPos = [&](unsigned x) {
return int(90 * 16.f + arcLen(x - from)) % 5760;
};
painter.setPen(QPen(QColor::fromHsv(h, s, v), squareSize * thickness, Qt::SolidLine, Qt::FlatCap));
painter.setBrush(Qt::NoBrush);
painter.drawArc(middle(0.5 + row / 2), arcPos(nfrom), arcLen(ncount));
};
auto pieProgress2 = [&](unsigned h, unsigned s, unsigned v, float row, float orbit, float thickness, unsigned nfrom, unsigned ncount) {
pieProgress(h, s, v, row - orbit, thickness, nfrom, ncount);
pieProgress(h, s, v, row + orbit, thickness, nfrom, ncount);
};
auto pieLabel = [&](QString text, float points, QColor fore, QColor back) {
painter.setBrush(QBrush(back));
painter.setFont(QFont("Helvetica", points, QFont::Bold));
QRectF r = painter.boundingRect(middle(1.f), Qt::AlignCenter, text);
r.adjust(-r.width() / 4, -r.height() / 8, r.width() / 4, r.height() / 8);
painter.setPen(QPen(fore, r.height() / 20));
painter.drawRoundedRect(r, r.height() / 4, r.height() / 4);
painter.drawText(r, Qt::AlignCenter, text);
};
float lineHeight = painter.boundingRect(rect(), Qt::AlignTop | Qt::AlignHCenter, "Ay").height();
auto hProgress = [&](unsigned h, unsigned s, unsigned v, float row, float thickness, unsigned nfrom, unsigned ncount) {
QRectF r = rect();
painter.setPen(QPen(QColor::fromHsv(h, s, v), r.height() * thickness * 3, Qt::SolidLine, Qt::FlatCap));
painter.setBrush(Qt::NoBrush);
auto y = row * (r.height() - lineHeight) + lineHeight;
painter.drawLine(QPointF((nfrom - from) * r.width() / count, y), QPointF((nfrom + ncount - from) * r.width() / count, y));
};
auto hProgress2 = [&](unsigned h, unsigned s, unsigned v, float row, float orbit, float thickness, unsigned nfrom, unsigned ncount) {
hProgress(h, s, v, row - orbit * 3, thickness, nfrom, ncount);
hProgress(h, s, v, row + orbit * 3, thickness, nfrom, ncount);
};
auto hLabel = [&](QString text, float points, QColor fore, QColor back) {
painter.setBrush(QBrush(back));
painter.setFont(QFont("Helvetica", points, QFont::Bold));
QRectF r = painter.boundingRect(rect(), Qt::AlignTop | Qt::AlignHCenter, text);
r.adjust(-r.width() / 4, r.height() / 8, r.width() / 4, 3 * r.height() / 8);
painter.setPen(QPen(fore, r.height() / 20));
painter.drawRoundedRect(r, r.height() / 4, r.height() / 4);
painter.drawText(r, Qt::AlignCenter, text);
};
function<void(unsigned h, unsigned s, unsigned v, float row, float thickness, unsigned nfrom, unsigned ncount)> progress;
function<void(unsigned h, unsigned s, unsigned v, float row, float orbit, float thickness, unsigned nfrom, unsigned ncount)> progress2;
function<void(QString text, float points, QColor fore, QColor back)> label;
if (rect().width() / rect().height() > 5)
{
progress = hProgress;
progress2 = hProgress2;
label = hLabel;
}
else if (rect().height() / rect().width() > 5)
{
}
else
{
progress = pieProgress;
progress2 = pieProgress2;
label = pieLabel;
}
if (sync.state != SyncState::Idle)
{
progress(0, 0, 220, 0.4f, 0.02f, from, hashDone - from); // Download rail
progress(240, 25, 170, 0.4f, 0.02f, downloadDone, downloadPoint - downloadDone); // Latest download point
progress(240, 50, 120, 0.4f, 0.04f, from, downloadDone - from); // Downloaded
}
progress(0, 0, 220, 0.8f, 0.01f, from, count); // Sync rail
progress(0, 0, 170, 0.8f, 0.02f, from, syncUnverified - from); // Verification rail
progress2(60, 25, 170, 0.8f, 0.06f, 0.005f, from, syncVerifying - from); // Verifying.
progress2(120, 25, 170, 0.8f, 0.06f, 0.005f, from, syncVerified - from); // Verified.
progress(120, 50, 120, 0.8f, 0.05f, from, syncFrom - from); // Imported.
progress(0, 0, 120, 0.8f, 0.02f, syncFrom, syncImporting - syncFrom); // Importing.
if (sync.state != SyncState::Idle || (sync.state == SyncState::Idle && !syncCount))
label(labelText, 11, labelFore, labelBack);
}

14
alethzero/DownloadView.h

@ -32,21 +32,25 @@
#endif
namespace dev { namespace eth {
class DownloadMan;
class Client;
}}
class DownloadView: public QWidget
class SyncView: public QWidget
{
Q_OBJECT
public:
DownloadView(QWidget* _p = nullptr);
SyncView(QWidget* _p = nullptr);
void setDownloadMan(dev::eth::DownloadMan const* _man) { m_man = _man; }
void setEthereum(dev::eth::Client const* _c) { m_client = _c; }
protected:
virtual void paintEvent(QPaintEvent*);
private:
dev::eth::DownloadMan const* m_man = nullptr;
dev::eth::Client const* m_client = nullptr;
unsigned m_lastSyncFrom = (unsigned)-1;
unsigned m_lastSyncCount = 0;
bool m_wasEstimate = false;
};

18
alethzero/ExportState.cpp

@ -127,11 +127,21 @@ void ExportStateDialog::fillContracts()
ui->contracts->clear();
ui->accounts->setEnabled(true);
ui->contracts->setEnabled(true);
for (auto i: ethereum()->addresses(m_block))
try
{
string r = m_main->render(i);
(new QListWidgetItem(QString("%2: %1 [%3]").arg(formatBalance(ethereum()->balanceAt(i)).c_str()).arg(QString::fromStdString(r)).arg((unsigned)ethereum()->countAt(i)), ethereum()->codeAt(i).empty() ? ui->accounts : ui->contracts))
->setData(Qt::UserRole, QByteArray((char const*)i.data(), Address::size));
for (auto i: ethereum()->addresses(m_block))
{
string r = m_main->render(i);
(new QListWidgetItem(QString("%2: %1 [%3]").arg(formatBalance(ethereum()->balanceAt(i)).c_str()).arg(QString::fromStdString(r)).arg((unsigned)ethereum()->countAt(i)), ethereum()->codeAt(i).empty() ? ui->accounts : ui->contracts))
->setData(Qt::UserRole, QByteArray((char const*)i.data(), Address::size));
}
}
catch (InterfaceNotSupported const&)
{
ui->accounts->setEnabled(false);
ui->contracts->setEnabled(false);
ui->json->setEnabled(false);
ui->json->setText(QString("This feature requires compilation with FATDB support."));
}
}

14
alethzero/Main.ui

@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
<string>AlethZero Ethereum Client</string>
<string>AlethZero ++Ethereum</string>
</property>
<property name="dockNestingEnabled">
<bool>true</bool>
@ -132,7 +132,7 @@
<x>0</x>
<y>0</y>
<width>1617</width>
<height>25</height>
<height>24</height>
</rect>
</property>
<widget class="QMenu" name="menu_File">
@ -199,6 +199,7 @@
<addaction name="usePrivate"/>
<addaction name="retryUnknown"/>
<addaction name="confirm"/>
<addaction name="rewindChain"/>
</widget>
<widget class="QMenu" name="menu_View">
<property name="title">
@ -1149,7 +1150,7 @@ font-size: 14pt</string>
<number>0</number>
</property>
<item>
<widget class="DownloadView" name="downloadView" native="true"/>
<widget class="SyncView" name="downloadView" native="true"/>
</item>
</layout>
</widget>
@ -1804,6 +1805,11 @@ font-size: 14pt</string>
<string>&amp;Sentinel...</string>
</property>
</action>
<action name="rewindChain">
<property name="text">
<string>&amp;Rewind Chain...</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
@ -1814,7 +1820,7 @@ font-size: 14pt</string>
<container>1</container>
</customwidget>
<customwidget>
<class>DownloadView</class>
<class>SyncView</class>
<extends>QWidget</extends>
<header>DownloadView.h</header>
<container>1</container>

21
alethzero/MainWin.cpp

@ -136,6 +136,12 @@ Main::Main(QWidget *parent) :
QtWebEngine::initialize();
setWindowFlags(Qt::Window);
ui->setupUi(this);
if (c_network == eth::Network::Olympic)
setWindowTitle("AlethZero Olympic");
else if (c_network == eth::Network::Frontier)
setWindowTitle("AlethZero Frontier");
g_logPost = [=](string const& s, char const* c)
{
simpleDebugOut(s, c);
@ -1038,6 +1044,17 @@ void Main::on_vmInterpreter_triggered() { VMFactory::setKind(VMKind::Interpreter
void Main::on_vmJIT_triggered() { VMFactory::setKind(VMKind::JIT); }
void Main::on_vmSmart_triggered() { VMFactory::setKind(VMKind::Smart); }
void Main::on_rewindChain_triggered()
{
bool ok;
int n = QInputDialog::getInt(this, "Rewind Chain", "Enter the number of the new chain head.", ethereum()->number() * 9 / 10, 1, ethereum()->number(), 1, &ok);
if (ok)
{
ethereum()->rewind(n);
refreshAll();
}
}
void Main::on_urlEdit_returnPressed()
{
QString s = ui->urlEdit->text();
@ -1987,12 +2004,12 @@ void Main::on_net_triggered()
web3()->setNetworkPreferences(netPrefs(), ui->dropPeers->isChecked());
ethereum()->setNetworkId(m_privateChain.size() ? sha3(m_privateChain.toStdString()) : h256());
web3()->startNetwork();
ui->downloadView->setDownloadMan(ethereum()->downloadMan());
ui->downloadView->setEthereum(ethereum());
ui->enode->setText(QString::fromStdString(web3()->enode()));
}
else
{
ui->downloadView->setDownloadMan(nullptr);
ui->downloadView->setEthereum(nullptr);
writeSettings();
web3()->stopNetwork();
}

1
alethzero/MainWin.h

@ -187,6 +187,7 @@ private slots:
void on_vmInterpreter_triggered();
void on_vmJIT_triggered();
void on_vmSmart_triggered();
void on_rewindChain_triggered();
// Debugger
void on_debugCurrent_triggered();

3
cmake/EthCompilerSettings.cmake

@ -49,7 +49,8 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4221")
# warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/SAFESEH' specification
# warning LNK4099: pdb was not found with lib
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ignore:4099,4075")
# stack size 16MB
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ignore:4099,4075 /STACK:16777216")
# windows likes static
if (NOT ETH_STATIC)

25
eth/main.cpp

@ -75,12 +75,8 @@ void interactiveHelp()
<< "Commands:" << endl
<< " netstart <port> Starts the network subsystem on a specific port." << endl
<< " netstop Stops the network subsystem." << endl
<< " jsonstart <port> Starts the JSON-RPC server." << endl
<< " jsonstop Stops the JSON-RPC server." << endl
<< " connect <addr> <port> Connects to a specific peer." << endl
<< " verbosity (<level>) Gets or sets verbosity level." << endl
<< " setetherprice <p> Resets the ether price." << endl
<< " setpriority <p> Resets the transaction priority." << endl
<< " minestart Starts mining." << endl
<< " minestop Stops mining." << endl
<< " mineforce <enable> Forces mining, even when there are no transactions." << endl
@ -1026,9 +1022,7 @@ void interactiveMode(eth::Client* c, std::shared_ptr<eth::TrivialGasPricer> gasP
{
string path;
iss >> path;
RLPStream config(2);
config << signingKey << beneficiary;
writeFile(path, config.out());
writeFile(path, rlpList(signingKey, beneficiary));
}
else
cwarn << "Require parameter: exportConfig PATH";
@ -1471,17 +1465,22 @@ int main(int argc, char** argv)
}
}
if (g_logVerbosity > 0)
{
cout << EthGrayBold "(++)Ethereum" EthReset << endl;
if (c_network == eth::Network::Olympic)
cout << "Welcome to Olympic!" << endl;
else if (c_network == eth::Network::Frontier)
cout << "Welcome to the " EthMaroonBold "Frontier" EthReset "!" << endl;
}
m.execute();
KeyManager keyManager;
for (auto const& s: passwordsToNote)
keyManager.notePassword(s);
{
RLPStream config(2);
config << signingKey << beneficiary;
writeFile(configFile, config.out());
}
writeFile(configFile, rlpList(signingKey, beneficiary));
if (sessionKey)
signingKey = sessionKey;
@ -1703,7 +1702,7 @@ int main(int argc, char** argv)
cout << "Transaction Signer: " << signingKey << endl;
cout << "Mining Benefactor: " << beneficiary << endl;
if (bootstrap || !remoteHost.empty())
if (bootstrap || !remoteHost.empty() || disableDiscovery)
{
web3.startNetwork();
cout << "Node ID: " << web3.enode() << endl;

2
exp/main.cpp

@ -135,7 +135,7 @@ int main()
DownloadSub s0(man);
DownloadSub s1(man);
DownloadSub s2(man);
man.resetToChain(h256s({u256(0), u256(1), u256(2), u256(3), u256(4), u256(5), u256(6), u256(7), u256(8)}));
man.resetToChain(h256s({u256(0), u256(1), u256(2), u256(3), u256(4), u256(5), u256(6), u256(7), u256(8)}), 0);
assert((s0.nextFetch(2) == h256Set{(u256)7, (u256)8}));
assert((s1.nextFetch(2) == h256Set{(u256)5, (u256)6}));
assert((s2.nextFetch(2) == h256Set{(u256)3, (u256)4}));

43
libdevcore/Base64.cpp

@ -27,6 +27,8 @@
/// Originally by René Nyffenegger, modified by some other guy and then devified by Gav Wood.
#include "Base64.h"
using namespace std;
using namespace dev;
static inline bool is_base64(byte c)
@ -44,14 +46,14 @@ static inline byte find_base64_char_index(byte c)
else return 1 + find_base64_char_index('/');
}
std::string dev::toBase64(bytesConstRef _in)
string dev::toBase64(bytesConstRef _in)
{
static const char base64_chars[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
std::string ret;
string ret;
int i = 0;
int j = 0;
byte char_array_3[3];
@ -60,15 +62,17 @@ std::string dev::toBase64(bytesConstRef _in)
auto buf = _in.data();
auto bufLen = _in.size();
while (bufLen--) {
while (bufLen--)
{
char_array_3[i++] = *(buf++);
if (i == 3) {
if (i == 3)
{
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
char_array_4[3] = char_array_3[2] & 0x3f;
for(i = 0; (i <4) ; i++)
for (i = 0; i < 4; i++)
ret += base64_chars[char_array_4[i]];
i = 0;
}
@ -76,7 +80,7 @@ std::string dev::toBase64(bytesConstRef _in)
if (i)
{
for(j = i; j < 3; j++)
for (j = i; j < 3; j++)
char_array_3[j] = '\0';
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
@ -84,28 +88,31 @@ std::string dev::toBase64(bytesConstRef _in)
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
char_array_4[3] = char_array_3[2] & 0x3f;
for (j = 0; (j < i + 1); j++)
for (j = 0; j < i + 1; j++)
ret += base64_chars[char_array_4[j]];
while((i++ < 3))
while (i++ < 3)
ret += '=';
}
return ret;
}
bytes dev::fromBase64(std::string const& encoded_string)
bytes dev::fromBase64(string const& encoded_string)
{
auto in_len = encoded_string.size();
int i = 0;
int j = 0;
int in_ = 0;
byte char_array_4[4], char_array_3[3];
byte char_array_3[3];
byte char_array_4[4];
bytes ret;
while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
while (in_len-- && encoded_string[in_] != '=' && is_base64(encoded_string[in_]))
{
char_array_4[i++] = encoded_string[in_]; in_++;
if (i == 4) {
if (i == 4)
{
for (i = 0; i < 4; i++)
char_array_4[i] = find_base64_char_index(char_array_4[i]);
@ -119,7 +126,8 @@ bytes dev::fromBase64(std::string const& encoded_string)
}
}
if (i) {
if (i)
{
for (j = i; j < 4; j++)
char_array_4[j] = 0;
@ -130,7 +138,8 @@ bytes dev::fromBase64(std::string const& encoded_string)
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
for (j = 0; (j < i - 1); j++) ret.push_back(char_array_3[j]);
for (j = 0; j < i - 1; j++)
ret.push_back(char_array_3[j]);
}
return ret;

2
libdevcore/Common.cpp

@ -28,7 +28,7 @@ using namespace dev;
namespace dev
{
char const* Version = "0.9.28";
char const* Version = "0.9.29";
const u256 UndefinedU256 = ~(u256)0;

6
libdevcore/FixedHash.h

@ -24,6 +24,7 @@
#pragma once
#include <array>
#include <cstdint>
#include <random>
#include <algorithm>
#include "CommonData.h"
@ -81,7 +82,7 @@ public:
explicit FixedHash(byte const* _bs, ConstructFromPointerType) { memcpy(m_data.data(), _bs, N); }
/// Explicitly construct, copying from a string.
explicit FixedHash(std::string const& _s, ConstructFromStringType _t = FromHex, ConstructFromHashType _ht = FailIfDifferent): FixedHash(_t == FromHex ? fromHex(_s) : dev::asBytes(_s), _ht) {}
explicit FixedHash(std::string const& _s, ConstructFromStringType _t = FromHex, ConstructFromHashType _ht = FailIfDifferent): FixedHash(_t == FromHex ? fromHex(_s, WhenError::Throw) : dev::asBytes(_s), _ht) {}
/// Convert to arithmetic type.
operator Arith() const { return fromBigEndian<Arith>(m_data); }
@ -105,6 +106,7 @@ public:
FixedHash& operator&=(FixedHash const& _c) { for (unsigned i = 0; i < N; ++i) m_data[i] &= _c.m_data[i]; return *this; }
FixedHash operator&(FixedHash const& _c) const { return FixedHash(*this) &= _c; }
FixedHash operator~() const { FixedHash ret; for (unsigned i = 0; i < N; ++i) ret[i] = ~m_data[i]; return ret; }
FixedHash& operator++() { for (unsigned i = size; i > 0 && !++m_data[--i]; ) {} return *this; }
/// @returns true if all one-bits in @a _c are set in this object.
bool contains(FixedHash const& _c) const { return (*this & _c) == _c; }
@ -150,7 +152,7 @@ public:
{
FixedHash ret;
for (auto& i: ret.m_data)
i = std::uniform_int_distribution<uint16_t>(0, 255)(_eng);
i = (uint8_t)std::uniform_int_distribution<uint16_t>(0, 255)(_eng);
return ret;
}

14
libdevcore/RangeMask.h

@ -200,6 +200,20 @@ public:
return c;
}
size_t firstOut() const
{
if (m_ranges.empty() || !m_ranges.count(m_all.first))
return m_all.first;
return m_ranges.at(m_all.first);
}
size_t lastIn() const
{
if (m_ranges.empty())
return m_all.first;
return m_ranges.rbegin()->second - 1;
}
private:
/// The ground range.
UnsignedRange m_all;

162
libdevcore/TrieDB.h

@ -66,7 +66,7 @@ class GenericTrieDB
public:
using DB = _DB;
GenericTrieDB(DB* _db = nullptr): m_db(_db) {}
explicit GenericTrieDB(DB* _db = nullptr): m_db(_db) {}
GenericTrieDB(DB* _db, h256 const& _root, Verification _v = Verification::Normal) { open(_db, _root, _v); }
~GenericTrieDB() {}
@ -96,11 +96,72 @@ public:
/// True if the trie is initialised but empty (i.e. that the DB contains the root node which is empty).
bool isEmpty() const { return m_root == c_shaNull && node(m_root).size(); }
h256 const& root() const { if (!node(m_root).size()) BOOST_THROW_EXCEPTION(BadRoot()); /*std::cout << "Returning root as " << ret << " (really " << m_root << ")" << std::endl;*/ return m_root; } // patch the root in the case of the empty trie. TODO: handle this properly.
h256 const& root() const { if (node(m_root).empty()) BOOST_THROW_EXCEPTION(BadRoot()); /*std::cout << "Returning root as " << ret << " (really " << m_root << ")" << std::endl;*/ return m_root; } // patch the root in the case of the empty trie. TODO: handle this properly.
std::string at(bytes const& _key) const { return at(&_key); }
std::string at(bytesConstRef _key) const;
void insert(bytes const& _key, bytes const& _value) { insert(&_key, &_value); }
void insert(bytesConstRef _key, bytes const& _value) { insert(_key, &_value); }
void insert(bytes const& _key, bytesConstRef _value) { insert(&_key, _value); }
void insert(bytesConstRef _key, bytesConstRef _value);
void remove(bytes const& _key) { remove(&_key); }
void remove(bytesConstRef _key);
bool contains(bytes const& _key) { return contains(&_key); }
bool contains(bytesConstRef _key) { return !at(_key).empty(); }
class iterator
{
public:
using value_type = std::pair<bytesConstRef, bytesConstRef>;
iterator() {}
explicit iterator(GenericTrieDB const* _db);
iterator(GenericTrieDB const* _db, bytesConstRef _key);
iterator& operator++() { next(); return *this; }
value_type operator*() const { return at(); }
value_type operator->() const { return at(); }
bool operator==(iterator const& _c) const { return _c.m_trail == m_trail; }
bool operator!=(iterator const& _c) const { return _c.m_trail != m_trail; }
value_type at() const;
private:
void next();
void next(NibbleSlice _key);
struct Node
{
std::string rlp;
std::string key; // as hexPrefixEncoding.
byte child; // 255 -> entering, 16 -> actually at the node, 17 -> exiting, 0-15 -> actual children.
// 255 -> 16 -> 0 -> 1 -> ... -> 15 -> 17
void setChild(unsigned _i) { child = _i; }
void setFirstChild() { child = 16; }
void incrementChild() { child = child == 16 ? 0 : child == 15 ? 17 : (child + 1); }
bool operator==(Node const& _c) const { return rlp == _c.rlp && key == _c.key && child == _c.child; }
bool operator!=(Node const& _c) const { return !operator==(_c); }
};
protected:
std::vector<Node> m_trail;
GenericTrieDB<DB> const* m_that;
};
iterator begin() const { return iterator(this); }
iterator end() const { return iterator(); }
iterator lower_bound(bytesConstRef _key) const { return iterator(this, _key); }
void debugPrint() {}
void descendKey(h256 _k, h256Hash& _keyMask, bool _wasExt, std::ostream* _out, int _indent = 0) const
/// Used for debugging, scans the whole trie.
void descendKey(h256 const& _k, h256Hash& _keyMask, bool _wasExt, std::ostream* _out, int _indent = 0) const
{
_keyMask.erase(_k);
if (_k == m_root && _k == c_shaNull) // root allowed to be empty
@ -108,6 +169,7 @@ public:
descendList(RLP(node(_k)), _keyMask, _wasExt, _out, _indent); // if not, it must be a list
}
/// Used for debugging, scans the whole trie.
void descendEntry(RLP const& _r, h256Hash& _keyMask, bool _wasExt, std::ostream* _out, int _indent) const
{
if (_r.isData() && _r.size() == 32)
@ -118,6 +180,7 @@ public:
BOOST_THROW_EXCEPTION(InvalidTrie());
}
/// Used for debugging, scans the whole trie.
void descendList(RLP const& _r, h256Hash& _keyMask, bool _wasExt, std::ostream* _out, int _indent) const
{
if (_r.isList() && _r.itemCount() == 2 && (!_wasExt || _out))
@ -139,6 +202,7 @@ public:
BOOST_THROW_EXCEPTION(InvalidTrie());
}
/// Used for debugging, scans the whole trie.
h256Hash leftOvers(std::ostream* _out = nullptr) const
{
h256Hash k = m_db->keys();
@ -146,11 +210,14 @@ public:
return k;
}
/// Used for debugging, scans the whole trie.
void debugStructure(std::ostream& _out) const
{
leftOvers(&_out);
}
/// Used for debugging, scans the whole trie.
/// @param _requireNoLeftOvers if true, requires that all keys are reachable.
bool check(bool _requireNoLeftOvers) const
{
try
@ -164,66 +231,6 @@ public:
}
}
std::string at(bytes const& _key) const { return at(&_key); }
std::string at(bytesConstRef _key) const;
void insert(bytes const& _key, bytes const& _value) { insert(&_key, &_value); }
void insert(bytesConstRef _key, bytes const& _value) { insert(_key, &_value); }
void insert(bytes const& _key, bytesConstRef _value) { insert(&_key, _value); }
void insert(bytesConstRef _key, bytesConstRef _value);
void remove(bytes const& _key) { remove(&_key); }
void remove(bytesConstRef _key);
bool contains(bytes const& _key) { return contains(&_key); }
bool contains(bytesConstRef _key) { return !at(_key).empty(); }
class iterator
{
public:
using value_type = std::pair<bytesConstRef, bytesConstRef>;
iterator() {}
iterator(GenericTrieDB const* _db);
iterator(GenericTrieDB const* _db, bytesConstRef _key);
iterator& operator++() { next(); return *this; }
value_type operator*() const { return at(); }
value_type operator->() const { return at(); }
bool operator==(iterator const& _c) const { return _c.m_trail == m_trail; }
bool operator!=(iterator const& _c) const { return _c.m_trail != m_trail; }
value_type at() const;
private:
void next();
void next(NibbleSlice _key);
struct Node
{
std::string rlp;
std::string key; // as hexPrefixEncoding.
byte child; // 255 -> entering, 16 -> actually at the node, 17 -> exiting, 0-15 -> actual children.
// 255 -> 16 -> 0 -> 1 -> ... -> 15 -> 17
void setChild(unsigned _i) { child = _i; }
void setFirstChild() { child = 16; }
void incrementChild() { child = child == 16 ? 0 : child == 15 ? 17 : (child + 1); }
bool operator==(Node const& _c) const { return rlp == _c.rlp && key == _c.key && child == _c.child; }
bool operator!=(Node const& _c) const { return !operator==(_c); }
};
protected:
std::vector<Node> m_trail;
GenericTrieDB<DB> const* m_that;
};
iterator begin() const { return this; }
iterator end() const { return iterator(); }
iterator lower_bound(bytesConstRef _key) const { return iterator(this, _key); }
protected:
DB* db() const { return m_db; }
@ -279,12 +286,12 @@ private:
bool isTwoItemNode(RLP const& _n) const;
std::string deref(RLP const& _n) const;
std::string node(h256 _h) const { return m_db->lookup(_h); }
std::string node(h256 const& _h) const { return m_db->lookup(_h); }
// These are low-level node insertion functions that just go straight through into the DB.
h256 forceInsertNode(bytesConstRef _v) { auto h = sha3(_v); forceInsertNode(h, _v); return h; }
void forceInsertNode(h256 _h, bytesConstRef _v) { m_db->insert(_h, _v); }
void forceKillNode(h256 _h) { m_db->kill(_h); }
void forceInsertNode(h256 const& _h, bytesConstRef _v) { m_db->insert(_h, _v); }
void forceKillNode(h256 const& _h) { m_db->kill(_h); }
// This are semantically-aware node insertion functions that only kills when the node's
// data is < 32 bytes. It can safely be used when pruning the trie but won't work correctly
@ -305,6 +312,9 @@ std::ostream& operator<<(std::ostream& _out, GenericTrieDB<DB> const& _db)
return _out;
}
/**
* Different view on a GenericTrieDB that can use different key types.
*/
template <class Generic, class _KeyType>
class SpecificTrieDB: public Generic
{
@ -753,14 +763,14 @@ template <class DB> void GenericTrieDB<DB>::insert(bytesConstRef _key, bytesCons
tdebug << "Insert" << toHex(_key.cropped(0, 4)) << "=>" << toHex(_value);
#endif
std::string rv = node(m_root);
assert(rv.size());
bytes b = mergeAt(RLP(rv), m_root, NibbleSlice(_key), _value);
std::string rootValue = node(m_root);
assert(rootValue.size());
bytes b = mergeAt(RLP(rootValue), m_root, NibbleSlice(_key), _value);
// mergeAt won't attempt to delete the node if it's less than 32 bytes
// However, we know it's the root node and thus always hashed.
// So, if it's less than 32 (and thus should have been deleted but wasn't) then we delete it here.
if (rv.size() < 32)
if (rootValue.size() < 32)
forceKillNode(m_root);
m_root = forceInsertNode(&b);
}
@ -1066,11 +1076,11 @@ template <class DB> bytes GenericTrieDB<DB>::place(RLP const& _orig, NibbleSlice
killNode(_orig);
if (_orig.isEmpty())
return (RLPStream(2) << hexPrefixEncode(_k, true) << _s).out();
return rlpList(hexPrefixEncode(_k, true), _s);
assert(_orig.isList() && (_orig.itemCount() == 2 || _orig.itemCount() == 17));
if (_orig.itemCount() == 2)
return (RLPStream(2) << _orig[0] << _s).out();
return rlpList(_orig[0], _s);
auto s = RLPStream(17);
for (unsigned i = 0; i < 16; ++i)
@ -1152,7 +1162,7 @@ template <class DB> bytes GenericTrieDB<DB>::graft(RLP const& _orig)
}
assert(n.itemCount() == 2);
return (RLPStream(2) << hexPrefixEncode(keyOf(_orig), keyOf(n), isLeaf(n)) << n[1]).out();
return rlpList(hexPrefixEncode(keyOf(_orig), keyOf(n), isLeaf(n)), n[1]);
// auto ret =
// std::cout << keyOf(_orig) << " ++ " << keyOf(n) << " == " << keyOf(RLP(ret)) << std::endl;
// return ret;
@ -1201,11 +1211,7 @@ template <class DB> bytes GenericTrieDB<DB>::branch(RLP const& _orig)
for (unsigned i = 0; i < 16; ++i)
if (i == b)
if (isLeaf(_orig) || k.size() > 1)
{
RLPStream bottom(2);
bottom << hexPrefixEncode(k.mid(1), isLeaf(_orig)) << _orig[1];
streamNode(r, bottom.out());
}
streamNode(r, rlpList(hexPrefixEncode(k.mid(1), isLeaf(_orig)), _orig[1]));
else
r << _orig[1];
else

12
libdevcrypto/Common.cpp

@ -22,6 +22,7 @@
#include "Common.h"
#include <random>
#include <cstdint>
#include <chrono>
#include <thread>
#include <mutex>
@ -262,16 +263,9 @@ bytes dev::scrypt(std::string const& _pass, bytes const& _salt, uint64_t _n, uin
KeyPair KeyPair::create()
{
static boost::thread_specific_ptr<mt19937_64> 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<uint16_t> 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;
}
@ -353,7 +347,7 @@ void Nonce::initialiseIfNeeded()
std::mt19937_64 s_eng(time(0) + chrono::high_resolution_clock::now().time_since_epoch().count());
std::uniform_int_distribution<uint16_t> d(0, 255);
for (unsigned i = 0; i < 32; ++i)
m_value[i] = byte(d(s_eng));
m_value[i] = (uint8_t)d(s_eng);
}
if (!m_value)
BOOST_THROW_EXCEPTION(InvalidState());

2
libethash-cl/ethash_cl_miner.h

@ -20,7 +20,7 @@
class ethash_cl_miner
{
private:
enum { c_maxSearchResults = 63, c_bufferCount = 2, c_hashBatchSize = 1024, c_searchBatchSize = 1024 * 16 };
enum { c_maxSearchResults = 63, c_bufferCount = 2, c_hashBatchSize = 1024 };
public:
struct search_hook

4
libethcore/Ethash.cpp

@ -55,8 +55,8 @@ namespace eth
{
const unsigned Ethash::defaultLocalWorkSize = 64;
const unsigned Ethash::defaultGlobalWorkSizeMultiplier = 512; // * CL_DEFAULT_LOCAL_WORK_SIZE
const unsigned Ethash::defaultMSPerBatch = 100;
const unsigned Ethash::defaultGlobalWorkSizeMultiplier = 4096; // * CL_DEFAULT_LOCAL_WORK_SIZE
const unsigned Ethash::defaultMSPerBatch = 0;
const Ethash::WorkPackage Ethash::NullWorkPackage = Ethash::WorkPackage();
std::string Ethash::name()

62
libethereum/BlockChain.cpp

@ -273,7 +273,7 @@ void BlockChain::rebuild(std::string const& _path, std::function<void(unsigned,
h256 lastHash = m_lastBlockHash;
Timer t;
for (unsigned d = 1; d < originalNumber; ++d)
for (unsigned d = 1; d <= originalNumber; ++d)
{
if (!(d % 1000))
{
@ -799,6 +799,25 @@ void BlockChain::clearBlockBlooms(unsigned _begin, unsigned _end)
}
}
void BlockChain::rewind(unsigned _newHead)
{
DEV_WRITE_GUARDED(x_lastBlockHash)
{
if (_newHead >= m_lastBlockNumber)
return;
m_lastBlockHash = numberHash(_newHead);
m_lastBlockNumber = _newHead;
auto o = m_extrasDB->Put(m_writeOptions, ldb::Slice("best"), ldb::Slice((char const*)&m_lastBlockHash, 32));
if (!o.ok())
{
cwarn << "Error writing to extras database: " << o.ToString();
cout << "Put" << toHex(bytesConstRef(ldb::Slice("best"))) << "=>" << toHex(bytesConstRef(ldb::Slice((char const*)&m_lastBlockHash, 32)));
cwarn << "Fail writing to extras database. Bombing out.";
exit(-1);
}
}
}
tuple<h256s, h256, unsigned> BlockChain::treeRoute(h256 const& _from, h256 const& _to, bool _common, bool _pre, bool _post) const
{
// cdebug << "treeRoute" << _from << "..." << _to;
@ -871,33 +890,21 @@ template <class T> static unsigned getHashSize(unordered_map<h256, T> const& _ma
void BlockChain::updateStats() const
{
{
ReadGuard l(x_blocks);
m_lastStats.memBlocks = 0;
m_lastStats.memBlocks = 0;
DEV_READ_GUARDED(x_blocks)
for (auto const& i: m_blocks)
m_lastStats.memBlocks += i.second.size() + 64;
}
{
ReadGuard l(x_details);
DEV_READ_GUARDED(x_details)
m_lastStats.memDetails = getHashSize(m_details);
}
{
ReadGuard l1(x_logBlooms);
ReadGuard l2(x_blocksBlooms);
m_lastStats.memLogBlooms = getHashSize(m_logBlooms) + getHashSize(m_blocksBlooms);
}
{
ReadGuard l(x_receipts);
DEV_READ_GUARDED(x_logBlooms)
DEV_READ_GUARDED(x_blocksBlooms)
m_lastStats.memLogBlooms = getHashSize(m_logBlooms) + getHashSize(m_blocksBlooms);
DEV_READ_GUARDED(x_receipts)
m_lastStats.memReceipts = getHashSize(m_receipts);
}
{
ReadGuard l(x_blockHashes);
DEV_READ_GUARDED(x_blockHashes)
m_lastStats.memBlockHashes = getHashSize(m_blockHashes);
}
{
ReadGuard l(x_transactionAddresses);
DEV_READ_GUARDED(x_transactionAddresses)
m_lastStats.memTransactionAddresses = getHashSize(m_transactionAddresses);
}
}
void BlockChain::garbageCollect(bool _force)
@ -954,10 +961,8 @@ void BlockChain::garbageCollect(bool _force)
void BlockChain::checkConsistency()
{
{
WriteGuard l(x_details);
DEV_WRITE_GUARDED(x_details)
m_details.clear();
}
ldb::Iterator* it = m_blocksDB->NewIterator(m_readOptions);
for (it->SeekToFirst(); it->Valid(); it->Next())
if (it->key().size() == 32)
@ -969,13 +974,9 @@ void BlockChain::checkConsistency()
{
auto dp = details(p);
if (asserts(contains(dp.children, h)))
{
cnote << "Apparently the database is corrupt. Not much we can do at this stage...";
}
if (assertsEqual(dp.number, dh.number - 1))
{
cnote << "Apparently the database is corrupt. Not much we can do at this stage...";
}
}
}
delete it;
@ -1088,7 +1089,8 @@ bool BlockChain::isKnown(h256 const& _hash) const
if (d.empty())
return false;
}
return true;
// return true;
return details(_hash).number <= m_lastBlockNumber; // to allow rewind functionality.
}
bytes BlockChain::block(h256 const& _hash) const

3
libethereum/BlockChain.h

@ -218,6 +218,9 @@ public:
/// Will call _progress with the progress in this operation first param done, second total.
void rebuild(std::string const& _path, ProgressCallback const& _progress = std::function<void(unsigned, unsigned)>(), bool _prepPoW = false);
/// Alter the head of the chain to some prior block along it.
void rewind(unsigned _newHead);
/** @returns a tuple of:
* - an vector of hashes of all blocks between @a _from and @a _to, all blocks are ordered first by a number of
* blocks that are parent-to-child, then two sibling blocks, then a number of blocks that are child-to-parent;

15
libethereum/BlockChainSync.cpp

@ -80,7 +80,7 @@ DownloadMan& BlockChainSync::downloadMan()
void BlockChainSync::abortSync()
{
downloadMan().resetToChain(h256s());
downloadMan().reset();
}
void BlockChainSync::onPeerStatus(std::shared_ptr<EthereumPeer> _peer)
@ -296,10 +296,16 @@ void BlockChainSync::onPeerNewBlock(std::shared_ptr<EthereumPeer> _peer, RLP con
case ImportResult::FutureTimeUnknown:
case ImportResult::UnknownParent:
{
logNewBlock(h);
clog(NetMessageDetail) << "Received block with no known parent. Resyncing...";
resetSyncFor(_peer, h, _r[1].toInt<u256>());
u256 totalDifficulty = _r[1].toInt<u256>();
if (totalDifficulty > _peer->m_totalDifficulty)
{
clog(NetMessageDetail) << "Received block with no known parent. Resyncing...";
resetSyncFor(_peer, h, totalDifficulty);
}
break;
}
default:;
}
@ -397,7 +403,6 @@ void PV60Sync::transition(std::shared_ptr<EthereumPeer> _peer, SyncState _s, boo
if (m_state == SyncState::Idle && _s != SyncState::Idle)
_peer->m_requireTransactions = true;
RLPStream s;
if (_s == SyncState::Hashes)
{
if (m_state == SyncState::Idle || m_state == SyncState::Hashes)
@ -1165,9 +1170,9 @@ SyncStatus PV61Sync::status() const
{
RecursiveGuard l(x_sync);
SyncStatus res = PV60Sync::status();
res.protocolVersion = 61;
if (m_state == SyncState::Hashes && isPV61Syncing())
{
res.protocolVersion = 61;
res.hashesReceived = 0;
for (auto const& d : m_readyChainMap)
res.hashesReceived += d.second.size();

6
libethereum/BlockChainSync.h

@ -58,6 +58,9 @@ public:
/// @returns true is Sync is in progress
virtual bool isSyncing() const = 0;
/// Restart sync
virtual void restartSync() = 0;
/// Called by peer to report status
virtual void onPeerStatus(std::shared_ptr<EthereumPeer> _peer);
@ -92,9 +95,6 @@ protected:
/// Resume downloading after witing state
virtual void continueSync() = 0;
/// Restart sync
virtual void restartSync() = 0;
/// Called after all blocks have been donloaded
virtual void completeSync() = 0;

4
libethereum/BlockDetails.h

@ -59,7 +59,7 @@ struct BlockLogBlooms
{
BlockLogBlooms() {}
BlockLogBlooms(RLP const& _r) { blooms = _r.toVector<LogBloom>(); size = _r.data().size(); }
bytes rlp() const { RLPStream s; s << blooms; size = s.out().size(); return s.out(); }
bytes rlp() const { bytes r = dev::rlp(blooms); size = r.size(); return r; }
LogBlooms blooms;
mutable unsigned size;
@ -69,7 +69,7 @@ struct BlocksBlooms
{
BlocksBlooms() {}
BlocksBlooms(RLP const& _r) { blooms = _r.toArray<LogBloom, c_bloomIndexSize>(); size = _r.data().size(); }
bytes rlp() const { RLPStream s; s << blooms; size = s.out().size(); return s.out(); }
bytes rlp() const { bytes r = dev::rlp(blooms); size = r.size(); return r; }
std::array<LogBloom, c_bloomIndexSize> blooms;
mutable unsigned size;

4
libethereum/BlockQueue.cpp

@ -215,8 +215,10 @@ ImportResult BlockQueue::import(bytesConstRef _block, BlockChain const& _bc, boo
return ImportResult::Malformed;
}
clog(BlockQueueTraceChannel) << "Block" << h << "is" << bi.number << "parent is" << bi.parentHash;
// Check block doesn't already exist first!
if (_bc.details(h))
if (_bc.isKnown(h))
{
cblockq << "Already known in chain.";
return ImportResult::AlreadyInChain;

2
libethereum/Client.cpp

@ -67,7 +67,7 @@ static const Addresses c_canaries =
Address("4bb7e8ae99b645c2b7860b8f3a2328aae28bd80a"), // gav
Address("1baf27b88c48dd02b744999cf3522766929d2b2a"), // vitalik
Address("a8edb1ac2c86d3d9d78f96cd18001f60df29e52c"), // jeff
Address("60d11b58744784dc97f878f7e3749c0f1381a004") // christoph
Address("ace7813896a84d3f5f80223916a5353ab16e46e6") // christoph
};
VersionChecker::VersionChecker(string const& _dbPath)

2
libethereum/Client.h

@ -217,6 +217,8 @@ public:
std::string const& sentinel() const { return m_sentinel; }
/// Set the extra data that goes into mined blocks.
void setExtraData(bytes const& _extraData) { m_extraData = _extraData; }
/// Rewind to a prior head.
void rewind(unsigned _n) { m_bc.rewind(_n); }
protected:
/// InterfaceStub methods

4
libethereum/ClientBase.cpp

@ -45,7 +45,7 @@ State ClientBase::asOf(BlockNumber _h) const
return asOf(bc().numberHash(_h));
}
h256 ClientBase::submitTransaction(TransactionSkeleton const& _t, Secret const& _secret)
pair<h256, Address> ClientBase::submitTransaction(TransactionSkeleton const& _t, Secret const& _secret)
{
prepareForTransaction();
@ -59,7 +59,7 @@ h256 ClientBase::submitTransaction(TransactionSkeleton const& _t, Secret const&
StructuredLogger::transactionReceived(t.sha3().abridged(), t.sender().abridged());
cnote << "New transaction " << t;
return t.sha3();
return make_pair(t.sha3(), toAddress(ts.from, ts.nonce));
}
// TODO: remove try/catch, allow exceptions

2
libethereum/ClientBase.h

@ -77,7 +77,7 @@ public:
/// Submits the given transaction.
/// @returns the new transaction's hash.
virtual h256 submitTransaction(TransactionSkeleton const& _t, Secret const& _secret) override;
virtual std::pair<h256, Address> submitTransaction(TransactionSkeleton const& _t, Secret const& _secret) override;
using Interface::submitTransaction;
/// Makes the given call. Nothing is recorded into the state.

10
libethereum/DownloadMan.cpp

@ -24,6 +24,16 @@ using namespace std;
using namespace dev;
using namespace dev::eth;
DownloadMan::Overview DownloadMan::overview() const
{
ReadGuard l(m_lock);
Overview ret;
ret.firstIncomplete = m_blocksGot.firstOut();
ret.lastComplete = ret.lastStarted = m_blocksGot.lastIn();// TODO: lastStarted properly
ret.total = m_blocksGot.size();
return ret;
}
DownloadSub::DownloadSub(DownloadMan& _man): m_man(&_man)
{
WriteGuard l(m_man->x_subs);

33
libethereum/DownloadMan.h

@ -82,6 +82,14 @@ class DownloadMan
friend class DownloadSub;
public:
struct Overview
{
size_t total;
size_t firstIncomplete;
size_t lastComplete;
size_t lastStarted;
};
~DownloadMan()
{
for (auto i: m_subs)
@ -97,11 +105,9 @@ public:
void resetToChain(h256s const& _chain)
{
{
ReadGuard l(x_subs);
DEV_READ_GUARDED(x_subs)
for (auto i: m_subs)
i->resetFetch();
}
WriteGuard l(m_lock);
m_chain.clear();
m_chain.reserve(_chain.size());
@ -112,11 +118,9 @@ public:
void reset()
{
{
ReadGuard l(x_subs);
DEV_READ_GUARDED(x_subs)
for (auto i: m_subs)
i->resetFetch();
}
WriteGuard l(m_lock);
m_chain.clear();
m_blocksGot.reset();
@ -127,11 +131,9 @@ public:
ReadGuard l(m_lock);
auto ret = m_blocksGot;
if (!_desperate)
{
ReadGuard l(x_subs);
for (auto i: m_subs)
ret += i->m_asked;
}
DEV_READ_GUARDED(x_subs)
for (auto i: m_subs)
ret += i->m_asked;
return ret;
}
@ -144,12 +146,15 @@ public:
h256s remaining() const
{
h256s ret;
ReadGuard l(m_lock);
for (auto i: m_blocksGot.inverted())
ret.push_back(m_chain[i]);
DEV_READ_GUARDED(m_lock)
for (auto i: m_blocksGot.inverted())
ret.push_back(m_chain[i]);
return ret;
}
h256 firstBlock() const { return m_chain.empty() ? h256() : m_chain[0]; }
Overview overview() const;
size_t chainSize() const { ReadGuard l(m_lock); return m_chain.size(); }
size_t chainEmpty() const { ReadGuard l(m_lock); return m_chain.empty(); }
void foreachSub(std::function<void(DownloadSub const&)> const& _f) const { ReadGuard l(x_subs); for(auto i: m_subs) _f(*i); }

51
libethereum/EthereumHost.cpp

@ -45,6 +45,12 @@ static unsigned const c_maxSendTransactions = 256;
char const* const EthereumHost::s_stateNames[static_cast<int>(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<EthereumPeer>(),
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();
@ -82,6 +88,7 @@ void EthereumHost::reset()
if (m_sync)
m_sync->abortSync();
m_sync.reset();
m_syncStart = 0;
m_latestBlockSent = h256();
Guard tl(x_transactions);
@ -109,6 +116,21 @@ void EthereumHost::doWork()
foreachPeer([](std::shared_ptr<EthereumPeer> _p) { _p->tick(); return true; });
if (m_syncStart)
{
DEV_GUARDED(x_sync);
if (!m_sync)
{
time_t now = std::chrono::system_clock::to_time_t(chrono::system_clock::now());
if (now - m_syncStart > 10)
{
m_sync.reset(new PV60Sync(*this));
m_syncStart = 0;
m_sync->restartSync();
}
}
}
// return netChange;
// TODO: Figure out what to do with netChange.
(void)netChange;
@ -150,7 +172,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 +228,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<EthereumPeer> const& p: get<0>(s))
for (auto const& b: blocks)
{
@ -249,7 +275,14 @@ BlockChainSync* EthereumHost::sync()
pv61 = true;
return !pv61;
});
m_sync.reset(pv61 ? new PV61Sync(*this) : new PV60Sync(*this));
if (pv61)
{
m_syncStart = 0;
m_sync.reset(new PV61Sync(*this));
}
else if (!m_syncStart)
m_syncStart = std::chrono::system_clock::to_time_t(chrono::system_clock::now());
return m_sync.get();
}
@ -292,11 +325,11 @@ void EthereumHost::onPeerTransactions(std::shared_ptr<EthereumPeer> _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 +384,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:

3
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.
@ -136,6 +138,7 @@ private:
mutable Mutex x_transactions;
DownloadMan m_man;
std::unique_ptr<BlockChainSync> m_sync;
std::atomic<time_t> m_syncStart = { 0 };
};
}

20
libethereum/ExtVM.cpp

@ -33,13 +33,21 @@ namespace
static unsigned const c_depthLimit = 1024;
/// Upper bound of stack space needed by single CALL/CREATE execution. Set experimentally.
static size_t const c_singleExecutionStackSize = 12 * 1024;
static size_t const c_singleExecutionStackSize =
#ifdef NDEBUG
12 * 1024;
#else
33 * 1024;
#endif
/// Standard OSX thread stack limit. Should be reasonable for other platforms too.
static size_t const c_defaultStackSize = 512 * 1024;
/// Stack overhead prior to allocation.
static size_t const c_entryOverhead = 128 * 1024;
/// On what depth execution should be offloaded to additional separated stack space.
static unsigned const c_offloadPoint = c_defaultStackSize / c_singleExecutionStackSize;
static unsigned const c_offloadPoint = (c_defaultStackSize - c_entryOverhead) / c_singleExecutionStackSize;
void goOnOffloadedStack(Executive& _e, OnOpFunc const& _onOp)
{
@ -70,11 +78,10 @@ void go(unsigned _depth, Executive& _e, OnOpFunc const& _onOp)
// Current stack is too small to handle more CALL/CREATE executions.
// It needs to be done only once as newly allocated stack space it enough to handle
// the rest of the calls up to the depth limit (c_depthLimit).
#if __GNUC__
if (_depth == c_offloadPoint)
goOnOffloadedStack(_e, _onOp);
else
#endif
_e.go(_onOp);
}
}
@ -84,7 +91,11 @@ bool ExtVM::call(CallParameters& _p)
Executive e(m_s, lastHashes, depth + 1);
if (!e.call(_p, gasPrice, origin))
{
#if __clang__ // Enabled for clang only as the problem affects OSX
go(depth, e, _p.onOp);
#else
e.go(_p.onOp);
#endif
e.accrueSubState(sub);
}
_p.gas = e.gas();
@ -106,4 +117,3 @@ h160 ExtVM::create(u256 _endowment, u256& io_gas, bytesConstRef _code, OnOpFunc
io_gas = e.gas();
return e.newAddress();
}

3
libethereum/Interface.cpp

@ -46,6 +46,5 @@ Address Interface::submitTransaction(Secret const& _secret, u256 const& _endowme
ts.gas = _gas;
ts.gasPrice = _gasPrice;
ts.nonce = _nonce;
submitTransaction(ts, _secret);
return toAddress(toAddress(_secret), _nonce);
return submitTransaction(ts, _secret).second;
}

2
libethereum/Interface.h

@ -67,7 +67,7 @@ public:
/// Submits a new transaction.
/// @returns the transaction's hash.
virtual h256 submitTransaction(TransactionSkeleton const& _t, Secret const& _secret) = 0;
virtual std::pair<h256, Address> submitTransaction(TransactionSkeleton const& _t, Secret const& _secret) = 0;
/// Submits the given message-call transaction.
void submitTransaction(Secret const& _secret, u256 const& _value, Address const& _dest, bytes const& _data = bytes(), u256 const& _gas = 10000, u256 const& _gasPrice = 10 * szabo, u256 const& _nonce = UndefinedU256);

32
libethereum/State.cpp

@ -445,7 +445,8 @@ u256 State::enactOn(VerifiedBlockRef const& _block, BlockChain const& _bc, Impor
#if ETH_TIMED_ENACTMENTS
enactment = t.elapsed();
cnote << "popVer/popGrand/syncReset/enactment = " << populateVerify << "/" << populateGrand << "/" << syncReset << "/" << enactment;
if (populateVerify + populateGrand + syncReset + enactment > 0.5)
clog(StateChat) << "popVer/popGrand/syncReset/enactment = " << populateVerify << "/" << populateGrand << "/" << syncReset << "/" << enactment;
#endif
return ret;
}
@ -513,18 +514,17 @@ pair<TransactionReceipts, bool> State::sync(BlockChain const& _bc, TransactionQu
{
if (t.gasPrice() >= _gp.ask(*this))
{
// Timer t;
// Timer t;
if (lh.empty())
lh = _bc.lastHashes();
execute(lh, t);
ret.first.push_back(m_receipts.back());
++goodTxs;
// cnote << "TX took:" << t.elapsed() * 1000;
// cnote << "TX took:" << t.elapsed() * 1000;
}
else if (t.gasPrice() < _gp.ask(*this) * 9 / 10)
{
// less than 90% of our ask price for gas. drop.
cnote << t.sha3() << "Dropping El Cheapo transaction (<90% of ask price)";
clog(StateTrace) << t.sha3() << "Dropping El Cheapo transaction (<90% of ask price)";
_tq.drop(t.sha3());
}
}
@ -536,22 +536,13 @@ pair<TransactionReceipts, bool> State::sync(BlockChain const& _bc, TransactionQu
if (req > got)
{
// too old
/* for (Transaction const& mt: m_transactions)
{
if (mt.from() == t.from())
{
if (mt.nonce() < t.nonce())
cnote << t.sha3() << "Dropping old transaction (nonce too low)";
else if (mt.nonce() == t.nonce() && mt.gasPrice() <= t.gasPrice())
cnote << t.sha3() << "Dropping old transaction (gas price lower)";
}
}*/
clog(StateTrace) << t.sha3() << "Dropping old transaction (nonce too low)";
_tq.drop(t.sha3());
}
else if (got > req + _tq.waiting(t.sender()))
{
// too new
cnote << t.sha3() << "Dropping new transaction (too many nonces ahead)";
clog(StateTrace) << t.sha3() << "Dropping new transaction (too many nonces ahead)";
_tq.drop(t.sha3());
}
else
@ -562,7 +553,7 @@ pair<TransactionReceipts, bool> State::sync(BlockChain const& _bc, TransactionQu
bigint const& got = *boost::get_error_info<errinfo_got>(e);
if (got > m_currentBlock.gasLimit)
{
cnote << t.sha3() << "Dropping over-gassy transaction (gas > block's gas limit)";
clog(StateTrace) << t.sha3() << "Dropping over-gassy transaction (gas > block's gas limit)";
_tq.drop(t.sha3());
}
else
@ -576,14 +567,14 @@ pair<TransactionReceipts, bool> State::sync(BlockChain const& _bc, TransactionQu
catch (Exception const& _e)
{
// Something else went wrong - drop it.
cnote << t.sha3() << "Dropping invalid transaction:" << diagnostic_information(_e);
clog(StateTrace) << t.sha3() << "Dropping invalid transaction:" << diagnostic_information(_e);
_tq.drop(t.sha3());
}
catch (std::exception const&)
{
// Something else went wrong - drop it.
_tq.drop(t.sha3());
cnote << t.sha3() << "Transaction caused low-level exception :(";
cwarn << t.sha3() << "Transaction caused low-level exception :(";
}
}
if (chrono::steady_clock::now() > deadline)
@ -965,6 +956,8 @@ void State::commitToMine(BlockChain const& _bc, bytes const& _extraData)
m_currentBlock.stateRoot = m_state.root();
m_currentBlock.parentHash = m_previousBlock.hash();
m_currentBlock.extraData = _extraData;
if (m_currentBlock.extraData.size() > 32)
m_currentBlock.extraData.resize(32);
m_committedToMine = true;
}
@ -1269,7 +1262,6 @@ 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 + e.gasUsedNoRefunds(), e.logs())); // TODO: Switch in to be compliant with YP.
m_receipts.push_back(TransactionReceipt(rootHash(), startGasUsed + e.gasUsed(), e.logs()));
m_transactionSet.insert(e.t().sha3());
}

21
libethereum/TransactionQueue.cpp

@ -36,12 +36,12 @@ TransactionQueue::TransactionQueue(unsigned _limit, unsigned _futureLimit):
m_limit(_limit),
m_futureLimit(_futureLimit)
{
unsigned verifierThreads = std::max(thread::hardware_concurrency(), 3U) - 2U;
for (unsigned i = 0; i < verifierThreads; ++i)
m_verifiers.emplace_back([=](){
setThreadName("txcheck" + toString(i));
this->verifierBody();
});
unsigned verifierThreads = std::max(thread::hardware_concurrency(), 3U) - 2U;
for (unsigned i = 0; i < verifierThreads; ++i)
m_verifiers.emplace_back([=](){
setThreadName("txcheck" + toString(i));
this->verifierBody();
});
}
TransactionQueue::~TransactionQueue()
@ -68,6 +68,9 @@ ImportResult TransactionQueue::import(bytesConstRef _transactionRLP, IfDropped _
try
{
// Check validity of _transactionRLP as a transaction. To do this we just deserialise and attempt to determine the sender.
// If it doesn't work, the signature is bad.
// The transaction's nonce may yet be invalid (or, it could be "valid" but we may be missing a marginally older transaction).
t = Transaction(_transactionRLP, CheckTransaction::Everything);
UpgradeGuard ul(l);
ir = manageImport_WITH_LOCK(h, t);
@ -99,7 +102,6 @@ ImportResult TransactionQueue::import(Transaction const& _transaction, IfDropped
ImportResult ret;
{
UpgradableGuard l(m_lock);
// TODO: keep old transactions around and check in State for nonce validity
auto ir = check_WITH_LOCK(h, _ik);
if (ir != ImportResult::Success)
return ir;
@ -132,11 +134,7 @@ ImportResult TransactionQueue::manageImport_WITH_LOCK(h256 const& _h, Transactio
{
try
{
// Check validity of _transactionRLP as a transaction. To do this we just deserialise and attempt to determine the sender.
// If it doesn't work, the signature is bad.
// The transaction's nonce may yet be invalid (or, it could be "valid" but we may be missing a marginally older transaction).
assert(_h == _transaction.sha3());
// Remove any prior transaction with the same nonce but a lower gas price.
// Bomb out if there's a prior transaction with higher gas price.
auto cs = m_currentByAddressAndNonce.find(_transaction.from());
@ -263,7 +261,6 @@ unsigned TransactionQueue::waiting(Address const& _a) const
void TransactionQueue::setFuture(h256 const& _txHash)
{
// cdebug << "txQ::setFuture" << _t.first;
WriteGuard l(m_lock);
auto it = m_currentByHash.find(_txHash);
if (it == m_currentByHash.end())

63
libethereum/TransactionQueue.h

@ -42,39 +42,84 @@ struct TransactionQueueChannel: public LogChannel { static const char* name(); s
struct TransactionQueueTraceChannel: public LogChannel { static const char* name(); static const int verbosity = 7; };
#define ctxq dev::LogOutputStream<dev::eth::TransactionQueueTraceChannel, true>()
enum class IfDropped { Ignore, Retry };
/// Import transaction policy
enum class IfDropped
{
Ignore, ///< Don't import transaction that was previously dropped.
Retry ///< Import transaction even if it was dropped before.
};
/**
* @brief A queue of Transactions, each stored as RLP.
* Maintains a transaction queue sorted by nonce diff and gas price
* Maintains a transaction queue sorted by nonce diff and gas price.
* @threadsafe
*/
class TransactionQueue
{
public:
/// @brief TransactionQueue
/// @param _limit Maximum number of pending transactions in the queue
/// @param _futureLimit Maximum number of future nonce transactions
/// @param _limit Maximum number of pending transactions in the queue.
/// @param _futureLimit Maximum number of future nonce transactions.
TransactionQueue(unsigned _limit = 1024, unsigned _futureLimit = 1024);
~TransactionQueue();
/// Add transaction to the queue to be verified and imported.
/// @param _data RLP encoded transaction data.
/// @param _nodeId Optional network identified of a node transaction comes from.
void enqueue(RLP const& _data, h512 const& _nodeId);
/// Verify and add transaction to the queue synchronously.
/// @param _tx RLP encoded transaction data.
/// @param _ik Set to Retry to force re-addinga transaction that was previously dropped.
/// @returns Import result code.
ImportResult import(bytes const& _tx, IfDropped _ik = IfDropped::Ignore) { return import(&_tx, _ik); }
/// Verify and add transaction to the queue synchronously.
/// @param _tx Trasnaction data.
/// @param _ik Set to Retry to force re-addinga transaction that was previously dropped.
/// @returns Import result code.
ImportResult import(Transaction const& _tx, IfDropped _ik = IfDropped::Ignore);
/// Remove transaction from the queue
/// @param _txHash Trasnaction hash
void drop(h256 const& _txHash);
/// Get number of pending transactions for account.
/// @returns Pending transaction count.
unsigned waiting(Address const& _a) const;
/// Get top transactions from the queue. Returned transactions are not removed from the queue automatically.
/// @param _limit Max number of transactions to return.
/// @returns up to _limit transactions ordered by nonce and gas price.
Transactions topTransactions(unsigned _limit) const;
/// Get a hash set of transactions in the queue
/// @returns A hash set of all transactions in the queue
h256Hash knownTransactions() const;
/// Get max nonce for an account
/// @returns Max transaction nonce for account in the queue
u256 maxNonce(Address const& _a) const;
/// Mark transaction as future. It wont be retured in topTransactions list until a transaction with a preceeding nonce is imported or marked with dropGood
/// @param _t Transaction hash
void setFuture(h256 const& _t);
/// Drop a trasnaction from the list if exists and move following future trasnactions to current (if any)
/// @param _t Transaction hash
void dropGood(Transaction const& _t);
/// Clear the queue
void clear();
/// Register a handler that will be called once there is a new transaction imported
template <class T> Handler<> onReady(T const& _t) { return m_onReady.add(_t); }
/// Register a handler that will be called once asynchronous verification is comeplte an transaction has been imported
template <class T> Handler<ImportResult, h256 const&, h512 const&> onImport(T const& _t) { return m_onImport.add(_t); }
private:
/// Verified and imported transaction
struct VerifiedTransaction
{
VerifiedTransaction(Transaction const& _t): transaction(_t) {}
@ -83,26 +128,28 @@ private:
VerifiedTransaction(VerifiedTransaction const&) = delete;
VerifiedTransaction& operator=(VerifiedTransaction const&) = delete;
Transaction transaction;
Transaction transaction; ///< Transaction data
};
/// Trasnaction pending verification
struct UnverifiedTransaction
{
UnverifiedTransaction() {}
UnverifiedTransaction(bytesConstRef const& _t, h512 const& _nodeId): transaction(std::move(_t.toBytes())), nodeId(_nodeId) {}
UnverifiedTransaction(bytesConstRef const& _t, h512 const& _nodeId): transaction(_t.toBytes()), nodeId(_nodeId) {}
UnverifiedTransaction(UnverifiedTransaction&& _t): transaction(std::move(_t.transaction)) {}
UnverifiedTransaction& operator=(UnverifiedTransaction&& _other) { transaction = std::move(_other.transaction); nodeId = std::move(_other.nodeId); return *this; }
UnverifiedTransaction(UnverifiedTransaction const&) = delete;
UnverifiedTransaction& operator=(UnverifiedTransaction const&) = delete;
bytes transaction;
h512 nodeId;
bytes transaction; ///< RLP encoded transaction data
h512 nodeId; ///< Network Id of the peer transaction comes from
};
struct PriorityCompare
{
TransactionQueue& queue;
/// Compare transaction by nonce height and gas price.
bool operator()(VerifiedTransaction const& _first, VerifiedTransaction const& _second) const
{
u256 const& height1 = _first.transaction.nonce() - queue.m_currentByAddressAndNonce[_first.transaction.sender()].begin()->first;

4
libweb3jsonrpc/AccountHolder.cpp

@ -109,7 +109,7 @@ AddressHash SimpleAccountHolder::realAccounts() const
h256 SimpleAccountHolder::authenticate(dev::eth::TransactionSkeleton const& _t)
{
if (isRealAccount(_t.from))
return m_client()->submitTransaction(_t, m_keyManager.secret(_t.from, [&](){ return m_getPassword(_t.from); }));
return m_client()->submitTransaction(_t, m_keyManager.secret(_t.from, [&](){ return m_getPassword(_t.from); })).first;
else if (isProxyAccount(_t.from))
queueTransaction(_t);
return h256();
@ -118,7 +118,7 @@ h256 SimpleAccountHolder::authenticate(dev::eth::TransactionSkeleton const& _t)
h256 FixedAccountHolder::authenticate(dev::eth::TransactionSkeleton const& _t)
{
if (isRealAccount(_t.from))
return m_client()->submitTransaction(_t, m_accounts[_t.from]);
return m_client()->submitTransaction(_t, m_accounts[_t.from]).first;
else if (isProxyAccount(_t.from))
queueTransaction(_t);
return h256();

4
libwhisper/BloomFilter.h

@ -88,7 +88,7 @@ template <unsigned N>
bool TopicBloomFilterBase<N>::isBitSet(FixedHash<N> const& _h, unsigned _index)
{
unsigned iByte = _index / 8;
unsigned iBit = _index & 0x7;
unsigned iBit = _index % 8;
return (_h[iByte] & c_powerOfTwoBitMmask[iBit]) != 0;
}
@ -96,7 +96,7 @@ template <unsigned N>
void TopicBloomFilterBase<N>::setBit(FixedHash<N>& _h, unsigned _index)
{
unsigned iByte = _index / 8;
unsigned iBit = _index & 0x7;
unsigned iBit = _index % 8;
_h[iByte] |= c_powerOfTwoBitMmask[iBit];
}

4
libwhisper/Message.cpp

@ -170,7 +170,7 @@ void Envelope::proveWork(unsigned _ms)
chrono::high_resolution_clock::time_point then = chrono::high_resolution_clock::now() + chrono::milliseconds(_ms);
while (chrono::high_resolution_clock::now() < then)
// do it rounds of 1024 for efficiency
for (unsigned i = 0; i < 1024; ++i)
for (unsigned i = 0; i < 1024; ++i, ++d[1])
{
auto fbs = dev::sha3(chuck).firstBitSet();
if (fbs > bestBitSet)
@ -178,8 +178,6 @@ void Envelope::proveWork(unsigned _ms)
bestBitSet = fbs;
m_nonce = (h256::Arith)d[1];
}
incrementHash(d[1]);
}
}

1
libwhisper/Message.h

@ -81,7 +81,6 @@ public:
void proveWork(unsigned _ms);
bool matchesBloomFilter(TopicBloomFilterHash const& f) const;
static void incrementHash(h256& _h) { for (unsigned i = h256::size; i > 0 && !++_h[--i]; ) {} }
private:
Envelope(unsigned _exp, unsigned _ttl, AbridgedTopics const& _topic): m_expiry(_exp), m_ttl(_ttl), m_topic(_topic) {}

5
mix/CMakeLists.txt

@ -15,6 +15,11 @@ include_directories(BEFORE ${JSONCPP_INCLUDE_DIRS})
include_directories(${Boost_INCLUDE_DIRS})
include_directories(BEFORE ..)
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
# Supress warnings for qt headers for clang+ccache
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-inconsistent-missing-override")
endif ()
find_package (Qt5WebEngine QUIET)
qt5_add_resources(UI_RESOURCES res.qrc qml.qrc)

3
mix/ClientModel.cpp

@ -674,8 +674,7 @@ void ClientModel::debugRecord(unsigned _index)
Address ClientModel::deployContract(bytes const& _code, TransactionSettings const& _ctrTransaction)
{
Address newAddress = m_client->submitTransaction(_ctrTransaction.sender, _ctrTransaction.value, _code, _ctrTransaction.gas, _ctrTransaction.gasPrice, _ctrTransaction.gasAuto);
return newAddress;
return m_client->submitTransaction(_ctrTransaction.sender, _ctrTransaction.value, _code, _ctrTransaction.gas, _ctrTransaction.gasPrice, _ctrTransaction.gasAuto);
}
void ClientModel::callAddress(Address const& _contract, bytes const& _data, TransactionSettings const& _tr)

2
mix/ClientModel.h

@ -252,7 +252,7 @@ private:
QVariantMap contractAddresses() const;
QVariantList gasCosts() const;
void executeSequence(std::vector<TransactionSettings> const& _sequence);
dev::Address deployContract(bytes const& _code, TransactionSettings const& _tr = TransactionSettings());
Address deployContract(bytes const& _code, TransactionSettings const& _tr = TransactionSettings());
void callAddress(Address const& _contract, bytes const& _data, TransactionSettings const& _tr);
void onNewTransaction();
void onStateReset();

7
mix/MixClient.cpp

@ -303,14 +303,15 @@ State MixClient::asOf(h256 const& _block) const
return ret;
}
h256 MixClient::submitTransaction(eth::TransactionSkeleton const& _ts, Secret const& _secret, bool _gasAuto)
pair<h256, Address> MixClient::submitTransaction(eth::TransactionSkeleton const& _ts, Secret const& _secret, bool _gasAuto)
{
WriteGuard l(x_state);
TransactionSkeleton ts = _ts;
ts.nonce = m_state.transactionsFrom(toAddress(_secret));
ts.from = toAddress(_secret);
ts.nonce = m_state.transactionsFrom(ts.from);
eth::Transaction t(ts, _secret);
executeTransaction(t, m_state, false, _gasAuto, _secret);
return t.sha3();
return make_pair(t.sha3(), toAddress(ts.from, ts.nonce));
}
dev::eth::ExecutionResult MixClient::call(Address const& _from, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice, BlockNumber _blockNumber, bool _gasAuto, FudgeFactor _ff)

7
mix/MixClient.h

@ -58,8 +58,8 @@ public:
dev::eth::ExecutionResult create(Address const& _secret, u256 _value, bytes const& _data = bytes(), u256 _gas = 10000, u256 _gasPrice = 10 * eth::szabo, eth::BlockNumber _blockNumber = eth::PendingBlock, eth::FudgeFactor _ff = eth::FudgeFactor::Strict) override;
using ClientBase::submitTransaction;
virtual h256 submitTransaction(eth::TransactionSkeleton const& _ts, Secret const& _secret) override { return submitTransaction(_ts, _secret, false); }
h256 submitTransaction(eth::TransactionSkeleton const& _ts, Secret const& _secret, bool _gasAuto);
virtual std::pair<h256, Address> submitTransaction(eth::TransactionSkeleton const& _ts, Secret const& _secret) override { return submitTransaction(_ts, _secret, false); }
std::pair<h256, Address> submitTransaction(eth::TransactionSkeleton const& _ts, Secret const& _secret, bool _gasAuto);
dev::eth::ExecutionResult call(Address const& _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice, eth::BlockNumber _blockNumber, bool _gasAuto, eth::FudgeFactor _ff = eth::FudgeFactor::Strict);
void setAddress(Address _us) override;
@ -76,6 +76,9 @@ public:
using Interface::blockInfo; // to remove warning about hiding virtual function
eth::BlockInfo blockInfo() const;
/// return the new address generated by the last tr (if creation). returns empty address if other cases.
Address lastCreatedContractAddr() const;
protected:
/// ClientBase methods
using ClientBase::asOf;

8
neth/main.cpp

@ -363,11 +363,7 @@ int main(int argc, char** argv)
coinbase = config[1].toHash<Address>();
}
else
{
RLPStream config(2);
config << us.secret() << coinbase;
writeFile(configFile, config.out());
}
writeFile(configFile, rlpList(us.secret(), coinbase));
for (int i = 1; i < argc; ++i)
{
@ -1061,9 +1057,7 @@ int main(int argc, char** argv)
else if (gas < minGas)
cwarn << "Minimum gas amount is" << minGas;
else
{
c->submitTransaction(us.secret(), endowment, init, gas);
}
}
}
else if (c && cmd == "inspect")

133
test/fuzzTesting/fuzzHelper.cpp

@ -74,7 +74,7 @@ std::string RandomCode::generate(int _maxOpNumber, RandomCodeOptions _options)
uint8_t opcode = weightsDefined ? randOpCodeWeight() : randOpCodeGen();
dev::eth::InstructionInfo info = dev::eth::instructionInfo((dev::eth::Instruction) opcode);
if (info.name.find_first_of("INVALID_INSTRUCTION") > 0)
if (info.name.find("INVALID_INSTRUCTION") != std::string::npos)
{
//Byte code is yet not implemented
if (_options.useUndefinedOpCodes == false)
@ -85,12 +85,12 @@ std::string RandomCode::generate(int _maxOpNumber, RandomCodeOptions _options)
}
else
{
if (info.name.find_first_of("PUSH") > 0)
if (info.name.find("PUSH") != std::string::npos)
code += toCompactHex(opcode);
code += fillArguments((dev::eth::Instruction) opcode, _options);
}
if (info.name.find_first_of("PUSH") <= 0)
if (info.name.find("PUSH") == std::string::npos)
{
std::string byte = toCompactHex(opcode);
code += (byte == "") ? "00" : byte;
@ -149,113 +149,34 @@ std::string RandomCode::fillArguments(dev::eth::Instruction _opcode, RandomCodeO
if (smart)
{
switch (_opcode)
//PUSH1 ... PUSH32
if (dev::eth::Instruction::PUSH1 <= _opcode && _opcode <= dev::eth::Instruction::PUSH32)
{
case dev::eth::Instruction::PUSH1: code += rndByteSequence(1); break;
case dev::eth::Instruction::PUSH2: code += rndByteSequence(2); break;
case dev::eth::Instruction::PUSH3: code += rndByteSequence(3); break;
case dev::eth::Instruction::PUSH4: code += rndByteSequence(4); break;
case dev::eth::Instruction::PUSH5: code += rndByteSequence(5); break;
case dev::eth::Instruction::PUSH6: code += rndByteSequence(6); break;
case dev::eth::Instruction::PUSH7: code += rndByteSequence(7); break;
case dev::eth::Instruction::PUSH8: code += rndByteSequence(8); break;
case dev::eth::Instruction::PUSH9: code += rndByteSequence(9); break;
case dev::eth::Instruction::PUSH10: code += rndByteSequence(10); break;
case dev::eth::Instruction::PUSH11: code += rndByteSequence(11); break;
case dev::eth::Instruction::PUSH12: code += rndByteSequence(12); break;
case dev::eth::Instruction::PUSH13: code += rndByteSequence(13); break;
case dev::eth::Instruction::PUSH14: code += rndByteSequence(14); break;
case dev::eth::Instruction::PUSH15: code += rndByteSequence(15); break;
case dev::eth::Instruction::PUSH16: code += rndByteSequence(16); break;
case dev::eth::Instruction::PUSH17: code += rndByteSequence(17); break;
case dev::eth::Instruction::PUSH18: code += rndByteSequence(18); break;
case dev::eth::Instruction::PUSH19: code += rndByteSequence(19); break;
case dev::eth::Instruction::PUSH20: code += rndByteSequence(20); break;
case dev::eth::Instruction::PUSH21: code += rndByteSequence(21); break;
case dev::eth::Instruction::PUSH22: code += rndByteSequence(22); break;
case dev::eth::Instruction::PUSH23: code += rndByteSequence(23); break;
case dev::eth::Instruction::PUSH24: code += rndByteSequence(24); break;
case dev::eth::Instruction::PUSH25: code += rndByteSequence(25); break;
case dev::eth::Instruction::PUSH26: code += rndByteSequence(26); break;
case dev::eth::Instruction::PUSH27: code += rndByteSequence(27); break;
case dev::eth::Instruction::PUSH28: code += rndByteSequence(28); break;
case dev::eth::Instruction::PUSH29: code += rndByteSequence(29); break;
case dev::eth::Instruction::PUSH30: code += rndByteSequence(30); break;
case dev::eth::Instruction::PUSH31: code += rndByteSequence(31); break;
case dev::eth::Instruction::PUSH32: code += rndByteSequence(32); break;
case dev::eth::Instruction::SWAP1:
case dev::eth::Instruction::SWAP2:
case dev::eth::Instruction::SWAP3:
case dev::eth::Instruction::SWAP4:
case dev::eth::Instruction::SWAP5:
case dev::eth::Instruction::SWAP6:
case dev::eth::Instruction::SWAP7:
case dev::eth::Instruction::SWAP8:
case dev::eth::Instruction::SWAP9:
case dev::eth::Instruction::SWAP10:
case dev::eth::Instruction::SWAP11:
case dev::eth::Instruction::SWAP12:
case dev::eth::Instruction::SWAP13:
case dev::eth::Instruction::SWAP14:
case dev::eth::Instruction::SWAP15:
case dev::eth::Instruction::SWAP16:
case dev::eth::Instruction::DUP1:
case dev::eth::Instruction::DUP2:
case dev::eth::Instruction::DUP3:
case dev::eth::Instruction::DUP4:
case dev::eth::Instruction::DUP5:
case dev::eth::Instruction::DUP6:
case dev::eth::Instruction::DUP7:
case dev::eth::Instruction::DUP8:
case dev::eth::Instruction::DUP9:
case dev::eth::Instruction::DUP10:
case dev::eth::Instruction::DUP11:
case dev::eth::Instruction::DUP12:
case dev::eth::Instruction::DUP13:
case dev::eth::Instruction::DUP14:
case dev::eth::Instruction::DUP15:
case dev::eth::Instruction::DUP16:
int times;
switch (_opcode)
{
case dev::eth::Instruction::DUP1: times = 1; break;
case dev::eth::Instruction::SWAP1:
case dev::eth::Instruction::DUP2: times = 2; break;
case dev::eth::Instruction::SWAP2:
case dev::eth::Instruction::DUP3: times = 3; break;
case dev::eth::Instruction::SWAP3:
case dev::eth::Instruction::DUP4: times = 4; break;
case dev::eth::Instruction::SWAP4:
case dev::eth::Instruction::DUP5: times = 5; break;
case dev::eth::Instruction::SWAP5:
case dev::eth::Instruction::DUP6: times = 6; break;
case dev::eth::Instruction::SWAP6:
case dev::eth::Instruction::DUP7: times = 7; break;
case dev::eth::Instruction::SWAP7:
case dev::eth::Instruction::DUP8: times = 8; break;
case dev::eth::Instruction::SWAP8:
case dev::eth::Instruction::DUP9: times = 9; break;
case dev::eth::Instruction::SWAP9:
case dev::eth::Instruction::DUP10: times = 10; break;
case dev::eth::Instruction::SWAP10:
case dev::eth::Instruction::DUP11: times = 11; break;
case dev::eth::Instruction::SWAP11:
case dev::eth::Instruction::DUP12: times = 12; break;
case dev::eth::Instruction::SWAP12:
case dev::eth::Instruction::DUP13: times = 13; break;
case dev::eth::Instruction::SWAP13:
case dev::eth::Instruction::DUP14: times = 14; break;
case dev::eth::Instruction::SWAP14:
case dev::eth::Instruction::DUP15: times = 15; break;
case dev::eth::Instruction::SWAP15:
case dev::eth::Instruction::DUP16: times = 16; break;
case dev::eth::Instruction::SWAP16: times = 17; break;
default: times = 1;
}
code += rndByteSequence(int(_opcode) - int(dev::eth::Instruction::PUSH1) + 1);
return code;
}
//SWAP1 ... SWAP16 || DUP1 ... DUP16
bool isSWAP = (dev::eth::Instruction::SWAP1 <= _opcode && _opcode <= dev::eth::Instruction::SWAP16);
bool isDUP = (dev::eth::Instruction::DUP1 <= _opcode && _opcode <= dev::eth::Instruction::DUP16);
if (isSWAP || isDUP)
{
int times = 0;
if (isSWAP)
times = int(_opcode) - int(dev::eth::Instruction::SWAP1) + 2;
else
if (isDUP)
times = int(_opcode) - int(dev::eth::Instruction::DUP1) + 1;
for (int i = 0; i < times; i ++)
code += getPushCode(randUniIntGen() % 32);
break;
return code;
}
switch (_opcode)
{
case dev::eth::Instruction::CREATE:
//(CREATE value mem1 mem2)
code += getPushCode(randUniIntGen() % 128); //memlen1

40
test/libdevcore/FixedHash.cpp

@ -100,6 +100,46 @@ BOOST_AUTO_TEST_CASE(FixedHashContains)
BOOST_CHECK(!h1.contains(h3));
}
void incrementSingleIteration(unsigned seed)
{
unsigned next = seed + 1;
FixedHash<4> h1(seed);
FixedHash<4> h2 = h1;
FixedHash<4> h3(next);
FixedHash<32> hh1(seed);
FixedHash<32> hh2 = hh1;
FixedHash<32> hh3(next);
BOOST_CHECK_EQUAL(++h2, h3);
BOOST_CHECK_EQUAL(++hh2, hh3);
BOOST_CHECK(h2 > h1);
BOOST_CHECK(hh2 > hh1);
unsigned reverse1 = ((FixedHash<4>::Arith)h2).convert_to<unsigned>();
unsigned reverse2 = ((FixedHash<32>::Arith)hh2).convert_to<unsigned>();
BOOST_CHECK_EQUAL(next, reverse1);
BOOST_CHECK_EQUAL(next, reverse2);
}
BOOST_AUTO_TEST_CASE(FixedHashIncrement)
{
incrementSingleIteration(0);
incrementSingleIteration(1);
incrementSingleIteration(0xBAD);
incrementSingleIteration(0xBEEF);
incrementSingleIteration(0xFFFF);
incrementSingleIteration(0xFEDCBA);
incrementSingleIteration(0x7FFFFFFF);
FixedHash<4> h(0xFFFFFFFF);
FixedHash<4> zero;
BOOST_CHECK_EQUAL(++h, zero);
}
BOOST_AUTO_TEST_SUITE_END()
}

41
test/libdevcore/core.cpp

@ -0,0 +1,41 @@
/*
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 core.cpp
* @author Dimitry Khokhlov <winsvega@mail.ru>
* @date 2014
* CORE test functions.
*/
#include <boost/test/unit_test.hpp>
#include <libdevcore/CommonIO.h>
#include <test/TestHelper.h>
BOOST_AUTO_TEST_SUITE(CoreLibTests)
BOOST_AUTO_TEST_CASE(byteRef)
{
cnote << "bytesRef copyTo and toString...";
dev::bytes originalSequence = dev::fromHex("0102030405060708091011121314151617181920212223242526272829303132");
dev::bytesRef out(&originalSequence.at(0), 32);
dev::h256 hash32("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347");
hash32.ref().copyTo(out);
BOOST_CHECK_MESSAGE(out.size() == 32, "Error wrong result size when h256::ref().copyTo(dev::bytesRef out)");
BOOST_CHECK_MESSAGE(out.toBytes() == originalSequence, "Error when h256::ref().copyTo(dev::bytesRef out)");
}
BOOST_AUTO_TEST_SUITE_END()

2
test/libdevcrypto/AES.cpp

@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE(AuthenticatedStreamConstructor)
{
cout << "AuthenticatedStreamConstructor" << endl;
Secret const sec("test");
Secret const sec(dev::sha3("test"));
crypto::aes::AuthenticatedStream as(crypto::aes::Encrypt, sec, 0);
BOOST_CHECK(as.getMacInterval() == 0);
as.adjustInterval(1);

277
test/libethereum/BlockchainTestsFiller/bcBlockGasLimitTestFiller.json

@ -0,0 +1,277 @@
{
"SuicideTransaction" : {
"genesisBlockHeader" : {
"bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
"difficulty" : "131072",
"extraData" : "0x42",
"gasLimit" : "125000",
"gasUsed" : "0",
"mixHash" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"nonce" : "0x0102030405060708",
"number" : "0",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
"timestamp" : "0x54c98c81",
"transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
"expect" : {
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "10000000000"
}
},
"pre" : {
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "90000000000000000000000000",
"nonce" : "0",
"code" : "",
"storage": {}
},
"aaaf5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "10000000000",
"nonce" : "0",
"code" : "0x73a94f5374fce5edbc8e2a8697c15331677e6ebf0bff",
"storage": {}
}
},
"blocks" : [
{
"transactions" : [
{
"data" : "",
"gasLimit" : "100000",
"gasPrice" : "10",
"nonce" : "0",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"to" : "aaaf5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "10"
}
],
"uncleHeaders" : [
]
}
]
},
"GasUsedHigherThanBlockGasLimitButNotWithRefundsSuicideLast" : {
"genesisBlockHeader" : {
"bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
"difficulty" : "131072",
"extraData" : "0x42",
"gasLimit" : "147000",
"gasUsed" : "0",
"mixHash" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"nonce" : "0x0102030405060708",
"number" : "0",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
"timestamp" : "0x54c98c81",
"transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
"expect" : {
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "10000000000"
}
},
"pre" : {
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "90000000000000000000000000",
"nonce" : "0",
"code" : "",
"storage": {}
},
"aaaf5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "10000000000",
"nonce" : "0",
"code" : "0x73a94f5374fce5edbc8e2a8697c15331677e6ebf0bff",
"storage": {}
}
},
"blocks" : [
{
"transactions" : [
{
"data" : "",
"gasLimit" : "21000",
"gasPrice" : "10",
"nonce" : "0",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "10"
},
{
"data" : "",
"gasLimit" : "21000",
"gasPrice" : "10",
"nonce" : "1",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "10"
},
{
"data" : "",
"gasLimit" : "21000",
"gasPrice" : "10",
"nonce" : "2",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "10"
},
{
"data" : "",
"gasLimit" : "21000",
"gasPrice" : "10",
"nonce" : "3",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "10"
},
{
"data" : "",
"gasLimit" : "21000",
"gasPrice" : "10",
"nonce" : "4",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "10"
},
{
"data" : "",
"gasLimit" : "21000",
"gasPrice" : "10",
"nonce" : "5",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "10"
},
{
"data" : "",
"gasLimit" : "22000",
"gasPrice" : "10",
"nonce" : "6",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"to" : "aaaf5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "10"
}
],
"uncleHeaders" : [
]
}
]
},
"GasUsedHigherThanBlockGasLimitButNotWithRefundsSuicideFirst" : {
"genesisBlockHeader" : {
"bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
"difficulty" : "131072",
"extraData" : "0x42",
"gasLimit" : "147000",
"gasUsed" : "0",
"mixHash" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"nonce" : "0x0102030405060708",
"number" : "0",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"receiptTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"stateRoot" : "0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a",
"timestamp" : "0x54c98c81",
"transactionsTrie" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
"expect" : {
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "10000000000"
}
},
"pre" : {
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "90000000000000000000000000",
"nonce" : "0",
"code" : "",
"storage": {}
},
"aaaf5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "10000000000",
"nonce" : "0",
"code" : "0x73a94f5374fce5edbc8e2a8697c15331677e6ebf0bff",
"storage": {}
}
},
"blocks" : [
{
"transactions" : [
{
"data" : "",
"gasLimit" : "21000",
"gasPrice" : "10",
"nonce" : "6",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "10"
},
{
"data" : "",
"gasLimit" : "21000",
"gasPrice" : "10",
"nonce" : "1",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "10"
},
{
"data" : "",
"gasLimit" : "21000",
"gasPrice" : "10",
"nonce" : "2",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "10"
},
{
"data" : "",
"gasLimit" : "21000",
"gasPrice" : "10",
"nonce" : "3",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "10"
},
{
"data" : "",
"gasLimit" : "21000",
"gasPrice" : "10",
"nonce" : "4",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "10"
},
{
"data" : "",
"gasLimit" : "21000",
"gasPrice" : "10",
"nonce" : "5",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "10"
},
{
"data" : "",
"gasLimit" : "22000",
"gasPrice" : "10",
"nonce" : "0",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"to" : "aaaf5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "10"
}
],
"uncleHeaders" : [
]
}
]
}
}

5
test/libethereum/blockchain.cpp

@ -837,6 +837,11 @@ BOOST_AUTO_TEST_CASE(bcBruncleTest)
dev::test::executeTests("bcBruncleTest", "/BlockchainTests",dev::test::getFolder(__FILE__) + "/BlockchainTestsFiller", dev::test::doBlockchainTests);
}
BOOST_AUTO_TEST_CASE(bcBlockGasLimitTest)
{
dev::test::executeTests("bcBlockGasLimitTest", "/BlockchainTests",dev::test::getFolder(__FILE__) + "/BlockchainTestsFiller", dev::test::doBlockchainTests);
}
BOOST_AUTO_TEST_CASE(bcWalletTest)
{
if (test::Options::get().wallet)

Loading…
Cancel
Save