Skip to content

Commit da1fcbb

Browse files
committed
DAG generation improvements.
Generate next DAG in AZ! Cleanups to Ethash & Aux. DAG Progress in AZ.
1 parent 2eed2ca commit da1fcbb

13 files changed

Lines changed: 161 additions & 91 deletions

File tree

alethzero/Main.ui

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
</property>
152152
<addaction name="mine"/>
153153
<addaction name="turboMining"/>
154+
<addaction name="prepNextDAG"/>
154155
<addaction name="separator"/>
155156
<addaction name="newTransaction"/>
156157
<addaction name="newAccount"/>
@@ -1727,6 +1728,11 @@ font-size: 14pt</string>
17271728
<string>In&amp;ject Block</string>
17281729
</property>
17291730
</action>
1731+
<action name="prepNextDAG">
1732+
<property name="text">
1733+
<string>Prepare Next &amp;DAG</string>
1734+
</property>
1735+
</action>
17301736
</widget>
17311737
<layoutdefault spacing="6" margin="11"/>
17321738
<customwidgets>

alethzero/MainWin.cpp

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ Main::Main(QWidget *parent) :
204204
QSettings s("ethereum", "alethzero");
205205
m_networkConfig = s.value("peers").toByteArray();
206206
bytesConstRef network((byte*)m_networkConfig.data(), m_networkConfig.size());
207-
m_webThree.reset(new WebThreeDirect(string("AlethZero/v") + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM), getDataDir(), WithExisting::Trust, {"eth", "shh"}, p2p::NetworkPreferences(), network));
207+
m_webThree.reset(new WebThreeDirect(string("AlethZero/v") + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM), getDataDir(), WithExisting::Trust, {"eth"/*, "shh"*/}, p2p::NetworkPreferences(), network));
208208

209209
m_httpConnector.reset(new jsonrpc::HttpServer(SensibleHttpPort, "", "", dev::SensibleHttpThreads));
210210
m_server.reset(new OurWebThreeStubServer(*m_httpConnector, *web3(), this));
@@ -943,22 +943,30 @@ void Main::on_preview_triggered()
943943
refreshAll();
944944
}
945945

946+
void Main::on_prepNextDAG_triggered()
947+
{
948+
EthashAux::computeFull(ethereum()->blockChain().number() + ETHASH_EPOCH_LENGTH);
949+
}
950+
946951
void Main::refreshMining()
947952
{
953+
pair<uint64_t, unsigned> gp = EthashAux::fullGeneratingProgress();
954+
QString t;
955+
if (gp.first != EthashAux::NotGenerating)
956+
t = QString("DAG for #%1-#%2: %3% complete; ").arg(gp.first).arg(gp.first + ETHASH_EPOCH_LENGTH - 1).arg(gp.second);
948957
MiningProgress p = ethereum()->miningProgress();
949-
ui->mineStatus->setText(ethereum()->isMining() ? QString("%1s @ %2kH/s").arg(p.ms / 1000).arg(p.ms ? p.hashes / p.ms : 0) : "Not mining");
950-
if (!ui->miningView->isVisible())
951-
return;
952-
list<MineInfo> l = ethereum()->miningHistory();
953-
static unsigned lh = 0;
954-
if (p.hashes < lh)
955-
ui->miningView->resetStats();
956-
lh = p.hashes;
957-
ui->miningView->appendStats(l, p);
958-
/* if (p.ms)
959-
for (MineInfo const& i: l)
960-
cnote << i.hashes * 10 << "h/sec, need:" << i.requirement << " best:" << i.best << " best-so-far:" << p.best << " avg-speed:" << (p.hashes * 1000 / p.ms) << "h/sec";
961-
*/
958+
ui->mineStatus->setText(t + (ethereum()->isMining() ? p.hashes > 0 ? QString("%1s @ %2kH/s").arg(p.ms / 1000).arg(p.ms ? p.hashes / p.ms : 0) : "Awaiting DAG" : "Not mining"));
959+
if (ethereum()->isMining() && p.hashes > 0)
960+
{
961+
if (!ui->miningView->isVisible())
962+
return;
963+
list<MineInfo> l = ethereum()->miningHistory();
964+
static unsigned lh = 0;
965+
if (p.hashes < lh)
966+
ui->miningView->resetStats();
967+
lh = p.hashes;
968+
ui->miningView->appendStats(l, p);
969+
}
962970
}
963971

