Changeset View
Changeset View
Standalone View
Standalone View
src/consensus/tx_verify.cpp
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* Calculates the block height and previous block's median time past at | * Calculates the block height and previous block's median time past at | ||||
* which the transaction will be considered final in the context of BIP 68. | * which the transaction will be considered final in the context of BIP 68. | ||||
* Also removes from the vector of input heights any entries which did not | * Also removes from the vector of input heights any entries which did not | ||||
* correspond to sequence locked inputs as they do not affect the calculation. | * correspond to sequence locked inputs as they do not affect the calculation. | ||||
*/ | */ | ||||
std::pair<int, int64_t> CalculateSequenceLocks(const CTransaction &tx, | std::pair<int, int64_t> CalculateSequenceLocks(const CTransaction &tx, | ||||
int flags, | int flags, | ||||
std::vector<int> *prevHeights, | std::vector<int> &prevHeights, | ||||
const CBlockIndex &block) { | const CBlockIndex &block) { | ||||
assert(prevHeights->size() == tx.vin.size()); | assert(prevHeights.size() == tx.vin.size()); | ||||
// Will be set to the equivalent height- and time-based nLockTime | // Will be set to the equivalent height- and time-based nLockTime | ||||
// values that would be necessary to satisfy all relative lock- | // values that would be necessary to satisfy all relative lock- | ||||
// time constraints given our view of block chain history. | // time constraints given our view of block chain history. | ||||
// The semantics of nLockTime are the last invalid height/time, so | // The semantics of nLockTime are the last invalid height/time, so | ||||
// use -1 to have the effect of any height or time being valid. | // use -1 to have the effect of any height or time being valid. | ||||
int nMinHeight = -1; | int nMinHeight = -1; | ||||
int64_t nMinTime = -1; | int64_t nMinTime = -1; | ||||
Show All 13 Lines | std::pair<int, int64_t> CalculateSequenceLocks(const CTransaction &tx, | ||||
for (size_t txinIndex = 0; txinIndex < tx.vin.size(); txinIndex++) { | for (size_t txinIndex = 0; txinIndex < tx.vin.size(); txinIndex++) { | ||||
const CTxIn &txin = tx.vin[txinIndex]; | const CTxIn &txin = tx.vin[txinIndex]; | ||||
// Sequence numbers with the most significant bit set are not | // Sequence numbers with the most significant bit set are not | ||||
// treated as relative lock-times, nor are they given any | // treated as relative lock-times, nor are they given any | ||||
// consensus-enforced meaning at this point. | // consensus-enforced meaning at this point. | ||||
if (txin.nSequence & CTxIn::SEQUENCE_LOCKTIME_DISABLE_FLAG) { | if (txin.nSequence & CTxIn::SEQUENCE_LOCKTIME_DISABLE_FLAG) { | ||||
// The height of this input is not relevant for sequence locks | // The height of this input is not relevant for sequence locks | ||||
(*prevHeights)[txinIndex] = 0; | prevHeights[txinIndex] = 0; | ||||
continue; | continue; | ||||
} | } | ||||
int nCoinHeight = (*prevHeights)[txinIndex]; | int nCoinHeight = prevHeights[txinIndex]; | ||||
if (txin.nSequence & CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG) { | if (txin.nSequence & CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG) { | ||||
int64_t nCoinTime = block.GetAncestor(std::max(nCoinHeight - 1, 0)) | int64_t nCoinTime = block.GetAncestor(std::max(nCoinHeight - 1, 0)) | ||||
->GetMedianTimePast(); | ->GetMedianTimePast(); | ||||
// NOTE: Subtract 1 to maintain nLockTime semantics. | // NOTE: Subtract 1 to maintain nLockTime semantics. | ||||
// BIP 68 relative lock times have the semantics of calculating the | // BIP 68 relative lock times have the semantics of calculating the | ||||
// first block or time at which the transaction would be valid. When | // first block or time at which the transaction would be valid. When | ||||
// calculating the effective block time or height for the entire | // calculating the effective block time or height for the entire | ||||
Show All 28 Lines | bool EvaluateSequenceLocks(const CBlockIndex &block, | ||||
if (lockPair.first >= block.nHeight || lockPair.second >= nBlockTime) { | if (lockPair.first >= block.nHeight || lockPair.second >= nBlockTime) { | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool SequenceLocks(const CTransaction &tx, int flags, | bool SequenceLocks(const CTransaction &tx, int flags, | ||||
std::vector<int> *prevHeights, const CBlockIndex &block) { | std::vector<int> &prevHeights, const CBlockIndex &block) { | ||||
return EvaluateSequenceLocks( | return EvaluateSequenceLocks( | ||||
block, CalculateSequenceLocks(tx, flags, prevHeights, block)); | block, CalculateSequenceLocks(tx, flags, prevHeights, block)); | ||||
} | } | ||||
namespace Consensus { | namespace Consensus { | ||||
bool CheckTxInputs(const CTransaction &tx, TxValidationState &state, | bool CheckTxInputs(const CTransaction &tx, TxValidationState &state, | ||||
const CCoinsViewCache &inputs, int nSpendHeight, | const CCoinsViewCache &inputs, int nSpendHeight, | ||||
Amount &txfee) { | Amount &txfee) { | ||||
▲ Show 20 Lines • Show All 50 Lines • Show Last 20 Lines |