Browse Source

Merge branch 'develop' of github.com:ethereum/cpp-ethereum into develop

cl-refactor
Gav Wood 10 years ago
parent
commit
c973c3069f
  1. 146
      libdevcore/RangeMask.h
  2. 3
      libethereum/BlockChain.h
  3. 8
      libethereum/BlockChainSync.cpp
  4. 1
      libethereum/BlockChainSync.h
  5. 2
      libethereum/BlockQueue.cpp
  6. 21
      libethereum/ClientBase.cpp
  7. 4
      libethereum/ClientBase.h
  8. 1
      libethereum/EthereumHost.h
  9. 1
      libethereum/EthereumPeer.h
  10. 5
      libethereum/Interface.h
  11. 1
      libp2p/Host.h
  12. 2
      libp2p/Session.cpp
  13. 1
      libp2p/Session.h
  14. 45
      libweb3jsonrpc/WebThreeStubServerBase.cpp
  15. 8
      libweb3jsonrpc/WebThreeStubServerBase.h
  16. 16
      libweb3jsonrpc/abstractwebthreestubserver.h
  17. 8
      libweb3jsonrpc/spec.json
  18. 28
      libwhisper/BloomFilter.cpp
  19. 6
      libwhisper/BloomFilter.h
  20. 2
      libwhisper/Common.cpp
  21. 7
      libwhisper/Common.h
  22. 9
      libwhisper/Message.cpp
  23. 2
      libwhisper/Message.h
  24. 24
      libwhisper/WhisperHost.cpp
  25. 2
      libwhisper/WhisperHost.h
  26. 43
      libwhisper/WhisperPeer.cpp
  27. 4
      libwhisper/WhisperPeer.h
  28. 148
      test/libdevcore/RangeMask.cpp
  29. 64
      test/libethereum/transactionqueue.cpp
  30. 24
      test/libweb3jsonrpc/webthreestubclient.h
  31. 8
      test/libwhisper/bloomFilter.cpp

146
libdevcore/RangeMask.h

@ -24,6 +24,7 @@
#include <map>
#include <utility>
#include <vector>
#include <iterator>
#include <iostream>
#include <assert.h>
@ -35,6 +36,12 @@ class RLPStream;
using UnsignedRange = std::pair<unsigned, unsigned>;
using UnsignedRanges = std::vector<UnsignedRange>;
/**
* Set of elements of a certain "ground range" representable by unions of ranges inside this
* ground range.
* Ranges are given as pairs (begin, end), denoting the interval [begin, end), i.e. end is excluded.
* Supports set-theoretic operators, size and iteration.
*/
template <class T>
class RangeMask
{
@ -44,14 +51,19 @@ public:
using Range = std::pair<T, T>;
using Ranges = std::vector<Range>;
/// Constructs an empty range mask with empty ground range.
RangeMask(): m_all(0, 0) {}
/// Constructs an empty range mask with ground range [_begin, _end).
RangeMask(T _begin, T _end): m_all(_begin, _end) {}
/// Constructs an empty range mask with ground range _c.
RangeMask(Range const& _c): m_all(_c) {}
/// @returns the union with the range mask _m, taking also the union of the ground ranges.
RangeMask unionedWith(RangeMask const& _m) const { return operator+(_m); }
RangeMask operator+(RangeMask const& _m) const { return RangeMask(*this) += _m; }
RangeMask lowest(T _items) const
/// @returns a new range mask containing the smallest _items elements (not ranges).
RangeMask lowest(decltype(T{} - T{}) _items) const
{
RangeMask ret(m_all);
for (auto i = m_ranges.begin(); i != m_ranges.end() && _items; ++i)
@ -59,8 +71,10 @@ public:
return ret;
}
/// @returns the complement of the range mask relative to the ground range.
RangeMask operator~() const { return inverted(); }
/// @returns a copy of this range mask representing the complement relative to the ground range.
RangeMask inverted() const
{
RangeMask ret(m_all);
@ -76,6 +90,8 @@ public:
return ret;
}
/// Changes the range mask to its complement relative to the ground range and returns a
/// reference to itself.
RangeMask& invert() { return *this = inverted(); }
template <class S> RangeMask operator-(S const& _m) const { auto ret = *this; return ret -= _m; }
@ -92,61 +108,13 @@ public:
return *this;
}
RangeMask& operator+=(Range const& _m) { return unionWith(_m); }
RangeMask& unionWith(Range const& _m)
{
for (auto i = _m.first; i < _m.second;)
{
assert(i >= m_all.first);
assert(i < m_all.second);
// for each number, we find the element equal or next lower. this, if any, must contain the value.
auto uit = m_ranges.upper_bound(i);
auto it = uit == m_ranges.begin() ? m_ranges.end() : std::prev(uit);
if (it == m_ranges.end() || it->second < i)
// lower range is too low to merge.
// if the next higher range is too high.
if (uit == m_ranges.end() || uit->first > _m.second)
{
// just create a new range
m_ranges[i] = _m.second;
break;
}
else
{
if (uit->first == i)
// move i to end of range
i = uit->second;
else
{
// merge with the next higher range
// move i to end of range
i = m_ranges[i] = uit->second;
i = uit->second;
m_ranges.erase(uit);
}
}
else if (it->second == i)
{
// if the next higher range is too high.
if (uit == m_ranges.end() || uit->first > _m.second)
{
// merge with the next lower range
m_ranges[it->first] = _m.second;
break;
}
else
{
// merge with both next lower & next higher.
i = m_ranges[it->first] = uit->second;
m_ranges.erase(uit);
}
}
else
i = it->second;
}
return *this;
}
/// Modifies this range mask to also include the range _m, which has to be a subset of
/// the ground range.
RangeMask& unionWith(Range const& _m);
/// Adds the single element _i to the range mask.
RangeMask& operator+=(T _m) { return unionWith(_m); }
/// Adds the single element _i to the range mask.
RangeMask& unionWith(T _i)
{
return operator+=(Range(_i, _i + 1));
@ -181,10 +149,12 @@ public:
m_all = std::make_pair(0, 0);
}
/// @returns the ground range.
std::pair<T, T> const& all() const { return m_all; }
/// Extends the ground range to include _i.
void extendAll(T _i) { m_all = std::make_pair(std::min(m_all.first, _i), std::max(m_all.second, _i + 1)); }
class const_iterator
class const_iterator: public std::iterator<std::forward_iterator_tag, T>
{
friend class RangeMask;
@ -208,6 +178,8 @@ public:
const_iterator begin() const { return const_iterator(*this, false); }
const_iterator end() const { return const_iterator(*this, true); }
/// @returns the smallest element in the range mask that is larger than _t or the end of the
/// base range if such an element does not exist.
T next(T _t) const
{
_t++;
@ -219,6 +191,7 @@ public:
return uit == m_ranges.end() ? m_all.second : uit->first;
}
/// @returns the number of elements (not ranges) in the range mask.
size_t size() const
{
size_t c = 0;
@ -228,7 +201,9 @@ public:
}
private:
/// The ground range.
UnsignedRange m_all;
/// Mapping begin -> end containing the ranges.
std::map<T, T> m_ranges;
};
@ -241,4 +216,65 @@ template <class T> inline std::ostream& operator<<(std::ostream& _out, RangeMask
return _out;
}
template <class T>
RangeMask<T>& RangeMask<T>::unionWith(typename RangeMask<T>::Range const& _m)
{
for (auto i = _m.first; i < _m.second;)
{
assert(i >= m_all.first);
assert(i < m_all.second);
// For each number, we find the element equal or next lower. this, if any, must contain the value.
// First range that starts after i.
auto rangeAfter = m_ranges.upper_bound(i);
// Range before rangeAfter or "end" if the rangeAfter is the first ever...
auto it = rangeAfter == m_ranges.begin() ? m_ranges.end() : std::prev(rangeAfter);
if (it == m_ranges.end() || it->second < i)
{
// i is either before the first range or between two ranges (with some distance
// so that we cannot merge it onto "it").
// lower range is too low to merge.
// if the next higher range is too high.
if (rangeAfter == m_ranges.end() || rangeAfter->first > _m.second)
{
// just create a new range
m_ranges[i] = _m.second;
break;
}
else
{
if (rangeAfter->first == i)
// move i to end of range
i = rangeAfter->second;
else
{
// merge with the next higher range
// move i to end of range
i = m_ranges[i] = rangeAfter->second;
m_ranges.erase(rangeAfter);
}
}
}
else if (it->second == i)
{
// The range before i ends with i.
// if the next higher range is too high.
if (rangeAfter == m_ranges.end() || rangeAfter->first > _m.second)
{
// merge with the next lower range
m_ranges[it->first] = _m.second;
break;
}
else
{
// merge with both next lower & next higher.
i = m_ranges[it->first] = rangeAfter->second;
m_ranges.erase(rangeAfter);
}
}
else
i = it->second;
}
return *this;
}
}

