Skip to content

Commit

Permalink
squash: use activation state for utxo hasher
Browse files Browse the repository at this point in the history
  • Loading branch information
domob1812 committed Jan 19, 2021
1 parent baaf905 commit 6cc0d44
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions divi/src/UtxoCheckingAndUpdating.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ extern BlockMap mapBlockIndex;

uint256 TransactionUtxoHasher::GetUtxoHash(const CTransaction& tx) const
{
if (as.IsActive(Fork::SegwitLight))
return tx.GetBareTxid();
return tx.GetHash();
}

Expand Down
9 changes: 8 additions & 1 deletion divi/src/UtxoCheckingAndUpdating.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@ class uint256;
class TransactionUtxoHasher
{

private:

const ActivationState& as;

public:

TransactionUtxoHasher() = default;
explicit TransactionUtxoHasher(const ActivationState& a)
: as(a)
{}

virtual ~TransactionUtxoHasher() = default;

TransactionUtxoHasher(const TransactionUtxoHasher&) = delete;
Expand Down
6 changes: 3 additions & 3 deletions divi/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1373,7 +1373,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
std::vector<std::pair<CSpentIndexKey, CSpentIndexValue> > spentIndex;

const ActivationState as(pindex);
const TransactionUtxoHasher utxoHasher;
const TransactionUtxoHasher utxoHasher(as);

// undo transactions in reverse order
for (int i = block.vtx.size() - 1; i >= 0; i--) {
Expand Down Expand Up @@ -1619,7 +1619,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
unsigned int nMaxBlockSigOps = MAX_BLOCK_SIGOPS_CURRENT;

const ActivationState as(pindex);
const TransactionUtxoHasher utxoHasher;
const TransactionUtxoHasher utxoHasher(as);
static const CChainParams& chainParameters = Params();
static const SuperblockSubsidyContainer subsidiesContainer(chainParameters);
static const BlockIncentivesPopulator incentives(
Expand Down Expand Up @@ -3275,7 +3275,7 @@ bool static LoadBlockIndexDB(string& strError)
return false;
}
const ActivationState as(block);
const TransactionUtxoHasher utxoHasher;
const TransactionUtxoHasher utxoHasher(as);

std::vector<CTxUndo> vtxundo;
vtxundo.reserve(block.vtx.size() - 1);
Expand Down
6 changes: 3 additions & 3 deletions divi/src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ void CTxMemPool::remove(const CTransaction& origTx, std::list<CTransaction>& rem
{
LOCK(cs);
const ActivationState as(chainActive.Tip());
const TransactionUtxoHasher utxoHasher;
const TransactionUtxoHasher utxoHasher(as);
std::deque<uint256> txToRemove;
txToRemove.push_back(origTx.GetHash());
if (fRecursive && !mapTx.count(origTx.GetHash())) {
Expand Down Expand Up @@ -698,7 +698,7 @@ void CTxMemPool::check(const CCoinsViewCache* pcoins) const
CCoinsViewCache mempoolDuplicate(const_cast<CCoinsViewCache*>(pcoins));

const ActivationState as(chainActive.Tip());
const TransactionUtxoHasher utxoHasher;
const TransactionUtxoHasher utxoHasher(as);

LOCK(cs);
list<const CTxMemPoolEntry*> waitingOnDependants;
Expand Down Expand Up @@ -797,7 +797,7 @@ bool CTxMemPool::lookupOutpoint(const uint256& hash, CTransaction& result) const
mempool is not allowed in a time window "around" the fork, so that
this should be good enough. */
const ActivationState as(chainActive.Tip());
const TransactionUtxoHasher utxoHasher;
const TransactionUtxoHasher utxoHasher(as);

/* The TransactionUtxoHasher can only tell us the txid to use once we
know the transaction already. Thus we check both txid and bare txid
Expand Down

0 comments on commit 6cc0d44

Please sign in to comment.