rob the rich to pay the poor

This commit is contained in:
Brannon King 2020-03-03 09:03:51 -07:00
parent 4664f07b22
commit b2186806e3
12 changed files with 2235 additions and 35 deletions

View file

@ -148,6 +148,7 @@ BITCOIN_CORE_H = \
policy/fees.h \ policy/fees.h \
policy/policy.h \ policy/policy.h \
policy/rbf.h \ policy/rbf.h \
primitives/robin_hood.h \
pow.h \ pow.h \
protocol.h \ protocol.h \
random.h \ random.h \

View file

@ -9,7 +9,7 @@
/** Template base class for fixed-sized opaque blobs. */ /** Template base class for fixed-sized opaque blobs. */
template<uint32_t BITS> 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> template<uint32_t BITS>
CBaseBlob<BITS>::CBaseBlob(const CBaseBlob& o) CBaseBlob<BITS>::CBaseBlob(const CBaseBlob& o) noexcept
{ {
*this = o; *this = o;
} }
template<uint32_t BITS> template<uint32_t BITS>
CBaseBlob<BITS>& CBaseBlob<BITS>::operator=(const CBaseBlob& o) CBaseBlob<BITS>& CBaseBlob<BITS>::operator=(const CBaseBlob& o) noexcept
{ {
data = o.data; data = o.data;
return *this; return *this;

View file

@ -12,15 +12,15 @@ class CBaseBlob
{ {
std::array<uint8_t, BITS / 8> data; std::array<uint8_t, BITS / 8> data;
public: public:
CBaseBlob(); CBaseBlob() noexcept;
explicit CBaseBlob(const std::vector<uint8_t>& vec); explicit CBaseBlob(const std::vector<uint8_t>& vec);
CBaseBlob(CBaseBlob&&) = default; CBaseBlob(CBaseBlob&&) = default;
CBaseBlob& operator=(CBaseBlob&&) = default; CBaseBlob& operator=(CBaseBlob&&) = default;
CBaseBlob(const CBaseBlob& o); CBaseBlob(const CBaseBlob& o) noexcept;
CBaseBlob& operator=(const CBaseBlob& o); CBaseBlob& operator=(const CBaseBlob& o) noexcept;
int Compare(const CBaseBlob& b) const; int Compare(const CBaseBlob& b) const;
bool operator<(const CBaseBlob& b) const; bool operator<(const CBaseBlob& b) const;

View file

@ -45,18 +45,18 @@ namespace std {
template <> template <>
struct hash<uint160> 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 <> template <>
struct hash<uint256> 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());
} }
}; };
} }

View file

@ -15,7 +15,7 @@
#include <boost/signals2/signal.hpp> #include <boost/signals2/signal.hpp>
#include <unordered_map> #include <primitives/robin_hood.h>
#include <set> #include <set>
/** A virtual base class for key stores */ /** A virtual base class for key stores */
@ -47,9 +47,9 @@ class CBasicKeyStore : public CKeyStore
protected: protected:
mutable CCriticalSection cs_KeyStore; mutable CCriticalSection cs_KeyStore;
using KeyMap = std::unordered_map<CKeyID, CKey>; using KeyMap = robin_hood::unordered_map<CKeyID, CKey>;
using WatchKeyMap = std::unordered_map<CKeyID, CPubKey>; using WatchKeyMap = robin_hood::unordered_map<CKeyID, CPubKey>;
using ScriptMap = std::unordered_map<CScriptID, CScript>; using ScriptMap = robin_hood::unordered_map<CScriptID, CScript>;
using WatchOnlySet = std::set<CScript>; using WatchOnlySet = std::set<CScript>;
KeyMap mapKeys GUARDED_BY(cs_KeyStore); KeyMap mapKeys GUARDED_BY(cs_KeyStore);

2198
src/primitives/robin_hood.h Normal file

File diff suppressed because it is too large Load diff

View file

@ -40,9 +40,9 @@ namespace std {
template <> template <>
struct hash<CKeyID> 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());
} }
}; };
} }

View file

@ -31,9 +31,9 @@ namespace std {
template <> template <>
struct hash<CScriptID> 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());
} }
}; };
} }

View file

@ -17,6 +17,7 @@
#include <nameclaim.h> #include <nameclaim.h>
#include <protocol.h> // For CMessageHeader::MessageStartChars #include <protocol.h> // For CMessageHeader::MessageStartChars
#include <policy/feerate.h> #include <policy/feerate.h>
#include <primitives/robin_hood.h>
#include <script/script_error.h> #include <script/script_error.h>
#include <sync.h> #include <sync.h>
#include <txmempool.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) { inline iterator find(const uint256& blockHash) {
CBlockIndex temp(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 { inline const_iterator find(const uint256& blockHash) const {
CBlockIndex temp(blockHash); CBlockIndex temp(blockHash);
return std::unordered_set<CBlockIndex*, BlockMapHasher, BlockMapComparer>::find(&temp); return robin_hood::unordered_flat_set<CBlockIndex*, BlockMapHasher, BlockMapComparer>::find(&temp);
} }
}; };

View file

