Skip to content

Commit

Permalink
TestLockPointValidity to txmempool
Browse files Browse the repository at this point in the history
Summary:
This is a partial backport of [[bitcoin/bitcoin#22677 | core#22677]] and [[bitcoin/bitcoin#23649 | core#23649]]
bitcoin/bitcoin@1b3a11e
bitcoin/bitcoin@ddd74ff

Depends on D12442

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D12440
  • Loading branch information
glozow authored and PiRK committed Nov 10, 2022
1 parent 1517838 commit bd99a74
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
19 changes: 19 additions & 0 deletions src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ struct update_lock_points {
const LockPoints &lp;
};

bool TestLockPointValidity(const CChain &active_chain, const LockPoints *lp) {
AssertLockHeld(cs_main);
assert(lp);
// If there are relative lock times then the maxInputBlock will be set
// If there are no relative lock times, the LockPoints don't depend on the
// chain
if (lp->maxInputBlock) {
// Check whether active_chain is an extension of the block at which the
// LockPoints calculation was valid. If not LockPoints are no longer
// valid
if (!active_chain.Contains(lp->maxInputBlock)) {
return false;
}
}

// LockPoints still valid
return true;
}

CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef &_tx, const Amount fee,
int64_t time, unsigned int entry_height,
bool spends_coinbase, int64_t sigops_count,
Expand Down
8 changes: 8 additions & 0 deletions src/txmempool.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <vector>

class CBlockIndex;
class CChain;
class CChainState;
class Config;

Expand All @@ -53,6 +54,13 @@ struct LockPoints {
CBlockIndex *maxInputBlock{nullptr};
};

/**
* Test whether the LockPoints height and time are still valid on the current
* chain.
*/
bool TestLockPointValidity(const CChain &active_chain, const LockPoints *lp)
EXCLUSIVE_LOCKS_REQUIRED(cs_main);

struct CompareIteratorById {
// SFINAE for T where T is either a pointer type (e.g., a txiter) or a
// reference_wrapper<T> (e.g. a wrapped CTxMemPoolEntry&)
Expand Down
19 changes: 0 additions & 19 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,25 +156,6 @@ CBlockIndex *BlockManager::FindForkInGlobalIndex(const CChain &chain,
static uint32_t GetNextBlockScriptFlags(const Consensus::Params &params,
const CBlockIndex *pindex);

bool TestLockPointValidity(const CChain &active_chain, const LockPoints *lp) {
AssertLockHeld(cs_main);
assert(lp);
// If there are relative lock times then the maxInputBlock will be set
// If there are no relative lock times, the LockPoints don't depend on the
// chain
if (lp->maxInputBlock) {
// Check whether active_chain is an extension of the block at which
// the LockPoints calculation was valid. If not LockPoints are no longer
// valid.
if (!active_chain.Contains(lp->maxInputBlock)) {
return false;
}
}

// LockPoints still valid
return true;
}

bool CheckSequenceLocks(CBlockIndex *tip, const CCoinsView &coins_view,
const CTransaction &tx, int flags, LockPoints *lp,
bool useExistingLockPoints) {
Expand Down
7 changes: 0 additions & 7 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,13 +470,6 @@ void SpendCoins(CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo,
void UpdateCoins(CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo,
int nHeight);

/**
* Test whether the LockPoints height and time are still valid on the current
* chain.
*/
bool TestLockPointValidity(const CChain &active_chain, const LockPoints *lp)
EXCLUSIVE_LOCKS_REQUIRED(cs_main);

/**
* Check if transaction will be BIP68 final in the next block to be created on
* top of tip.
Expand Down

0 comments on commit bd99a74

Please sign in to comment.