3
libethereum/BlockChain.h

@ -178,6 +178,9 @@ public:
std::vector<unsigned> withBlockBloom(LogBloom const& _b, unsigned _earliest, unsigned _latest) const;
std::vector<unsigned> withBlockBloom(LogBloom const& _b, unsigned _earliest, unsigned _latest, unsigned _topLevel, unsigned _index) const;
/// Returns true if transaction is known. Thread-safe
bool isKnownTransaction(h256 const& _transactionHash) const { TransactionAddress ta = queryExtras<TransactionAddress, ExtraTransactionAddress>(_transactionHash, m_transactionAddresses, x_transactionAddresses, NullTransactionAddress); return !!ta; }
/// Get a transaction from its hash. Thread-safe.
bytes transaction(h256 const& _transactionHash) const { TransactionAddress ta = queryExtras<TransactionAddress, ExtraTransactionAddress>(_transactionHash, m_transactionAddresses, x_transactionAddresses, NullTransactionAddress); if (!ta) return bytes(); return transaction(ta.blockHash, ta.index); }
std::pair<h256, unsigned> transactionLocation(h256 const& _transactionHash) const { TransactionAddress ta = queryExtras<TransactionAddress, ExtraTransactionAddress>(_transactionHash, m_transactionAddresses, x_transactionAddresses, NullTransactionAddress); if (!ta) return std::pair<h256, unsigned>(h256(), 0); return std::make_pair(ta.blockHash, ta.index); }

8
libethereum/BlockChainSync.cpp

@ -791,10 +791,6 @@ bool PV60Sync::invariants() const
return false;
if (m_state == SyncState::Hashes)
{
bool hashes = false;
host().foreachPeer([&](std::shared_ptr<EthereumPeer> _p) { if (_p->m_asking == Asking::Hashes) hashes = true; return !hashes; });
if (!hashes)
return false;
if (!m_syncingLatestHash)
return false;
if (m_syncingNeededBlocks.empty() != (!m_syncingLastReceivedHash))
@ -802,10 +798,6 @@ bool PV60Sync::invariants() const
}
if (m_state == SyncState::Blocks || m_state == SyncState::NewBlocks)
{
bool blocks = false;
host().foreachPeer([&](std::shared_ptr<EthereumPeer> _p) { if (_p->m_asking == Asking::Blocks) blocks = true; return !blocks; });
if (!blocks)
return false;
if (downloadMan().isComplete())
return false;
}

