Skip to content

Commit 737e616

Browse files
committed
Merge branch 'develop' into crypto
Conflicts: libdevcrypto/Common.cpp libdevcrypto/EC.cpp
2 parents fab63ce + 759b85a commit 737e616

18 files changed

Lines changed: 225 additions & 75 deletions

File tree

alethzero/MainWin.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,9 +1258,10 @@ void Main::on_blocks_currentItemChanged()
12581258
s << "<br/>Coinbase: <b>" << pretty(info.coinbaseAddress).toHtmlEscaped().toStdString() << "</b> " << info.coinbaseAddress;
12591259
s << "<br/>Nonce: <b>" << info.nonce << "</b>";
12601260
s << "<br/>Parent: <b>" << info.parentHash << "</b>";
1261-
s << "<br/>Bloom: <b>" << details.bloom << "</b>";
1261+
// s << "<br/>Bloom: <b>" << details.bloom << "</b>";
12621262
s << "<br/>Log Bloom: <b>" << info.logBloom << "</b>";
12631263
s << "<br/>Transactions: <b>" << block[1].itemCount() << "</b> @<b>" << info.transactionsRoot << "</b>";
1264+
s << "<br/>Receipts: @<b>" << info.receiptsRoot << "</b>:";
12641265
s << "<br/>Uncles: <b>" << block[2].itemCount() << "</b> @<b>" << info.sha3Uncles << "</b>";
12651266
for (auto u: block[2])
12661267
{
@@ -1283,6 +1284,7 @@ void Main::on_blocks_currentItemChanged()
12831284
Transaction tx(block[1][txi].data());
12841285
auto ss = tx.safeSender();
12851286
h256 th = sha3(rlpList(ss, tx.nonce()));
1287+
auto receipt = ethereum()->blockChain().receipts(h).receipts[txi];
12861288
s << "<h3>" << th << "</h3>";
12871289
s << "<h4>" << h << "[<b>" << txi << "</b>]</h4>";
12881290
s << "<br/>From: <b>" << pretty(ss).toHtmlEscaped().toStdString() << "</b> " << ss;
@@ -1298,6 +1300,10 @@ void Main::on_blocks_currentItemChanged()
12981300
s << "<br/>R: <b>" << hex << nouppercase << tx.signature().r << "</b>";
12991301
s << "<br/>S: <b>" << hex << nouppercase << tx.signature().s << "</b>";
13001302
s << "<br/>Msg: <b>" << tx.sha3(eth::WithoutSignature) << "</b>";
1303+
s << "<div>Hex: <span style=\"font-family: Monospace,Lucida Console,Courier,Courier New,sans-serif; font-size: small\">" << toHex(block[1][txi].data()) << "</span></div>";
1304+
auto r = receipt.rlp();
1305+
s << "<div>Receipt: " << toString(RLP(r)) << "</div>";
1306+
s << "<div>Receipt-Hex: <span style=\"font-family: Monospace,Lucida Console,Courier,Courier New,sans-serif; font-size: small\">" << toHex(receipt.rlp()) << "</span></div>";
13011307
if (tx.isCreation())
13021308
{
13031309
if (tx.data().size())

alethzero/MainWin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ private slots:
154154
void on_newIdentity_triggered();
155155

156156
void refreshWhisper();
157+
void refreshBlockChain();
157158
void addNewId(QString _ids);
158159

159160
signals:
@@ -214,7 +215,6 @@ private slots:
214215
void refreshPending();
215216
void refreshAccounts();
216217
void refreshDestination();
217-
void refreshBlockChain();
218218
void refreshBlockCount();
219219
void refreshBalances();
220220

exp/main.cpp

Lines changed: 59 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,27 @@ using namespace dev::eth;
3636
using namespace dev::p2p;
3737
using namespace dev::shh;
3838

39-
#if 0
39+
#if 1
4040
int main()
4141
{
4242
DownloadMan man;
4343
DownloadSub s0(man);
4444
DownloadSub s1(man);
4545
DownloadSub s2(man);
4646
man.resetToChain(h256s({u256(0), u256(1), u256(2), u256(3), u256(4), u256(5), u256(6), u256(7), u256(8)}));
47-
cnote << s0.nextFetch(2);
48-
cnote << s1.nextFetch(2);
49-
cnote << s2.nextFetch(2);
50-
s0.noteBlock(u256(0));
47+
assert((s0.nextFetch(2) == h256Set{(u256)7, (u256)8}));
48+
assert((s1.nextFetch(2) == h256Set{(u256)5, (u256)6}));
49+
assert((s2.nextFetch(2) == h256Set{(u256)3, (u256)4}));
50+
s0.noteBlock(u256(8));
5151
s0.doneFetch();
52-
cnote << s0.nextFetch(2);
53-
s1.noteBlock(u256(2));
54-
s1.noteBlock(u256(3));
52+
assert((s0.nextFetch(2) == h256Set{(u256)2, (u256)7}));
53+
s1.noteBlock(u256(6));
54+
s1.noteBlock(u256(5));
5555
s1.doneFetch();
56-
cnote << s1.nextFetch(2);
57-
s0.doneFetch();
58-
cnote << s0.nextFetch(2);
56+
assert((s1.nextFetch(2) == h256Set{(u256)0, (u256)1}));
57+
s0.doneFetch(); // TODO: check exact semantics of doneFetch & nextFetch. Not sure if they're right -> doneFetch calls resetFetch which kills all the info of past fetches.
58+
cdebug << s0.nextFetch(2);
59+
assert((s0.nextFetch(2) == h256Set{(u256)3, (u256)4}));
5960

6061
/* RangeMask<unsigned> m(0, 100);
6162
cnote << m;
@@ -73,49 +74,70 @@ int main()
7374
}
7475
#endif
7576

76-
int main(int argc, char** argv)
77+
/*int other(bool& o_started)
7778
{
78-
g_logVerbosity = 20;
79-
80-
short listenPort = 30303;
81-
string remoteHost;
82-
short remotePort = 30303;
79+
setThreadName("other");
8380
84-
for (int i = 1; i < argc; ++i)
85-
{
86-
string arg = argv[i];
87-
if (arg == "-l" && i + 1 < argc)
88-
listenPort = (short)atoi(argv[++i]);
89-
else if (arg == "-r" && i + 1 < argc)
90-
remoteHost = argv[++i];
91-
else if (arg == "-p" && i + 1 < argc)
92-
remotePort = (short)atoi(argv[++i]);
93-
else
94-
remoteHost = argv[i];
95-
}
81+
short listenPort = 30300;
9682
9783
Host ph("Test", NetworkPreferences(listenPort, "", false, true));
9884
auto wh = ph.registerCapability(new WhisperHost());
9985
10086
ph.start();
10187
102-
if (!remoteHost.empty())
103-
ph.connect(remoteHost, remotePort);
88+
o_started = true;
10489
10590
/// Only interested in odd packets
10691
auto w = wh->installWatch(BuildTopicMask()("odd"));
10792
108-
KeyPair us = KeyPair::create();
109-
for (int i = 0; ; ++i)
93+
unsigned last = 0;
94+
unsigned total = 0;
95+
96+
for (int i = 0; i < 100 && last < 81; ++i)
11097
{
111-
wh->post(us.sec(), RLPStream().append(i * i).out(), BuildTopic(i)(i % 2 ? "odd" : "even"));
11298
for (auto i: wh->checkWatch(w))
11399
{
114100
Message msg = wh->envelope(i).open();
115-
101+
last = RLP(msg.payload()).toInt<unsigned>();
116102
cnote << "New message from:" << msg.from().abridged() << RLP(msg.payload()).toInt<unsigned>();
103+
total += last;
117104
}
118-
this_thread::sleep_for(chrono::seconds(1));
105+
this_thread::sleep_for(chrono::milliseconds(50));
119106
}
120-
return 0;
107+
return total;
121108
}
109+
110+
int main(int, char**)
111+
{
112+
g_logVerbosity = 0;
113+
114+
bool started = false;
115+
unsigned result;
116+
std::thread listener([&](){ return (result = other(started)); });
117+
while (!started)
118+
this_thread::sleep_for(chrono::milliseconds(50));
119+
120+
short listenPort = 30303;
121+
string remoteHost = "127.0.0.1";
122+
short remotePort = 30300;
123+
124+
Host ph("Test", NetworkPreferences(listenPort, "", false, true));
125+
auto wh = ph.registerCapability(new WhisperHost());
126+
127+
ph.start();
128+
129+
if (!remoteHost.empty())
130+
ph.connect(remoteHost, remotePort);
131+
132+
KeyPair us = KeyPair::create();
133+
for (int i = 0; i < 10; ++i)
134+
{
135+
wh->post(us.sec(), RLPStream().append(i * i).out(), BuildTopic(i)(i % 2 ? "odd" : "even"));
136+
this_thread::sleep_for(chrono::milliseconds(250));
137+
}
138+
139+
listener.join();
140+
assert(result == 1 + 9 + 25 + 49 + 81);
141+
142+
return 0;
143+
}*/

libdevcore/Common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ using namespace dev;
2727
namespace dev
2828
{
2929

30-
char const* Version = "0.7.9";
30+
char const* Version = "0.7.10";
3131

3232
}
3333

libdevcore/CommonIO.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ string dev::memDump(bytes const& _b, unsigned _w, bool _html)
3030
{
3131
stringstream ret;
3232
if (_html)
33-
ret << "<pre style=\"font-family: Monospace, sans-serif; font-size: small\">";
33+
ret << "<pre style=\"font-family: Monospace,Lucida Console,Courier,Courier New,sans-serif; font-size: small\">";
3434
for (unsigned i = 0; i < _b.size(); i += _w)
3535
{
3636
ret << hex << setw(4) << setfill('0') << i << " ";

libdevcore/RLP.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class RLP
158158

159159
/// Best-effort conversion operators.
160160
explicit operator std::string() const { return toString(); }
161+
explicit operator bytes() const { return toBytes(); }
161162
explicit operator RLPs() const { return toList(); }
162163
explicit operator uint8_t() const { return toInt<uint8_t>(); }
163164
explicit operator uint16_t() const { return toInt<uint16_t>(); }
@@ -341,7 +342,7 @@ class RLPStream
341342
RLPStream& append(char const* _s) { return append(std::string(_s)); }
342343
template <unsigned N> RLPStream& append(FixedHash<N> _s, bool _compact = false, bool _allOrNothing = false) { return _allOrNothing && !_s ? append(bytesConstRef()) : append(_s.ref(), _compact); }
343344

344-
/// Appends an arbitrary RLP fragment - this *must* be a single item.
345+
/// Appends an arbitrary RLP fragment - this *must* be a single item unless @a _itemCount is given.
345346
RLPStream& append(RLP const& _rlp, unsigned _itemCount = 1) { return appendRaw(_rlp.data(), _itemCount); }
346347

347348
/// Appends a sequence of data to the stream as a list.

libdevcrypto/Common.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222

2323
#include <random>
24+
#include <chrono>
2425
#include <mutex>
2526
#include "SHA3.h"
2627
#include "FileSystem.h"
@@ -85,7 +86,7 @@ bool dev::verify(Public _p, Signature _s, h256 _hash)
8586

8687
KeyPair KeyPair::create()
8788
{
88-
static mt19937_64 s_eng(time(0));
89+
static mt19937_64 s_eng(time(0) + chrono::high_resolution_clock::now().time_since_epoch().count());
8990
uniform_int_distribution<uint16_t> d(0, 255);
9091

9192
for (int i = 0; i < 100; ++i)

libethcore/CommonEth.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace dev
3333
namespace eth
3434
{
3535

36-
const unsigned c_protocolVersion = 39;
36+
const unsigned c_protocolVersion = 40;
3737
const unsigned c_databaseVersion = 4;
3838

3939
static const vector<pair<u256, string>> g_units =

libethereum/Executive.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,7 @@ bool Executive::call(Address _receiveAddress, Address _senderAddress, u256 _valu
123123
m_ext = new ExtVM(m_s, _receiveAddress, _senderAddress, _originAddress, _value, _gasPrice, _data, &c, m_ms);
124124
}
125125
else
126-
{
127126
m_endGas = _gas;
128-
if (m_ext)
129-
m_ext->sub.logs.push_back(LogEntry(_receiveAddress, {u256((u160)_senderAddress) + 1}, bytes()));
130-
}
131127
return !m_ext;
132128
}
133129

@@ -177,7 +173,10 @@ bool Executive::go(OnOpFunc const& _onOp)
177173
{
178174
m_out = m_vm->go(*m_ext, _onOp);
179175
if (m_ext)
176+
{
180177
m_endGas += min((m_t.gas() - m_endGas) / 2, m_ext->sub.refunds);
178+
m_logs = m_ext->sub.logs;
179+
}
181180
m_endGas = m_vm->gas();
182181
}
183182
catch (StepsDone const&)

libethereum/State.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121

2222
#include "State.h"
2323

24-
#include <boost/filesystem.hpp>
25-
#include <time.h>
24+
#include <ctime>
2625
#include <random>
26+
#include <boost/filesystem.hpp>
27+
#include <boost/timer.hpp>
2728
#include <secp256k1/secp256k1.h>
2829
#include <libdevcore/CommonIO.h>
2930
#include <libevmcore/Instruction.h>
@@ -549,10 +550,12 @@ h256s State::sync(TransactionQueue& _tq, bool* o_transactionQueueChanged)
549550
try
550551
{
551552
uncommitToMine();
553+
// boost::timer t;
552554
execute(i.second);
553555
ret.push_back(m_receipts.back().changes().bloom());
554556
_tq.noteGood(i);
555557
++goodTxs;
558+
// cnote << "TX took:" << t.elapsed() * 1000;
556559
}
557560
catch (InvalidNonce const& in)
558561
{
@@ -1190,11 +1193,14 @@ bool State::call(Address _receiveAddress, Address _codeAddress, Address _senderA
11901193
auto it = !(_codeAddress & ~h160(0xffffffff)) ? c_precompiled.find((unsigned)(u160)_codeAddress) : c_precompiled.end();
11911194
if (it != c_precompiled.end())
11921195
{
1193-
if (*_gas >= it->second.gas)
1196+
if (*_gas < it->second.gas)
11941197
{
1195-
*_gas -= it->second.gas;
1196-
it->second.exec(_data, _out);
1198+
*_gas = 0;
1199+
return false;
11971200
}
1201+
1202+
*_gas -= it->second.gas;
1203+
it->second.exec(_data, _out);
11981204
}
11991205
else if (addressHasCode(_codeAddress))
12001206
{
@@ -1235,12 +1241,6 @@ bool State::call(Address _receiveAddress, Address _codeAddress, Address _senderA
12351241

12361242
return !revert;
12371243
}
1238-
else
1239-
{
1240-
// non-contract call
1241-
if (o_sub)
1242-
o_sub->logs.push_back(LogEntry(_receiveAddress, {u256((u160)_senderAddress) + 1}, bytes()));
1243-
}
12441244
return true;
12451245
}
12461246

0 commit comments

Comments
 (0)