summaryrefslogtreecommitdiff
path: root/bip-0068.mediawiki
diff options
context:
space:
mode:
authorLuke-Jr <luke_github1@dashjr.org>2016-02-04 23:51:03 +0000
committerLuke-Jr <luke_github1@dashjr.org>2016-02-04 23:51:03 +0000
commita6d333ed6bc25b717fce52f08124baac0777f4d9 (patch)
treed85a7dcf647c45ddb31d7f5c22e9ff07151b62b3 /bip-0068.mediawiki
parent3c6a8e5f9160f84b3d9dfd352816834a9c994225 (diff)
parent4a515ee2dc5917066a8b126187cd733f4d252a82 (diff)
downloadbips-a6d333ed6bc25b717fce52f08124baac0777f4d9.tar.xz
Merge pull request #319 from btcdrak/bip68nit
Minor update of implementation for BIP68
Diffstat (limited to 'bip-0068.mediawiki')
-rw-r--r--bip-0068.mediawiki25
1 files changed, 15 insertions, 10 deletions
diff --git a/bip-0068.mediawiki b/bip-0068.mediawiki
index e93d748..3183cff 100644
--- a/bip-0068.mediawiki
+++ b/bip-0068.mediawiki
@@ -89,10 +89,10 @@ static const uint32_t SEQUENCE_LOCKTIME_MASK = 0x0000ffff;
static const int SEQUENCE_LOCKTIME_GRANULARITY = 9;
/**
- * Calculates the block height and time which the transaction must be later than
- * in order to be considered final in the context of BIP 68. It 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.
+ * 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.
+ * 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.
*/
static std::pair<int, int64_t> CalculateSequenceLocks(const CTransaction &tx, int flags, std::vector<int>* prevHeights, const CBlockIndex& block)
{
@@ -134,6 +134,14 @@ static std::pair<int, int64_t> CalculateSequenceLocks(const CTransaction &tx, in
if (txin.nSequence & CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG) {
int64_t nCoinTime = block.GetAncestor(std::max(nCoinHeight-1, 0))->GetMedianTimePast();
+ // NOTE: Subtract 1 to maintain nLockTime semantics
+ // BIP 68 relative lock times have the semantics of calculating
+ // the first block or time at which the transaction would be
+ // valid. When calculating the effective block time or height
+ // for the entire transaction, we switch to using the
+ // semantics of nLockTime which is the last invalid block
+ // time or height. Thus we subtract 1 from the calculated
+ // time or height.
// Time-based relative lock-times are measured from the
// smallest allowed timestamp of the block containing the
@@ -141,10 +149,6 @@ static std::pair<int, int64_t> CalculateSequenceLocks(const CTransaction &tx, in
// block prior.
nMinTime = std::max(nMinTime, nCoinTime + (int64_t)((txin.nSequence & CTxIn::SEQUENCE_LOCKTIME_MASK) << CTxIn::SEQUENCE_LOCKTIME_GRANULARITY) - 1);
} else {
- // We subtract 1 from relative lock-times because a lock-
- // time of 0 has the semantics of "same block," so a lock-
- // time of 1 should mean "next block," but nLockTime has
- // the semantics of "last invalid block height."
nMinHeight = std::max(nMinHeight, nCoinHeight + (int)(txin.nSequence & CTxIn::SEQUENCE_LOCKTIME_MASK) - 1);
}
}
@@ -154,7 +158,8 @@ static std::pair<int, int64_t> CalculateSequenceLocks(const CTransaction &tx, in
static bool EvaluateSequenceLocks(const CBlockIndex& block, std::pair<int, int64_t> lockPair)
{
- int64_t nBlockTime = block.pprev ? block.pprev->GetMedianTimePast() : 0;
+ assert(block.pprev);
+ int64_t nBlockTime = block.pprev->GetMedianTimePast();
if (lockPair.first >= block.nHeight || lockPair.second >= nBlockTime)
return false;
@@ -189,7 +194,7 @@ bool CheckSequenceLocks(const CTransaction &tx, int flags)
const CTxIn& txin = tx.vin[txinIndex];
CCoins coins;
if (!viewMemPool.GetCoins(txin.prevout.hash, coins)) {
- return error("%s: Missing input", __func__);
+ return error("%s: Missing input", __func__);
}
if (coins.nHeight == MEMPOOL_HEIGHT) {
// Assume all mempool transaction confirm in the next block