21static bool IsFinalTx(
const CTransaction &tx,
int nBlockHeight,
23 if (tx.nLockTime == 0) {
27 int64_t lockTime = tx.nLockTime;
28 int64_t lockTimeLimit =
30 if (lockTime < lockTimeLimit) {
34 for (
const auto &txin : tx.vin) {
43 const CTransaction &tx,
45 int64_t nMedianTimePast) {
50 "bad-txns-nonfinal",
"non-final transaction");
57 "bad-txns-undersize");
85 const int nBlockHeight = active_chain_tip.
nHeight + 1;
107 std::vector<int> &prevHeights,
109 assert(prevHeights.size() == tx.vin.size());
117 int64_t nMinTime = -1;
122 bool fEnforceBIP68 =
static_cast<uint32_t
>(tx.nVersion) >= 2 &&
127 if (!fEnforceBIP68) {
128 return std::make_pair(nMinHeight, nMinTime);
131 for (
size_t txinIndex = 0; txinIndex < tx.vin.size(); txinIndex++) {
132 const CTxIn &txin = tx.vin[txinIndex];
139 prevHeights[txinIndex] = 0;
143 int nCoinHeight = prevHeights[txinIndex];
146 const int64_t nCoinTime{
148 ->GetMedianTimePast()};
167 nMinHeight = std::max(
174 return std::make_pair(nMinHeight, nMinTime);
178 std::pair<int, int64_t> lockPair) {
181 if (lockPair.first >= block.
nHeight || lockPair.second >= nBlockTime) {
189 std::vector<int> &prevHeights,
const CBlockIndex &block) {
201 "bad-txns-inputs-missingorspent",
202 strprintf(
"%s: inputs missing/spent", __func__));
206 for (
const auto &in : tx.vin) {
207 const COutPoint &prevout = in.prevout;
216 "bad-txns-premature-spend-of-coinbase",
217 strprintf(
"tried to spend coinbase at depth %d",
225 "bad-txns-inputvalues-outofrange");
229 const Amount value_out = tx.GetValueOut();
230 if (nValueIn < value_out) {
238 const Amount txfee_aux = nValueIn - value_out;
241 "bad-txns-fee-outofrange");
bool IsWellingtonEnabled(const Consensus::Params ¶ms, int32_t nHeight)
Check if May 15th, 2023 protocol upgrade has activated.
bool IsMagneticAnomalyEnabled(const Consensus::Params ¶ms, int32_t nHeight)
Check if Nov 15, 2018 HF has activated using block height.
bool MoneyRange(const Amount nValue)
#define Assert(val)
Identity function.
The block chain is a tree shaped structure starting with the genesis block at the root,...
CBlockIndex * pprev
pointer to the index of the predecessor of this block
int64_t GetMedianTimePast() const
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
int nHeight
height of the entry in the chain. The genesis block has height 0
CCoinsView that adds a memory cache for transactions to another CCoinsView.
bool HaveInputs(const CTransaction &tx) const
Check whether all prevouts of the transaction are present in the UTXO set represented by this view.
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to Coin in the cache, or coinEmpty if not found.
static constexpr int32_t MAX_VERSION
static constexpr int32_t MIN_VERSION
static const uint32_t SEQUENCE_LOCKTIME_DISABLE_FLAG
If this flag set, CTxIn::nSequence is NOT interpreted as a relative lock-time.
static const uint32_t SEQUENCE_LOCKTIME_MASK
If CTxIn::nSequence encodes a relative lock-time, this mask is applied to extract that lock-time from...
static const uint32_t SEQUENCE_FINAL
Setting nSequence to this value for every input in a transaction disables nLockTime.
static const uint32_t SEQUENCE_LOCKTIME_TYPE_FLAG
If CTxIn::nSequence encodes a relative lock-time and this flag is set, the relative lock-time has uni...
static const int SEQUENCE_LOCKTIME_GRANULARITY
In order to use the same number of bits to encode roughly the same wall-clock duration,...
uint32_t GetHeight() const
bool Invalid(Result result, const std::string &reject_reason="", const std::string &debug_message="")
@ TX_MISSING_INPUTS
transaction was missing some of its inputs
@ TX_PREMATURE_SPEND
transaction spends a coinbase too early, or violates locktime/sequence locks
@ TX_CONSENSUS
invalid by consensus rules
static constexpr unsigned int LOCKTIME_VERIFY_SEQUENCE
Flags for nSequence and nLockTime locks.
static const uint64_t MIN_TX_SIZE
The minimum allowed size for a transaction, in bytes.
static const int COINBASE_MATURITY
Coinbase transaction outputs can only be spent after this number of new blocks (network rule).
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
std::string FormatMoney(const Amount amt)
Do not use these functions to represent or parse monetary amounts to or from JSON but use AmountFromV...
bool CheckTxInputs(const CTransaction &tx, TxValidationState &state, const CCoinsViewCache &inputs, int nSpendHeight, Amount &txfee)
Check whether all inputs of this transaction are valid (no double spends and amounts).
static const unsigned int LOCKTIME_THRESHOLD
size_t GetSerializeSize(const T &t, int nVersion=0)
static constexpr Amount zero() noexcept
Parameters that influence chain consensus.
bool ContextualCheckTransactionForCurrentBlock(const CBlockIndex &active_chain_tip, const Consensus::Params ¶ms, const CTransaction &tx, TxValidationState &state)
static bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
bool EvaluateSequenceLocks(const CBlockIndex &block, std::pair< int, int64_t > lockPair)
std::pair< int, int64_t > CalculateSequenceLocks(const CTransaction &tx, int flags, std::vector< int > &prevHeights, const CBlockIndex &block)
Calculates the block height and previous block's median time past at which the transaction will be co...
bool SequenceLocks(const CTransaction &tx, int flags, std::vector< int > &prevHeights, const CBlockIndex &block)
Check if transaction is final per BIP 68 sequence numbers and can be included in a block.
bool ContextualCheckTransaction(const Consensus::Params ¶ms, const CTransaction &tx, TxValidationState &state, int nHeight, int64_t nMedianTimePast)
Context dependent validity checks for non coinbase transactions.
static const int PROTOCOL_VERSION
network protocol versioning