964972
void Main::setBeneficiary(Address const& _b)
@@ -1878,6 +1886,7 @@ void Main::on_mine_triggered()
18781886
{
18791887
if (ui->mine->isChecked())
18801888
{
1889+
// EthashAux::computeFull(ethereum()->blockChain().number());
18811890
ethereum()->setAddress(m_beneficiary);
18821891
ethereum()->startMining();
18831892
}
@@ -2027,6 +2036,7 @@ std::string Main::prettyU256(dev::u256 const& _n) const
20272036

20282037
void Main::on_post_clicked()
20292038
{
2039+
return;
20302040
shh::Message m;
20312041
m.setTo(stringToPublic(ui->shhTo->currentText()));
20322042
m.setPayload(parseData(ui->shhData->toPlainText().toStdString()));
@@ -2051,6 +2061,7 @@ int Main::authenticate(QString _title, QString _text)
20512061

20522062
void Main::refreshWhispers()
20532063
{
2064+
return;
20542065
ui->whispers->clear();
20552066
for (auto const& w: whisper()->all())
20562067
{

alethzero/MainWin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ private slots:
124124

125125
// Mining
126126
void on_mine_triggered();
127+
void on_prepNextDAG_triggered();
127128

128129
// View
129130
void on_refresh_triggered();

alethzero/Transact.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,9 @@ void Transact::rejigData()
299299
return;
300300

301301
// Determine how much balance we have to play with...
302-
auto s = findSecret(value() + ethereum()->gasLimitRemaining() * gasPrice());
303-
auto b = ethereum()->balanceAt(KeyPair(s).address(), PendingBlock);
302+
//findSecret(value() + ethereum()->gasLimitRemaining() * gasPrice());
303+
auto s = fromAccount();
304+
auto b = ethereum()->balanceAt(s, PendingBlock);
304305

305306
m_allGood = true;
306307
QString htmlInfo;

eth/main.cpp

Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ void help()
158158
<< " --port <port> Connect to remote port (default: 30303)." << endl
159159
<< " --network-id <n> Only connect to other hosts with this network id (default:0)." << endl
160160
<< " --upnp <on/off> Use UPnP for NAT (default: on)." << endl
161+
<< endl
162+
<< "Client structured logging:" << endl
163+
<< " --structured-logging Enable structured logging (default output to stdout)." << endl
164+
<< " --structured-logging-format <format> Set the structured logging time format." << endl
165+
<< " --structured-logging-url <URL> Set the structured logging destination (currently only file:// supported)." << endl
161166
#if ETH_JSONRPC || !ETH_TRUE
162167
<< endl
163168
<< "Work farming mode:" << endl
@@ -806,8 +811,11 @@ int main(int argc, char** argv)
806811
structuredLoggingFormat = string(argv[++i]);
807812
else if (arg == "--structured-logging")
808813
structuredLogging = true;
809-
else if (arg == "--structured-logging-destination" && i + 1 < argc)
814+
else if (arg == "--structured-logging-url" && i + 1 < argc)
815+
{
816+
structuredLogging = true;
810817
structuredLoggingURL = argv[++i];
818+
}
811819
else if ((arg == "-d" || arg == "--path" || arg == "--db-path") && i + 1 < argc)
812820
dbPath = argv[++i];
813821
else if ((arg == "-D" || arg == "--create-dag") && i + 1 < argc)
@@ -1033,6 +1041,28 @@ int main(int argc, char** argv)
10331041
if (!clientName.empty())
10341042
clientName += "/";
10351043

1044+
string logbuf;
1045+
bool silence = false;
1046+
std::string additional;
1047+
g_logPost = [&](std::string const& a, char const*){
1048+
if (silence)
1049+
logbuf += a + "\n";
1050+
else
1051+
cout << "\r \r" << a << endl << additional << flush;
1052+
};
1053+
1054+
auto getPassword = [&](string const& prompt){
1055+
auto s = silence;
1056+
silence = true;
1057+
cout << endl;
1058+
string ret = dev::getPassword(prompt);
1059+
silence = s;
1060+
return ret;
1061+
};
1062+
auto getAccountPassword = [&](Address const& a){
1063+
return getPassword("Enter password for address " + keyManager.accountDetails()[a].first + " (" + a.abridged() + "; hint:" + keyManager.accountDetails()[a].second + "): ");
1064+
};
1065+
10361066
StructuredLogger::get().initialize(structuredLogging, structuredLoggingFormat, structuredLoggingURL);
10371067
VMFactory::setKind(jit ? VMKind::JIT : VMKind::Interpreter);
10381068
auto netPrefs = publicIP.empty() ? NetworkPreferences(listenIP ,listenPort, upnp) : NetworkPreferences(publicIP, listenIP ,listenPort, upnp);
@@ -1042,13 +1072,38 @@ int main(int argc, char** argv)
10421072
clientImplString,
10431073
dbPath,
10441074
killChain,
1045-
nodeMode == NodeMode::Full ? set<string>{"eth", "shh"} : set<string>(),
1075+
nodeMode == NodeMode::Full ? set<string>{"eth"/*, "shh"*/} : set<string>(),
10461076
netPrefs,
10471077
&nodesState);
10481078

10491079
if (mode == OperationMode::DAGInit)
10501080
doInitDAG(web3.ethereum()->blockChain().number() + (initDAG == PendingBlock ? 30000 : 0));
10511081

1082+
if (keyManager.exists())
1083+
while (masterPassword.empty())
1084+
{
1085+
masterPassword = getPassword("Please enter your MASTER password: ");
1086+
if (!keyManager.load(masterPassword))
1087+
{
1088+
cout << "Password invalid. Try again." << endl;
1089+
masterPassword.clear();
1090+
}
1091+
}
1092+
else
1093+
{
1094+
while (masterPassword.empty())
1095+
{
1096+
masterPassword = getPassword("Please enter a MASTER password to protect your key store (make it strong!): ");
1097+
string confirm = getPassword("Please confirm the password by entering it again: ");
1098+
if (masterPassword != confirm)
1099+
{
1100+
cout << "Passwords were different. Try again." << endl;
1101+
masterPassword.clear();
1102+
}
1103+
}
1104+
keyManager.create(masterPassword);
1105+
}
1106+
10521107
auto toNumber = [&](string const& s) -> unsigned {
10531108
if (s == "latest")
10541109
return web3.ethereum()->number();
@@ -1137,53 +1192,13 @@ int main(int argc, char** argv)
11371192
if (remoteHost.size())
11381193
web3.addNode(p2p::NodeId(), remoteHost + ":" + toString(remotePort));
11391194

1140-
if (keyManager.exists())
1141-
while (masterPassword.empty())
1142-
{
1143-
masterPassword = getPassword("Please enter your MASTER password: ");
1144-
if (!keyManager.load(masterPassword))
1145-
{
1146-
cout << "Password invalid. Try again." << endl;
1147-
masterPassword.clear();
1148-
}
1149-
}
1150-
else
1151-
{
1152-
while (masterPassword.empty())
1153-
{
1154-
masterPassword = getPassword("Please enter a MASTER password to protect your key store (make it strong!): ");
1155-
string confirm = getPassword("Please confirm the password by entering it again: ");
1156-
if (masterPassword != confirm)
1157-
{
1158-
cout << "Passwords were different. Try again." << endl;
1159-
masterPassword.clear();
1160-
}
1161-
}
1162-
keyManager.create(masterPassword);
1163-
}
1164-
1165-
string logbuf;
1166-
bool silence = false;
1167-
std::string additional;
1168-
g_logPost = [&](std::string const& a, char const*) { if (silence) logbuf += a + "\n"; else cout << "\r \r" << a << endl << additional << flush; };
1169-
1170-
// TODO: give hints &c.
1171-
auto getPassword = [&](Address const& a){
1172-
auto s = silence;
1173-
silence = true;
1174-
cout << endl;
1175-
string ret = dev::getPassword("Enter password for address " + keyManager.accountDetails()[a].first + " (" + a.abridged() + "; hint:" + keyManager.accountDetails()[a].second + "): ");
1176-
silence = s;
1177-
return ret;
1178-
};
1179-
11801195
#if ETH_JSONRPC || !ETH_TRUE
11811196
shared_ptr<WebThreeStubServer> jsonrpcServer;
11821197
unique_ptr<jsonrpc::AbstractServerConnector> jsonrpcConnector;
11831198
if (jsonrpc > -1)
11841199
{
11851200
jsonrpcConnector = unique_ptr<jsonrpc::AbstractServerConnector>(new jsonrpc::HttpServer(jsonrpc, "", "", SensibleHttpThreads));
1186-
jsonrpcServer = shared_ptr<WebThreeStubServer>(new WebThreeStubServer(*jsonrpcConnector.get(), web3, make_shared<SimpleAccountHolder>([&](){return web3.ethereum();}, getPassword, keyManager), vector<KeyPair>()));
1201+
jsonrpcServer = shared_ptr<WebThreeStubServer>(new WebThreeStubServer(*jsonrpcConnector.get(), web3, make_shared<SimpleAccountHolder>([&](){return web3.ethereum();}, getAccountPassword, keyManager), vector<KeyPair>()));
11871202
jsonrpcServer->StartListening();
11881203
}
11891204
#endif
@@ -1327,7 +1342,7 @@ int main(int argc, char** argv)
13271342
if (jsonrpc < 0)
13281343
jsonrpc = SensibleHttpPort;
13291344
jsonrpcConnector = unique_ptr<jsonrpc::AbstractServerConnector>(new jsonrpc::HttpServer(jsonrpc, "", "", SensibleHttpThreads));
1330-
jsonrpcServer = shared_ptr<WebThreeStubServer>(new WebThreeStubServer(*jsonrpcConnector.get(), web3, make_shared<SimpleAccountHolder>([&](){return web3.ethereum();}, getPassword, keyManager), vector<KeyPair>()));
1345+
jsonrpcServer = shared_ptr<WebThreeStubServer>(new WebThreeStubServer(*jsonrpcConnector.get(), web3, make_shared<SimpleAccountHolder>([&](){return web3.ethereum();}, getAccountPassword, keyManager), vector<KeyPair>()));
13311346
jsonrpcServer->StartListening();
13321347
}
13331348
else if (cmd == "jsonstop")
@@ -1479,7 +1494,7 @@ int main(int argc, char** argv)
14791494
try
14801495
{
14811496
Address dest = h160(fromHex(hexAddr, WhenError::Throw));
1482-
c->submitTransaction(keyManager.secret(signingKey, [&](){ return getPassword(signingKey); }), amount, dest, bytes(), minGas);
1497+
c->submitTransaction(keyManager.secret(signingKey, [&](){ return getAccountPassword(signingKey); }), amount, dest, bytes(), minGas);
14831498
}
14841499
catch (BadHexCharacter& _e)
14851500
{
@@ -1548,7 +1563,7 @@ int main(int argc, char** argv)
15481563
else if (gas < minGas)
15491564
cwarn << "Minimum gas amount is" << minGas;
15501565
else
1551-
c->submitTransaction(keyManager.secret(signingKey, [&](){ return getPassword(signingKey); }), endowment, init, gas, gasPrice);
1566+
c->submitTransaction(keyManager.secret(signingKey, [&](){ return getAccountPassword(signingKey); }), endowment, init, gas, gasPrice);
15521567
}
15531568
else
15541569
cwarn << "Require parameters: contract ENDOWMENT GASPRICE GAS CODEHEX";

libdevcore/Common.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,12 @@ class TimerHelper
199199
#define DEV_TIMED_FUNCTION DEV_TIMED_SCOPE(__PRETTY_FUNCTION__)
200200
#endif
201201

202-
#define DEV_TIMED_IF(S, MS) for (::std::pair<::dev::TimerHelper, bool> __eth_t(::dev::TimerHelper(#S, MS), true); __eth_t.second; __eth_t.second = false)
203-
#define DEV_TIMED_SCOPE_IF(S) ::dev::TimerHelper __eth_t(S, MS)
202+
#define DEV_TIMED_ABOVE(S, MS) for (::std::pair<::dev::TimerHelper, bool> __eth_t(::dev::TimerHelper(#S, MS), true); __eth_t.second; __eth_t.second = false)
203+
#define DEV_TIMED_SCOPE_ABOVE(S) ::dev::TimerHelper __eth_t(S, MS)
204204
#if WIN32
205-
#define DEV_TIMED_FUNCTION_IF(MS) DEV_TIMED_SCOPE_IF(__FUNCSIG__, MS)
205+
#define DEV_TIMED_FUNCTION_ABOVE(MS) DEV_TIMED_SCOPE_ABOVE(__FUNCSIG__, MS)
206206
#else
207-
#define DEV_TIMED_FUNCTION_IF(MS) DEV_TIMED_SCOPE_IF(__PRETTY_FUNCTION__, MS)
207+
#define DEV_TIMED_FUNCTION_ABOVE(MS) DEV_TIMED_SCOPE_ABOVE(__PRETTY_FUNCTION__, MS)
208208
#endif
209209

210210
enum class WithExisting: int

libdevcore/Worker.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ void Worker::startWorking()
6565
m_state.exchange(ex);
6666

6767
// cnote << "Waiting until not Stopped...";
68-
DEV_TIMED_IF(Worker stopping, 100)
68+
DEV_TIMED_ABOVE(Worker stopping, 100)
6969
while (m_state == WorkerState::Stopped)
7070
this_thread::sleep_for(chrono::milliseconds(20));
7171
}
7272
}));
7373
// cnote << "Spawning" << m_name;
7474
}
75-
DEV_TIMED_IF(Start worker, 100)
76-
while (m_state != WorkerState::Started)
75+
DEV_TIMED_ABOVE(Start worker, 100)
76+
while (m_state == WorkerState::Starting)
7777
this_thread::sleep_for(chrono::microseconds(20));
7878
}
7979