1
libethereum/BlockChainSync.h

@ -24,7 +24,6 @@
#include <mutex>
#include <libdevcore/Guards.h>
#include <libdevcore/RangeMask.h>
#include <libethcore/Common.h>
#include <libp2p/Common.h>
#include "CommonNet.h"

2
libethereum/BlockQueue.cpp

@ -184,7 +184,7 @@ void BlockQueue::drainVerified_WITH_BOTH_LOCKS()
ImportResult BlockQueue::import(bytesConstRef _block, BlockChain const& _bc, bool _isOurs)
{
cdebug << std::this_thread::get_id();
clog(BlockQueueTraceChannel) << std::this_thread::get_id();
// Check if we already know this block.
h256 h = BlockInfo::headerHash(_block);

21
libethereum/ClientBase.cpp

@ -480,3 +480,24 @@ int ClientBase::compareBlockHashes(h256 _h1, h256 _h2) const
}
return -1;
}
bool ClientBase::isKnown(h256 const& _hash) const
{
return _hash == PendingBlockHash ||
_hash == LatestBlockHash ||
_hash == EarliestBlockHash ||
bc().isKnown(_hash);
}
bool ClientBase::isKnown(BlockNumber _block) const
{
return _block == PendingBlock ||
_block == LatestBlock ||
bc().numberHash(_block) != h256();
}
bool ClientBase::isKnownTransaction(h256 const& _transactionHash) const
{
return bc().isKnownTransaction(_transactionHash);
}

4
libethereum/ClientBase.h

@ -149,6 +149,10 @@ public:
/// Get the coinbase address
virtual Address address() const override;
virtual bool isKnown(h256 const& _hash) const override;
virtual bool isKnown(BlockNumber _block) const override;
virtual bool isKnownTransaction(h256 const& _transactionHash) const override;
/// TODO: consider moving it to a separate interface
virtual void startMining() override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("ClientBase::startMining")); }

1
libethereum/EthereumHost.h

@ -31,7 +31,6 @@
#include <libdevcore/Guards.h>
#include <libdevcore/Worker.h>
#include <libdevcore/RangeMask.h>
#include <libethcore/Common.h>
#include <libp2p/Common.h>
#include "CommonNet.h"

1
libethereum/EthereumPeer.h

@ -31,7 +31,6 @@
#include <libdevcore/RLP.h>
#include <libdevcore/Guards.h>
#include <libdevcore/RangeMask.h>
#include <libethcore/Common.h>
#include <libp2p/Capability.h>
#include "CommonNet.h"

5
libethereum/Interface.h

@ -133,12 +133,15 @@ public:
// [BLOCK QUERY API]
virtual bool isKnownTransaction(h256 const& _transactionHash) const = 0;
virtual Transaction transaction(h256 _transactionHash) const = 0;
virtual std::pair<h256, unsigned> transactionLocation(h256 const& _transactionHash) const = 0;
virtual h256 hashFromNumber(BlockNumber _number) const = 0;
virtual BlockNumber numberFromHash(h256 _blockHash) const = 0;
virtual int compareBlockHashes(h256 _h1, h256 _h2) const = 0;
virtual bool isKnown(BlockNumber _block) const = 0;
virtual bool isKnown(h256 const& _hash) const = 0;
virtual BlockInfo blockInfo(h256 _hash) const = 0;
virtual BlockDetails blockDetails(h256 _hash) const = 0;
virtual Transaction transaction(h256 _blockHash, unsigned _i) const = 0;
@ -151,7 +154,7 @@ public:
BlockInfo blockInfo(BlockNumber _block) const { return blockInfo(hashFromNumber(_block)); }
BlockDetails blockDetails(BlockNumber _block) const { return blockDetails(hashFromNumber(_block)); }
Transaction transaction(BlockNumber _block, unsigned _i) const { if (_block == PendingBlock) { auto p = pending(); return _i < p.size() ? p[_i] : Transaction(); } return transaction(hashFromNumber(_block)); }
Transaction transaction(BlockNumber _block, unsigned _i) const { auto p = transactions(_block); return _i < p.size() ? p[_i] : Transaction(); }
unsigned transactionCount(BlockNumber _block) const { if (_block == PendingBlock) { auto p = pending(); return p.size(); } return transactionCount(hashFromNumber(_block)); }
Transactions transactions(BlockNumber _block) const { if (_block == PendingBlock) return pending(); return transactions(hashFromNumber(_block)); }
TransactionHashes transactionHashes(BlockNumber _block) const { if (_block == PendingBlock) return pendingHashes(); return transactionHashes(hashFromNumber(_block)); }

1
libp2p/Host.h

@ -33,7 +33,6 @@
#include <libdevcore/Guards.h>
#include <libdevcore/Worker.h>
#include <libdevcore/RangeMask.h>
#include <libdevcrypto/Common.h>
#include <libdevcrypto/ECDHE.h>
#include "NodeTable.h"

2
libp2p/Session.cpp

@ -382,7 +382,7 @@ void Session::doRead()
}
catch (std::exception const& _e)
{
clog(NetWarn) << "Exception decoding frame header RLP:" << bytesConstRef(m_data.data(), h128::size).cropped(3);
clog(NetWarn) << "Exception decoding frame header RLP:" << _e.what() << bytesConstRef(m_data.data(), h128::size).cropped(3);
drop(BadProtocol);
return;
}

1
libp2p/Session.h

@ -31,7 +31,6 @@
#include <libdevcore/Common.h>
#include <libdevcore/RLP.h>
#include <libdevcore/RangeMask.h>
#include <libdevcore/Guards.h>
#include "RLPXFrameCoder.h"
#include "RLPXSocket.h"

