aboutsummaryrefslogtreecommitdiff
path: root/src/miner.cpp
diff options
context:
space:
mode:
authorMark Friedenbach <mark@friedenbach.org>2015-06-03 12:55:45 -0700
committerBtcDrak <btcdrak@gmail.com>2015-10-23 21:33:31 +0100
commita1d3c6fb9de8a3fc3e36bc3753a6831cb1dfdbcb (patch)
treec1e715d570a58016ced625d97cf7cb9e95b06485 /src/miner.cpp
parentdfe55bdc32b5333dcce1a7f2c74628f64028d1fe (diff)
downloadbitcoin-a1d3c6fb9de8a3fc3e36bc3753a6831cb1dfdbcb.tar.xz
Add rules--presently disabled--for using GetMedianTimePast as endpoint for lock-time calculations
The lock-time code currently uses CBlock::nTime as the cutoff point for time based locked transactions. This has the unfortunate outcome of creating a perverse incentive for miners to lie about the time of a block in order to collect more fees by including transactions that by wall clock determination have not yet matured. By using CBlockIndex::GetMedianTimePast from the prior block instead, the self-interested miner no longer gains from generating blocks with fraudulent timestamps. Users can compensate for this change by simply adding an hour (3600 seconds) to their time-based lock times. If enforced, this would be a soft-fork change. This commit only adds the functionality on an unexecuted code path, without changing the behaviour of Bitcoin Core.
Diffstat (limited to 'src/miner.cpp')
-rw-r--r--src/miner.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/miner.cpp b/src/miner.cpp
index f5919ca3af..5972f74212 100644
--- a/src/miner.cpp
+++ b/src/miner.cpp
@@ -139,6 +139,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
CBlockIndex* pindexPrev = chainActive.Tip();
const int nHeight = pindexPrev->nHeight + 1;
pblock->nTime = GetAdjustedTime();
+ const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast();
CCoinsViewCache view(pcoinsTip);
// Priority order to process transactions
@@ -153,7 +154,12 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
mi != mempool.mapTx.end(); ++mi)
{
const CTransaction& tx = mi->second.GetTx();
- if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, pblock->nTime))
+
+ int64_t nLockTimeCutoff = (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST)
+ ? nMedianTimePast
+ : pblock->GetBlockTime();
+
+ if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff))
continue;
COrphan* porphan = NULL;