rob the rich to pay the poor
This commit is contained in:
parent
4664f07b22
commit
b2186806e3
12 changed files with 2235 additions and 35 deletions
|
@ -148,6 +148,7 @@ BITCOIN_CORE_H = \
|
|||
policy/fees.h \
|
||||
policy/policy.h \
|
||||
policy/rbf.h \
|
||||
primitives/robin_hood.h \
|
||||
pow.h \
|
||||
protocol.h \
|
||||
random.h \
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
/** Template base class for fixed-sized opaque blobs. */
|
||||
template<uint32_t BITS>
|
||||
CBaseBlob<BITS>::CBaseBlob() : data{}
|
||||
CBaseBlob<BITS>::CBaseBlob() noexcept : data{}
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -21,13 +21,13 @@ CBaseBlob<BITS>::CBaseBlob(const std::vector<uint8_t>& vec)
|
|||
}
|
||||
|
||||
template<uint32_t BITS>
|
||||
CBaseBlob<BITS>::CBaseBlob(const CBaseBlob& o)
|
||||
CBaseBlob<BITS>::CBaseBlob(const CBaseBlob& o) noexcept
|
||||
{
|
||||
*this = o;
|
||||
}
|
||||
|
||||
template<uint32_t BITS>
|
||||
CBaseBlob<BITS>& CBaseBlob<BITS>::operator=(const CBaseBlob& o)
|
||||
CBaseBlob<BITS>& CBaseBlob<BITS>::operator=(const CBaseBlob& o) noexcept
|
||||
{
|
||||
data = o.data;
|
||||
return *this;
|
||||
|
|
|
@ -12,15 +12,15 @@ class CBaseBlob
|
|||
{
|
||||
std::array<uint8_t, BITS / 8> data;
|
||||
public:
|
||||
CBaseBlob();
|
||||
CBaseBlob() noexcept;
|
||||
|
||||
explicit CBaseBlob(const std::vector<uint8_t>& vec);
|
||||
|
||||
CBaseBlob(CBaseBlob&&) = default;
|
||||
CBaseBlob& operator=(CBaseBlob&&) = default;
|
||||
|
||||
CBaseBlob(const CBaseBlob& o);
|
||||
CBaseBlob& operator=(const CBaseBlob& o);
|
||||
CBaseBlob(const CBaseBlob& o) noexcept;
|
||||
CBaseBlob& operator=(const CBaseBlob& o) noexcept;
|
||||
|
||||
int Compare(const CBaseBlob& b) const;
|
||||
bool operator<(const CBaseBlob& b) const;
|
||||
|
|
|
@ -45,18 +45,18 @@ namespace std {
|
|||
template <>
|
||||
struct hash<uint160>
|
||||
{
|
||||
std::size_t operator()(const uint160& k) const
|
||||
size_t operator()(const uint160& k) const
|
||||
{
|
||||
return *reinterpret_cast<const std::size_t*>(k.begin());
|
||||
return *reinterpret_cast<const size_t*>(k.begin());
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<uint256>
|
||||
{
|
||||
std::size_t operator()(const uint256& k) const
|
||||
size_t operator()(const uint256& k) const
|
||||
{
|
||||
return *reinterpret_cast<const std::size_t*>(k.begin());
|
||||
return *reinterpret_cast<const size_t*>(k.begin());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
#include <boost/signals2/signal.hpp>
|
||||
|
||||
#include <unordered_map>
|
||||
#include <primitives/robin_hood.h>
|
||||
#include <set>
|
||||
|
||||
/** A virtual base class for key stores */
|
||||
|
@ -47,9 +47,9 @@ class CBasicKeyStore : public CKeyStore
|
|||
protected:
|
||||
mutable CCriticalSection cs_KeyStore;
|
||||
|
||||
using KeyMap = std::unordered_map<CKeyID, CKey>;
|
||||
using WatchKeyMap = std::unordered_map<CKeyID, CPubKey>;
|
||||
using ScriptMap = std::unordered_map<CScriptID, CScript>;
|
||||
using KeyMap = robin_hood::unordered_map<CKeyID, CKey>;
|
||||
using WatchKeyMap = robin_hood::unordered_map<CKeyID, CPubKey>;
|
||||
using ScriptMap = robin_hood::unordered_map<CScriptID, CScript>;
|
||||
using WatchOnlySet = std::set<CScript>;
|
||||
|
||||
KeyMap mapKeys GUARDED_BY(cs_KeyStore);
|
||||
|
|
2198
src/primitives/robin_hood.h
Normal file
2198
src/primitives/robin_hood.h
Normal file
File diff suppressed because it is too large
Load diff
|
@ -40,9 +40,9 @@ namespace std {
|
|||
template <>
|
||||
struct hash<CKeyID>
|
||||
{
|
||||
std::size_t operator()(const CKeyID& k) const
|
||||
size_t operator()(const CKeyID& k) const
|
||||
{
|
||||
return *reinterpret_cast<const std::size_t*>(k.begin());
|
||||
return *reinterpret_cast<const size_t*>(k.begin());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -31,9 +31,9 @@ namespace std {
|
|||
template <>
|
||||
struct hash<CScriptID>
|
||||
{
|
||||
std::size_t operator()(const CScriptID& k) const
|
||||
size_t operator()(const CScriptID& k) const
|
||||
{
|
||||
return *reinterpret_cast<const std::size_t*>(k.begin());
|
||||
return *reinterpret_cast<const size_t*>(k.begin());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <nameclaim.h>
|
||||
#include <protocol.h> // For CMessageHeader::MessageStartChars
|
||||
#include <policy/feerate.h>
|
||||
#include <primitives/robin_hood.h>
|
||||
#include <script/script_error.h>
|
||||
#include <sync.h>
|
||||
#include <txmempool.h>
|
||||
|
@ -157,15 +158,15 @@ struct BlockMapComparer {
|
|||
}
|
||||
};
|
||||
|
||||
struct BlockMap : public std::unordered_set<CBlockIndex*, BlockMapHasher, BlockMapComparer> {
|
||||
struct BlockMap : public robin_hood::unordered_flat_set<CBlockIndex*, BlockMapHasher, BlockMapComparer> {
|
||||
inline iterator find(const uint256& blockHash) {
|
||||
CBlockIndex temp(blockHash);
|
||||
return std::unordered_set<CBlockIndex*, BlockMapHasher, BlockMapComparer>::find(&temp);
|
||||
return robin_hood::unordered_flat_set<CBlockIndex*, BlockMapHasher, BlockMapComparer>::find(&temp);
|
||||
}
|
||||
|
||||
inline const_iterator find(const uint256& blockHash) const {
|
||||
CBlockIndex temp(blockHash);
|
||||
return std::unordered_set<CBlockIndex*, BlockMapHasher, BlockMapComparer>::find(&temp);
|
||||
return robin_hood::unordered_flat_set<CBlockIndex*, BlockMapHasher, BlockMapComparer>::find(&temp);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1286,7 +1286,7 @@ static UniValue getreceivedbyaddress(const JSONRPCRequest& request)
|
|||
|
||||
// Tally
|
||||
CAmount nAmount = 0;
|
||||
for (const std::pair<const uint256, CWalletTx>& pairWtx : pwallet->mapWallet) {
|
||||
for (const auto& pairWtx : pwallet->mapWallet) {
|
||||
const CWalletTx& wtx = pairWtx.second;
|
||||
if (wtx.IsCoinBase() || !CheckFinalTx(*wtx.tx))
|
||||
continue;
|
||||
|
@ -1354,7 +1354,7 @@ static UniValue getreceivedbylabel(const JSONRPCRequest& request)
|
|||
|
||||
// Tally
|
||||
CAmount nAmount = 0;
|
||||
for (const std::pair<const uint256, CWalletTx>& pairWtx : pwallet->mapWallet) {
|
||||
for (const auto& pairWtx : pwallet->mapWallet) {
|
||||
const CWalletTx& wtx = pairWtx.second;
|
||||
if (wtx.IsCoinBase() || !CheckFinalTx(*wtx.tx))
|
||||
continue;
|
||||
|
@ -2138,7 +2138,7 @@ static UniValue ListReceived(CWallet * const pwallet, const UniValue& params, bo
|
|||
|
||||
// Tally
|
||||
std::map<CTxDestination, tallyitem> mapTally;
|
||||
for (const std::pair<const uint256, CWalletTx>& pairWtx : pwallet->mapWallet) {
|
||||
for (const auto& pairWtx : pwallet->mapWallet) {
|
||||
const CWalletTx& wtx = pairWtx.second;
|
||||
|
||||
if (wtx.IsCoinBase() || !CheckFinalTx(*wtx.tx))
|
||||
|
@ -2731,7 +2731,7 @@ static UniValue listaccounts(const JSONRPCRequest& request)
|
|||
}
|
||||
}
|
||||
|
||||
for (const std::pair<const uint256, CWalletTx>& pairWtx : pwallet->mapWallet) {
|
||||
for (const auto& pairWtx : pwallet->mapWallet) {
|
||||
const CWalletTx& wtx = pairWtx.second;
|
||||
CAmount nFee;
|
||||
std::string strSentAccount;
|
||||
|
@ -2869,7 +2869,7 @@ static UniValue listsinceblock(const JSONRPCRequest& request)
|
|||
|
||||
UniValue transactions(UniValue::VARR);
|
||||
|
||||
for (const std::pair<const uint256, CWalletTx>& pairWtx : pwallet->mapWallet) {
|
||||
for (const auto& pairWtx : pwallet->mapWallet) {
|
||||
CWalletTx tx = pairWtx.second;
|
||||
|
||||
if (depth == -1 || tx.GetDepthInMainChain() < depth) {
|
||||
|
|
|
@ -948,7 +948,7 @@ void CWallet::MarkDirty()
|
|||
{
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
for (std::pair<const uint256, CWalletTx>& item : mapWallet)
|
||||
for (auto& item : mapWallet)
|
||||
item.second.MarkDirty();
|
||||
}
|
||||
}
|
||||
|
@ -991,7 +991,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
|
|||
uint256 hash = wtxIn.GetHash();
|
||||
|
||||
// Inserts only if not already there, returns tx inserted or tx found
|
||||
auto ret = mapWallet.insert(std::make_pair(hash, wtxIn));
|
||||
auto ret = mapWallet.emplace(hash, wtxIn);
|
||||
CWalletTx& wtx = (*ret.first).second;
|
||||
wtx.BindWallet(this);
|
||||
bool fInsertedNew = ret.second;
|
||||
|
@ -1868,7 +1868,7 @@ void CWallet::ReacceptWalletTransactions()
|
|||
std::map<int64_t, CWalletTx*> mapSorted;
|
||||
|
||||
// Sort pending wallet transactions based on their initial wallet insertion order
|
||||
for (std::pair<const uint256, CWalletTx>& item : mapWallet)
|
||||
for (auto& item : mapWallet)
|
||||
{
|
||||
const uint256& wtxid = item.first;
|
||||
CWalletTx& wtx = item.second;
|
||||
|
@ -2123,7 +2123,7 @@ std::vector<uint256> CWallet::ResendWalletTransactionsBefore(int64_t nTime, CCon
|
|||
|
||||
// Sort them in chronological order
|
||||
std::multimap<unsigned int, CWalletTx*> mapSorted;
|
||||
for (std::pair<const uint256, CWalletTx>& item : mapWallet)
|
||||
for (auto& item : mapWallet)
|
||||
{
|
||||
CWalletTx& wtx = item.second;
|
||||
// Don't rebroadcast if newer than nTime:
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <amount.h>
|
||||
#include <outputtype.h>
|
||||
#include <policy/feerate.h>
|
||||
#include <primitives/robin_hood.h>
|
||||
#include <streams.h>
|
||||
#include <tinyformat.h>
|
||||
#include <ui_interface.h>
|
||||
|
@ -29,7 +30,6 @@
|
|||
#include <set>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
|
@ -699,7 +699,7 @@ private:
|
|||
* detect and report conflicts (double-spends or
|
||||
* mutated transactions where the mutant gets mined).
|
||||
*/
|
||||
typedef std::unordered_map<uint256, std::unordered_map<uint32_t, std::vector<uint256>>> TxSpends;
|
||||
typedef robin_hood::unordered_flat_map<uint256, robin_hood::unordered_flat_map<uint32_t, std::vector<uint256>>> TxSpends;
|
||||
TxSpends mapTxSpends;
|
||||
void AddToSpends(const COutPoint& outpoint, const uint256& wtxid);
|
||||
void AddToSpends(const uint256& wtxid);
|
||||
|
@ -808,10 +808,10 @@ public:
|
|||
void MarkPreSplitKeys();
|
||||
|
||||
// Map from Key ID to key metadata.
|
||||
std::unordered_map<CKeyID, CKeyMetadata> mapKeyMetadata;
|
||||
robin_hood::unordered_flat_map<CKeyID, CKeyMetadata> mapKeyMetadata;
|
||||
|
||||
// Map from Script ID to key metadata (for watch-only keys).
|
||||
std::unordered_map<CScriptID, CKeyMetadata> m_script_metadata;
|
||||
robin_hood::unordered_flat_map<CScriptID, CKeyMetadata> m_script_metadata;
|
||||
|
||||
typedef std::map<unsigned int, CMasterKey> MasterKeyMap;
|
||||
MasterKeyMap mapMasterKeys;
|
||||
|
@ -831,7 +831,7 @@ public:
|
|||
encrypted_batch = nullptr;
|
||||
}
|
||||
|
||||
std::unordered_map<uint256, CWalletTx> mapWallet;
|
||||
robin_hood::unordered_node_map<uint256, CWalletTx> mapWallet;
|
||||
std::list<CAccountingEntry> laccentries;
|
||||
|
||||
typedef std::pair<CWalletTx*, CAccountingEntry*> TxPair;
|
||||
|
|
Loading…
Reference in a new issue