45
libweb3jsonrpc/WebThreeStubServerBase.cpp

@ -142,7 +142,7 @@ string WebThreeStubServerBase::eth_getStorageAt(string const& _address, string c
{
try
{
return toJS(client()->stateAt(jsToAddress(_address), jsToU256(_position), jsToBlockNumber(_blockNumber)));
return toJS(toCompactBigEndian(client()->stateAt(jsToAddress(_address), jsToU256(_position), jsToBlockNumber(_blockNumber)), 1));
}
catch (...)
{
@ -162,11 +162,15 @@ string WebThreeStubServerBase::eth_getTransactionCount(string const& _address, s
}
}
string WebThreeStubServerBase::eth_getBlockTransactionCountByHash(string const& _blockHash)
Json::Value WebThreeStubServerBase::eth_getBlockTransactionCountByHash(string const& _blockHash)
{
try
{
return toJS(client()->transactionCount(jsToFixed<32>(_blockHash)));
h256 blockHash = jsToFixed<32>(_blockHash);
if (!client()->isKnown(blockHash))
return Json::Value(Json::nullValue);
return toJS(client()->transactionCount(blockHash));
}
catch (...)
{
@ -174,10 +178,14 @@ string WebThreeStubServerBase::eth_getBlockTransactionCountByHash(string const&
}
}
string WebThreeStubServerBase::eth_getBlockTransactionCountByNumber(string const& _blockNumber)
Json::Value WebThreeStubServerBase::eth_getBlockTransactionCountByNumber(string const& _blockNumber)
{
try
{
BlockNumber blockNumber = jsToBlockNumber(_blockNumber);
if (!client()->isKnown(blockNumber))
return Json::Value(Json::nullValue);
return toJS(client()->transactionCount(jsToBlockNumber(_blockNumber)));
}
catch (...)
@ -186,11 +194,15 @@ string WebThreeStubServerBase::eth_getBlockTransactionCountByNumber(string const
}
}
string WebThreeStubServerBase::eth_getUncleCountByBlockHash(string const& _blockHash)
Json::Value WebThreeStubServerBase::eth_getUncleCountByBlockHash(string const& _blockHash)
{
try
{
return toJS(client()->uncleCount(jsToFixed<32>(_blockHash)));
h256 blockHash = jsToFixed<32>(_blockHash);
if (!client()->isKnown(blockHash))
return Json::Value(Json::nullValue);
return toJS(client()->uncleCount(blockHash));
}
catch (...)
{
@ -198,11 +210,15 @@ string WebThreeStubServerBase::eth_getUncleCountByBlockHash(string const& _block
}
}
string WebThreeStubServerBase::eth_getUncleCountByBlockNumber(string const& _blockNumber)
Json::Value WebThreeStubServerBase::eth_getUncleCountByBlockNumber(string const& _blockNumber)
{
try
{
return toJS(client()->uncleCount(jsToBlockNumber(_blockNumber)));
BlockNumber blockNumber = jsToBlockNumber(_blockNumber);
if (!client()->isKnown(blockNumber))
return Json::Value(Json::nullValue);
return toJS(client()->uncleCount(blockNumber));
}
catch (...)
{
@ -330,7 +346,10 @@ Json::Value WebThreeStubServerBase::eth_getBlockByHash(string const& _blockHash,
{
try
{
auto h = jsToFixed<32>(_blockHash);
h256 h = jsToFixed<32>(_blockHash);
if (!client()->isKnown(h))
return Json::Value(Json::nullValue);
if (_includeTransactions)
return toJson(client()->blockInfo(h), client()->blockDetails(h), client()->uncleHashes(h), client()->transactions(h));
else
@ -346,7 +365,10 @@ Json::Value WebThreeStubServerBase::eth_getBlockByNumber(string const& _blockNum
{
try
{
auto h = jsToBlockNumber(_blockNumber);
BlockNumber h = jsToBlockNumber(_blockNumber);
if (!client()->isKnown(h))
return Json::Value(Json::nullValue);
if (_includeTransactions)
return toJson(client()->blockInfo(h), client()->blockDetails(h), client()->uncleHashes(h), client()->transactions(h));
else
@ -363,6 +385,9 @@ Json::Value WebThreeStubServerBase::eth_getTransactionByHash(string const& _tran
try
{
h256 h = jsToFixed<32>(_transactionHash);
if (!client()->isKnownTransaction(h))
return Json::Value(Json::nullValue);
auto l = client()->transactionLocation(h);
return toJson(client()->transaction(h), l, client()->numberFromHash(l.first));
}

8
libweb3jsonrpc/WebThreeStubServerBase.h

@ -106,10 +106,10 @@ public:
virtual std::string eth_getBalance(std::string const& _address, std::string const& _blockNumber);
virtual std::string eth_getStorageAt(std::string const& _address, std::string const& _position, std::string const& _blockNumber);
virtual std::string eth_getTransactionCount(std::string const& _address, std::string const& _blockNumber);
virtual std::string eth_getBlockTransactionCountByHash(std::string const& _blockHash);
virtual std::string eth_getBlockTransactionCountByNumber(std::string const& _blockNumber);
virtual std::string eth_getUncleCountByBlockHash(std::string const& _blockHash);
virtual std::string eth_getUncleCountByBlockNumber(std::string const& _blockNumber);
virtual Json::Value eth_getBlockTransactionCountByHash(std::string const& _blockHash);
virtual Json::Value eth_getBlockTransactionCountByNumber(std::string const& _blockNumber);
virtual Json::Value eth_getUncleCountByBlockHash(std::string const& _blockHash);
virtual Json::Value eth_getUncleCountByBlockNumber(std::string const& _blockNumber);
virtual std::string eth_getCode(std::string const& _address, std::string const& _blockNumber);
virtual std::string eth_sendTransaction(Json::Value const& _json);
virtual std::string eth_call(Json::Value const& _json, std::string const& _blockNumber);

16
libweb3jsonrpc/abstractwebthreestubserver.h

@ -27,10 +27,10 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
this->bindAndAddMethod(jsonrpc::Procedure("eth_getBalance", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getBalanceI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_getStorageAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING,"param3",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getStorageAtI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_getTransactionCount", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getTransactionCountI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_getBlockTransactionCountByHash", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getBlockTransactionCountByHashI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_getBlockTransactionCountByNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getBlockTransactionCountByNumberI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_getUncleCountByBlockHash", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getUncleCountByBlockHashI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_getUncleCountByBlockNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getUncleCountByBlockNumberI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_getBlockTransactionCountByHash", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getBlockTransactionCountByHashI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_getBlockTransactionCountByNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getBlockTransactionCountByNumberI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_getUncleCountByBlockHash", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getUncleCountByBlockHashI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_getUncleCountByBlockNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getUncleCountByBlockNumberI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_getCode", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getCodeI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_sendTransaction", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::eth_sendTransactionI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_call", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_OBJECT,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_callI);
@ -476,10 +476,10 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
virtual std::string eth_getBalance(const std::string& param1, const std::string& param2) = 0;
virtual std::string eth_getStorageAt(const std::string& param1, const std::string& param2, const std::string& param3) = 0;
virtual std::string eth_getTransactionCount(const std::string& param1, const std::string& param2) = 0;
virtual std::string eth_getBlockTransactionCountByHash(const std::string& param1) = 0;
virtual std::string eth_getBlockTransactionCountByNumber(const std::string& param1) = 0;
virtual std::string eth_getUncleCountByBlockHash(const std::string& param1) = 0;
virtual std::string eth_getUncleCountByBlockNumber(const std::string& param1) = 0;
virtual Json::Value eth_getBlockTransactionCountByHash(const std::string& param1) = 0;
virtual Json::Value eth_getBlockTransactionCountByNumber(const std::string& param1) = 0;
virtual Json::Value eth_getUncleCountByBlockHash(const std::string& param1) = 0;
virtual Json::Value eth_getUncleCountByBlockNumber(const std::string& param1) = 0;
virtual std::string eth_getCode(const std::string& param1, const std::string& param2) = 0;
virtual std::string eth_sendTransaction(const Json::Value& param1) = 0;
virtual std::string eth_call(const Json::Value& param1, const std::string& param2) = 0;

8
libweb3jsonrpc/spec.json

@ -16,10 +16,10 @@
{ "name": "eth_getBalance", "params": ["", ""], "order": [], "returns" : ""},
{ "name": "eth_getStorageAt", "params": ["", "", ""], "order": [], "returns": ""},
{ "name": "eth_getTransactionCount", "params": ["", ""], "order": [], "returns" : ""},
{ "name": "eth_getBlockTransactionCountByHash", "params": [""], "order": [], "returns" : ""},
{ "name": "eth_getBlockTransactionCountByNumber", "params": [""], "order": [], "returns" : ""},
{ "name": "eth_getUncleCountByBlockHash", "params": [""], "order": [], "returns" : ""},
{ "name": "eth_getUncleCountByBlockNumber", "params": [""], "order": [], "returns" : ""},
{ "name": "eth_getBlockTransactionCountByHash", "params": [""], "order": [], "returns" : {}},
{ "name": "eth_getBlockTransactionCountByNumber", "params": [""], "order": [], "returns" : {}},
{ "name": "eth_getUncleCountByBlockHash", "params": [""], "order": [], "returns" : {}},
{ "name": "eth_getUncleCountByBlockNumber", "params": [""], "order": [], "returns" : {}},
{ "name": "eth_getCode", "params": ["", ""], "order": [], "returns": ""},
{ "name": "eth_sendTransaction", "params": [{}], "order": [], "returns": ""},
{ "name": "eth_call", "params": [{}, ""], "order": [], "returns": ""},

28
libwhisper/BloomFilter.cpp

@ -1,28 +0,0 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file BloomFilter.cpp
* @author Vladislav Gluhovsky <vlad@ethdev.com>
* @date June 2015
*/
#include "BloomFilter.h"
using namespace std;
using namespace dev;
using namespace dev::shh;

6
libwhisper/BloomFilter.h

@ -42,14 +42,12 @@ public:
void addRaw(FixedHash<N> const& _h);
void removeRaw(FixedHash<N> const& _h);
bool containsRaw(FixedHash<N> const& _h) const { return this->contains(_h); }
enum { BitsPerBloom = 3 };
private:
void init() { for (unsigned i = 0; i < CounterSize; ++i) m_refCounter[i] = 0; }
static bool isBitSet(FixedHash<N> const& _h, unsigned _index);
enum { CounterSize = 8 * TopicBloomFilterBase::size };
static const unsigned CounterSize = N * 8;
std::array<uint16_t, CounterSize> m_refCounter;
};
@ -91,7 +89,7 @@ bool TopicBloomFilterBase<N>::isBitSet(FixedHash<N> const& _h, unsigned _index)
return (_h[iByte] & c_powerOfTwoBitMmask[iBit]) != 0;
}
using TopicBloomFilter = TopicBloomFilterBase<c_topicBloomFilterSize>;
using TopicBloomFilter = TopicBloomFilterBase<TopicBloomFilterSize>;
}
}

2
libwhisper/Common.cpp

@ -100,7 +100,7 @@ TopicBloomFilterHash TopicFilter::exportBloom() const
TopicBloomFilterHash ret;
for (TopicMask const& t: m_topicMasks)
for (auto const& i: t)
ret |= i.first.template bloomPart<TopicBloomFilter::BitsPerBloom, c_topicBloomFilterSize>();
ret |= i.first.template bloomPart<BitsPerBloom, TopicBloomFilterSize>();
return ret;
}

7
libwhisper/Common.h

@ -58,8 +58,9 @@ enum WhisperPacket
PacketCount
};
static const int c_topicBloomFilterSize = 64;
static const int c_whisperProtocolVersion = 3;
static const unsigned TopicBloomFilterSize = 64;
static const unsigned BitsPerBloom = 3;
static const unsigned WhisperProtocolVersion = 3;
using AbridgedTopic = FixedHash<4>;
using Topic = h256;
@ -67,7 +68,7 @@ using Topic = h256;
using AbridgedTopics = std::vector<AbridgedTopic>;
using Topics = h256s;
using TopicBloomFilterHash = FixedHash<c_topicBloomFilterSize>;
using TopicBloomFilterHash = FixedHash<TopicBloomFilterSize>;
AbridgedTopic abridge(Topic const& _topic);
AbridgedTopics abridge(Topics const& _topics);

9
libwhisper/Message.cpp

@ -181,3 +181,12 @@ void Envelope::proveWork(unsigned _ms)
}
}
}
bool Envelope::matchesBloomFilter(TopicBloomFilterHash const& f) const
{
for (AbridgedTopic t: m_topic)
if (f.contains(t.template bloomPart<BitsPerBloom, TopicBloomFilterSize>()))
return true;
return false;
}

2
libwhisper/Message.h

@ -80,6 +80,8 @@ public:
unsigned workProved() const;
void proveWork(unsigned _ms);
bool matchesBloomFilter(TopicBloomFilterHash const& f) const;
private:
Envelope(unsigned _exp, unsigned _ttl, AbridgedTopics const& _topic): m_expiry(_exp), m_ttl(_ttl), m_topic(_topic) {}

24
libwhisper/WhisperHost.cpp

@ -51,6 +51,8 @@ void WhisperHost::streamMessage(h256 _m, RLPStream& _s) const
void WhisperHost::inject(Envelope const& _m, WhisperPeer* _p)
{
// this function processes messages originated both by local host (_p == null), and by remote peers (_p != null)
cnote << this << ": inject: " << _m.expiry() << _m.ttl() << _m.topic() << toHex(_m.data());
if (_m.expiry() <= (unsigned)time(0))
@ -66,21 +68,25 @@ void WhisperHost::inject(Envelope const& _m, WhisperPeer* _p)
m_expiryQueue.insert(make_pair(_m.expiry(), h));
}
DEV_GUARDED(m_filterLock)
{
for (auto const& f: m_filters)
if (f.second.filter.matches(_m))
for (auto& i: m_watches)
if (i.second.id == f.first)
i.second.changes.push_back(h);
}
int rating = 1; // rating for local host is based upon: 1. installed watch; 2. proof of work
if (_p) // incoming message from remote peer
DEV_GUARDED(m_filterLock)
for (auto const& f: m_filters)
if (f.second.filter.matches(_m))
for (auto& i: m_watches)
if (i.second.id == f.first)
{
i.second.changes.push_back(h);
rating += 10; // subject to review
}
// TODO p2p: capability-based rating
for (auto i: peerSessions())
{
auto w = i.first->cap<WhisperPeer>().get();
if (w == _p)
w->addRating(1);
w->addRating(rating);
else
w->noteNewMessage(h, _m);
}

2
libwhisper/WhisperHost.h

@ -50,7 +50,7 @@ class WhisperHost: public HostCapability<WhisperPeer>, public Interface, public
public:
WhisperHost();
virtual ~WhisperHost();
unsigned protocolVersion() const { return c_whisperProtocolVersion; }
unsigned protocolVersion() const { return WhisperProtocolVersion; }
/// remove old messages
void cleanup();
std::map<h256, Envelope> all() const { dev::ReadGuard l(x_messages); return m_messages; }

43
libwhisper/WhisperPeer.cpp

@ -91,19 +91,17 @@ void WhisperPeer::sendMessages()
if (m_advertiseTopicsOfInterest)
sendTopicsOfInterest(host()->bloom());
multimap<unsigned, h256> available;
DEV_GUARDED(x_unseen)
m_unseen.swap(available);
RLPStream amalg;
unsigned msgCount = 0;
{
Guard l(x_unseen);
msgCount = m_unseen.size();
while (m_unseen.size())
{
auto p = *m_unseen.begin();
m_unseen.erase(m_unseen.begin());
host()->streamMessage(p.second, amalg);
}
}
// send the highest rated messages first
for (auto i = available.rbegin(); i != available.rend(); ++i)
host()->streamMessage(i->second, amalg);
unsigned msgCount = available.size();
if (msgCount)
{
RLPStream s;
@ -114,8 +112,27 @@ void WhisperPeer::sendMessages()
void WhisperPeer::noteNewMessage(h256 _h, Envelope const& _m)
{
unsigned rate = ratingForPeer(_m);
Guard l(x_unseen);
m_unseen.insert(make_pair(rating(_m), _h));
m_unseen.insert(make_pair(rate, _h));
}
unsigned WhisperPeer::ratingForPeer(Envelope const& e) const
{
// we try to estimate, how valuable this nessage will be for the remote peer,
// according to the following criteria:
// 1. bloom filter
// 2. proof of work
static const unsigned BloomFilterMatchReward = 256; // vlad todo: move to common.h
unsigned rating = 0;
DEV_GUARDED(x_bloom)
if (e.matchesBloomFilter(m_bloom))
rating += BloomFilterMatchReward;
rating += e.sha3().firstBitSet();
return rating;
}
void WhisperPeer::sendTopicsOfInterest(TopicBloomFilterHash const& _bloom)

4
libwhisper/WhisperPeer.h

@ -53,7 +53,7 @@ public:
virtual ~WhisperPeer();
WhisperHost* host() const;
static std::string name() { return "shh"; }
static u256 version() { return c_whisperProtocolVersion; }
static u256 version() { return WhisperProtocolVersion; }
static unsigned messageCount() { return PacketCount; }
TopicBloomFilterHash bloom() const { dev::Guard g(x_bloom); return m_bloom; }
void sendTopicsOfInterest(TopicBloomFilterHash const& _bloom); ///< sends our bloom filter to remote peer
@ -62,7 +62,7 @@ public:
private:
virtual bool interpret(unsigned _id, RLP const&) override;
void sendMessages();
unsigned rating(Envelope const&) const { return 0; } // TODO
unsigned ratingForPeer(Envelope const& e) const;
void noteNewMessage(h256 _h, Envelope const& _m);
void setBloom(TopicBloomFilterHash const& _b) { dev::Guard g(x_bloom); m_bloom = _b; }

148
test/libdevcore/RangeMask.cpp

@ -0,0 +1,148 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file RangeMask.cpp
* @author Christian <c@ethdev.com>
* @date 2015
*/
#include <libdevcore/RangeMask.h>
#include "../TestHelper.h"
using namespace std;
using namespace dev;
namespace dev
{
namespace test
{
BOOST_AUTO_TEST_SUITE(RangeMaskTest)
BOOST_AUTO_TEST_CASE(constructor)
{
using RM = RangeMask<unsigned>;
using Range = pair<unsigned, unsigned>;
for (RM r: {RM(), RM(1, 10), RM(Range(2, 10))})
{
BOOST_CHECK(r.empty());
BOOST_CHECK(!r.contains(0));
BOOST_CHECK(!r.contains(1));
BOOST_CHECK_EQUAL(0, r.size());
}
BOOST_CHECK(RM().full());
BOOST_CHECK(!RM(1, 10).full());
BOOST_CHECK(!RM(Range(2, 10)).full());
}
BOOST_AUTO_TEST_CASE(simple_unions)
{
using RM = RangeMask<unsigned>;
using Range = pair<unsigned, unsigned>;
RM m(Range(0, 2000));
m.unionWith(Range(1, 2));
BOOST_CHECK_EQUAL(m.size(), 1);
m.unionWith(Range(50, 250));
BOOST_CHECK_EQUAL(m.size(), 201);
m.unionWith(Range(10, 16));
BOOST_CHECK_EQUAL(m.size(), 207);
BOOST_CHECK(m.contains(1));
BOOST_CHECK(m.contains(11));
BOOST_CHECK(m.contains(51));
BOOST_CHECK(m.contains(200));
BOOST_CHECK(!m.contains(2));
BOOST_CHECK(!m.contains(7));
BOOST_CHECK(!m.contains(17));
BOOST_CHECK(!m.contains(258));
}
BOOST_AUTO_TEST_CASE(empty_union)
{
using RM = RangeMask<unsigned>;
using Range = pair<unsigned, unsigned>;
RM m(Range(0, 2000));
m.unionWith(Range(3, 6));
BOOST_CHECK_EQUAL(m.size(), 3);
m.unionWith(Range(50, 50));
BOOST_CHECK_EQUAL(m.size(), 3);
m.unionWith(Range(0, 0));
BOOST_CHECK_EQUAL(m.size(), 3);
m.unionWith(Range(1, 1));
BOOST_CHECK_EQUAL(m.size(), 3);
m.unionWith(Range(2, 2));
BOOST_CHECK_EQUAL(m.size(), 3);
m.unionWith(Range(3, 3));
BOOST_CHECK_EQUAL(m.size(), 3);
}
BOOST_AUTO_TEST_CASE(overlapping_unions)
{
using RM = RangeMask<unsigned>;
using Range = pair<unsigned, unsigned>;
RM m(Range(0, 2000));
m.unionWith(Range(10, 20));
BOOST_CHECK_EQUAL(10, m.size());
m.unionWith(Range(30, 40));
BOOST_CHECK_EQUAL(20, m.size());
m.unionWith(Range(15, 30));
BOOST_CHECK_EQUAL(40 - 10, m.size());
m.unionWith(Range(50, 60));
m.unionWith(Range(45, 55));
// [40, 45) still missing here
BOOST_CHECK_EQUAL(60 - 10 - 5, m.size());
m.unionWith(Range(15, 56));
BOOST_CHECK_EQUAL(60 - 10, m.size());
m.unionWith(Range(15, 65));
BOOST_CHECK_EQUAL(65 - 10, m.size());
m.unionWith(Range(5, 70));
BOOST_CHECK_EQUAL(70 - 5, m.size());
}
BOOST_AUTO_TEST_CASE(complement)
{
using RM = RangeMask<unsigned>;
using Range = pair<unsigned, unsigned>;
RM m(Range(0, 2000));
m.unionWith(7).unionWith(9);
m = ~m;
m.unionWith(7).unionWith(9);
m = ~m;
BOOST_CHECK(m.empty());
m += Range(0, 10);
m += Range(1000, 2000);
m.invert();
BOOST_CHECK_EQUAL(m.size(), 1000 - 10);
}
BOOST_AUTO_TEST_CASE(iterator)
{
using RM = RangeMask<unsigned>;
using Range = pair<unsigned, unsigned>;
RM m(Range(0, 2000));
m.unionWith(Range(7, 9));
m.unionWith(11);
m.unionWith(Range(200, 205));
vector<unsigned> elements;
copy(m.begin(), m.end(), back_inserter(elements));
BOOST_CHECK(elements == (vector<unsigned>{7, 8, 11, 200, 201, 202, 203, 204}));
}
BOOST_AUTO_TEST_SUITE_END()
}
}

64
test/libethereum/transactionqueue.cpp

@ -0,0 +1,64 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file transactionqueue.cpp
* @author Christoph Jentzsch <cj@ethdev.com>
* @date 2015
* TransactionQueue test functions.
*/
#include <libethereum/TransactionQueue.h>
#include "../TestHelper.h"
using namespace std;
using namespace dev;
using namespace dev::eth;
BOOST_AUTO_TEST_SUITE(TransactionQueue)
BOOST_AUTO_TEST_CASE(maxNonce)
{
dev::eth::TransactionQueue txq;
// from a94f5374fce5edbc8e2a8697c15331677e6ebf0b
const u256 gasCost = 10 * szabo;
const u256 gas = 25000;
Address dest = Address("0x095e7baea6a6c7c4c2dfeb977efac326af552d87");
Address to = Address("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b");
Secret sec = Secret("0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8");
Transaction tx0(0, gasCost, gas, dest, bytes(), 0, sec );
Transaction tx0_1(1, gasCost, gas, dest, bytes(), 0, sec );
Transaction tx1(0, gasCost, gas, dest, bytes(), 1, sec );
Transaction tx2(0, gasCost, gas, dest, bytes(), 2, sec );
Transaction tx9(0, gasCost, gas, dest, bytes(), 9, sec );
txq.import(tx0);
BOOST_CHECK(1 == txq.maxNonce(to));
txq.import(tx0);
BOOST_CHECK(1 == txq.maxNonce(to));
txq.import(tx0_1);
BOOST_CHECK(1 == txq.maxNonce(to));
txq.import(tx1);
BOOST_CHECK(2 == txq.maxNonce(to));
txq.import(tx9);
BOOST_CHECK(10 == txq.maxNonce(to));
txq.import(tx2);
BOOST_CHECK(10 == txq.maxNonce(to));
}
BOOST_AUTO_TEST_SUITE_END()

24
test/libweb3jsonrpc/webthreestubclient.h

@ -166,43 +166,43 @@ class WebThreeStubClient : public jsonrpc::Client
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string eth_getBlockTransactionCountByHash(const std::string& param1) throw (jsonrpc::JsonRpcException)
Json::Value eth_getBlockTransactionCountByHash(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->CallMethod("eth_getBlockTransactionCountByHash",p);
if (result.isString())
return result.asString();
if (result.isObject())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string eth_getBlockTransactionCountByNumber(const std::string& param1) throw (jsonrpc::JsonRpcException)
Json::Value eth_getBlockTransactionCountByNumber(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->CallMethod("eth_getBlockTransactionCountByNumber",p);
if (result.isString())
return result.asString();
if (result.isObject())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string eth_getUncleCountByBlockHash(const std::string& param1) throw (jsonrpc::JsonRpcException)
Json::Value eth_getUncleCountByBlockHash(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->CallMethod("eth_getUncleCountByBlockHash",p);
if (result.isString())
return result.asString();
if (result.isObject())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string eth_getUncleCountByBlockNumber(const std::string& param1) throw (jsonrpc::JsonRpcException)
Json::Value eth_getUncleCountByBlockNumber(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->CallMethod("eth_getUncleCountByBlockNumber",p);
if (result.isString())
return result.asString();
if (result.isObject())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}

8
test/libwhisper/bloomFilter.cpp

@ -28,7 +28,7 @@ using namespace dev;
using namespace dev::shh;
using TopicBloomFilterShort = TopicBloomFilterBase<4>;
using TopicBloomFilterTest = TopicBloomFilterBase<c_topicBloomFilterSize>;
using TopicBloomFilterTest = TopicBloomFilterBase<TopicBloomFilterSize>;
void testAddNonExisting(TopicBloomFilterShort& _f, AbridgedTopic const& _h)
{
@ -61,7 +61,7 @@ void testRemoveExistingBloom(TopicBloomFilterShort& _f, AbridgedTopic const& _h)
double calculateExpected(TopicBloomFilterTest const& f, int n)
{
int const m = f.size * 8; // number of bits in the bloom
int const k = f.BitsPerBloom; // number of hash functions (e.g. bits set to 1 in every bloom)
int const k = BitsPerBloom; // number of hash functions (e.g. bits set to 1 in every bloom)
double singleBitSet = 1.0 / m; // probability of any bit being set after inserting a single bit
double singleBitNotSet = (1.0 - singleBitSet);
@ -256,7 +256,7 @@ void updateDistribution(FixedHash<DistributionTestSize> const& _h, array<unsigne
if (_h[i] & c_powerOfTwoBitMmask[j])
{
_distribution[i * 8 + j]++;
if (++bits >= TopicBloomFilterTest::BitsPerBloom)
if (++bits >= BitsPerBloom)
return;
}
}
@ -274,7 +274,7 @@ BOOST_AUTO_TEST_CASE(distributionRate)
for (unsigned i = 0; i < 22000; ++i)
{
x = sha3(x);
FixedHash<DistributionTestSize> h = x.template bloomPart<TopicBloomFilterTest::BitsPerBloom, DistributionTestSize>();
FixedHash<DistributionTestSize> h = x.template bloomPart<BitsPerBloom, DistributionTestSize>();
updateDistribution(h, distribution);
}

Loading…
Cancel
Save