@ -1286,7 +1286,7 @@ static UniValue getreceivedbyaddress(const JSONRPCRequest& request)
// Tally // Tally
CAmount nAmount = 0; CAmount nAmount = 0;
for (const std::pair<const uint256, CWalletTx>& pairWtx : pwallet->mapWallet) { for (const auto& pairWtx : pwallet->mapWallet) {
const CWalletTx& wtx = pairWtx.second; const CWalletTx& wtx = pairWtx.second;
if (wtx.IsCoinBase() || !CheckFinalTx(*wtx.tx)) if (wtx.IsCoinBase() || !CheckFinalTx(*wtx.tx))
continue; continue;
@ -1354,7 +1354,7 @@ static UniValue getreceivedbylabel(const JSONRPCRequest& request)
// Tally // Tally
CAmount nAmount = 0; CAmount nAmount = 0;
for (const std::pair<const uint256, CWalletTx>& pairWtx : pwallet->mapWallet) { for (const auto& pairWtx : pwallet->mapWallet) {
const CWalletTx& wtx = pairWtx.second; const CWalletTx& wtx = pairWtx.second;
if (wtx.IsCoinBase() || !CheckFinalTx(*wtx.tx)) if (wtx.IsCoinBase() || !CheckFinalTx(*wtx.tx))
continue; continue;
@ -2138,7 +2138,7 @@ static UniValue ListReceived(CWallet * const pwallet, const UniValue& params, bo
// Tally // Tally
std::map<CTxDestination, tallyitem> mapTally; 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; const CWalletTx& wtx = pairWtx.second;
if (wtx.IsCoinBase() || !CheckFinalTx(*wtx.tx)) 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; const CWalletTx& wtx = pairWtx.second;
CAmount nFee; CAmount nFee;
std::string strSentAccount; std::string strSentAccount;
@ -2869,7 +2869,7 @@ static UniValue listsinceblock(const JSONRPCRequest& request)
UniValue transactions(UniValue::VARR); UniValue transactions(UniValue::VARR);
for (const std::pair<const uint256, CWalletTx>& pairWtx : pwallet->mapWallet) { for (const auto& pairWtx : pwallet->mapWallet) {
CWalletTx tx = pairWtx.second; CWalletTx tx = pairWtx.second;
if (depth == -1 || tx.GetDepthInMainChain() < depth) { if (depth == -1 || tx.GetDepthInMainChain() < depth) {

View file

@ -948,7 +948,7 @@ void CWallet::MarkDirty()
{ {
{ {
LOCK(cs_wallet); LOCK(cs_wallet);
for (std::pair<const uint256, CWalletTx>& item : mapWallet) for (auto& item : mapWallet)
item.second.MarkDirty(); item.second.MarkDirty();
} }
} }
@ -991,7 +991,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
uint256 hash = wtxIn.GetHash(); uint256 hash = wtxIn.GetHash();
// Inserts only if not already there, returns tx inserted or tx found // 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; CWalletTx& wtx = (*ret.first).second;
wtx.BindWallet(this); wtx.BindWallet(this);
bool fInsertedNew = ret.second; bool fInsertedNew = ret.second;
@ -1868,7 +1868,7 @@ void CWallet::ReacceptWalletTransactions()
std::map<int64_t, CWalletTx*> mapSorted; std::map<int64_t, CWalletTx*> mapSorted;
// Sort pending wallet transactions based on their initial wallet insertion order // 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; const uint256& wtxid = item.first;
CWalletTx& wtx = item.second; CWalletTx& wtx = item.second;
@ -2123,7 +2123,7 @@ std::vector<uint256> CWallet::ResendWalletTransactionsBefore(int64_t nTime, CCon
// Sort them in chronological order // Sort them in chronological order
std::multimap<unsigned int, CWalletTx*> mapSorted; std::multimap<unsigned int, CWalletTx*> mapSorted;
for (std::pair<const uint256, CWalletTx>& item : mapWallet) for (auto& item : mapWallet)
{ {
CWalletTx& wtx = item.second; CWalletTx& wtx = item.second;
// Don't rebroadcast if newer than nTime: // Don't rebroadcast if newer than nTime:

View file

@ -9,6 +9,7 @@
#include <amount.h> #include <amount.h>
#include <outputtype.h> #include <outputtype.h>
#include <policy/feerate.h> #include <policy/feerate.h>
#include <primitives/robin_hood.h>
#include <streams.h> #include <streams.h>
#include <tinyformat.h> #include <tinyformat.h>
#include <ui_interface.h> #include <ui_interface.h>
@ -29,7 +30,6 @@
#include <set> #include <set>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <unordered_map>
#include <utility> #include <utility>
#include <vector> #include <vector>
@ -699,7 +699,7 @@ private:
* detect and report conflicts (double-spends or * detect and report conflicts (double-spends or
* mutated transactions where the mutant gets mined). * 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; TxSpends mapTxSpends;
void AddToSpends(const COutPoint& outpoint, const uint256& wtxid); void AddToSpends(const COutPoint& outpoint, const uint256& wtxid);
void AddToSpends(const uint256& wtxid); void AddToSpends(const uint256& wtxid);
@ -808,10 +808,10 @@ public:
void MarkPreSplitKeys(); void MarkPreSplitKeys();
// Map from Key ID to key metadata. // 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). // 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; typedef std::map<unsigned int, CMasterKey> MasterKeyMap;
MasterKeyMap mapMasterKeys; MasterKeyMap mapMasterKeys;
@ -831,7 +831,7 @@ public:
encrypted_batch = nullptr; encrypted_batch = nullptr;
} }
std::unordered_map<uint256, CWalletTx> mapWallet; robin_hood::unordered_node_map<uint256, CWalletTx> mapWallet;
std::list<CAccountingEntry> laccentries; std::list<CAccountingEntry> laccentries;
typedef std::pair<CWalletTx*, CAccountingEntry*> TxPair; typedef std::pair<CWalletTx*, CAccountingEntry*> TxPair;