From bdaca3dced2644099661966e06ef6e0acc08892e Mon Sep 17 00:00:00 2001 From: Alexandre Van de Sande Date: Tue, 7 Apr 2015 17:52:19 -0300 Subject: [PATCH 01/19] change highlight color --- mix/qml/html/cm/solarized.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix/qml/html/cm/solarized.css b/mix/qml/html/cm/solarized.css index d8c31bfb5..10cfe14a0 100644 --- a/mix/qml/html/cm/solarized.css +++ b/mix/qml/html/cm/solarized.css @@ -166,7 +166,7 @@ view-port /* Code execution */ .CodeMirror-exechighlight { - background: #eee8d5; + background: #0C4250; } /* Error annotation */ From 76f0be58760424c22cd0ba40e1bc67def9902288 Mon Sep 17 00:00:00 2001 From: arkpar Date: Thu, 9 Apr 2015 14:18:08 +0200 Subject: [PATCH 02/19] load html urls through a proxy in AZ --- alethzero/DappLoader.cpp | 55 ++++++++++++++++++++++++++++++++-------- alethzero/DappLoader.h | 7 +++++ alethzero/MainWin.cpp | 27 ++++++++++---------- alethzero/MainWin.h | 1 + 4 files changed, 66 insertions(+), 24 deletions(-) diff --git a/alethzero/DappLoader.cpp b/alethzero/DappLoader.cpp index 9baf0c82e..69555521d 100644 --- a/alethzero/DappLoader.cpp +++ b/alethzero/DappLoader.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -96,13 +97,31 @@ DappLocation DappLoader::resolveAppUri(QString const& _uri) void DappLoader::downloadComplete(QNetworkReply* _reply) { + QUrl requestUrl = _reply->request().url(); + if (m_pageUrls.count(requestUrl) != 0) + { + //inject web3 js + QByteArray content = "\n"); + content.append(_reply->readAll()); + QString contentType = _reply->header(QNetworkRequest::ContentTypeHeader).toString(); + if (contentType.isEmpty()) + { + QMimeDatabase db; + contentType = db.mimeTypeForUrl(requestUrl).name(); + } + pageReady(content, contentType, requestUrl); + return; + } + try { //try to interpret as rlp QByteArray data = _reply->readAll(); _reply->deleteLater(); - h256 expected = m_uriHashes[_reply->request().url()]; + h256 expected = m_uriHashes[requestUrl]; bytes package(reinterpret_cast(data.constData()), reinterpret_cast(data.constData() + data.size())); Secp256k1 dec; dec.decrypt(expected, package); @@ -144,15 +163,7 @@ void DappLoader::loadDapp(RLP const& _rlp) if (entry->path == "/deployment.js") { //inject web3 code - QString code; - code += contentsOfQResource(":/js/bignumber.min.js"); - code += "\n"; - code += contentsOfQResource(":/js/webthree.js"); - code += "\n"; - code += contentsOfQResource(":/js/setup.js"); - code += "\n"; - QByteArray res = code.toLatin1(); - bytes b(res.data(), res.data() + res.size()); + bytes b(web3Content().data(), web3Content().data() + web3Content().size()); b.insert(b.end(), content.begin(), content.end()); dapp.content[hash] = b; } @@ -165,6 +176,22 @@ void DappLoader::loadDapp(RLP const& _rlp) emit dappReady(dapp); } +QByteArray const& DappLoader::web3Content() +{ + if (m_web3Js.isEmpty()) + { + QString code; + code += contentsOfQResource(":/js/bignumber.min.js"); + code += "\n"; + code += contentsOfQResource(":/js/webthree.js"); + code += "\n"; + code += contentsOfQResource(":/js/setup.js"); + code += "\n"; + m_web3Js = code.toLatin1(); + } + return m_web3Js; +} + Manifest DappLoader::loadManifest(std::string const& _manifest) { /// https://github.com/ethereum/go-ethereum/wiki/URL-Scheme @@ -216,3 +243,11 @@ void DappLoader::loadDapp(QString const& _uri) m_net.get(request); } +void DappLoader::loadPage(QString const& _uri) +{ + QUrl uri(_uri); + QNetworkRequest request(uri); + m_pageUrls.insert(uri); + m_net.get(request); +} + diff --git a/alethzero/DappLoader.h b/alethzero/DappLoader.h index 463b65d0a..deba62c68 100644 --- a/alethzero/DappLoader.h +++ b/alethzero/DappLoader.h @@ -73,9 +73,13 @@ public: ///Load a new DApp. Resolves a name with a name reg contract. Asynchronous. dappReady is emitted once everything is read, dappError othervise ///@param _uri Eth name path void loadDapp(QString const& _uri); + ///Load a regular html page + ///@param _uri Page Uri + void loadPage(QString const& _uri); signals: void dappReady(Dapp& _dapp); + void pageReady(QByteArray const& _content, QString const& _mimeType, QUrl const& _uri); void dappError(); private slots: @@ -86,9 +90,12 @@ private: DappLocation resolveAppUri(QString const& _uri); void loadDapp(dev::RLP const& _rlp); Manifest loadManifest(std::string const& _manifest); + QByteArray const& web3Content(); dev::WebThreeDirect* m_web3; QNetworkAccessManager m_net; std::map m_uriHashes; + std::set m_pageUrls; + QByteArray m_web3Js; }; diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index 94a58dec0..bbacaf539 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -183,13 +183,6 @@ Main::Main(QWidget *parent) : m_webPage = webPage; connect(webPage, &WebPage::consoleMessage, [this](QString const& _msg) { Main::addConsoleMessage(_msg, QString()); }); ui->webView->setPage(m_webPage); - connect(ui->webView, &QWebEngineView::loadFinished, [this]() - { - auto f = ui->webView->page(); - f->runJavaScript(contentsOfQResource(":/js/bignumber.min.js")); - f->runJavaScript(contentsOfQResource(":/js/webthree.js")); - f->runJavaScript(contentsOfQResource(":/js/setup.js")); - }); connect(ui->webView, &QWebEngineView::titleChanged, [=]() { @@ -199,6 +192,7 @@ Main::Main(QWidget *parent) : m_dappHost.reset(new DappHost(8081)); m_dappLoader = new DappLoader(this, web3()); connect(m_dappLoader, &DappLoader::dappReady, this, &Main::dappLoaded); + connect(m_dappLoader, &DappLoader::pageReady, this, &Main::pageLoaded); // ui->webView->page()->settings()->setAttribute(QWebEngineSettings::DeveloperExtrasEnabled, true); // QWebEngineInspector* inspector = new QWebEngineInspector(); // inspector->setPage(page); @@ -264,7 +258,7 @@ NetworkPreferences Main::netPrefs() const { listenIP.clear(); } - + auto publicIP = ui->forcePublicIP->text().toStdString(); try { @@ -274,7 +268,7 @@ NetworkPreferences Main::netPrefs() const { publicIP.clear(); } - + if (isPublicAddress(publicIP)) return NetworkPreferences(publicIP, listenIP, ui->port->value(), ui->upnp->isChecked()); else @@ -918,6 +912,7 @@ void Main::on_urlEdit_returnPressed() { //try do resolve dapp url m_dappLoader->loadDapp(s); + return; } catch (...) { @@ -931,8 +926,7 @@ void Main::on_urlEdit_returnPressed() else url.setScheme("http"); else {} - qDebug() << url.toString(); - ui->webView->page()->setUrl(url); + m_dappLoader->loadPage(url.toString()); } void Main::on_nameReg_textChanged() @@ -1799,7 +1793,7 @@ void Main::on_connect_triggered() ui->net->setChecked(true); on_net_triggered(); } - + m_connect.setEnvironment(m_servers); if (m_connect.exec() == QDialog::Accepted) { @@ -1811,9 +1805,9 @@ void Main::on_connect_triggered() nodeID = NodeId(fromHex(m_connect.nodeId().toStdString())); } catch (BadHexCharacter&) {} - + m_connect.reset(); - + if (required) web3()->requirePeer(nodeID, host); else @@ -2016,3 +2010,8 @@ void Main::dappLoaded(Dapp& _dapp) QUrl url = m_dappHost->hostDapp(std::move(_dapp)); ui->webView->page()->setUrl(url); } + +void Main::pageLoaded(QByteArray const& _content, QString const& _mimeType, QUrl const& _uri) +{ + ui->webView->page()->setContent(_content, _mimeType, _uri); +} diff --git a/alethzero/MainWin.h b/alethzero/MainWin.h index fccbc855d..a5c74eeaa 100644 --- a/alethzero/MainWin.h +++ b/alethzero/MainWin.h @@ -179,6 +179,7 @@ private slots: // Dapps void dappLoaded(Dapp& _dapp); //qt does not support rvalue refs for signals + void pageLoaded(QByteArray const& _content, QString const& _mimeType, QUrl const& _uri); signals: void poll(); From 50d18453c7b813cf6aa8572236d59a5952afb89e Mon Sep 17 00:00:00 2001 From: Alexandre Van de Sande Date: Thu, 9 Apr 2015 15:14:17 -0300 Subject: [PATCH 03/19] triangles and debugging --- mix/qml/DebugInfoList.qml | 4 +- mix/qml/Debugger.qml | 80 +++++++++++---------- mix/qml/img/closedtriangleindicator.png | Bin 422 -> 242 bytes mix/qml/img/closedtriangleindicator@2x.png | Bin 0 -> 423 bytes mix/qml/img/opentriangleindicator.png | Bin 425 -> 257 bytes mix/qml/img/opentriangleindicator@2x.png | Bin 836 -> 429 bytes 6 files changed, 45 insertions(+), 39 deletions(-) create mode 100644 mix/qml/img/closedtriangleindicator@2x.png diff --git a/mix/qml/DebugInfoList.qml b/mix/qml/DebugInfoList.qml index 5b1a67519..b479d6d28 100644 --- a/mix/qml/DebugInfoList.qml +++ b/mix/qml/DebugInfoList.qml @@ -40,11 +40,9 @@ ColumnLayout { height: 25 id: header Image { - source: "qrc:/qml/img/opentriangleindicator.png" + source: "img/closedtriangleindicator.png" width: 15 height: 15 - sourceSize.width: 15 - sourceSize.height: 15 id: storageImgArrow } diff --git a/mix/qml/Debugger.qml b/mix/qml/Debugger.qml index e5c7e576d..b059a0336 100644 --- a/mix/qml/Debugger.qml +++ b/mix/qml/Debugger.qml @@ -206,8 +206,10 @@ Rectangle { anchors.top: parent.top anchors.topMargin: 15 anchors.left: parent.left; - anchors.leftMargin: machineStates.sideMargin - width: debugScrollArea.width - machineStates.sideMargin * 2 - 20; + anchors.leftMargin: machineStates.sideMargin + //anchors.right: parent.right; + // anchors.rightMargin: machineStates.sideMargin + width: debugScrollArea.width - machineStates.sideMargin * 2 - 20 ; spacing: machineStates.sideMargin Rectangle { @@ -218,15 +220,15 @@ Rectangle { color: "transparent" Rectangle { - anchors.top: parent.top - anchors.bottom: parent.bottom - anchors.left: parent.left + anchors.fill: parent color: "transparent" - width: parent.width * 0.4 + //width: parent.width * 0.4 RowLayout { - anchors.horizontalCenter: parent.horizontalCenter + //anchors.horizontalCenter: parent.horizontalCenter + anchors.fill: parent id: jumpButtons - spacing: 3 + spacing: 2 + layoutDirection: Qt.LeftToRight StepActionImage { @@ -239,6 +241,7 @@ Rectangle { buttonShortcut: "Ctrl+Shift+F8" buttonTooltip: qsTr("Start Debugging") visible: true + Layout.alignment: Qt.AlignLeft } StepActionImage @@ -351,35 +354,40 @@ Rectangle { buttonTooltip: qsTr("Run Forward") visible: false } - } - } - Rectangle { - anchors.top: parent.top - anchors.bottom: parent.bottom - anchors.right: parent.right - width: parent.width * 0.6 - color: "transparent" - Slider { - id: statesSlider - anchors.fill: parent - tickmarksEnabled: true - stepSize: 1.0 - onValueChanged: Debugger.jumpTo(value); - style: SliderStyle { - groove: Rectangle { - implicitHeight: 3 - color: "#7da4cd" - radius: 8 - } - handle: Rectangle { - anchors.centerIn: parent - color: control.pressed ? "white" : "lightgray" - border.color: "gray" - border.width: 2 - implicitWidth: 10 - implicitHeight: 10 - radius: 12 + Rectangle { + anchors.top: parent.top + anchors.bottom: parent.bottom + anchors.right: parent.right + //width: parent.width * 0.6 + //minimumWidth: parent.width * 0.6 + color: "transparent" + Layout.fillWidth: true + //Layout.minimumWidth: parent.width * 0.6 + Layout.alignment: Qt.AlignRight + + Slider { + id: statesSlider + anchors.fill: parent + tickmarksEnabled: true + stepSize: 1.0 + onValueChanged: Debugger.jumpTo(value); + style: SliderStyle { + groove: Rectangle { + implicitHeight: 3 + color: "#7da4cd" + radius: 8 + } + handle: Rectangle { + anchors.centerIn: parent + color: control.pressed ? "white" : "lightgray" + border.color: "gray" + border.width: 2 + implicitWidth: 10 + implicitHeight: 10 + radius: 12 + } + } } } } diff --git a/mix/qml/img/closedtriangleindicator.png b/mix/qml/img/closedtriangleindicator.png index 440adb711e74368beeb0792158ed8e7524ae919b..ccf6c66d4d37b6217c3fb018de58836c711369fe 100644 GIT binary patch literal 242 zcmeAS@N?(olHy`uVBq!ia0vp^{2W; zCrH>GIDI;MVskSyzoNY1!vKNPM~{}CyLxGc)I$ztaD0e0svj2WxfCa literal 422 zcmV;X0a^ZuP)Px$U`a$lR7eeDU>F6XAuu9Cz{|^Pk%NN+4>di{M5JM{TwGk|+}+)ch*VEd8L<|F z3{qugWFK!z81y0p%*HECs>NW#7#SJ8I5{~l z0Uh9k*K|CRWLXR{4`{h05bp+B-U9SJ3m!YLN|9|b)HEib<<-E1cMzEJ<+0j;Ly%I7 zVa8ek85e+-2g3vi(bTdSWRCz4uK`*`E695SS0+;G(JNW0)N?KYaL* z2;<h|s1*WghDm!g)%$ABhA0WEz9H<Px$VM#F6XAuwV?z{|^Pk%NN+548e-i3EdUxwyE_xx2d?k)Q{sQc^4i z8KTO}%zWI#!=n($X2fYK5fY?Y3^J09iHWJt)6;VcFz7{yumh_Sax4ZL#K_3##mUKe z3FrVPtR@o>B->(;xj@S$fp|C2@)n@)SqRvLB2AISP?MN|mRAE4-a%l>mq#%j4~H5S z!;H5AGA;lu4~7Zgqp4{z$Q}V8UIVmzhNYz?Cp|5O*_AFJATS@s!A4Wt$1po)e)#Yq z5yrtrlavy%8Gt7C;s5{tsoS@2UxOx&!KJ3f$AG3s0WE!qVG9-kY6SH^pfB6Lefws= zZQC}YECsoPA|C@Sd=4}t2I$LuSUiPSh-@DNE!_q*S)UwBK`tW4$G`sl`&Y4J$Bqd= z{r^FRkON4y`1aqwe!5;N+?u4KQ}l0|KH!?9Xf5t z_WgZ(d%I4GVOk1bM=eldvzC_DuAZKrsEnfh|Ni}by|euNz4jB2H1rxgYySVUWj)~* z$Wao>dZG1sLRNx_m&5@U$1SsG&lWYX;bV$D^y&Zq|GBrf=YMD9`tKgboRnO_xa`5Z zySw{CLqq>F{+#6?zSF+q!vkrbK9O0RFN9=+On4l(GPJ$7uD{K8L=@-^22WQ%mvv4F FO#ss8Zh8O! literal 425 zcmV;a0apHrP)Px$V@X6oR7ef&RIy6LKoCt-tZl86{DHNtB=`YxoZ4JvcZI!`jbC74qaR=+3F%VZ zFIXf&tgaD~LK8Sl*0+#_Wp5{JECgW}mYsR?-c0r_#BuDh4p;}Q1OLqdm-^r+iXKrr zr|J{%r#Ox;RQ`?%h`ecDF*>{@BZ^Vv{WO8RutVBP|Mp?4e$rQKq{ z6_`$q-&k&u=lN?81c$(mud&u0ajhtOI_V!)&c9lpE>XY632S; TplQRi00000NkvXXu0mjfZRW#V diff --git a/mix/qml/img/opentriangleindicator@2x.png b/mix/qml/img/opentriangleindicator@2x.png index fd948d73b76a58fa6c48af563742943064805193..320749684b2ffa7a1d4383845b778a5087379c33 100644 GIT binary patch literal 429 zcmV;e0aE^nP)Px$XGugsR7ef&RIyIOFc3`uF|&3~@(0YUC=nlkssc+Vwhrt}EPMe&7x(~{Dp9sf z{RM_3LQGwdk^vH_A_>nTmMqJ;I&27AvV8aM-OKgas%4pF954NlB{K_EZQ1at?maF6fc&#+t8NGw*L^?ZW%Q`-3kM1?HNUR~Ec#8sS#xESNt z-@*E&h*7b&16%~w-XdP}Tsqf%U4nVEX6j;uw;_ z`ZnCQLpV_2o~>eT*6TkaNtwyXg-SE#T$`sT7kL=)w7e&2g@rpEaG?3>%OC2VFerZq?= zuwkbf|93M6o8Bqf`G?Kyd&pap*ZbFA&8ki`*mg+cq}An@U+k_;)A@b8_;kN!h{P$* z?YG~aOxk#(^?RfS%U&aWmJt zB7X04zF$7OuPIlFoON0G%iCOrDy;>lRCO)CU$Fk2P^oe0Gc#@7 zpM^JGtFZsLQOQ|llEJC$J`SxN=ak)ray<5F+l6iTCe`aAq;|g|dETS44Q%S19~=7x zPlvyen|4w6^sg`t5k03e*J?Y~c>M8)Vw}$1(DREK7n&Sdu4 zDv{fzW>G?F26N8G7udzSU7CKaF@MtHDfb^+|NN*nSL3{pex@bIoSE$rmv2Xx&iS=% zRaxV&DB)u>EA8f=*S?`^wcMHalB)D3-qZyvmaJXkD)ZvGyu~Upjkm9z#0u)0_SK3n z5dK*>=f1P(g|$H|zi@iy=Nlb*S9h%Z6YqLp>9lqTkFw?4dabGM6n$;CM-k9NMR zer4^$$;;Lp|KrP_&X)eDwbwSjQ@Lqxe1OM*`3wUJ Date: Fri, 10 Apr 2015 09:28:08 -0300 Subject: [PATCH 04/19] stylistic adjustments to error and running style --- mix/qml/Debugger.qml | 13 +++---------- mix/qml/StatusPane.qml | 21 +++++++++++++++++---- mix/qml/html/cm/solarized.css | 10 +++++++--- mix/qml/img/signerroricon32.png | Bin 1681 -> 0 bytes mix/qml/img/warningicon.png | Bin 0 -> 498 bytes mix/qml/img/warningicon@2x.png | Bin 0 -> 1049 bytes mix/res.qrc | 5 ++++- 7 files changed, 31 insertions(+), 18 deletions(-) delete mode 100644 mix/qml/img/signerroricon32.png create mode 100644 mix/qml/img/warningicon.png create mode 100644 mix/qml/img/warningicon@2x.png diff --git a/mix/qml/Debugger.qml b/mix/qml/Debugger.qml index b059a0336..ef83ef390 100644 --- a/mix/qml/Debugger.qml +++ b/mix/qml/Debugger.qml @@ -207,8 +207,6 @@ Rectangle { anchors.topMargin: 15 anchors.left: parent.left; anchors.leftMargin: machineStates.sideMargin - //anchors.right: parent.right; - // anchors.rightMargin: machineStates.sideMargin width: debugScrollArea.width - machineStates.sideMargin * 2 - 20 ; spacing: machineStates.sideMargin @@ -222,12 +220,10 @@ Rectangle { Rectangle { anchors.fill: parent color: "transparent" - //width: parent.width * 0.4 RowLayout { - //anchors.horizontalCenter: parent.horizontalCenter anchors.fill: parent id: jumpButtons - spacing: 2 + spacing: 3 layoutDirection: Qt.LeftToRight StepActionImage @@ -359,11 +355,9 @@ Rectangle { anchors.top: parent.top anchors.bottom: parent.bottom anchors.right: parent.right - //width: parent.width * 0.6 - //minimumWidth: parent.width * 0.6 color: "transparent" Layout.fillWidth: true - //Layout.minimumWidth: parent.width * 0.6 + Layout.minimumWidth: parent.width * 0.2 Layout.alignment: Qt.AlignRight Slider { @@ -488,7 +482,7 @@ Rectangle { anchors.top : parent.top anchors.bottom: parent.bottom anchors.right: parent.right - height: parent.height //- 2 * stateListContainer.border.width + height: parent.height color: "transparent" ColumnLayout { @@ -528,7 +522,6 @@ Rectangle { title : qsTr("Stack") itemDelegate: Item { id: renderedItem - //height: 25 width: parent.width RowLayout { diff --git a/mix/qml/StatusPane.qml b/mix/qml/StatusPane.qml index 9e10edbe9..064fe42e5 100644 --- a/mix/qml/StatusPane.qml +++ b/mix/qml/StatusPane.qml @@ -229,13 +229,26 @@ Rectangle { Button { z: 4 - anchors.right: parent.right - anchors.rightMargin: 9 - anchors.verticalCenter: parent.verticalCenter + anchors.centerIn: parent id: goToLineBtn text: "" - iconSource: "qrc:/qml/img/signerroricon32.png" + width: 30 + height: 30 action: goToCompilationError + style: ButtonStyle { + background: Rectangle { + color: "transparent" + + Image { + source: "qrc:/qml/img/warningicon.png" + height: 30 + width: 30 + sourceSize.width: 30 + sourceSize.height: 30 + anchors.centerIn: parent + } + } + } } } } diff --git a/mix/qml/html/cm/solarized.css b/mix/qml/html/cm/solarized.css index 10cfe14a0..e99c6de57 100644 --- a/mix/qml/html/cm/solarized.css +++ b/mix/qml/html/cm/solarized.css @@ -166,20 +166,24 @@ view-port /* Code execution */ .CodeMirror-exechighlight { - background: #0C4250; + border-bottom: double 1px #94A2A2; } + /* Error annotation */ .CodeMirror-errorannotation { - border-bottom: 1px solid #b58900; + border-bottom: 1px solid #DD3330; + margin-bottom: 4px; } .CodeMirror-errorannotation-context { font-family: monospace; font-size: small; - color: #586e75; + color: #EEE9D5; background: #b58900; padding: 2px; + text-shadow: none !important; + border-top: solid 2px #063742; } span.CodeMirror-selectedtext { color: #586e75 !important; } diff --git a/mix/qml/img/signerroricon32.png b/mix/qml/img/signerroricon32.png deleted file mode 100644 index 703ac5e2cb7e2d63c152280f6a51d5b9f9b686a3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1681 zcmV;C25$L@P)F7{{M;?`?Zqacu__1*&1P0Rqt}Fxe76(9lE~h?!q>_>%0Ci7~`1G0Q&amo1yi z&@J)9Otws?(Iv~`93~Dd>IWv_HId4K0U0pfL0;?&ZEx?{b1!XeZ*N<+Cuz^Ur}v!y z?|II1&vQy3iQThWYl9w7N6o^*9Q+S^n3req2ZMX;V`Fy`Jwp=x(4Lib*krL>o0^^d z%fGs6+rPa0pCF!8R$6?MlMY>4TH*NU=+PRN>(;sf{yuc*C>pA#V|7Q4 z09{>$mlrQWufyT=A;kMBBH?Oo&i1vpw=uoF1^R{t0KFcB_I4P$dsi5nm}sa|K*Rvd zo;!CUt)%4pU|%1jtE&SD27!tq079%>xdJ_p9ywP%9$UT3HLE7>?d!`WKHmfHg$wyw zyB&y52Oy2dc>>+tF#Owv$52%C(0}7bK8Il^TJ5W`VTk^Ic;4A5j89D+JLq=bi~uy7 z&4;#FEH`ua?&bJ>`{D+MTZ#}bZ{LRA?r!I**IV_0%Ox+zQ=4tmYdJX&`T6+*ZFxBW z$GsX8o+C7m@a!2p9~clOrl$|16Tip+Jp~03Pu4$fFy|f_o4U6lYT)E zY_D4^WTPmyZB9=w<|`}J#lz!6*8zl>oSwe6dwBS`3@}twWabEI*;rd!#%5*3QBx%p zLSUAIb7aK1f#XOXiW_$A0$|xV@kkq<%k75M!NKkz!`SnOhZiF`FqEHfVkrG%Lv?ip zo1Pvos_=vg0(b`oB)WxG5pk6QdM@G6tLhNsjk1xf&1%tV{M#6C|hCO>K zSd&TBlelXHkxea9QXfW3^!emgc=4i(Qd(U&J-wW8A8=Z&CI*+oP+VNjq@}4(s(eGF z7D1$FNM6cyD7s|m(I*ArQ8Yowrnx8qS(T3-CD-*e5_E^n#yAMky{j# zgrbdx?oqslvTXI+Gc$`RcfzoBS*>P95L)?+jNL?|SrbMt#jq%P2qEtxf@`YL1Q6u7 z9+Bg!D^$dj0!a2aJ6nQi(dcw#@>)t>Dn+91l>j2cbc-5|{oT2_#Y7rO0VMm?WO~ae zicbxMa7t0CxR1W}P%6A++2VsME60N?VwMQ<=T@>sS6aLv_1oMUK?HgTL8>qQF@#iS58mq*ZO>dpoNjz|uK?K7>m3L)f3sHPGj-57fN*W0&Q$cVQ30mvQ@@l@b@qTo&-8y0N5`BEWX!f82%HWZXW-)xYo`=NedW?(hb;{0W9wU{FVl=t&5O` zc}nkMIr9xFUaGjsO7PDVR{c#F@-68A@2mifqVOobpo@3}@r$8x${YzzL=k}KaSm+F z=tzzcVDkbVE%16mga2Q!Hv3X8K@Ro@aM{D&h9{?M;gs%G$4TcS5_+CSL83Dv0?;Xi b_mce!KXe&g-g0BD00000NkvXXu0mjf(T5bq diff --git a/mix/qml/img/warningicon.png b/mix/qml/img/warningicon.png new file mode 100644 index 0000000000000000000000000000000000000000..0215030da74395d350f911fea5c8eb0a2b72f6ea GIT binary patch literal 498 zcmVPx$tVu*cR7ef&R4YsaK@ff0YY8Da3zPt+2{fq$O40<2AmQt97z_qb2m~k`2^g@r zDlj+%27y9WfFw8w0tg8-=`u6d>s@=fW4A$(n`Dyd%zN{8X152VmTn;3z#nZub<;Zu?m$r6X&=KvliCV%ZpH0f!11_V#!>M5gGGwKk< z0&srPz{P1pV#-O)LflH2?sXeb1&ri@p#cZ^en(=?NzGi@SXfWZ4MM41Y5n{fDEKke z1QS#eBV%DWy$3X{8!OB;!6fRnible^yf8_OHF-=-eF;tM$Nbm`)5J0=(Ts%Q{nr3Ug8f$r8TYJ^!gTH51Ti2rO63bB5~rEOHa)AA(y+S zX@(=r*%>c&brUJkA)ipMkE^@O&uG!hWaA2w&t`XGMfW!YYNt3Kl)1oO0BVn7S4}U4 z?{q`pJb|hCSmH{L7+%uEd=1`Jbgnu)VK`=y0PFMlwMQ&gm{<+1uuhC4^3e#hQ?MQI oNJrk{9_{J$SGs|81OI6QKlJf*<)bO)AOHXW07*qoM6N<$f^<6BS^xk5 literal 0 HcmV?d00001 diff --git a/mix/qml/img/warningicon@2x.png b/mix/qml/img/warningicon@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..e41615f3760f6a62bd05c145daad5a11a8d420a9 GIT binary patch literal 1049 zcmV+!1m^pRP)Px&(@8`@RA>e5SlvrhK@>l8{RAu0!jK+{zN3u5HCG4{dyq)NRU!}yBBIBV=!1GF z2r8p5dJX@89-d++Ss*}F6Q5OYA8IdjhM zoZoNmoqO*BShEUP1*`&A0jq#jz$#!BunJfOtO8a6s{pV zfU6*cd1LG#Ft#US|F|Y%G6v{dFn&q%wN2$vQ}qsaa!qjC{0odvZ((D7e}d!kTP@Bn zT_Jl_)tMC8>J!vefg^1aDXS={^#MatxX= z!n~n9ihXywdY_zjO~u6T>s-k7$7=8xAK{6lt5kp|nSfgnt49hAn zVz)KY9%bZYK9P(V0!xY%+NqT=ukTogWV{@cpN2-#^lRrh$S#H2IRb;jWFL8YsUL77TCdD9N^dQ#Sj{kFUSy6U6fs0rBuj5Y*9lYG+T%k!qCuu0-wCK*@}tvkxz?Zqn{VYK_kMZ8XC;~ zVh{q5*Y2-`in8~3Ipddsg4I+5+`5psmrq{>_%^AKgdv4zZN;5^jVH63aK#vQ{1CvtrbJ&a z`T*`f0ElNfxKb>59CvyL8+i0K<;ro8-#yIO9c8lA7?C}U2l>j%#2<~xr)(&!sHvRb z3k*#d9~G@gw#A1SYD4Ec(J{;bEp-H zFyGlmKef7lx?pTm*1B}hdQIl@#`v)#3q5!vv(D8Ho2)R30dzo-B`;$loAikV^Z!Dh z(mdKRh>xQ>^DRm$a2R3(58YRoBuwTCbx8{#7C$Op24tuvee?oCwL@BH!mR(vFz|RY z*6qdDAp8n2ZK6gm)fBZ&m$Ud*0jq#jz$#!BunJfOtO8a6tAJI&Dqt1(j}-U^xh&(r TKuU**00000NkvXXu0mjfpFis? literal 0 HcmV?d00001 diff --git a/mix/res.qrc b/mix/res.qrc index f5798ca58..f175fab1f 100644 --- a/mix/res.qrc +++ b/mix/res.qrc @@ -20,6 +20,7 @@ qml/img/bugiconactive.png qml/img/bugiconinactive.png qml/img/closedtriangleindicator.png + qml/img/closedtriangleindicator@2x.png qml/img/closedtriangleindicator_filesproject.png qml/img/console.png qml/img/copy.png @@ -43,6 +44,7 @@ qml/img/note.png qml/img/openedfolder.png qml/img/opentriangleindicator.png + qml/img/opentriangleindicator@2x.png qml/img/opentriangleindicator_filesproject.png qml/img/plus.png qml/img/projecticon.png @@ -63,6 +65,7 @@ qml/img/copyiconactive.png qml/img/searchicon.png qml/img/stop_button2x.png - qml/img/signerroricon32.png + qml/img/warningicon.png + qml/img/warningicon@2x.png From a42f6407350c8271b60cf24ca6b4571babf7cfe4 Mon Sep 17 00:00:00 2001 From: Alexandre Van de Sande Date: Fri, 10 Apr 2015 09:32:43 -0300 Subject: [PATCH 05/19] Removed comments --- mix/qml/html/cm/solarized.css | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mix/qml/html/cm/solarized.css b/mix/qml/html/cm/solarized.css index e99c6de57..b8cede806 100644 --- a/mix/qml/html/cm/solarized.css +++ b/mix/qml/html/cm/solarized.css @@ -154,8 +154,10 @@ http://ethanschoonover.com/solarized/img/solarized-palette.png } /* + Active line. Negative margin compensates left padding of the text in the view-port + */ .cm-s-solarized.cm-s-dark .CodeMirror-activeline-background { background: rgba(255, 255, 255, 0.10); From 7226fe23aa0c7f4e477de3711ed356f5ddb281c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Fri, 10 Apr 2015 14:47:43 +0200 Subject: [PATCH 06/19] Change instruction scheduler Try different instruction scheduler in LLVM, other crashes sometimes. Also parse command line options properly for random tests. --- evmjit/libevmjit/ExecutionEngine.cpp | 4 ++-- test/state.cpp | 2 ++ test/vm.cpp | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/evmjit/libevmjit/ExecutionEngine.cpp b/evmjit/libevmjit/ExecutionEngine.cpp index 0ed4a65b5..e15dad969 100644 --- a/evmjit/libevmjit/ExecutionEngine.cpp +++ b/evmjit/libevmjit/ExecutionEngine.cpp @@ -88,10 +88,10 @@ void parseOptions() //cl::ParseEnvironmentOptions("evmjit", "EVMJIT", "Ethereum EVM JIT Compiler"); // FIXME: LLVM workaround: - // Manually select instruction scheduler other than "source". + // Manually select instruction scheduler. Confirmed bad schedulers: source, list-burr, list-hybrid. // "source" scheduler has a bug: http://llvm.org/bugs/show_bug.cgi?id=22304 auto envLine = std::getenv("EVMJIT"); - auto commandLine = std::string{"evmjit "} + (envLine ? envLine : "") + " -pre-RA-sched=list-burr\0"; + auto commandLine = std::string{"evmjit "} + (envLine ? envLine : "") + " -pre-RA-sched=list-ilp\0"; static const auto c_maxArgs = 20; char const* argv[c_maxArgs] = {nullptr, }; auto arg = std::strtok(&*commandLine.begin(), " "); diff --git a/test/state.cpp b/test/state.cpp index 813c3b4d7..65f333538 100644 --- a/test/state.cpp +++ b/test/state.cpp @@ -218,6 +218,8 @@ BOOST_AUTO_TEST_CASE(stCreateTest) BOOST_AUTO_TEST_CASE(stRandom) { + test::Options::get(); // parse command line options, e.g. to enable JIT + string testPath = dev::test::getTestPath(); testPath += "/StateTests/RandomTests"; diff --git a/test/vm.cpp b/test/vm.cpp index d92989133..4728b8a53 100644 --- a/test/vm.cpp +++ b/test/vm.cpp @@ -524,6 +524,8 @@ BOOST_AUTO_TEST_CASE(vmInputLimitsLightTest) BOOST_AUTO_TEST_CASE(vmRandom) { + test::Options::get(); // parse command line options, e.g. to enable JIT + string testPath = getTestPath(); testPath += "/VMTests/RandomTests"; From c533f1cbda327a85b0cdde498fa008e6d7d389a8 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 10 Apr 2015 16:41:58 +0200 Subject: [PATCH 07/19] OpenCL stuff, Fix for eth_call. --- exp/CMakeLists.txt | 18 +++ exp/main.cpp | 29 ++++- libdevcore/CommonIO.cpp | 6 +- libdevcore/CommonIO.h | 2 +- libdevcore/RangeMask.h | 1 + .../TransientDirectory.cpp | 4 +- .../TransientDirectory.h | 4 - libethash/util.h | 2 +- libethcore/Ethasher.cpp | 38 ++++++ libethcore/Ethasher.h | 2 + libethcore/ProofOfWork.cpp | 117 ++++++++---------- libethcore/ProofOfWork.h | 6 +- libethereum/CMakeLists.txt | 7 +- libethereum/Client.cpp | 1 + libethereum/ClientBase.cpp | 2 +- libtestutils/BlockChainLoader.h | 2 +- libtestutils/StateLoader.h | 2 +- libweb3jsonrpc/WebThreeStubServerBase.cpp | 67 +++++----- test/TestUtils.cpp | 1 + test/blockchain.cpp | 2 +- 20 files changed, 186 insertions(+), 127 deletions(-) rename {libtestutils => libdevcore}/TransientDirectory.cpp (95%) rename {libtestutils => libdevcore}/TransientDirectory.h (96%) diff --git a/exp/CMakeLists.txt b/exp/CMakeLists.txt index 548f48da8..7e670cfaa 100644 --- a/exp/CMakeLists.txt +++ b/exp/CMakeLists.txt @@ -10,8 +10,26 @@ set(EXECUTABLE exp) add_executable(${EXECUTABLE} ${SRC_LIST}) +target_link_libraries(${EXECUTABLE} ${Boost_REGEX_LIBRARIES}) + +if (READLINE_FOUND) + target_link_libraries(${EXECUTABLE} ${READLINE_LIBRARIES}) +endif() + +if (JSONRPC) + target_link_libraries(${EXECUTABLE} web3jsonrpc) +endif() + +target_link_libraries(${EXECUTABLE} webthree) target_link_libraries(${EXECUTABLE} ethereum) target_link_libraries(${EXECUTABLE} p2p) +target_link_libraries(${EXECUTABLE} ethash-cl) +target_link_libraries(${EXECUTABLE} ethash) +target_link_libraries(${EXECUTABLE} OpenCL) install( TARGETS ${EXECUTABLE} DESTINATION bin) + + + + diff --git a/exp/main.cpp b/exp/main.cpp index 23c907ed1..6c067f83e 100644 --- a/exp/main.cpp +++ b/exp/main.cpp @@ -19,18 +19,25 @@ * @date 2014 * Ethereum client. */ +#define __CL_ENABLE_EXCEPTIONS +#define CL_USE_DEPRECATED_OPENCL_2_0_APIS +#include "libethash-cl/cl.hpp" + #include -#include #include #include #include #include #include -#include +#include #include +#include #include -#include +#include +#include #include +#include +#include #include #include #include @@ -101,6 +108,22 @@ int main() #else int main() { + std::vector platforms; + cl::Platform::get(&platforms); + if (platforms.empty()) + { + cdebug << "No OpenCL platforms found."; + return false; + } + + EthashCL ecl; + BlockInfo genesis = CanonBlockChain::genesis(); + TransientDirectory td; + std::pair r; + while (!r.first.completed) + r = ecl.mine(genesis, 1000); + EthashCL::assignResult(r.second, genesis); + assert(EthashCPU::verify(genesis)); return 0; } #endif diff --git a/libdevcore/CommonIO.cpp b/libdevcore/CommonIO.cpp index 46d6e3a6b..a1a1056cb 100644 --- a/libdevcore/CommonIO.cpp +++ b/libdevcore/CommonIO.cpp @@ -58,7 +58,7 @@ string dev::memDump(bytes const& _bytes, unsigned _width, bool _html) } // Don't forget to delete[] later. -bytesRef dev::contentsNew(std::string const& _file) +bytesRef dev::contentsNew(std::string const& _file, bytesRef _dest) { std::ifstream is(_file, std::ifstream::binary); if (!is) @@ -68,8 +68,10 @@ bytesRef dev::contentsNew(std::string const& _file) streamoff length = is.tellg(); if (length == 0) // return early, MSVC does not like reading 0 bytes return bytesRef(); + if (!_dest.empty() && _dest.size() != (unsigned)length) + return bytesRef(); is.seekg (0, is.beg); - bytesRef ret(new byte[length], length); + bytesRef ret = _dest.empty() ? bytesRef(new byte[length], length) : _dest; is.read((char*)ret.data(), length); is.close(); return ret; diff --git a/libdevcore/CommonIO.h b/libdevcore/CommonIO.h index f42f449bb..3889f6171 100644 --- a/libdevcore/CommonIO.h +++ b/libdevcore/CommonIO.h @@ -46,7 +46,7 @@ namespace dev bytes contents(std::string const& _file); std::string contentsString(std::string const& _file); /// Retrieve and returns the allocated contents of the given file. If the file doesn't exist or isn't readable, returns nullptr. Don't forget to delete [] when finished. -bytesRef contentsNew(std::string const& _file); +bytesRef contentsNew(std::string const& _file, bytesRef _dest = bytesRef()); /// Write the given binary data into the given file, replacing the file if it pre-exists. void writeFile(std::string const& _file, bytesConstRef _data); diff --git a/libdevcore/RangeMask.h b/libdevcore/RangeMask.h index 19262515c..bdf00e687 100644 --- a/libdevcore/RangeMask.h +++ b/libdevcore/RangeMask.h @@ -25,6 +25,7 @@ #include #include #include +#include namespace dev { diff --git a/libtestutils/TransientDirectory.cpp b/libdevcore/TransientDirectory.cpp similarity index 95% rename from libtestutils/TransientDirectory.cpp rename to libdevcore/TransientDirectory.cpp index 694784e25..db702181e 100644 --- a/libtestutils/TransientDirectory.cpp +++ b/libdevcore/TransientDirectory.cpp @@ -20,11 +20,11 @@ */ #include -#include +#include "Exceptions.h" #include "TransientDirectory.h" +#include "CommonIO.h" using namespace std; using namespace dev; -using namespace dev::test; TransientDirectory::TransientDirectory(): TransientDirectory((boost::filesystem::temp_directory_path() / "eth_transient" / toString(FixedHash<4>::random())).string()) diff --git a/libtestutils/TransientDirectory.h b/libdevcore/TransientDirectory.h similarity index 96% rename from libtestutils/TransientDirectory.h rename to libdevcore/TransientDirectory.h index 21a338e59..6c90982a3 100644 --- a/libtestutils/TransientDirectory.h +++ b/libdevcore/TransientDirectory.h @@ -22,12 +22,9 @@ #pragma once #include -#include "Common.h" namespace dev { -namespace test -{ /** * @brief temporary directory implementation @@ -48,4 +45,3 @@ private: }; } -} diff --git a/libethash/util.h b/libethash/util.h index ba8957815..1e6d4fbab 100644 --- a/libethash/util.h +++ b/libethash/util.h @@ -29,7 +29,7 @@ extern "C" { #ifdef _MSC_VER void debugf(const char *str, ...); #else -#define debugf printf +#define debugf(...) fprintf(stderr, __VA_ARGS__) #endif static inline uint32_t min_u32(uint32_t a, uint32_t b) diff --git a/libethcore/Ethasher.cpp b/libethcore/Ethasher.cpp index 75f0bcd5a..6cd2504b3 100644 --- a/libethcore/Ethasher.cpp +++ b/libethcore/Ethasher.cpp @@ -123,6 +123,44 @@ ethash_params Ethasher::params(BlockInfo const& _header) return params((unsigned)_header.number); } +void Ethasher::readFull(BlockInfo const& _header, void* _dest) +{ + if (!m_fulls.count(_header.seedHash())) + { + // @memoryleak @bug place it on a pile for deletion - perhaps use shared_ptr. +/* if (!m_fulls.empty()) + { + delete [] m_fulls.begin()->second.data(); + m_fulls.erase(m_fulls.begin()); + }*/ + + try { + boost::filesystem::create_directories(getDataDir("ethash")); + } catch (...) {} + + auto info = rlpList(c_ethashRevision, _header.seedHash()); + std::string oldMemoFile = getDataDir("ethash") + "/full"; + std::string memoFile = getDataDir("ethash") + "/full-R" + toString(c_ethashRevision) + "-" + toHex(_header.seedHash().ref().cropped(0, 8)); + if (boost::filesystem::exists(oldMemoFile) && contents(oldMemoFile + ".info") == info) + { + // memofile valid - rename. + boost::filesystem::rename(oldMemoFile, memoFile); + } + + IGNORE_EXCEPTIONS(boost::filesystem::remove(oldMemoFile)); + IGNORE_EXCEPTIONS(boost::filesystem::remove(oldMemoFile + ".info")); + + ethash_params p = params((unsigned)_header.number); + bytesRef r = contentsNew(memoFile, bytesRef((byte*)_dest, p.full_size)); + if (!r) + { + auto c = light(_header); + ethash_prep_full(_dest, &p, c); + writeFile(memoFile, bytesConstRef((byte*)_dest, p.full_size)); + } + } +} + ethash_params Ethasher::params(unsigned _n) { ethash_params p; diff --git a/libethcore/Ethasher.h b/libethcore/Ethasher.h index 8d1a1e84c..32622929f 100644 --- a/libethcore/Ethasher.h +++ b/libethcore/Ethasher.h @@ -56,6 +56,8 @@ public: static ethash_params params(BlockInfo const& _header); static ethash_params params(unsigned _n); + void readFull(BlockInfo const& _header, void* _dest); + struct Result { h256 value; diff --git a/libethcore/ProofOfWork.cpp b/libethcore/ProofOfWork.cpp index a34e75d71..c87f51a78 100644 --- a/libethcore/ProofOfWork.cpp +++ b/libethcore/ProofOfWork.cpp @@ -33,32 +33,6 @@ #include #if ETH_ETHASHCL #include -#define ETHASH_REVISION REVISION -#define ETHASH_DATASET_BYTES_INIT DATASET_BYTES_INIT -#define ETHASH_DATASET_BYTES_GROWTH DATASET_BYTES_GROWTH -#define ETHASH_CACHE_BYTES_INIT CACHE_BYTES_INIT -#define ETHASH_CACHE_BYTES_GROWTH CACHE_BYTES_GROWTH -#define ETHASH_DAGSIZE_BYTES_INIT DAGSIZE_BYTES_INIT -#define ETHASH_DAG_GROWTH DAG_GROWTH -#define ETHASH_EPOCH_LENGTH EPOCH_LENGTH -#define ETHASH_MIX_BYTES MIX_BYTES -#define ETHASH_HASH_BYTES HASH_BYTES -#define ETHASH_DATASET_PARENTS DATASET_PARENTS -#define ETHASH_CACHE_ROUNDS CACHE_ROUNDS -#define ETHASH_ACCESSES ACCESSES -#undef REVISION -#undef DATASET_BYTES_INIT -#undef DATASET_BYTES_GROWTH -#undef CACHE_BYTES_INIT -#undef CACHE_BYTES_GROWTH -#undef DAGSIZE_BYTES_INIT -#undef DAG_GROWTH -#undef EPOCH_LENGTH -#undef MIX_BYTES -#undef HASH_BYTES -#undef DATASET_PARENTS -#undef CACHE_ROUNDS -#undef ACCESSES #endif #include "BlockInfo.h" #include "Ethasher.h" @@ -131,16 +105,16 @@ std::pair EthashCPU::mine(BlockInfo const& _header, #if ETH_ETHASHCL /* -struct ethash_cl_search_hook -{ - // reports progress, return true to abort - virtual bool found(uint64_t const* nonces, uint32_t count) = 0; - virtual bool searched(uint64_t start_nonce, uint32_t count) = 0; -}; - class ethash_cl_miner { public: + struct search_hook + { + // reports progress, return true to abort + virtual bool found(uint64_t const* nonces, uint32_t count) = 0; + virtual bool searched(uint64_t start_nonce, uint32_t count) = 0; + }; + ethash_cl_miner(); bool init(ethash_params const& params, const uint8_t seed[32], unsigned workgroup_size = 64); @@ -150,58 +124,63 @@ public: }; */ -struct EthashCLHook: public ethash_cl_search_hook +struct EthashCLHook: public ethash_cl_miner::search_hook { - virtual bool found(uint64_t const* _nonces, uint32_t _count) + void abort() + { + if (m_aborted) + return; + m_abort = true; + for (unsigned timeout = 0; timeout < 100 && !m_aborted; ++timeout) + std::this_thread::sleep_for(chrono::milliseconds(30)); + if (!m_aborted) + cwarn << "Couldn't abort. Abandoning OpenCL process."; + m_aborted = m_abort = false; + m_found.clear(); + } + + vector fetchFound() { vector ret; Guard l(x_all); std::swap(ret, m_found); return ret; } + uint64_t fetchTotal() { Guard l(x_all); auto ret = m_total; m_total = 0; return ret; } + +protected: + virtual bool found(uint64_t const* _nonces, uint32_t _count) override { Guard l(x_all); for (unsigned i = 0; i < _count; ++i) - found.push_back((Nonce)(u64)_nonces[i]); - if (abort) - { - aborted = true; - return true; - } - return false; + m_found.push_back((Nonce)(u64)_nonces[i]); + m_aborted = true; + return true; } - virtual bool searched(uint64_t _startNonce, uint32_t _count) + virtual bool searched(uint64_t _startNonce, uint32_t _count) override { Guard l(x_all); - total += _count; - last = _startNonce + _count; - if (abort) + m_total += _count; + m_last = _startNonce + _count; + if (m_abort) { - aborted = true; + m_aborted = true; return true; } return false; } - vector fetchFound() { vector ret; Guard l(x_all); std::swap(ret, found); return ret; } - uint64_t fetchTotal() { Guard l(x_all); auto ret = total; total = 0; return ret; } - +private: Mutex x_all; - vector found; - uint64_t total; - uint64_t last; - bool abort = false; - bool aborted = false; + vector m_found; + uint64_t m_total; + uint64_t m_last; + bool m_abort = false; + bool m_aborted = true; }; EthashCL::EthashCL(): - m_miner(new ethash_cl_miner), m_hook(new EthashCLHook) { } EthashCL::~EthashCL() { - m_hook->abort = true; - for (unsigned timeout = 0; timeout < 100 && !m_hook->aborted; ++timeout) - std::this_thread::sleep_for(chrono::milliseconds(30)); - if (!m_hook->aborted) - cwarn << "Couldn't abort. Abandoning OpenCL process."; } bool EthashCL::verify(BlockInfo const& _header) @@ -211,13 +190,16 @@ bool EthashCL::verify(BlockInfo const& _header) std::pair EthashCL::mine(BlockInfo const& _header, unsigned _msTimeout, bool, bool) { - if (m_lastHeader.seedHash() != _header.seedHash()) + if (!m_lastHeader || m_lastHeader.seedHash() != _header.seedHash()) { - m_miner->init(Ethasher::params(_header), _header.seedHash().data()); - // TODO: reinit probably won't work when seed changes. + if (m_miner) + m_hook->abort(); + m_miner.reset(new ethash_cl_miner); + m_miner->init(Ethasher::params(_header), [&](void* d){ Ethasher::get()->readFull(_header, d); }); } if (m_lastHeader != _header) { + m_hook->abort(); static std::random_device s_eng; uint64_t tryNonce = (uint64_t)(u64)(m_last = Nonce::random(s_eng)); m_miner->search(_header.headerHash(WithoutNonce).data(), tryNonce, *m_hook); @@ -228,10 +210,11 @@ std::pair EthashCL::mine(BlockInfo const& _header, unsi auto found = m_hook->fetchFound(); if (!found.empty()) { - h256 mixHash; // ????? - return std::make_pair(MineInfo{0.0, 1e99, 0, true}, EthashCL::Proof((Nonce)(u64)found[0], mixHash)); + Nonce n = (Nonce)(u64)found[0]; + auto result = Ethasher::eval(_header, n); + return std::make_pair(MineInfo(true), EthashCL::Proof{n, result.mixHash}); } - return std::make_pair(MineInfo{0.0, 1e99, 0, false}, EthashCL::Proof()); + return std::make_pair(MineInfo(false), EthashCL::Proof()); } #endif diff --git a/libethcore/ProofOfWork.h b/libethcore/ProofOfWork.h index 245a96a02..48d52049a 100644 --- a/libethcore/ProofOfWork.h +++ b/libethcore/ProofOfWork.h @@ -42,6 +42,8 @@ namespace eth struct MineInfo { + MineInfo() = default; + MineInfo(bool _completed): completed(_completed) {} void combine(MineInfo const& _m) { requirement = std::max(requirement, _m.requirement); best = std::min(best, _m.best); hashes += _m.hashes; completed = completed || _m.completed; } double requirement = 0; double best = 1e99; @@ -67,6 +69,8 @@ protected: }; #if ETH_ETHASHCL +class EthashCLHook; + class EthashCL { public: @@ -88,7 +92,7 @@ protected: BlockInfo m_lastHeader; Nonce m_mined; std::unique_ptr m_miner; - std::unique_ptr m_hook; + std::unique_ptr m_hook; }; using Ethash = EthashCL; diff --git a/libethereum/CMakeLists.txt b/libethereum/CMakeLists.txt index 3df3b9bc3..8822394a3 100644 --- a/libethereum/CMakeLists.txt +++ b/libethereum/CMakeLists.txt @@ -25,19 +25,18 @@ else() add_library(${EXECUTABLE} SHARED ${SRC_LIST} ${HEADERS}) endif() -target_link_libraries(${EXECUTABLE} ${LEVELDB_LIBRARIES}) -target_link_libraries(${EXECUTABLE} ${Boost_REGEX_LIBRARIES}) - target_link_libraries(${EXECUTABLE} evm) target_link_libraries(${EXECUTABLE} lll) target_link_libraries(${EXECUTABLE} whisper) target_link_libraries(${EXECUTABLE} p2p) target_link_libraries(${EXECUTABLE} devcrypto) target_link_libraries(${EXECUTABLE} ethcore) +target_link_libraries(${EXECUTABLE} ${LEVELDB_LIBRARIES}) +target_link_libraries(${EXECUTABLE} ${Boost_REGEX_LIBRARIES}) target_link_libraries(${EXECUTABLE} secp256k1) - if (ETHASHCL) target_link_libraries(${EXECUTABLE} ethash-cl) + target_link_libraries(${EXECUTABLE} OpenCL) endif () if (CMAKE_COMPILER_IS_MINGW) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 80788aa22..87f474afe 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -334,6 +334,7 @@ void Client::setMiningThreads(unsigned _threads) { stopMining(); #if ETH_ETHASHCL + (void)_threads; unsigned t = 1; #else auto t = _threads ? _threads : thread::hardware_concurrency(); diff --git a/libethereum/ClientBase.cpp b/libethereum/ClientBase.cpp index f57b2b174..5a0aef7c3 100644 --- a/libethereum/ClientBase.cpp +++ b/libethereum/ClientBase.cpp @@ -75,7 +75,7 @@ ExecutionResult ClientBase::call(Secret _secret, u256 _value, Address _dest, byt u256 n = temp.transactionsFrom(a); Transaction t(_value, _gasPrice, _gas, _dest, _data, n, _secret); if (_ff == FudgeFactor::Lenient) - temp.addBalance(a, (u256)(t.gasRequired() * t.gasPrice() + t.value())); + temp.addBalance(a, (u256)(t.gas() * t.gasPrice() + t.value())); ret = temp.execute(bc().lastHashes(), t, Permanence::Reverted); } catch (...) diff --git a/libtestutils/BlockChainLoader.h b/libtestutils/BlockChainLoader.h index 6cb04c53c..58b1affaf 100644 --- a/libtestutils/BlockChainLoader.h +++ b/libtestutils/BlockChainLoader.h @@ -22,9 +22,9 @@ #pragma once #include #include +#include #include #include -#include "TransientDirectory.h" namespace dev { diff --git a/libtestutils/StateLoader.h b/libtestutils/StateLoader.h index e1346f69a..47eb26900 100644 --- a/libtestutils/StateLoader.h +++ b/libtestutils/StateLoader.h @@ -22,8 +22,8 @@ #pragma once #include +#include #include -#include "TransientDirectory.h" namespace dev { diff --git a/libweb3jsonrpc/WebThreeStubServerBase.cpp b/libweb3jsonrpc/WebThreeStubServerBase.cpp index 291415a68..c86274b15 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.cpp +++ b/libweb3jsonrpc/WebThreeStubServerBase.cpp @@ -449,64 +449,55 @@ static TransactionSkeleton toTransaction(Json::Value const& _json) string WebThreeStubServerBase::eth_sendTransaction(Json::Value const& _json) { - TransactionSkeleton t; - try { - t = toTransaction(_json); + string ret; + TransactionSkeleton t = toTransaction(_json); + + if (!t.from) + t.from = m_accounts->getDefaultTransactAccount(); + if (t.creation) + ret = toJS(right160(sha3(rlpList(t.from, client()->countAt(t.from)))));; + if (!t.gasPrice) + t.gasPrice = 10 * dev::eth::szabo; // TODO: should be determined by user somehow. + if (!t.gas) + t.gas = min(client()->gasLimitRemaining(), client()->balanceAt(t.from) / t.gasPrice); + + if (m_accounts->isRealAccount(t.from)) + authenticate(t, false); + else if (m_accounts->isProxyAccount(t.from)) + authenticate(t, true); + + return ret; } catch (...) { BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS)); } - - string ret; - if (!t.from) - t.from = m_accounts->getDefaultTransactAccount(); - if (t.creation) - ret = toJS(right160(sha3(rlpList(t.from, client()->countAt(t.from)))));; - if (!t.gasPrice) - t.gasPrice = 10 * dev::eth::szabo; // TODO: should be determined by user somehow. - if (!t.gas) - t.gas = min(client()->gasLimitRemaining(), client()->balanceAt(t.from) / t.gasPrice); - - if (m_accounts->isRealAccount(t.from)) - authenticate(t, false); - else if (m_accounts->isProxyAccount(t.from)) - authenticate(t, true); - - return ret; } string WebThreeStubServerBase::eth_call(Json::Value const& _json, string const& _blockNumber) { - TransactionSkeleton t; - int number; - try { - t = toTransaction(_json); - number = jsToBlockNumber(_blockNumber); + TransactionSkeleton t = toTransaction(_json); + if (!t.from) + t.from = m_accounts->getDefaultTransactAccount(); + // if (!m_accounts->isRealAccount(t.from)) + // return ret; + if (!t.gasPrice) + t.gasPrice = 10 * dev::eth::szabo; + if (!t.gas) + t.gas = client()->gasLimitRemaining(); + + return toJS(client()->call(m_accounts->secretKey(t.from), t.value, t.to, t.data, t.gas, t.gasPrice, jsToBlockNumber(_blockNumber), FudgeFactor::Lenient).output); } catch (...) { BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS)); } - string ret; - if (!t.from) - t.from = m_accounts->getDefaultTransactAccount(); -// if (!m_accounts->isRealAccount(t.from)) -// return ret; - if (!t.gasPrice) - t.gasPrice = 10 * dev::eth::szabo; - if (!t.gas) - t.gas = client()->gasLimitRemaining(); - - ret = toJS(client()->call(m_accounts->secretKey(t.from), t.value, t.to, t.data, t.gas, t.gasPrice, number).output); - - return ret; } bool WebThreeStubServerBase::eth_flush() diff --git a/test/TestUtils.cpp b/test/TestUtils.cpp index 6222955d5..ff5169d55 100644 --- a/test/TestUtils.cpp +++ b/test/TestUtils.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include "TestUtils.h" diff --git a/test/blockchain.cpp b/test/blockchain.cpp index 6c1cfebd6..ab01df5a5 100644 --- a/test/blockchain.cpp +++ b/test/blockchain.cpp @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include "TestHelper.h" From d0931bb0fcb59ae4fc1f64fa49ca903f9b6d633e Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 10 Apr 2015 17:09:45 +0200 Subject: [PATCH 08/19] Fix for MacOS --- libdevcore/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/libdevcore/CMakeLists.txt b/libdevcore/CMakeLists.txt index 03f7547e7..ec3472605 100644 --- a/libdevcore/CMakeLists.txt +++ b/libdevcore/CMakeLists.txt @@ -28,6 +28,7 @@ endif() target_link_libraries(${EXECUTABLE} ${Boost_THREAD_LIBRARIES}) target_link_libraries(${EXECUTABLE} ${Boost_SYSTEM_LIBRARIES}) +target_link_libraries(${EXECUTABLE} ${Boost_FILESYSTEM_LIBRARIES}) target_link_libraries(${EXECUTABLE} ${JSONCPP_LIBRARIES}) # transitive dependencies for windows executables From b5761c33b6f259c29f22d4171b6cb34c7788b650 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 10 Apr 2015 19:53:08 +0200 Subject: [PATCH 09/19] logging for jchow. testing for ethashcl. --- exp/main.cpp | 12 +++--------- libdevcore/Common.cpp | 2 +- libethcore/ProofOfWork.cpp | 3 +++ libethereum/BlockChain.cpp | 2 +- libethereum/Client.cpp | 18 +++++++++++++++--- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/exp/main.cpp b/exp/main.cpp index 6c067f83e..6887e6c49 100644 --- a/exp/main.cpp +++ b/exp/main.cpp @@ -108,20 +108,14 @@ int main() #else int main() { - std::vector platforms; - cl::Platform::get(&platforms); - if (platforms.empty()) - { - cdebug << "No OpenCL platforms found."; - return false; - } - EthashCL ecl; BlockInfo genesis = CanonBlockChain::genesis(); - TransientDirectory td; + genesis.difficulty = 1 << 18; + cdebug << (h256)u256((bigint(1) << 256) / genesis.difficulty); std::pair r; while (!r.first.completed) r = ecl.mine(genesis, 1000); + cdebug << r.second.mixHash << r.second.nonce; EthashCL::assignResult(r.second, genesis); assert(EthashCPU::verify(genesis)); return 0; diff --git a/libdevcore/Common.cpp b/libdevcore/Common.cpp index 75780fb10..b6e8e7f93 100644 --- a/libdevcore/Common.cpp +++ b/libdevcore/Common.cpp @@ -27,7 +27,7 @@ using namespace dev; namespace dev { -char const* Version = "0.9.6"; +char const* Version = "0.9.7"; } diff --git a/libethcore/ProofOfWork.cpp b/libethcore/ProofOfWork.cpp index c87f51a78..f85205484 100644 --- a/libethcore/ProofOfWork.cpp +++ b/libethcore/ProofOfWork.cpp @@ -128,6 +128,7 @@ struct EthashCLHook: public ethash_cl_miner::search_hook { void abort() { + cdebug << "Attempting to abort"; if (m_aborted) return; m_abort = true; @@ -149,12 +150,14 @@ protected: for (unsigned i = 0; i < _count; ++i) m_found.push_back((Nonce)(u64)_nonces[i]); m_aborted = true; + cdebug << "Found nonces: " << vector(_nonces, _nonces + _count); return true; } virtual bool searched(uint64_t _startNonce, uint32_t _count) override { Guard l(x_all); + cdebug << "Searched" << _count << "from" << _startNonce; m_total += _count; m_last = _startNonce + _count; if (m_abort) diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index cb2d26eff..bf2bce4fe 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -601,7 +601,7 @@ pair BlockChain::import(bytes const& _block, OverlayDB const& _db, m_extrasDB->Put(m_writeOptions, toSlice(h, ExtraTransactionAddress), (ldb::Slice)dev::ref(m_transactionAddresses[h].rlp())); } - clog(BlockChainNote) << " Imported and best" << td << ". Has" << (details(bi.parentHash).children.size() - 1) << "siblings. Route:" << toString(route); + clog(BlockChainNote) << " Imported and best" << td << " (#" << bi.number << "). Has" << (details(bi.parentHash).children.size() - 1) << "siblings. Route:" << toString(route); noteCanonChanged(); StructuredLogger::chainNewHead( diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 87f474afe..8c2d2b4fa 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -259,16 +259,28 @@ void Client::clearPending() noteChanged(changeds); } +template +static string filtersToString(T const& _fs) +{ + stringstream ret; + ret << "{"; + bool i = false; + for (h256 const& f: _fs) + ret << (i++ ? ", " : "") << (f == PendingChangedFilter ? "pending" : f == ChainChangedFilter ? "chain" : f.abridged()); + ret << "}"; + return ret.str(); +} + void Client::noteChanged(h256Set const& _filters) { Guard l(x_filtersWatches); if (_filters.size()) - cnote << "noteChanged(" << _filters << ")"; + cnote << "noteChanged(" << filtersToString(_filters) << ")"; // accrue all changes left in each filter into the watches. for (auto& w: m_watches) if (_filters.count(w.second.id)) { - cwatch << "!!!" << w.first << w.second.id; + cwatch << "!!!" << w.first << (m_filters.count(w.second.id) ? w.second.id.abridged() : w.second.id == PendingChangedFilter ? "pending" : w.second.id == ChainChangedFilter ? "chain" : "???"); if (m_filters.count(w.second.id)) // Normal filtering watch w.second.changes += m_filters.at(w.second.id).changes; else // Special ('pending'/'latest') watch @@ -523,7 +535,7 @@ void Client::doWork() clog(ClientChat) << "Live block:" << h.abridged(); for (auto const& th: m_bc.transactionHashes(h)) { - clog(ClientNote) << "Safely dropping transaction " << th; + clog(ClientNote) << "Safely dropping transaction " << th.abridged(); m_tq.drop(th); } } From 0547a6c1d59432b6220e34bf5430448094b75dd9 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 10 Apr 2015 21:02:00 +0200 Subject: [PATCH 10/19] Fix build. --- exp/main.cpp | 5 ++++- libethcore/BlockInfo.cpp | 7 +++++++ libethcore/BlockInfo.h | 4 +++- libethcore/ProofOfWork.cpp | 22 ++++++++++++++++------ 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/exp/main.cpp b/exp/main.cpp index 6887e6c49..48562f80e 100644 --- a/exp/main.cpp +++ b/exp/main.cpp @@ -19,10 +19,11 @@ * @date 2014 * Ethereum client. */ +#if ETH_ETHASHCL #define __CL_ENABLE_EXCEPTIONS #define CL_USE_DEPRECATED_OPENCL_2_0_APIS #include "libethash-cl/cl.hpp" - +#endif #include #include #include @@ -108,6 +109,7 @@ int main() #else int main() { +#if ETH_ETHASHCL EthashCL ecl; BlockInfo genesis = CanonBlockChain::genesis(); genesis.difficulty = 1 << 18; @@ -118,6 +120,7 @@ int main() cdebug << r.second.mixHash << r.second.nonce; EthashCL::assignResult(r.second, genesis); assert(EthashCPU::verify(genesis)); +#endif return 0; } #endif diff --git a/libethcore/BlockInfo.cpp b/libethcore/BlockInfo.cpp index 0be8cd765..6cd431931 100644 --- a/libethcore/BlockInfo.cpp +++ b/libethcore/BlockInfo.cpp @@ -75,6 +75,13 @@ h256 const& BlockInfo::hash() const return m_hash; } +h256 const& BlockInfo::boundary() const +{ + if (!m_boundary) + m_boundary = (h256)(u256)((bigint(1) << 256) / difficulty); + return m_boundary; +} + BlockInfo BlockInfo::fromHeader(bytesConstRef _header, Strictness _s, h256 const& _h) { BlockInfo ret; diff --git a/libethcore/BlockInfo.h b/libethcore/BlockInfo.h index 302db5f17..dffff73f4 100644 --- a/libethcore/BlockInfo.h +++ b/libethcore/BlockInfo.h @@ -118,7 +118,7 @@ public: void clear(); - void noteDirty() const { m_hash = m_seedHash = h256(); } + void noteDirty() const { m_hash = m_seedHash = m_boundary = h256(); } void populateFromHeader(RLP const& _header, Strictness _s = IgnoreNonce, h256 const& _h = h256()); void populate(bytesConstRef _block, Strictness _s = IgnoreNonce, h256 const& _h = h256()); @@ -131,6 +131,7 @@ public: u256 selectGasLimit(BlockInfo const& _parent) const; h256 const& seedHash() const; h256 const& hash() const; + h256 const& boundary() const; /// sha3 of the header only. h256 headerHash(IncludeNonce _n) const; @@ -139,6 +140,7 @@ public: private: mutable h256 m_seedHash; mutable h256 m_hash; ///< SHA3 hash of the block header! Not serialised. + mutable h256 m_boundary; ///< 2^256 / difficulty }; inline std::ostream& operator<<(std::ostream& _out, BlockInfo const& _bi) diff --git a/libethcore/ProofOfWork.cpp b/libethcore/ProofOfWork.cpp index f85205484..e24b2087c 100644 --- a/libethcore/ProofOfWork.cpp +++ b/libethcore/ProofOfWork.cpp @@ -128,9 +128,9 @@ struct EthashCLHook: public ethash_cl_miner::search_hook { void abort() { - cdebug << "Attempting to abort"; if (m_aborted) return; + cdebug << "Attempting to abort"; m_abort = true; for (unsigned timeout = 0; timeout < 100 && !m_aborted; ++timeout) std::this_thread::sleep_for(chrono::milliseconds(30)); @@ -198,14 +198,19 @@ std::pair EthashCL::mine(BlockInfo const& _header, unsi if (m_miner) m_hook->abort(); m_miner.reset(new ethash_cl_miner); - m_miner->init(Ethasher::params(_header), [&](void* d){ Ethasher::get()->readFull(_header, d); }); + auto cb = [&](void* d) { + Ethasher::get()->readFull(_header, d); + }; + m_miner->init(Ethasher::params(_header), cb); } if (m_lastHeader != _header) { m_hook->abort(); static std::random_device s_eng; uint64_t tryNonce = (uint64_t)(u64)(m_last = Nonce::random(s_eng)); - m_miner->search(_header.headerHash(WithoutNonce).data(), tryNonce, *m_hook); + auto hh = _header.headerHash(WithoutNonce); + cdebug << "Mining with headerhash" << hh << "from nonce" << m_last << "with boundary" << _header.boundary(); + m_miner->search(hh.data(), tryNonce, *m_hook); } m_lastHeader = _header; @@ -213,9 +218,14 @@ std::pair EthashCL::mine(BlockInfo const& _header, unsi auto found = m_hook->fetchFound(); if (!found.empty()) { - Nonce n = (Nonce)(u64)found[0]; - auto result = Ethasher::eval(_header, n); - return std::make_pair(MineInfo(true), EthashCL::Proof{n, result.mixHash}); + for (auto const& n: found) + { + auto result = Ethasher::eval(_header, n); + cdebug << "Got nonce " << n << "gives result" << result.value; + if (result.value < _header.boundary()) + return std::make_pair(MineInfo(true), EthashCL::Proof{n, result.mixHash}); + } + assert(false); } return std::make_pair(MineInfo(false), EthashCL::Proof()); } From 38e985e808ef28868d82a3af810062d4ef84c57a Mon Sep 17 00:00:00 2001 From: Alexandre Van de Sande Date: Fri, 10 Apr 2015 17:56:31 -0300 Subject: [PATCH 11/19] created a frame for the step action buttons --- mix/qml/Debugger.qml | 34 +++++----- mix/qml/StepActionImage.qml | 122 ++++++++++++++++++++++++++++++------ 2 files changed, 116 insertions(+), 40 deletions(-) diff --git a/mix/qml/Debugger.qml b/mix/qml/Debugger.qml index ef83ef390..3b8a87e8a 100644 --- a/mix/qml/Debugger.qml +++ b/mix/qml/Debugger.qml @@ -4,6 +4,7 @@ import QtQuick.Controls.Styles 1.1 import QtQuick.Dialogs 1.1 import QtQuick.Layouts 1.1 import Qt.labs.settings 1.0 +import QtGraphicalEffects 1.0 import "js/Debugger.js" as Debugger import "js/ErrorLocationFormater.js" as ErrorLocationFormater import "." @@ -231,9 +232,9 @@ Rectangle { id: playAction enabledStateImg: "qrc:/qml/img/play_button.png" disableStateImg: "qrc:/qml/img/play_button.png" + buttonLeft: true onClicked: projectModel.stateListModel.runState(transactionLog.selectedStateIndex) - width: 30 - height: 30 + width: 23 buttonShortcut: "Ctrl+Shift+F8" buttonTooltip: qsTr("Start Debugging") visible: true @@ -246,8 +247,7 @@ Rectangle { enabledStateImg: "qrc:/qml/img/stop_button2x.png" disableStateImg: "qrc:/qml/img/stop_button2x.png" onClicked: Debugger.init(null); - width: 30 - height: 30 + width: 23 buttonShortcut: "Ctrl+Shift+F9" buttonTooltip: qsTr("Stop Debugging") visible: true @@ -259,8 +259,7 @@ Rectangle { enabledStateImg: "qrc:/qml/img/jumpoutback.png" disableStateImg: "qrc:/qml/img/jumpoutbackdisabled.png" onClicked: Debugger.runBack() - width: 30 - height: 30 + width: 23 buttonShortcut: "Ctrl+Shift+F5" buttonTooltip: qsTr("Run Back") visible: false @@ -272,8 +271,7 @@ Rectangle { enabledStateImg: "qrc:/qml/img/jumpoutback.png" disableStateImg: "qrc:/qml/img/jumpoutbackdisabled.png" onClicked: Debugger.stepOutBack() - width: 30 - height: 30 + width: 23 buttonShortcut: "Ctrl+Shift+F11" buttonTooltip: qsTr("Step Out Back") } @@ -284,8 +282,7 @@ Rectangle { enabledStateImg: "qrc:/qml/img/jumpintoback.png" disableStateImg: "qrc:/qml/img/jumpintobackdisabled.png" onClicked: Debugger.stepIntoBack() - width: 30 - height: 30 + width: 23 buttonShortcut: "Ctrl+F11" buttonTooltip: qsTr("Step Into Back") } @@ -296,8 +293,7 @@ Rectangle { enabledStateImg: "qrc:/qml/img/jumpoverback.png" disableStateImg: "qrc:/qml/img/jumpoverbackdisabled.png" onClicked: Debugger.stepOverBack() - width: 30 - height: 30 + width: 23 buttonShortcut: "Ctrl+F10" buttonTooltip: qsTr("Step Over Back") } @@ -308,8 +304,7 @@ Rectangle { enabledStateImg: "qrc:/qml/img/jumpoverforward.png" disableStateImg: "qrc:/qml/img/jumpoverforwarddisabled.png" onClicked: Debugger.stepOverForward() - width: 30 - height: 30 + width: 23 buttonShortcut: "F10" buttonTooltip: qsTr("Step Over Forward") } @@ -320,8 +315,7 @@ Rectangle { enabledStateImg: "qrc:/qml/img/jumpintoforward.png" disableStateImg: "qrc:/qml/img/jumpintoforwarddisabled.png" onClicked: Debugger.stepIntoForward() - width: 30 - height: 30 + width: 23 buttonShortcut: "F11" buttonTooltip: qsTr("Step Into Forward") } @@ -332,10 +326,10 @@ Rectangle { enabledStateImg: "qrc:/qml/img/jumpoutforward.png" disableStateImg: "qrc:/qml/img/jumpoutforwarddisabled.png" onClicked: Debugger.stepOutForward() - width: 30 - height: 30 + width: 45 buttonShortcut: "Shift+F11" buttonTooltip: qsTr("Step Out Forward") + buttonRight: true } StepActionImage @@ -344,11 +338,11 @@ Rectangle { enabledStateImg: "qrc:/qml/img/jumpoutforward.png" disableStateImg: "qrc:/qml/img/jumpoutforwarddisabled.png" onClicked: Debugger.runForward() - width: 30 - height: 30 + width: 45 buttonShortcut: "Ctrl+F5" buttonTooltip: qsTr("Run Forward") visible: false + buttonRight: true } Rectangle { diff --git a/mix/qml/StepActionImage.qml b/mix/qml/StepActionImage.qml index 262c99def..a8c800b64 100644 --- a/mix/qml/StepActionImage.qml +++ b/mix/qml/StepActionImage.qml @@ -4,15 +4,22 @@ import QtQuick.Layouts 1.0 import QtQuick.Controls.Styles 1.1 + Rectangle { id: buttonActionContainer - color: "transparent" property string disableStateImg property string enabledStateImg property string buttonTooltip property string buttonShortcut + property bool buttonLeft + property bool buttonRight signal clicked + + color: "transparent" + width: 35 + height: 24 + function enabled(state) { buttonAction.enabled = state; @@ -22,29 +29,104 @@ Rectangle { debugImage.source = disableStateImg; } - Button - { - anchors.fill: parent - id: debugImg -/* iconSource: enabledStateImg -*/ action: buttonAction + Rectangle { + color: "#DCDADA" + width: 10 + height: 24 + radius: 4 + x: 0 + visible: buttonLeft + + Rectangle { + anchors { + left: parent.left + right: parent.right + top: parent.top + bottom: parent.bottom + bottomMargin:debugImg.pressed? 0 : 1; + topMargin:debugImg.pressed? 1 : 0; + } + color: "#FCFBFC" + radius: 3 + } } - Image { - id: debugImage - source: enabledStateImg - anchors.centerIn: parent - fillMode: Image.PreserveAspectFit - width: 15 - height: 15 + Rectangle { + color: "#DCDADA" + width: 10 + height: 24 + radius: 4 + x: 25 + visible: buttonRight + + Rectangle { + anchors { + left: parent.left + right: parent.right + top: parent.top + bottom: parent.bottom + bottomMargin:debugImg.pressed? 0 : 1; + topMargin:debugImg.pressed? 1 : 0; + } + color: "#FCFBFC" + radius: 3 + } } - Action { - tooltip: buttonTooltip - id: buttonAction - shortcut: buttonShortcut - onTriggered: { - buttonActionContainer.clicked(); + + Rectangle { + id: contentRectangle + width: 25 + height: 24 + color: "#DCDADA" + x: 5 + + Rectangle { + anchors { + left: parent.left + right: parent.right + top: parent.top + bottom: parent.bottom + bottomMargin:debugImg.pressed? 0 : 1; + topMargin:debugImg.pressed? 1 : 0; + } + color: "#FCFBFC" + + Image { + id: debugImage + source: enabledStateImg + anchors.centerIn: parent + anchors.topMargin: debugImg.pressed? 1 : 0; + + fillMode: Image.PreserveAspectFit + width: 15 + height: 15 + } + + } + + + Button { + anchors.fill: parent + id: debugImg + action: buttonAction + style: Rectangle { + color: "transparent" + } + } + + + Action { + tooltip: buttonTooltip + id: buttonAction + shortcut: buttonShortcut + onTriggered: { + // contentRectangle.anchors.bottomMargin = 0 + // contentRectangle.anchors.topMargin = 1 + buttonActionContainer.clicked(); + } } } + + } From 89dbad3bf85f854657de05e543be13a7ed4fd09d Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 10 Apr 2015 23:12:51 +0200 Subject: [PATCH 12/19] Working GPU miner. --- libethcore/ProofOfWork.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libethcore/ProofOfWork.cpp b/libethcore/ProofOfWork.cpp index e24b2087c..a97baca94 100644 --- a/libethcore/ProofOfWork.cpp +++ b/libethcore/ProofOfWork.cpp @@ -207,10 +207,10 @@ std::pair EthashCL::mine(BlockInfo const& _header, unsi { m_hook->abort(); static std::random_device s_eng; - uint64_t tryNonce = (uint64_t)(u64)(m_last = Nonce::random(s_eng)); auto hh = _header.headerHash(WithoutNonce); - cdebug << "Mining with headerhash" << hh << "from nonce" << m_last << "with boundary" << _header.boundary(); - m_miner->search(hh.data(), tryNonce, *m_hook); + uint64_t upper64OfBoundary = (uint64_t)(u64)((u256)_header.boundary() >> 192); + cdebug << "Mining with headerhash" << hh << "from nonce" << m_last << "with boundary" << _header.boundary() << " (" << upper64OfBoundary << ")"; + m_miner->search(hh.data(), upper64OfBoundary, *m_hook); } m_lastHeader = _header; From 6e78287401e219750e260512cdf385890a95ee46 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sat, 11 Apr 2015 00:45:21 +0200 Subject: [PATCH 13/19] Ability to switch GPU/CPU mining on the fly. --- CMakeLists.txt | 2 ++ alethzero/Main.ui | 18 +++++------ alethzero/MainWin.cpp | 3 ++ eth/main.cpp | 4 --- libethcore/ProofOfWork.cpp | 20 +++--------- libethcore/ProofOfWork.h | 34 ++++++++++----------- libethereum/Client.cpp | 16 +++++++--- libethereum/Client.h | 20 ++++++------ libethereum/ClientBase.h | 3 +- libethereum/Interface.h | 4 ++- libethereum/Miner.cpp | 4 ++- libethereum/Miner.h | 13 ++++---- libethereum/State.cpp | 25 ++------------- libethereum/State.h | 22 +++++++++++-- libweb3jsonrpc/WebThreeStubServerBase.cpp | 5 +++ libweb3jsonrpc/WebThreeStubServerBase.h | 1 + libweb3jsonrpc/abstractwebthreestubserver.h | 7 +++++ libweb3jsonrpc/spec.json | 5 +-- mix/MixClient.cpp | 10 ++++-- mix/MixClient.h | 3 +- test/blockchain.cpp | 7 +++-- test/stateOriginal.cpp | 5 +-- test/webthreestubclient.h | 10 ++++++ 23 files changed, 138 insertions(+), 103 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 100ef9139..e6a906b59 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,6 +62,8 @@ function(configureProject) if (GUI) add_definitions(-DETH_GUI) endif() + + add_definitions(-DETH_TRUE) endfunction() set(CPPETHEREUM 1) diff --git a/alethzero/Main.ui b/alethzero/Main.ui index 6c01f57f9..3f3d1e237 100644 --- a/alethzero/Main.ui +++ b/alethzero/Main.ui @@ -150,6 +150,7 @@ &Tools + @@ -176,7 +177,6 @@ - @@ -1608,14 +1608,6 @@ font-size: 14pt &Enable LLL Optimizer - - - true - - - &Reserved Debug 1 - - true @@ -1679,6 +1671,14 @@ font-size: 14pt &NatSpec Enabled + + + true + + + &GPU Mining + + diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index bbacaf539..374829a61 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -707,6 +707,7 @@ void Main::writeSettings() s.setValue("upnp", ui->upnp->isChecked()); s.setValue("forceAddress", ui->forcePublicIP->text()); s.setValue("forceMining", ui->forceMining->isChecked()); + s.setValue("turboMining", ui->turboMining->isChecked()); s.setValue("paranoia", ui->paranoia->isChecked()); s.setValue("natSpec", ui->natSpec->isChecked()); s.setValue("showAll", ui->showAll->isChecked()); @@ -777,6 +778,8 @@ void Main::readSettings(bool _skipGeometry) ui->dropPeers->setChecked(false); ui->forceMining->setChecked(s.value("forceMining", false).toBool()); on_forceMining_triggered(); + ui->turboMining->setChecked(s.value("turboMining", false).toBool()); + on_turboMining_triggered(); ui->paranoia->setChecked(s.value("paranoia", false).toBool()); ui->natSpec->setChecked(s.value("natSpec", true).toBool()); ui->showAll->setChecked(s.value("showAll", false).toBool()); diff --git a/eth/main.cpp b/eth/main.cpp index c83332c20..e9af192f9 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -273,7 +273,6 @@ int main(int argc, char** argv) unsigned mining = ~(unsigned)0; int miners = -1; bool forceMining = false; - bool turboMining = false; KeyPair us = KeyPair::create(); Address coinbase = us.address(); @@ -466,8 +465,6 @@ int main(int argc, char** argv) bootstrap = true; else if (arg == "-f" || arg == "--force-mining") forceMining = true; - else if (arg == "-T" || arg == "--turbo-mining") - turboMining = true; else if (arg == "-i" || arg == "--interactive") interactive = true; #if ETH_JSONRPC @@ -632,7 +629,6 @@ int main(int argc, char** argv) { c->setGasPricer(gasPricer); c->setForceMining(forceMining); - c->setTurboMining(turboMining); c->setAddress(coinbase); } diff --git a/libethcore/ProofOfWork.cpp b/libethcore/ProofOfWork.cpp index a97baca94..f7cf4944b 100644 --- a/libethcore/ProofOfWork.cpp +++ b/libethcore/ProofOfWork.cpp @@ -45,12 +45,12 @@ namespace dev namespace eth { -bool EthashCPU::verify(BlockInfo const& _header) +bool EthashPoW::verify(BlockInfo const& _header) { return Ethasher::verify(_header); } -std::pair EthashCPU::mine(BlockInfo const& _header, unsigned _msTimeout, bool _continue, bool _turbo) +std::pair EthashCPU::mine(BlockInfo const& _header, unsigned _msTimeout, bool _continue) { Ethasher::Miner m(_header); @@ -67,8 +67,6 @@ std::pair EthashCPU::mine(BlockInfo const& _header, // // evaluate until we run out of time auto startTime = std::chrono::steady_clock::now(); - if (!_turbo) - std::this_thread::sleep_for(std::chrono::milliseconds(_msTimeout * 90 / 100)); double best = 1e99; // high enough to be effectively infinity :) Proof result; unsigned hashCount = 0; @@ -102,7 +100,7 @@ std::pair EthashCPU::mine(BlockInfo const& _header, return ret; } -#if ETH_ETHASHCL +#if ETH_ETHASHCL || !ETH_TRUE /* class ethash_cl_miner @@ -186,12 +184,7 @@ EthashCL::~EthashCL() { } -bool EthashCL::verify(BlockInfo const& _header) -{ - return Ethasher::verify(_header); -} - -std::pair EthashCL::mine(BlockInfo const& _header, unsigned _msTimeout, bool, bool) +std::pair EthashCL::mine(BlockInfo const& _header, unsigned _msTimeout, bool) { if (!m_lastHeader || m_lastHeader.seedHash() != _header.seedHash()) { @@ -201,7 +194,7 @@ std::pair EthashCL::mine(BlockInfo const& _header, unsi auto cb = [&](void* d) { Ethasher::get()->readFull(_header, d); }; - m_miner->init(Ethasher::params(_header), cb); + m_miner->init(Ethasher::params(_header), cb, 32); } if (m_lastHeader != _header) { @@ -209,7 +202,6 @@ std::pair EthashCL::mine(BlockInfo const& _header, unsi static std::random_device s_eng; auto hh = _header.headerHash(WithoutNonce); uint64_t upper64OfBoundary = (uint64_t)(u64)((u256)_header.boundary() >> 192); - cdebug << "Mining with headerhash" << hh << "from nonce" << m_last << "with boundary" << _header.boundary() << " (" << upper64OfBoundary << ")"; m_miner->search(hh.data(), upper64OfBoundary, *m_hook); } m_lastHeader = _header; @@ -221,11 +213,9 @@ std::pair EthashCL::mine(BlockInfo const& _header, unsi for (auto const& n: found) { auto result = Ethasher::eval(_header, n); - cdebug << "Got nonce " << n << "gives result" << result.value; if (result.value < _header.boundary()) return std::make_pair(MineInfo(true), EthashCL::Proof{n, result.mixHash}); } - assert(false); } return std::make_pair(MineInfo(false), EthashCL::Proof()); } diff --git a/libethcore/ProofOfWork.h b/libethcore/ProofOfWork.h index 48d52049a..2e04e842c 100644 --- a/libethcore/ProofOfWork.h +++ b/libethcore/ProofOfWork.h @@ -51,7 +51,7 @@ struct MineInfo bool completed = false; }; -class EthashCPU +class EthashPoW { public: struct Proof @@ -61,31 +61,32 @@ public: }; static bool verify(BlockInfo const& _header); - std::pair mine(BlockInfo const& _header, unsigned _msTimeout = 100, bool _continue = true, bool _turbo = false); static void assignResult(Proof const& _r, BlockInfo& _header) { _header.nonce = _r.nonce; _header.mixHash = _r.mixHash; } + virtual unsigned defaultTimeout() const { return 100; } + virtual std::pair mine(BlockInfo const& _header, unsigned _msTimeout = 100, bool _continue = true) = 0; +}; + +class EthashCPU: public EthashPoW +{ +public: + std::pair mine(BlockInfo const& _header, unsigned _msTimeout = 100, bool _continue = true) override; + protected: Nonce m_last; }; -#if ETH_ETHASHCL +#if ETH_ETHASHCL || !ETH_TRUE class EthashCLHook; -class EthashCL +class EthashCL: public EthashPoW { public: - struct Proof - { - Nonce nonce; - h256 mixHash; - }; - EthashCL(); ~EthashCL(); - static bool verify(BlockInfo const& _header); - std::pair mine(BlockInfo const& _header, unsigned _msTimeout = 100, bool _continue = true, bool _turbo = false); - static void assignResult(Proof const& _r, BlockInfo& _header) { _header.nonce = _r.nonce; _header.mixHash = _r.mixHash; } + std::pair mine(BlockInfo const& _header, unsigned _msTimeout = 100, bool _continue = true) override; + unsigned defaultTimeout() const override { return 500; } protected: Nonce m_last; @@ -107,8 +108,9 @@ public: using Proof = Nonce; static bool verify(BlockInfo const& _header) { return (bigint)(u256)Evaluator::eval(_header.headerHash(WithoutNonce), _header.nonce) <= (bigint(1) << 256) / _header.difficulty; } - inline std::pair mine(BlockInfo const& _header, unsigned _msTimeout = 100, bool _continue = true, bool _turbo = false); + inline std::pair mine(BlockInfo const& _header, unsigned _msTimeout = 100, bool _continue = true); static void assignResult(Proof const& _r, BlockInfo& _header) { _header.nonce = _r; } + unsigned defaultTimeout() const { return 100; } protected: Nonce m_last; @@ -125,7 +127,7 @@ using SHA3ProofOfWork = ProofOfWorkEngine; using ProofOfWork = Ethash; template -std::pair::Proof> ProofOfWorkEngine::mine(BlockInfo const& _header, unsigned _msTimeout, bool _continue, bool _turbo) +std::pair::Proof> ProofOfWorkEngine::mine(BlockInfo const& _header, unsigned _msTimeout, bool _continue) { auto headerHashWithoutNonce = _header.headerHash(WithoutNonce); auto difficulty = _header.difficulty; @@ -142,8 +144,6 @@ std::pair::Proof> ProofOfWorkEng // // evaluate until we run out of time auto startTime = std::chrono::steady_clock::now(); - if (!_turbo) - std::this_thread::sleep_for(std::chrono::milliseconds(_msTimeout * 90 / 100)); double best = 1e99; // high enough to be effectively infinity :) ProofOfWorkEngine::Proof solution; unsigned h = 0; diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 8c2d2b4fa..4b197797f 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -345,11 +345,10 @@ void Client::setForceMining(bool _enable) void Client::setMiningThreads(unsigned _threads) { stopMining(); -#if ETH_ETHASHCL - (void)_threads; - unsigned t = 1; -#else auto t = _threads ? _threads : thread::hardware_concurrency(); +#if ETH_ETHASHCL || !ETH_TRUE + if (m_turboMining) + t = 1; #endif WriteGuard l(x_localMiners); m_localMiners.clear(); @@ -368,6 +367,15 @@ MineProgress Client::miningProgress() const return ret; } +uint64_t Client::hashrate() const +{ + uint64_t ret; + ReadGuard l(x_localMiners); + for (LocalMiner const& m: m_localMiners) + ret += m.miningProgress().hashes / m.miningProgress().ms; + return ret / 1000; +} + std::list Client::miningHistory() { std::list ret; diff --git a/libethereum/Client.h b/libethereum/Client.h index 57fe0d9de..cc51f9747 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -188,25 +188,27 @@ public: bool forceMining() const { return m_forceMining; } /// Enable/disable forcing of mining to happen, even without transactions. void setForceMining(bool _enable); - /// Are we mining as fast as we can? + /// Are we allowed to GPU mine? bool turboMining() const { return m_turboMining; } - /// Enable/disable fast mining. - void setTurboMining(bool _enable = true) { m_turboMining = _enable; } + /// Enable/disable GPU mining. + void setTurboMining(bool _enable = true) { bool was = isMining(); stopMining(); m_turboMining = _enable; setMiningThreads(0); if (was) startMining(); } /// Stops mining and sets the number of mining threads (0 for automatic). - virtual void setMiningThreads(unsigned _threads = 0); + void setMiningThreads(unsigned _threads = 0) override; /// Get the effective number of mining threads. - virtual unsigned miningThreads() const { ReadGuard l(x_localMiners); return m_localMiners.size(); } + unsigned miningThreads() const override { ReadGuard l(x_localMiners); return m_localMiners.size(); } /// Start mining. /// NOT thread-safe - call it & stopMining only from a single thread - virtual void startMining() { startWorking(); { ReadGuard l(x_localMiners); for (auto& m: m_localMiners) m.start(); } } + void startMining() override { startWorking(); { ReadGuard l(x_localMiners); for (auto& m: m_localMiners) m.start(); } } /// Stop mining. /// NOT thread-safe - virtual void stopMining() { { ReadGuard l(x_localMiners); for (auto& m: m_localMiners) m.stop(); } } + void stopMining() override { { ReadGuard l(x_localMiners); for (auto& m: m_localMiners) m.stop(); } } /// Are we mining now? - virtual bool isMining() { { ReadGuard l(x_localMiners); if (!m_localMiners.empty() && m_localMiners[0].isRunning()) return true; } return false; } + bool isMining() const override { { ReadGuard l(x_localMiners); if (!m_localMiners.empty() && m_localMiners[0].isRunning()) return true; } return false; } + /// Are we mining now? + uint64_t hashrate() const override; /// Check the progress of the mining. - virtual MineProgress miningProgress() const; + MineProgress miningProgress() const override; /// Get and clear the mining history. std::list miningHistory(); diff --git a/libethereum/ClientBase.h b/libethereum/ClientBase.h index 00bb02ed4..ddfbf1176 100644 --- a/libethereum/ClientBase.h +++ b/libethereum/ClientBase.h @@ -146,7 +146,8 @@ public: virtual unsigned miningThreads() const override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("dev::eth::ClientBase::miningThreads")); } virtual void startMining() override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("dev::eth::ClientBase::startMining")); } virtual void stopMining() override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("dev::eth::ClientBase::stopMining")); } - virtual bool isMining() override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("dev::eth::ClientBase::isMining")); } + virtual bool isMining() const override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("dev::eth::ClientBase::isMining")); } + virtual uint64_t hashrate() const override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("dev::eth::ClientBase::hashrate")); } virtual eth::MineProgress miningProgress() const override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("dev::eth::ClientBase::miningProgress")); } virtual std::pair getWork() override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("dev::eth::ClientBase::getWork")); } virtual bool submitWork(eth::ProofOfWork::Proof const&) override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("dev::eth::ClientBase::submitWork")); } diff --git a/libethereum/Interface.h b/libethereum/Interface.h index ac41b0ec1..02833743e 100644 --- a/libethereum/Interface.h +++ b/libethereum/Interface.h @@ -183,7 +183,9 @@ public: /// NOT thread-safe virtual void stopMining() = 0; /// Are we mining now? - virtual bool isMining() = 0; + virtual bool isMining() const = 0; + /// Current hash rate. + virtual uint64_t hashrate() const = 0; /// Get hash of the current block to be mined minus the nonce (the 'work hash'). virtual std::pair getWork() = 0; diff --git a/libethereum/Miner.cpp b/libethereum/Miner.cpp index 08bc426dc..b3a65f081 100644 --- a/libethereum/Miner.cpp +++ b/libethereum/Miner.cpp @@ -34,12 +34,14 @@ LocalMiner::LocalMiner(MinerHost* _host, unsigned _id): AsyncMiner(_host, _id), Worker("miner-" + toString(_id)) { + m_pow.reset(_host->turbo() ? new Ethash : (Ethash*)new EthashCPU); } void LocalMiner::setup(MinerHost* _host, unsigned _id) { AsyncMiner::setup(_host, _id); setName("miner-" + toString(m_id)); + m_pow.reset(_host->turbo() ? new Ethash : (Ethash*)new EthashCPU); } void LocalMiner::doWork() @@ -66,7 +68,7 @@ void LocalMiner::doWork() if (m_miningStatus == Mining) { // Mine for a while. - MineInfo mineInfo = m_mineState.mine(100, m_host->turbo()); + MineInfo mineInfo = m_mineState.mine(m_pow.get()); { Guard l(x_mineInfo); diff --git a/libethereum/Miner.h b/libethereum/Miner.h index 7c4f7e767..8c2fc4bb4 100644 --- a/libethereum/Miner.h +++ b/libethereum/Miner.h @@ -60,8 +60,8 @@ public: virtual void setupState(State& _s) = 0; ///< Reset the given State object to the one that should be being mined. virtual void onProgressed() {} ///< Called once some progress has been made. virtual void onComplete() {} ///< Called once a block is found. - virtual bool turbo() const = 0; ///< @returns true iff the Miner should mine as fast as possible. virtual bool force() const = 0; ///< @returns true iff the Miner should mine regardless of the number of transactions. + virtual bool turbo() const = 0; ///< @returns true iff the Miner should use GPU if possible. }; class Miner @@ -93,7 +93,7 @@ public: virtual void stop() {} /// @returns true iff the mining has been start()ed. It may still not be actually mining, depending on the host's turbo() & force(). - virtual bool isRunning() { return false; } + virtual bool isRunning() const { return false; } protected: MinerHost* m_host = nullptr; ///< Our host. @@ -122,10 +122,10 @@ public: LocalMiner(MinerHost* _host, unsigned _id = 0); /// Move-constructor. - LocalMiner(LocalMiner&& _m): Worker((Worker&&)_m) { std::swap(m_host, _m.m_host); } + LocalMiner(LocalMiner&& _m): Worker((Worker&&)_m) { std::swap(m_host, _m.m_host); std::swap(m_pow, _m.m_pow); } /// Move-assignment. - LocalMiner& operator=(LocalMiner&& _m) { Worker::operator=((Worker&&)_m); std::swap(m_host, _m.m_host); return *this; } + LocalMiner& operator=(LocalMiner&& _m) { Worker::operator=((Worker&&)_m); std::swap(m_host, _m.m_host); std::swap(m_pow, _m.m_pow); return *this; } /// Destructor. Stops miner. ~LocalMiner() { stop(); } @@ -143,7 +143,7 @@ public: virtual void noteStateChange() override { m_miningStatus = Preparing; } /// @returns true iff the mining has been start()ed. It may still not be actually mining, depending on the host's turbo() & force(). - bool isRunning() { return isWorking(); } + bool isRunning() const override { return isWorking(); } /// @returns true if mining is complete. virtual bool isComplete() const override { return m_miningStatus == Mined; } @@ -167,8 +167,9 @@ private: enum MiningStatus { Waiting, Preparing, Mining, Mined, Stopping, Stopped }; MiningStatus m_miningStatus = Waiting; ///< TODO: consider mutex/atomic variable. State m_mineState; ///< The state on which we are mining, generally equivalent to m_postMine. + std::unique_ptr m_pow; ///< Our miner. - mutable std::mutex x_mineInfo; ///< Lock for the mining progress & history. + mutable Mutex x_mineInfo; ///< Lock for the mining progress & history. MineProgress m_mineProgress; ///< What's our progress? std::list m_mineHistory; ///< What the history of our mining? }; diff --git a/libethereum/State.cpp b/libethereum/State.cpp index 5631ffe28..c1beee787 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -856,33 +856,12 @@ void State::commitToMine(BlockChain const& _bc) m_committedToMine = true; } -MineInfo State::mine(unsigned _msTimeout, bool _turbo) -{ - // Update difficulty according to timestamp. - m_currentBlock.difficulty = m_currentBlock.calculateDifficulty(m_previousBlock); - - MineInfo ret; - // TODO: Miner class that keeps dagger between mine calls (or just non-polling mining). - ProofOfWork::Proof r; - tie(ret, r) = m_pow.mine(m_currentBlock, _msTimeout, true, _turbo); - - if (!ret.completed) - m_currentBytes.clear(); - else - { - ProofOfWork::assignResult(r, m_currentBlock); - cnote << "Completed" << m_currentBlock.headerHash(WithoutNonce).abridged() << m_currentBlock.nonce.abridged() << m_currentBlock.difficulty << ProofOfWork::verify(m_currentBlock); - } - - return ret; -} - bool State::completeMine(ProofOfWork::Proof const& _nonce) { ProofOfWork::assignResult(_nonce, m_currentBlock); - if (!m_pow.verify(m_currentBlock)) - return false; +// if (!m_pow.verify(m_currentBlock)) +// return false; cnote << "Completed" << m_currentBlock.headerHash(WithoutNonce).abridged() << m_currentBlock.nonce.abridged() << m_currentBlock.difficulty << ProofOfWork::verify(m_currentBlock); diff --git a/libethereum/State.h b/libethereum/State.h index 336c58b1a..1b71038b4 100644 --- a/libethereum/State.h +++ b/libethereum/State.h @@ -168,7 +168,25 @@ public: /// This function is thread-safe. You can safely have other interactions with this object while it is happening. /// @param _msTimeout Timeout before return in milliseconds. /// @returns Information on the mining. - MineInfo mine(unsigned _msTimeout = 1000, bool _turbo = false); + template MineInfo mine(ProofOfWork* _pow) + { + // Update difficulty according to timestamp. + m_currentBlock.difficulty = m_currentBlock.calculateDifficulty(m_previousBlock); + + MineInfo ret; + typename ProofOfWork::Proof r; + std::tie(ret, r) = _pow->mine(m_currentBlock, _pow->defaultTimeout(), true); + + if (!ret.completed) + m_currentBytes.clear(); + else + { + ProofOfWork::assignResult(r, m_currentBlock); + cnote << "Completed" << m_currentBlock.headerHash(WithoutNonce).abridged() << m_currentBlock.nonce.abridged() << m_currentBlock.difficulty << ProofOfWork::verify(m_currentBlock); + } + + return ret; + } /** Commit to DB and build the final block if the previous call to mine()'s result is completion. * Typically looks like: @@ -371,8 +389,6 @@ private: Address m_ourAddress; ///< Our address (i.e. the address to which fees go). - ProofOfWork m_pow; ///< The PoW mining class. - u256 m_blockReward; static std::string c_defaultPath; diff --git a/libweb3jsonrpc/WebThreeStubServerBase.cpp b/libweb3jsonrpc/WebThreeStubServerBase.cpp index c86274b15..04bbe7345 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.cpp +++ b/libweb3jsonrpc/WebThreeStubServerBase.cpp @@ -296,6 +296,11 @@ string WebThreeStubServerBase::eth_coinbase() return toJS(client()->address()); } +string WebThreeStubServerBase::eth_hashrate() +{ + return toJS(client()->hashrate()); +} + bool WebThreeStubServerBase::eth_mining() { return client()->isMining(); diff --git a/libweb3jsonrpc/WebThreeStubServerBase.h b/libweb3jsonrpc/WebThreeStubServerBase.h index b57a54c87..22a31a762 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.h +++ b/libweb3jsonrpc/WebThreeStubServerBase.h @@ -78,6 +78,7 @@ public: virtual bool net_listening(); virtual std::string eth_protocolVersion(); + virtual std::string eth_hashrate(); virtual std::string eth_coinbase(); virtual bool eth_mining(); virtual std::string eth_gasPrice(); diff --git a/libweb3jsonrpc/abstractwebthreestubserver.h b/libweb3jsonrpc/abstractwebthreestubserver.h index 6cc5de3e6..0860ecaee 100644 --- a/libweb3jsonrpc/abstractwebthreestubserver.h +++ b/libweb3jsonrpc/abstractwebthreestubserver.h @@ -18,6 +18,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServerbindAndAddMethod(jsonrpc::Procedure("net_peerCount", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::net_peerCountI); this->bindAndAddMethod(jsonrpc::Procedure("net_listening", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::net_listeningI); this->bindAndAddMethod(jsonrpc::Procedure("eth_protocolVersion", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_protocolVersionI); + this->bindAndAddMethod(jsonrpc::Procedure("eth_hashrate", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_hashrateI); this->bindAndAddMethod(jsonrpc::Procedure("eth_coinbase", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_coinbaseI); this->bindAndAddMethod(jsonrpc::Procedure("eth_mining", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::eth_miningI); this->bindAndAddMethod(jsonrpc::Procedure("eth_gasPrice", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_gasPriceI); @@ -98,6 +99,11 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServereth_protocolVersion(); } + inline virtual void eth_hashrateI(const Json::Value &request, Json::Value &response) + { + (void)request; + response = this->eth_hashrate(); + } inline virtual void eth_coinbaseI(const Json::Value &request, Json::Value &response) { (void)request; @@ -309,6 +315,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer getWork() override { return std::pair(); } bool submitWork(eth::ProofOfWork::Proof const&) override { return false; } diff --git a/test/blockchain.cpp b/test/blockchain.cpp index ab01df5a5..15cda8037 100644 --- a/test/blockchain.cpp +++ b/test/blockchain.cpp @@ -192,7 +192,8 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) state.sync(bc, txs, gp); state.commitToMine(bc); MineInfo info; - for (info.completed = false; !info.completed; info = state.mine()) {} + ProofOfWork pow; + for (info.completed = false; !info.completed; info = state.mine(&pow)) {} state.completeMine(); } catch (Exception const& _e) @@ -577,7 +578,7 @@ void overwriteBlockHeader(BlockInfo& _currentBlockHeader, mObject& _blObj) std::pair ret; while (!ProofOfWork::verify(_currentBlockHeader)) { - ret = pow.mine(_currentBlockHeader, 1000, true, true); + ret = pow.mine(_currentBlockHeader, 1000, true); Ethash::assignResult(ret.second, _currentBlockHeader); } } @@ -623,7 +624,7 @@ void updatePoW(BlockInfo& _bi) std::pair ret; while (!ProofOfWork::verify(_bi)) { - ret = pow.mine(_bi, 10000, true, true); + ret = pow.mine(_bi, 10000, true); Ethash::assignResult(ret.second, _bi); } _bi.noteDirty(); diff --git a/test/stateOriginal.cpp b/test/stateOriginal.cpp index 572e84dcf..40f759434 100644 --- a/test/stateOriginal.cpp +++ b/test/stateOriginal.cpp @@ -68,7 +68,8 @@ BOOST_AUTO_TEST_CASE(Complex) // Mine to get some ether! s.commitToMine(bc); - while (!s.mine(100, true).completed) {} + ProofOfWork pow; + while (!s.mine(&pow).completed) {} s.completeMine(); bc.attemptImport(s.blockData(), stateDB); @@ -88,7 +89,7 @@ BOOST_AUTO_TEST_CASE(Complex) // Mine to get some ether and set in stone. s.commitToMine(bc); s.commitToMine(bc); - while (!s.mine(100, true).completed) {} + while (!s.mine(&pow).completed) {} s.completeMine(); bc.attemptImport(s.blockData(), stateDB); diff --git a/test/webthreestubclient.h b/test/webthreestubclient.h index a460ddda4..c1fdc3411 100644 --- a/test/webthreestubclient.h +++ b/test/webthreestubclient.h @@ -72,6 +72,16 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } + std::string eth_hashrate() throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p = Json::nullValue; + Json::Value result = this->CallMethod("eth_hashrate",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } std::string eth_coinbase() throw (jsonrpc::JsonRpcException) { Json::Value p; From 71c83172c5bd55f9297113a8007f79e70bd040c5 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 12 Apr 2015 12:15:56 +0200 Subject: [PATCH 14/19] Fixes #1597 --- libethereum/State.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libethereum/State.cpp b/libethereum/State.cpp index c1beee787..6d3301cd7 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -451,7 +451,7 @@ bool State::cull(TransactionQueue& _tq) const { try { - if (i.second.nonce() <= transactionsFrom(i.second.sender())) + if (i.second.nonce() < transactionsFrom(i.second.sender())) { _tq.drop(i.first); ret = true; From 927989907fbd3c1af1f30ab8f441d0e846e709ef Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 12 Apr 2015 12:17:28 +0200 Subject: [PATCH 15/19] Avoid ethashcl in exp. Fixes #1594 --- exp/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exp/CMakeLists.txt b/exp/CMakeLists.txt index 7e670cfaa..d2a0e9ead 100644 --- a/exp/CMakeLists.txt +++ b/exp/CMakeLists.txt @@ -23,10 +23,11 @@ endif() target_link_libraries(${EXECUTABLE} webthree) target_link_libraries(${EXECUTABLE} ethereum) target_link_libraries(${EXECUTABLE} p2p) +if (ETHASHCL) target_link_libraries(${EXECUTABLE} ethash-cl) target_link_libraries(${EXECUTABLE} ethash) target_link_libraries(${EXECUTABLE} OpenCL) - +endif() install( TARGETS ${EXECUTABLE} DESTINATION bin) From 07f780fa30d827950dbabf67caa86c24c0de092a Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 12 Apr 2015 12:22:45 +0200 Subject: [PATCH 16/19] Fixes #1573 --- libweb3jsonrpc/WebThreeStubServerBase.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libweb3jsonrpc/WebThreeStubServerBase.cpp b/libweb3jsonrpc/WebThreeStubServerBase.cpp index 04bbe7345..9f765935b 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.cpp +++ b/libweb3jsonrpc/WebThreeStubServerBase.cpp @@ -607,10 +607,10 @@ Json::Value WebThreeStubServerBase::eth_getCompilers() { Json::Value ret(Json::arrayValue); ret.append("lll"); -#if SOLIDITY +#if ETH_SOLIDITY || !TRUE ret.append("solidity"); #endif -#if SERPENT +#if ETH_SERPENT || !TRUE ret.append("serpent"); #endif return ret; @@ -632,7 +632,7 @@ string WebThreeStubServerBase::eth_compileSerpent(string const& _code) // TODO throw here jsonrpc errors string res; (void)_code; -#if SERPENT +#if ETH_SERPENT || !TRUE try { res = toJS(dev::asBytes(::compile(_code))); @@ -654,7 +654,7 @@ string WebThreeStubServerBase::eth_compileSolidity(string const& _code) // TOOD throw here jsonrpc errors (void)_code; string res; -#if SOLIDITY +#if ETH_SOLIDITY || !TRUE dev::solidity::CompilerStack compiler; try { From 2eab7a7c22883cfda35f341609f6af53b05ebc72 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 12 Apr 2015 16:34:35 +0200 Subject: [PATCH 17/19] Fixes some build issues. --- libethereum/Client.cpp | 2 +- libweb3jsonrpc/WebThreeStubServerBase.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 4b197797f..87eff7f08 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -369,7 +369,7 @@ MineProgress Client::miningProgress() const uint64_t Client::hashrate() const { - uint64_t ret; + uint64_t ret = 0; ReadGuard l(x_localMiners); for (LocalMiner const& m: m_localMiners) ret += m.miningProgress().hashes / m.miningProgress().ms; diff --git a/libweb3jsonrpc/WebThreeStubServerBase.cpp b/libweb3jsonrpc/WebThreeStubServerBase.cpp index 9f765935b..5b6c833bc 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.cpp +++ b/libweb3jsonrpc/WebThreeStubServerBase.cpp @@ -26,7 +26,7 @@ #include #include -#if ETH_SOLIDITY +#if ETH_SOLIDITY || !ETH_TRUE #include #include #include @@ -38,7 +38,7 @@ #include #include #include -#if ETH_SERPENT +#if ETH_SERPENT || !ETH_TRUE #include #endif #include "WebThreeStubServerBase.h" @@ -632,7 +632,7 @@ string WebThreeStubServerBase::eth_compileSerpent(string const& _code) // TODO throw here jsonrpc errors string res; (void)_code; -#if ETH_SERPENT || !TRUE +#if ETH_SERPENT || !ETH_TRUE try { res = toJS(dev::asBytes(::compile(_code))); @@ -654,7 +654,7 @@ string WebThreeStubServerBase::eth_compileSolidity(string const& _code) // TOOD throw here jsonrpc errors (void)_code; string res; -#if ETH_SOLIDITY || !TRUE +#if ETH_SOLIDITY || !ETH_TRUE dev::solidity::CompilerStack compiler; try { From 97a18e33feb60d72630ee26837cde4a775313dd9 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 12 Apr 2015 16:36:11 +0200 Subject: [PATCH 18/19] Avoid llvm warning. --- libethereum/Client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 87eff7f08..d8723430d 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -264,7 +264,7 @@ static string filtersToString(T const& _fs) { stringstream ret; ret << "{"; - bool i = false; + unsigned i = 0; for (h256 const& f: _fs) ret << (i++ ? ", " : "") << (f == PendingChangedFilter ? "pending" : f == ChainChangedFilter ? "chain" : f.abridged()); ret << "}"; From 1a67af3115eb16383f1e5b806426f37e7ea4d818 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 12 Apr 2015 23:25:20 +0200 Subject: [PATCH 19/19] Fix configuraion issues. --- CMakeLists.txt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e6a906b59..05862d9f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,7 +136,6 @@ if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release") endif () createDefaultCacheConfig() -configureProject() # Force chromium. set (ETH_HAVE_WEBENGINE 1) @@ -263,6 +262,8 @@ elseif (BUNDLE STREQUAL "user") set(TESTS OFF) endif () +configureProject() + # Default CMAKE_BUILD_TYPE to "Release". set(CMAKE_BUILD_TYPE CACHE STRING "Release") if ("x${CMAKE_BUILD_TYPE}" STREQUAL "x") @@ -272,7 +273,11 @@ endif () # Default TARGET_PLATFORM to "linux". set(TARGET_PLATFORM CACHE STRING "linux") if ("x${TARGET_PLATFORM}" STREQUAL "x") - set(TARGET_PLATFORM "linux") + if (WIN32) + set(TARGET_PLATFORM "windows") + else () + set(TARGET_PLATFORM "linux") + endif () endif () message("------------------------------------------------------------------------") @@ -308,7 +313,7 @@ include(EthCompilerSettings) message("-- CXXFLAGS: ${CMAKE_CXX_FLAGS}") -# this must be an include, as a function it would messs up with variable scope! +# this must be an include, as a function it would mess up with variable scope! include(EthDependencies) include(EthExecutableHelper)