@@ -85,7 +85,7 @@ void Worker::stopWorking()
8585
WorkerState ex = WorkerState::Started;
8686
m_state.compare_exchange_strong(ex, WorkerState::Stopping);
8787

88-
DEV_TIMED_IF(Stop worker, 100)
88+
DEV_TIMED_ABOVE(Stop worker, 100)
8989
while (m_state != WorkerState::Stopped)
9090
this_thread::sleep_for(chrono::microseconds(20));
9191
}
@@ -99,7 +99,7 @@ void Worker::terminate()
9999
{
100100
m_state.exchange(WorkerState::Killing);
101101

102-
DEV_TIMED_IF(Terminate worker, 100)
102+
DEV_TIMED_ABOVE(Terminate worker, 100)
103103
m_work->join();
104104

105105
m_work.reset();

libethcore/Ethash.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ Ethash::WorkPackage Ethash::package(BlockInfo const& _bi)
7676
return ret;
7777
}
7878

79-
void Ethash::prep(BlockInfo const& _header)
79+
void Ethash::prep(BlockInfo const& _header, std::function<int(unsigned)> const& _f)
8080
{
81-
EthashAux::full(_header);
81+
EthashAux::full((unsigned)_header.number, _f);
8282
}
8383

8484
bool Ethash::preVerify(BlockInfo const& _header)
@@ -310,6 +310,8 @@ void Ethash::GPUMiner::workLoop()
310310

311311
unsigned device = instances() > 1 ? index() : s_deviceId;
312312

313+
if (!EthashAux::computeFull(w.blockNumber))
314+
return;
313315
EthashAux::FullType dag = EthashAux::full(w.blockNumber);
314316
bytesConstRef dagData = dag->data();
315317
m_miner->init(dagData.data(), dagData.size(), 32, s_platformId, device);

libethcore/Ethash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class Ethash
7474

7575
static std::string name();
7676
static unsigned revision();
77-
static void prep(BlockInfo const& _header);
77+
static void prep(BlockInfo const& _header, std::function<int(unsigned)> const& _f = std::function<int(unsigned)>());
7878
static bool verify(BlockInfo const& _header);
7979
static bool preVerify(BlockInfo const& _header);
8080
static WorkPackage package(BlockInfo const& _header);

0 commit comments

Comments
 (0)