Skip to content

Cleanups related to the OutputHash work #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions divi/src/BlockMemoryPoolTransactionCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void BlockMemoryPoolTransactionCollector::RecordOrphanTransaction (
std::shared_ptr<COrphan>& porphan,
const CTransaction& tx,
const CTxIn& txin,
std::map<uint256, std::vector<std::shared_ptr<COrphan>>>& dependentTransactions) const
DependingTransactionsMap& dependentTransactions) const
{
if (porphan == nullptr)
porphan = std::make_shared<COrphan>(&tx);
Expand Down Expand Up @@ -138,7 +138,7 @@ void BlockMemoryPoolTransactionCollector::ComputeTransactionPriority (
}

void BlockMemoryPoolTransactionCollector::AddDependingTransactionsToPriorityQueue (
std::map<uint256, std::vector<std::shared_ptr<COrphan>>>& dependentTransactions,
DependingTransactionsMap& dependentTransactions,
const uint256& hash,
std::vector<TxPriority>& vecPriority,
TxPriorityCompare& comparer) const
Expand Down Expand Up @@ -184,7 +184,7 @@ void BlockMemoryPoolTransactionCollector::AddTransactionToBlock (

std::vector<TxPriority> BlockMemoryPoolTransactionCollector::PrioritizeMempoolTransactions (
const int& nHeight,
std::map<uint256, std::vector<std::shared_ptr<COrphan>>>& dependentTransactions,
DependingTransactionsMap& dependentTransactions,
CCoinsViewCache& view) const
{
std::vector<TxPriority> vecPriority;
Expand Down Expand Up @@ -272,7 +272,7 @@ std::vector<PrioritizedTransactionData> BlockMemoryPoolTransactionCollector::Pri
std::vector<TxPriority>& vecPriority,
const int& nHeight,
CCoinsViewCache& view,
std::map<uint256, std::vector<std::shared_ptr<COrphan>>>& dependentTransactions) const
DependingTransactionsMap& dependentTransactions) const
{
std::vector<PrioritizedTransactionData> prioritizedTransactions;

Expand Down Expand Up @@ -350,7 +350,7 @@ void BlockMemoryPoolTransactionCollector::AddTransactionsToBlockIfPossible (
CCoinsViewCache& view,
CBlockTemplate& blocktemplate) const
{
std::map<uint256, std::vector<std::shared_ptr<COrphan>>> dependentTransactions;
DependingTransactionsMap dependentTransactions;

std::vector<TxPriority> vecPriority =
PrioritizeMempoolTransactions(nHeight, dependentTransactions, view);
Expand Down
11 changes: 7 additions & 4 deletions divi/src/BlockMemoryPoolTransactionCollector.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class CChain;
class BlockMemoryPoolTransactionCollector: public I_BlockTransactionCollector
{
private:
using DependingTransactionsMap = std::map<uint256, std::vector<std::shared_ptr<COrphan>>>;

CCoinsViewCache* baseCoinsViewCache_;
const CChain& activeChain_;
CTxMemPool& mempool_;
Expand All @@ -58,13 +60,14 @@ class BlockMemoryPoolTransactionCollector: public I_BlockTransactionCollector
const unsigned blockMaxSize_;
const unsigned blockPrioritySize_;
const unsigned blockMinSize_;

private:
void UpdateTime(CBlockHeader* block, const CBlockIndex* pindexPrev) const;
void RecordOrphanTransaction (
std::shared_ptr<COrphan>& porphan,
const CTransaction& tx,
const CTxIn& txin,
std::map<uint256, std::vector<std::shared_ptr<COrphan>>>& mapDependers) const;
DependingTransactionsMap& mapDependers) const;

void ComputeTransactionPriority (
double& dPriority,
Expand All @@ -74,7 +77,7 @@ class BlockMemoryPoolTransactionCollector: public I_BlockTransactionCollector
std::vector<TxPriority>& vecPriority,
const CTransaction* mempoolTx) const;
void AddDependingTransactionsToPriorityQueue (
std::map<uint256, std::vector<std::shared_ptr<COrphan>>>& mapDependers,
DependingTransactionsMap& mapDependers,
const uint256& hash,
std::vector<TxPriority>& vecPriority,
TxPriorityCompare& comparer) const;
Expand All @@ -93,7 +96,7 @@ class BlockMemoryPoolTransactionCollector: public I_BlockTransactionCollector

std::vector<TxPriority> PrioritizeMempoolTransactions (
const int& nHeight,
std::map<uint256, std::vector<std::shared_ptr<COrphan>>>& mapDependers,
DependingTransactionsMap& mapDependers,
CCoinsViewCache& view) const;

void PrioritizeFeePastPrioritySize (
Expand All @@ -107,7 +110,7 @@ class BlockMemoryPoolTransactionCollector: public I_BlockTransactionCollector
std::vector<TxPriority>& vecPriority,
const int& nHeight,
CCoinsViewCache& view,
std::map<uint256, std::vector<std::shared_ptr<COrphan>>>& mapDependers) const;
DependingTransactionsMap& mapDependers) const;
void AddTransactionsToBlockIfPossible (
const int& nHeight,
CCoinsViewCache& view,
Expand Down
12 changes: 1 addition & 11 deletions divi/src/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <DataDirectory.h>
#include <chainparamsbase.h>
#include <uint256.h>
#include <serialize.h>
#include <Settings.h>

bool fDebug = false;
Expand All @@ -25,17 +26,6 @@ LOG_FORMAT_WITH_TOSTRING(uint256)

namespace
{
template <class T, class TAl>
inline T* begin_ptr(std::vector<T, TAl>& v)
{
return v.empty() ? NULL : &v[0];
}
/** Get begin pointer of vector (const version) */
template <class T, class TAl>
inline const T* begin_ptr(const std::vector<T, TAl>& v)
{
return v.empty() ? NULL : &v[0];
}

FILE* fileout = nullptr;

Expand Down
4 changes: 2 additions & 2 deletions divi/src/OrphanTransactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ std::map<uint256, std::set<uint256> > mapOrphanTransactionsByPrev;
const std::set<uint256>& GetOrphanSpendingTransactionIds(const uint256& txHash)
{
static std::set<uint256> emptySet;
std::map<uint256, std::set<uint256> >::const_iterator it = mapOrphanTransactionsByPrev.find(txHash);
const auto it = mapOrphanTransactionsByPrev.find(txHash);
if(it == mapOrphanTransactionsByPrev.end()) return emptySet;

return it->second;
Expand Down Expand Up @@ -76,7 +76,7 @@ void EraseOrphanTx(uint256 hash)
if (it == mapOrphanTransactions.end())
return;
BOOST_FOREACH (const CTxIn& txin, it->second.tx.vin) {
std::map<uint256, std::set<uint256> >::iterator itPrev = mapOrphanTransactionsByPrev.find(txin.prevout.hash);
const auto itPrev = mapOrphanTransactionsByPrev.find(txin.prevout.hash);
if (itPrev == mapOrphanTransactionsByPrev.end())
continue;
itPrev->second.erase(hash);
Expand Down
3 changes: 1 addition & 2 deletions divi/src/VaultManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class CTransaction;
class CBlock;
class CWalletTx;
class uint256;
using TransactionsByHash = std::map<uint256,CWalletTx>;

class I_VaultManagerDatabase;
class WalletTransactionRecord;
Expand Down Expand Up @@ -46,4 +45,4 @@ class VaultManager
const CWalletTx& GetTransaction(const uint256&) const;
const ManagedScripts& GetManagedScriptLimits() const;
};
#endif// VAULT_MANAGER_H
#endif// VAULT_MANAGER_H
4 changes: 2 additions & 2 deletions divi/src/addressindex.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct CMempoolAddressDelta
uint256 prevhash;
unsigned int prevout;

CMempoolAddressDelta(int64_t t, CAmount a, uint256 hash, unsigned int out) {
CMempoolAddressDelta(int64_t t, CAmount a, const uint256& hash, unsigned int out) {
time = t;
amount = a;
prevhash = hash;
Expand Down Expand Up @@ -240,7 +240,7 @@ struct CAddressUnspentKey {
index = ser_readdata32(s);
}

CAddressUnspentKey(unsigned int addressType, uint160 addressHash, uint256 txid, size_t indexValue) {
CAddressUnspentKey(unsigned int addressType, uint160 addressHash, const uint256& txid, size_t indexValue) {
type = addressType;
hashBytes = addressHash;
txhash = txid;
Expand Down
14 changes: 14 additions & 0 deletions divi/src/coins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "random.h"

#include <assert.h>
#include <sstream>

#include "FeeAndPriorityCalculator.h"

Expand Down Expand Up @@ -139,6 +140,19 @@ bool CCoins::Spend(const int nPos)
return Spend(nPos, undo);
}

std::string CCoins::ToString() const
{
std::ostringstream res;
res << "CCoins(coinbase=" << fCoinBase << ", coinstake=" << fCoinStake;
res << ", height=" << nHeight << ", version=" << nVersion << "):";
res << std::endl;

for (const auto& out : vout)
res << " " << out.ToString() << std::endl;

return res.str();
}


bool CCoinsView::GetCoins(const uint256& txid, CCoins& coins) const { return false; }
bool CCoinsView::HaveCoins(const uint256& txid) const { return false; }
Expand Down
19 changes: 10 additions & 9 deletions divi/src/coins.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ class CCoins
Cleanup();
}

std::string ToString() const;

};

Expand Down Expand Up @@ -310,12 +311,12 @@ class CCoinsViewBacked : public CCoinsView

public:
CCoinsViewBacked(CCoinsView* viewIn);
bool GetCoins(const uint256& txid, CCoins& coins) const;
bool HaveCoins(const uint256& txid) const;
uint256 GetBestBlock() const;
bool GetCoins(const uint256& txid, CCoins& coins) const override;
bool HaveCoins(const uint256& txid) const override;
uint256 GetBestBlock() const override;
void SetBackend(CCoinsView& viewIn);
bool BatchWrite(CCoinsMap& mapCoins, const uint256& hashBlock);
bool GetStats(CCoinsStats& stats) const;
bool BatchWrite(CCoinsMap& mapCoins, const uint256& hashBlock) override;
bool GetStats(CCoinsStats& stats) const override;
};

class CCoinsViewCache;
Expand Down Expand Up @@ -371,11 +372,11 @@ class CCoinsViewCache : public CCoinsViewBacked
~CCoinsViewCache();

// Standard CCoinsView methods
bool GetCoins(const uint256& txid, CCoins& coins) const;
bool HaveCoins(const uint256& txid) const;
uint256 GetBestBlock() const;
bool GetCoins(const uint256& txid, CCoins& coins) const override;
bool HaveCoins(const uint256& txid) const override;
uint256 GetBestBlock() const override;
void SetBestBlock(const uint256& hashBlock);
bool BatchWrite(CCoinsMap& mapCoins, const uint256& hashBlock);
bool BatchWrite(CCoinsMap& mapCoins, const uint256& hashBlock) override;

/**
* Return a pointer to CCoins in the cache, or NULL if not found. This is
Expand Down
3 changes: 1 addition & 2 deletions divi/src/divi-tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ static void MutateTxAddInput(CMutableTransaction& tx, const string& strInput)
throw runtime_error("invalid TX input vout");

// append to transaction input list
CTxIn txin(txid, vout);
tx.vin.push_back(txin);
tx.vin.emplace_back(COutPoint(txid, vout));
}

static void MutateTxAddOutAddr(CMutableTransaction& tx, const string& strInput)
Expand Down
2 changes: 1 addition & 1 deletion divi/src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class CCoinsViewErrorCatcher : public CCoinsViewBacked
{
public:
CCoinsViewErrorCatcher(CCoinsView* view) : CCoinsViewBacked(view) {}
bool GetCoins(const uint256& txid, CCoins& coins) const
bool GetCoins(const uint256& txid, CCoins& coins) const override
{
try {
return CCoinsViewBacked::GetCoins(txid, coins);
Expand Down
2 changes: 1 addition & 1 deletion divi/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ bool GetAddressUnspent(bool addresIndexEnabled,
return true;
}

bool GetSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value)
bool GetSpentIndex(const CSpentIndexKey &key, CSpentIndexValue &value)
{
if (!fSpentIndex)
return false;
Expand Down
2 changes: 1 addition & 1 deletion divi/src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,6 @@ bool GetAddressUnspent(bool addresIndexEnabled,
int type,
std::vector<std::pair<CAddressUnspentKey,
CAddressUnspentValue> > &unspentOutputs);
bool GetSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value);
bool GetSpentIndex(const CSpentIndexKey &key, CSpentIndexValue &value);

#endif // BITCOIN_MAIN_H
7 changes: 5 additions & 2 deletions divi/src/primitives/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@


COutPoint::COutPoint() { SetNull(); }
COutPoint::COutPoint(uint256 hashIn, uint32_t nIn) { hash = hashIn; n = nIn; }
COutPoint::COutPoint(const uint256& hashIn, uint32_t nIn)
: hash(hashIn), n(nIn)
{}

void COutPoint::SetNull() { hash.SetNull(); n = (uint32_t) -1; }
bool COutPoint::IsNull() const { return (hash.IsNull() && n == (uint32_t) -1); }
bool operator<(const COutPoint& a, const COutPoint& b)
Expand Down Expand Up @@ -80,7 +83,7 @@ CTxIn::CTxIn(COutPoint prevoutIn, CScript scriptSigIn, uint32_t nSequenceIn)
nSequence = nSequenceIn;
}

CTxIn::CTxIn(uint256 hashPrevTx, uint32_t nOut, CScript scriptSigIn, uint32_t nSequenceIn)
CTxIn::CTxIn(const uint256& hashPrevTx, uint32_t nOut, CScript scriptSigIn, uint32_t nSequenceIn)
{
prevout = COutPoint(hashPrevTx, nOut);
scriptSig = scriptSigIn;
Expand Down
7 changes: 4 additions & 3 deletions divi/src/primitives/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ class COutPoint
uint32_t n;

COutPoint();
COutPoint(uint256 hashIn, uint32_t nIn);
COutPoint(const uint256& hashIn, uint32_t nIn);

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
READWRITE(FLATDATA(*this));
READWRITE(hash);
READWRITE(n);
}

void SetNull();
Expand Down Expand Up @@ -56,7 +57,7 @@ class CTxIn

CTxIn();
explicit CTxIn(COutPoint prevoutIn, CScript scriptSigIn=CScript(), uint32_t nSequenceIn=std::numeric_limits<uint32_t>::max());
CTxIn(uint256 hashPrevTx, uint32_t nOut, CScript scriptSigIn=CScript(), uint32_t nSequenceIn=std::numeric_limits<uint32_t>::max());
CTxIn(const uint256& hashPrevTx, uint32_t nOut, CScript scriptSigIn=CScript(), uint32_t nSequenceIn=std::numeric_limits<uint32_t>::max());

ADD_SERIALIZE_METHODS;

Expand Down
4 changes: 2 additions & 2 deletions divi/src/rpcmisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ bool GetAddressIndex(bool addresIndexEnabled,

std::string GetWarnings(std::string strFor);

bool GetSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value);
bool GetSpentIndex(const CSpentIndexKey &key, CSpentIndexValue &value);

bool GetAddressUnspent(bool addresIndexEnabled,
CBlockTreeDB* pblocktree,
Expand Down Expand Up @@ -1016,7 +1016,7 @@ Value getspentinfo(const Array& params, bool fHelp)
uint256 txid = ParseHashV(txidValue, "txid");
int outputIndex = indexValue.get_int();

CSpentIndexKey key(txid, outputIndex);
const CSpentIndexKey key(txid, outputIndex);
CSpentIndexValue value;

if (!GetSpentIndex(key, value)) {
Expand Down
Loading