26 int64_t lockTimeLimit =
28 if (lockTime < lockTimeLimit) {
32 for (
const auto &txin : tx.
vin) {
43 int64_t nLockTimeCutoff,
44 int64_t nMedianTimePast) {
45 if (!
IsFinalTx(tx, nHeight, nLockTimeCutoff)) {
49 "bad-txns-nonfinal",
"non-final transaction");
56 "bad-txns-undersize");
71 std::vector<int> &prevHeights,
73 assert(prevHeights.size() == tx.
vin.size());
81 int64_t nMinTime = -1;
86 bool fEnforceBIP68 =
static_cast<uint32_t
>(tx.
nVersion) >= 2 &&
92 return std::make_pair(nMinHeight, nMinTime);
95 for (
size_t txinIndex = 0; txinIndex < tx.
vin.size(); txinIndex++) {
96 const CTxIn &txin = tx.
vin[txinIndex];
103 prevHeights[txinIndex] = 0;
107 int nCoinHeight = prevHeights[txinIndex];
110 int64_t nCoinTime = block.
GetAncestor(std::max(nCoinHeight - 1, 0))
130 nMinHeight = std::max(
137 return std::make_pair(nMinHeight, nMinTime);
141 std::pair<int, int64_t> lockPair) {
144 if (lockPair.first >= block.
nHeight || lockPair.second >= nBlockTime) {
152 std::vector<int> &prevHeights,
const CBlockIndex &block) {
164 "bad-txns-inputs-missingorspent",
165 strprintf(
"%s: inputs missing/spent", __func__));
169 for (
const auto &in : tx.
vin) {
179 "bad-txns-premature-spend-of-coinbase",
180 strprintf(
"tried to spend coinbase at depth %d",
188 "bad-txns-inputvalues-outofrange");
193 if (nValueIn < value_out) {
201 const Amount txfee_aux = nValueIn - value_out;
204 "bad-txns-fee-outofrange");
static constexpr unsigned int LOCKTIME_VERIFY_SEQUENCE
Flags for nSequence and nLockTime locks.
invalid by consensus rules
static constexpr Amount zero()
CBlockIndex * pprev
pointer to the index of the predecessor of this block
static bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to Coin in the cache, or coinEmpty if not found.
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...
transaction was missing some of its inputs
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_DISABLE_FLAG
If this flag set, CTxIn::nSequence is NOT interpreted as a relative lock-time.
Amount GetValueOut() const
static const int COINBASE_MATURITY
Coinbase transaction outputs can only be spent after this number of new blocks (network rule)...
static const int SEQUENCE_LOCKTIME_GRANULARITY
In order to use the same number of bits to encode roughly the same wall-clock duration, and because blocks are naturally limited to occur every 600s on average, the minimum granularity for time-based relative lock-time is fixed at 512 seconds.
static const uint64_t MIN_TX_SIZE
The minimum allowed size for a transaction, in bytes.
transaction spends a coinbase too early, or violates locktime/sequence locks
bool HaveInputs(const CTransaction &tx) const
Check whether all prevouts of the transaction are present in the UTXO set represented by this view...
const std::vector< CTxIn > vin
size_t GetSerializeSize(const T &t, int nVersion=0)
bool MoneyRange(const Amount nValue)
bool Invalid(Result result, const std::string &reject_reason="", const std::string &debug_message="")
An input of a transaction.
bool EvaluateSequenceLocks(const CBlockIndex &block, std::pair< int, int64_t > lockPair)
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...
Parameters that influence chain consensus.
An outpoint - a combination of a transaction hash and an index n into its vout.
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...
int64_t GetMedianTimePast() const
bool ContextualCheckTransaction(const Consensus::Params ¶ms, const CTransaction &tx, TxValidationState &state, int nHeight, int64_t nLockTimeCutoff, int64_t nMedianTimePast)
Context dependent validity checks for non coinbase transactions.
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...
The block chain is a tree shaped structure starting with the genesis block at the root...
uint32_t GetHeight() const
static const int PROTOCOL_VERSION
network protocol versioning
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
The basic transaction that is broadcasted on the network and contained in blocks. ...
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.
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
bool IsMagneticAnomalyEnabled(const Consensus::Params ¶ms, int32_t nHeight)
Check if Nov 15, 2018 HF has activated using block height.
std::string FormatMoney(const Amount amt)
Money parsing/formatting utilities.