Browse Source

Merge branch 'stashed' into develop

cl-refactor
Gav Wood 10 years ago
parent
commit
647566171e
  1. 1
      CMakeLists.txt
  2. 3
      libdevcrypto/Common.cpp
  3. 17
      libdevcrypto/CryptoPP.cpp
  4. 25
      libethereum/Client.cpp
  5. 18
      libethereum/Client.h
  6. 2
      libethereum/EthereumPeer.cpp
  7. 7
      libethereum/Interface.h
  8. 17
      libethereum/Utility.cpp
  9. 10
      libevm/ExtVMFace.h
  10. 12
      libjsqrc/js.qrc
  11. 2
      libqethereum/QEthereum.h
  12. 11
      libweb3jsonrpc/WebThreeStubServer.cpp

1
CMakeLists.txt

@ -49,6 +49,7 @@ endfunction()
function(createBuildInfo)
# Set build platform; to be written to BuildInfo.h
set(ETH_BUILD_PLATFORM ${TARGET_PLATFORM})
if (CMAKE_COMPILER_IS_MINGW)
set(ETH_BUILD_PLATFORM "${ETH_BUILD_PLATFORM}/mingw")
elseif (CMAKE_COMPILER_IS_MSYS)

3
libdevcrypto/Common.cpp

@ -23,6 +23,7 @@
#include <random>
#include <chrono>
#include <mutex>
#include <libdevcore/Guards.h>
#include "SHA3.h"
#include "FileSystem.h"
#include "CryptoPP.h"
@ -139,7 +140,7 @@ h256 Nonce::get(bool _commit)
static h256 s_seed;
static string s_seedFile(getDataDir() + "/seed");
static mutex s_x;
lock_guard<mutex> l(s_x);
Guard l(s_x);
if (!s_seed)
{
static Nonce s_nonce;

17
libdevcrypto/CryptoPP.cpp

@ -20,6 +20,7 @@
*/
#include "CryptoPP.h"
#include <libdevcore/Guards.h>
using namespace std;
using namespace dev;
@ -40,7 +41,7 @@ void Secp256k1::encrypt(Public const& _k, bytes& io_cipher)
ciphertext.resize(e.CiphertextLength(plen));
{
lock_guard<mutex> l(x_rng);
Guard l(x_rng);
e.Encrypt(m_rng, io_cipher.data(), plen, ciphertext.data());
}
@ -65,7 +66,7 @@ void Secp256k1::decrypt(Secret const& _k, bytes& io_text)
DecodingResult r;
{
lock_guard<mutex> l(x_rng);
Guard l(x_rng);
r = d.Decrypt(m_rng, io_text.data(), clen, plain.data());
}
@ -99,7 +100,7 @@ Signature Secp256k1::sign(Secret const& _key, h256 const& _hash)
ECP::Point rp;
Integer r;
{
lock_guard<mutex> l(x_params);
Guard l(x_params);
rp = m_params.ExponentiateBase(k);
r = m_params.ConvertElementToInteger(rp);
}
@ -149,7 +150,7 @@ Public Secp256k1::recover(Signature _signature, bytesConstRef _message)
ECP::Element x;
{
lock_guard<mutex> l(x_curve);
Guard l(x_curve);
m_curve.DecodePoint(x, encodedpoint, 33);
if (!m_curve.VerifyPoint(x))
return recovered;
@ -158,7 +159,7 @@ Public Secp256k1::recover(Signature _signature, bytesConstRef _message)
// if (_signature[64] & 2)
// {
// r += m_q;
// lock_guard<mutex> l(x_params);
// Guard l(x_params);
// if (r >= m_params.GetMaxExponent())
// return recovered;
// }
@ -171,7 +172,7 @@ Public Secp256k1::recover(Signature _signature, bytesConstRef _message)
ECP::Point p;
byte recoveredbytes[65];
{
lock_guard<mutex> l(x_curve);
Guard l(x_curve);
// todo: make generator member
p = m_curve.CascadeMultiply(u2, x, u1, m_params.GetSubgroupGenerator());
m_curve.EncodePoint(recoveredbytes, p, false);
@ -210,7 +211,7 @@ void Secp256k1::exportPublicKey(CryptoPP::DL_PublicKey_EC<CryptoPP::ECP> const&
bytes prefixedKey(_k.GetGroupParameters().GetEncodedElementSize(true));
{
lock_guard<mutex> l(x_params);
Guard l(x_params);
m_params.GetCurve().EncodePoint(prefixedKey.data(), _k.GetPublicElement(), false);
assert(Public::size + 1 == _k.GetGroupParameters().GetEncodedElementSize(true));
}
@ -223,7 +224,7 @@ void Secp256k1::exponentToPublic(Integer const& _e, Public& o_p)
CryptoPP::DL_PublicKey_EC<CryptoPP::ECP> pk;
{
lock_guard<mutex> l(x_params);
Guard l(x_params);
pk.Initialize(m_params, m_params.ExponentiateBase(_e));
}

25
libethereum/Client.cpp

@ -185,7 +185,7 @@ unsigned Client::installWatch(h256 _h)
unsigned Client::installWatch(LogFilter const& _f)
{
lock_guard<mutex> l(m_filterLock);
Guard l(m_filterLock);
h256 h = _f.sha3();
@ -199,7 +199,7 @@ void Client::uninstallWatch(unsigned _i)
{
cwatch << "XXX" << _i;
lock_guard<mutex> l(m_filterLock);
Guard l(m_filterLock);
auto it = m_watches.find(_i);
if (it == m_watches.end())
@ -215,7 +215,7 @@ void Client::uninstallWatch(unsigned _i)
void Client::noteChanged(h256Set const& _filters)
{
lock_guard<mutex> l(m_filterLock);
Guard l(m_filterLock);
for (auto& i: m_watches)
if (_filters.count(i.second.id))
{
@ -227,7 +227,7 @@ void Client::noteChanged(h256Set const& _filters)
void Client::appendFromNewPending(LogBloom _bloom, h256Set& o_changed) const
{
// TODO: more precise check on whether the txs match.
lock_guard<mutex> l(m_filterLock);
Guard l(m_filterLock);
for (pair<h256, InstalledFilter> const& i: m_filters)
if ((unsigned)i.second.filter.latest() > m_bc.number() && i.second.filter.matches(_bloom))
o_changed.insert(i.first);
@ -238,7 +238,7 @@ void Client::appendFromNewBlock(h256 _block, h256Set& o_changed) const
// TODO: more precise check on whether the txs match.
auto d = m_bc.info(_block);
lock_guard<mutex> l(m_filterLock);
Guard l(m_filterLock);
for (pair<h256, InstalledFilter> const& i: m_filters)
if ((unsigned)i.second.filter.latest() >= d.number && (unsigned)i.second.filter.earliest() <= d.number && i.second.filter.matches(d.logBloom))
o_changed.insert(i.first);
@ -592,16 +592,16 @@ BlockInfo Client::uncle(h256 _blockHash, unsigned _i) const
return BlockInfo::fromHeader(b[2][_i].data());
}
LogEntries Client::logs(LogFilter const& _f) const
LocalisedLogEntries Client::logs(LogFilter const& _f) const
{
LogEntries ret;
unsigned begin = min<unsigned>(m_bc.number(), (unsigned)_f.latest());
unsigned end = min(begin, (unsigned)_f.earliest());
LocalisedLogEntries ret;
unsigned begin = min<unsigned>(m_bc.number() + 1, (unsigned)_f.latest());
unsigned end = min(m_bc.number(), min(begin, (unsigned)_f.earliest()));
unsigned m = _f.max();
unsigned s = _f.skip();
// Handle pending transactions differently as they're not on the block chain.
if (begin == m_bc.number())
if (begin > m_bc.number())
{
ReadGuard l(x_stateDB);
for (unsigned i = 0; i < m_postMine.pending().size(); ++i)
@ -615,9 +615,10 @@ LogEntries Client::logs(LogFilter const& _f) const
if (s)
s--;
else
ret.insert(ret.begin(), le[j]);
ret.insert(ret.begin(), LocalisedLogEntry(le[j], begin));
}
}
begin = m_bc.number();
}
#if ETH_DEBUG
@ -649,7 +650,7 @@ LogEntries Client::logs(LogFilter const& _f) const
if (s)
s--;
else
ret.insert(ret.begin(), le[j]);
ret.insert(ret.begin(), LocalisedLogEntry(le[j], n));
}
}
}

18
libethereum/Client.h

@ -108,7 +108,7 @@ struct WorkChannel: public LogChannel { static const char* name() { return "-W-"
#define cworkout dev::LogOutputStream<dev::eth::WorkOutChannel, true>()
template <class T> struct ABISerialiser {};
template <unsigned N> struct ABISerialiser<FixedHash<N>> { static bytes serialise(FixedHash<N> const& _t) { static_assert(N < 32, "Parameter sizes must be at most 32 bytes."); return bytes(32 - N, 0) + _t.asBytes(); } };
template <unsigned N> struct ABISerialiser<FixedHash<N>> { static bytes serialise(FixedHash<N> const& _t) { static_assert(N <= 32, "Cannot serialise hash > 32 bytes."); static_assert(N > 0, "Cannot serialise zero-length hash."); return bytes(32 - N, 0) + _t.asBytes(); } };
template <> struct ABISerialiser<u256> { static bytes serialise(u256 const& _t) { return h256(_t).asBytes(); } };
template <> struct ABISerialiser<u160> { static bytes serialise(u160 const& _t) { return bytes(12, 0) + h160(_t).asBytes(); } };
template <> struct ABISerialiser<string32> { static bytes serialise(string32 const& _t) { return bytesConstRef((byte const*)_t.data(), 32).toBytes(); } };
@ -125,9 +125,9 @@ template <class ... T> bytes abiIn(std::string _id, T const& ... _t)
}
template <class T> struct ABIDeserialiser {};
template <unsigned N> struct ABIDeserialiser<FixedHash<N>> { static FixedHash<N> deserialise(bytesConstRef& io_t) { static_assert(N < 32, "Parameter sizes must be at most 32 bytes."); FixedHash<N> ret; io_t.cropped(32 - N, N).populate(ret.ref()); io_t = io_t.cropped(32); return ret; } };
template <unsigned N> struct ABIDeserialiser<FixedHash<N>> { static FixedHash<N> deserialise(bytesConstRef& io_t) { static_assert(N <= 32, "Parameter sizes must be at most 32 bytes."); FixedHash<N> ret; io_t.cropped(32 - N, N).populate(ret.ref()); io_t = io_t.cropped(32); return ret; } };
template <> struct ABIDeserialiser<u256> { static u256 deserialise(bytesConstRef& io_t) { u256 ret = fromBigEndian<u256>(io_t.cropped(0, 32)); io_t = io_t.cropped(32); return ret; } };
template <> struct ABIDeserialiser<u160> { static u256 deserialise(bytesConstRef& io_t) { u160 ret = fromBigEndian<u160>(io_t.cropped(12, 20)); io_t = io_t.cropped(32); return ret; } };
template <> struct ABIDeserialiser<u160> { static u160 deserialise(bytesConstRef& io_t) { u160 ret = fromBigEndian<u160>(io_t.cropped(12, 20)); io_t = io_t.cropped(32); return ret; } };
template <> struct ABIDeserialiser<string32> { static string32 deserialise(bytesConstRef& io_t) { string32 ret; io_t.cropped(0, 32).populate(vector_ref<char>(ret.data(), 32)); io_t = io_t.cropped(32); return ret; } };
template <class T> T abiOut(bytes const& _data)
@ -188,11 +188,11 @@ public:
virtual unsigned installWatch(LogFilter const& _filter);
virtual unsigned installWatch(h256 _filterId);
virtual void uninstallWatch(unsigned _watchId);
virtual bool peekWatch(unsigned _watchId) const { std::lock_guard<std::mutex> l(m_filterLock); try { return m_watches.at(_watchId).changes != 0; } catch (...) { return false; } }
virtual bool checkWatch(unsigned _watchId) { std::lock_guard<std::mutex> l(m_filterLock); bool ret = false; try { ret = m_watches.at(_watchId).changes != 0; m_watches.at(_watchId).changes = 0; } catch (...) {} return ret; }
virtual bool peekWatch(unsigned _watchId) const { Guard l(m_filterLock); try { return m_watches.at(_watchId).changes != 0; } catch (...) { return false; } }
virtual bool checkWatch(unsigned _watchId) { Guard l(m_filterLock); bool ret = false; try { ret = m_watches.at(_watchId).changes != 0; m_watches.at(_watchId).changes = 0; } catch (...) {} return ret; }
virtual LogEntries logs(unsigned _watchId) const { try { std::lock_guard<std::mutex> l(m_filterLock); return logs(m_filters.at(m_watches.at(_watchId).id).filter); } catch (...) { return LogEntries(); } }
virtual LogEntries logs(LogFilter const& _filter) const;
virtual LocalisedLogEntries logs(unsigned _watchId) const { try { Guard l(m_filterLock); return logs(m_filters.at(m_watches.at(_watchId).id).filter); } catch (...) { return LocalisedLogEntries(); } }
virtual LocalisedLogEntries logs(LogFilter const& _filter) const;
// [EXTRA API]:
@ -313,7 +313,7 @@ private:
TransactionQueue m_tq; ///< Maintains a list of incoming transactions not yet in a block on the blockchain.
BlockQueue m_bq; ///< Maintains a list of incoming blocks not yet on the blockchain (to be imported).
mutable boost::shared_mutex x_stateDB; ///< Lock on the state DB, effectively a lock on m_postMine.
mutable SharedMutex x_stateDB; ///< Lock on the state DB, effectively a lock on m_postMine.
OverlayDB m_stateDB; ///< Acts as the central point for the state database, so multiple States can share it.
State m_preMine; ///< The present state of the client.
State m_postMine; ///< The state of the client which we're mining (i.e. it'll have all the rewards added).
@ -321,7 +321,7 @@ private:
std::weak_ptr<EthereumHost> m_host; ///< Our Ethereum Host. Don't do anything if we can't lock.
std::vector<Miner> m_miners;
mutable boost::shared_mutex x_miners;
mutable SharedMutex x_miners;
bool m_paranoia = false; ///< Should we be paranoid about our state?
bool m_turboMining = false; ///< Don't squander all of our time mining actually just sleeping.
bool m_forceMining = false; ///< Mine even when there are no transactions pending?

2
libethereum/EthereumPeer.cpp

@ -317,6 +317,8 @@ bool EthereumPeer::interpret(unsigned _id, RLP const& _r)
disable("Blacklisted client version.");
else if (host()->isBanned(session()->id()))
disable("Peer banned for previous bad behaviour.");
else
transition(Asking::Nothing);
break;
}
case GetTransactionsPacket: break; // DEPRECATED.

7
libethereum/Interface.h

@ -86,8 +86,8 @@ public:
// [LOGS API]
virtual LogEntries logs(unsigned _watchId) const = 0;
virtual LogEntries logs(LogFilter const& _filter) const = 0;
virtual LocalisedLogEntries logs(unsigned _watchId) const = 0;
virtual LocalisedLogEntries logs(LogFilter const& _filter) const = 0;
/// Install, uninstall and query watches.
virtual unsigned installWatch(LogFilter const& _filter) = 0;
@ -180,8 +180,7 @@ public:
bool check() { return m_c ? m_c->checkWatch(m_id) : false; }
bool peek() { return m_c ? m_c->peekWatch(m_id) : false; }
// PastMessages messages() const { return m_c->messages(m_id); }
LogEntries logs() const { return m_c->logs(m_id); }
LocalisedLogEntries logs() const { return m_c->logs(m_id); }
private:
Interface* m_c = nullptr;

17
libethereum/Utility.cpp

@ -23,6 +23,7 @@
#include <boost/regex.hpp>
#include <libethcore/CommonEth.h>
#include <libdevcrypto/SHA3.h>
using namespace std;
using namespace dev;
using namespace dev::eth;
@ -32,7 +33,7 @@ bytes dev::eth::parseData(string const& _args)
bytes m_data;
boost::smatch what;
static const boost::regex r("(@|\\$)?\"([^\"]*)\"(\\s.*)?");
static const boost::regex r("(!|#|@|\\$)?\"([^\"]*)\"(\\s.*)?");
static const boost::regex d("(@|\\$)?([0-9]+)(\\s*(ether)|(finney)|(szabo))?(\\s.*)?");
static const boost::regex h("(@|\\$)?(0x)?(([a-fA-F0-9])+)(\\s.*)?");
@ -67,13 +68,15 @@ bytes dev::eth::parseData(string const& _args)
}
else if (boost::regex_match(s, what, r))
{
for (auto i: (string)what[2])
m_data.push_back((byte)i);
if (what[1] != "$")
for (int i = what[2].length(); i < 32; ++i)
m_data.push_back(0);
bytes d = asBytes(what[2]);
if (what[1] == "!")
m_data += FixedHash<4>(sha3(d)).asBytes();
else if (what[1] == "#")
m_data += sha3(d).asBytes();
else if (what[1] == "$")
m_data += d + bytes{0};
else
m_data.push_back(0);
m_data += d + bytes(32 - what[2].length() % 32, 0);
s = what[3];
}
else

10
libevm/ExtVMFace.h

@ -60,6 +60,16 @@ struct LogEntry
using LogEntries = std::vector<LogEntry>;
struct LocalisedLogEntry: public LogEntry
{
LocalisedLogEntry() {}
LocalisedLogEntry(LogEntry const& _le, unsigned _number): LogEntry(_le), number(_number) {}
unsigned number = 0;
};
using LocalisedLogEntries = std::vector<LocalisedLogEntry>;
inline LogBloom bloom(LogEntries const& _logs)
{
LogBloom ret;

12
libjsqrc/js.qrc

@ -1,7 +1,7 @@
<RCC version="1.0">
<qresource prefix="/js">
<file>es6-promise-2.0.0.js</file>
<file>setup.js</file>
<file alias="ethereum.js">ethereumjs/dist/ethereum.js</file>
</qresource>
<RCC>
<qresource prefix="/js">
<file>es6-promise-2.0.0.js</file>
<file>setup.js</file>
<file alias="webthree.js">ethereumjs/dist/ethereum.js</file>
</qresource>
</RCC>

2
libqethereum/QEthereum.h

@ -85,7 +85,7 @@ private:
_frame->addToJavaScriptWindowObject("_web3", qweb, QWebFrame::ScriptOwnership); \
_frame->addToJavaScriptWindowObject("env", _env, QWebFrame::QtOwnership); \
_frame->evaluateJavaScript(contentsOfQResource(":/js/es6-promise-2.0.0.js")); \
_frame->evaluateJavaScript(contentsOfQResource(":/js/ethereum.js")); \
_frame->evaluateJavaScript(contentsOfQResource(":/js/webthree.js")); \
_frame->evaluateJavaScript(contentsOfQResource(":/js/setup.js")); \
}

11
libweb3jsonrpc/WebThreeStubServer.cpp

@ -72,7 +72,7 @@ static Json::Value toJson(dev::eth::Transaction const& _t)
return res;
}
static Json::Value toJson(dev::eth::LogEntry const& _e)
static Json::Value toJson(dev::eth::LocalisedLogEntry const& _e)
{
Json::Value res;
@ -80,13 +80,14 @@ static Json::Value toJson(dev::eth::LogEntry const& _e)
res["address"] = toJS(_e.address);
for (auto const& t: _e.topics)
res["topics"].append(toJS(t));
res["number"] = _e.number;
return res;
}
static Json::Value toJson(dev::eth::LogEntries const& _es) // commented to avoid warning. Uncomment once in use @ poC-7.
static Json::Value toJson(dev::eth::LocalisedLogEntries const& _es) // commented to avoid warning. Uncomment once in use @ poC-7.
{
Json::Value res;
for (dev::eth::LogEntry const& e: _es)
for (dev::eth::LocalisedLogEntry const& e: _es)
res.append(toJson(e));
return res;
}
@ -634,7 +635,7 @@ std::string WebThreeStubServer::eth_transact(Json::Value const& _json)
{
auto b = m_accounts.begin()->first;
for (auto a: m_accounts)
if (client()->balanceAt(a.first) > client()->balanceAt(b))
if (client()->balanceAt(a.first, 0) > client()->balanceAt(b, 0))
b = a.first;
t.from = b;
}
@ -643,7 +644,7 @@ std::string WebThreeStubServer::eth_transact(Json::Value const& _json)
if (!t.gasPrice)
t.gasPrice = 10 * dev::eth::szabo;
if (!t.gas)
t.gas = min<u256>(client()->gasLimitRemaining(), client()->balanceAt(t.from) / t.gasPrice);
t.gas = min<u256>(client()->gasLimitRemaining(), client()->balanceAt(t.from, 0) / t.gasPrice);
if (authenticate(t))
{
if (t.to)

Loading…
Cancel
Save