Skip to content

Commit 8fe30fb

Browse files
committed
Merge pull request #6928
40cd32e Revert "Add rules--presently disabled--for using GetMedianTimePast as endpoint for lock-time calculations" (Gregory Maxwell) 8537ecd Revert "Enable policy enforcing GetMedianTimePast as the end point of lock-time constraints" (Gregory Maxwell)
2 parents a6d0d62 + 40cd32e commit 8fe30fb

File tree

6 files changed

+10
-58
lines changed

6 files changed

+10
-58
lines changed

src/consensus/consensus.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,4 @@ static const unsigned int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;
1313
/** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */
1414
static const int COINBASE_MATURITY = 100;
1515

16-
/** Flags for LockTime() */
17-
enum {
18-
/* Use GetMedianTimePast() instead of nTime for end point timestamp. */
19-
LOCKTIME_MEDIAN_TIME_PAST = (1 << 1),
20-
};
21-
2216
#endif // BITCOIN_CONSENSUS_CONSENSUS_H

src/main.cpp

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -650,35 +650,10 @@ bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
650650
return true;
651651
}
652652

653-
bool CheckFinalTx(const CTransaction &tx, int flags)
653+
bool CheckFinalTx(const CTransaction &tx)
654654
{
655655
AssertLockHeld(cs_main);
656-
657-
// By convention a negative value for flags indicates that the
658-
// current network-enforced consensus rules should be used. In
659-
// a future soft-fork scenario that would mean checking which
660-
// rules would be enforced for the next block and setting the
661-
// appropriate flags. At the present time no soft-forks are
662-
// scheduled, so no flags are set.
663-
flags = std::max(flags, 0);
664-
665-
// CheckFinalTx() uses chainActive.Height()+1 to evaluate
666-
// nLockTime because when IsFinalTx() is called within
667-
// CBlock::AcceptBlock(), the height of the block *being*
668-
// evaluated is what is used. Thus if we want to know if a
669-
// transaction can be part of the *next* block, we need to call
670-
// IsFinalTx() with one more than chainActive.Height().
671-
const int nBlockHeight = chainActive.Height() + 1;
672-
673-
// Timestamps on the other hand don't get any special treatment,
674-
// because we can't know what timestamp the next block will have,
675-
// and there aren't timestamp applications where it matters.
676-
// However this changes once median past time-locks are enforced:
677-
const int64_t nBlockTime = (flags & LOCKTIME_MEDIAN_TIME_PAST)
678-
? chainActive.Tip()->GetMedianTimePast()
679-
: GetAdjustedTime();
680-
681-
return IsFinalTx(tx, nBlockHeight, nBlockTime);
656+
return IsFinalTx(tx, chainActive.Height() + 1, GetAdjustedTime());
682657
}
683658

684659
unsigned int GetLegacySigOpCount(const CTransaction& tx)
@@ -822,7 +797,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
822797
// Only accept nLockTime-using transactions that can be mined in the next
823798
// block; we don't want our mempool filled up with transactions that can't
824799
// be mined yet.
825-
if (!CheckFinalTx(tx, STANDARD_LOCKTIME_VERIFY_FLAGS))
800+
if (!CheckFinalTx(tx))
826801
return state.DoS(0, false, REJECT_NONSTANDARD, "non-final");
827802

828803
// is it already in the memory pool?
@@ -2748,15 +2723,10 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn
27482723
const Consensus::Params& consensusParams = Params().GetConsensus();
27492724

27502725
// Check that all transactions are finalized
2751-
BOOST_FOREACH(const CTransaction& tx, block.vtx) {
2752-
int nLockTimeFlags = 0;
2753-
int64_t nLockTimeCutoff = (nLockTimeFlags & LOCKTIME_MEDIAN_TIME_PAST)
2754-
? pindexPrev->GetMedianTimePast()
2755-
: block.GetBlockTime();
2756-
if (!IsFinalTx(tx, nHeight, nLockTimeCutoff)) {
2726+
BOOST_FOREACH(const CTransaction& tx, block.vtx)
2727+
if (!IsFinalTx(tx, nHeight, block.GetBlockTime())) {
27572728
return state.DoS(10, error("%s: contains a non-final transaction", __func__), REJECT_INVALID, "bad-txns-nonfinal");
27582729
}
2759-
}
27602730

27612731
// Enforce block.nVersion=2 rule that the coinbase starts with serialized block height
27622732
// if 750 of the last 1,000 blocks are version 2 or greater (51/100 if testnet):

src/main.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,8 @@ bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime);
308308
* Check if transaction will be final in the next block to be created.
309309
*
310310
* Calls IsFinalTx() with current block height and appropriate block time.
311-
*
312-
* See consensus/consensus.h for flag definitions.
313311
*/
314-
bool CheckFinalTx(const CTransaction &tx, int flags = -1);
312+
bool CheckFinalTx(const CTransaction &tx);
315313

316314
/**
317315
* Closure representing one script verification

src/miner.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
148148
CBlockIndex* pindexPrev = chainActive.Tip();
149149
const int nHeight = pindexPrev->nHeight + 1;
150150
pblock->nTime = GetAdjustedTime();
151-
const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast();
152151
CCoinsViewCache view(pcoinsTip);
153152

154153
// Priority order to process transactions
@@ -163,12 +162,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
163162
mi != mempool.mapTx.end(); ++mi)
164163
{
165164
const CTransaction& tx = mi->GetTx();
166-
167-
int64_t nLockTimeCutoff = (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST)
168-
? nMedianTimePast
169-
: pblock->GetBlockTime();
170-
171-
if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff))
165+
if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, pblock->nTime))
172166
continue;
173167

174168
COrphan* porphan = NULL;

src/policy/policy.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ static const unsigned int STANDARD_SCRIPT_VERIFY_FLAGS = MANDATORY_SCRIPT_VERIFY
4343
/** For convenience, standard but not mandatory verify flags. */
4444
static const unsigned int STANDARD_NOT_MANDATORY_VERIFY_FLAGS = STANDARD_SCRIPT_VERIFY_FLAGS & ~MANDATORY_SCRIPT_VERIFY_FLAGS;
4545

46-
/** Used as the flags parameter to CheckFinalTx() in non-consensus code */
47-
static const unsigned int STANDARD_LOCKTIME_VERIFY_FLAGS = LOCKTIME_MEDIAN_TIME_PAST;
48-
4946
bool IsStandard(const CScript& scriptPubKey, txnouttype& whichType);
5047
/**
5148
* Check for standard transaction types

src/test/miner_tests.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include "chainparams.h"
66
#include "coins.h"
7-
#include "consensus/consensus.h"
87
#include "consensus/validation.h"
98
#include "main.h"
109
#include "miner.h"
@@ -230,7 +229,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
230229
tx.nLockTime = chainActive.Tip()->nHeight+1;
231230
hash = tx.GetHash();
232231
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
233-
BOOST_CHECK(!CheckFinalTx(tx, LOCKTIME_MEDIAN_TIME_PAST));
232+
BOOST_CHECK(!CheckFinalTx(tx));
234233

235234
// time locked
236235
tx2.vin.resize(1);
@@ -244,7 +243,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
244243
tx2.nLockTime = chainActive.Tip()->GetMedianTimePast()+1;
245244
hash = tx2.GetHash();
246245
mempool.addUnchecked(hash, CTxMemPoolEntry(tx2, 11, GetTime(), 111.0, 11));
247-
BOOST_CHECK(!CheckFinalTx(tx2, LOCKTIME_MEDIAN_TIME_PAST));
246+
BOOST_CHECK(!CheckFinalTx(tx2));
248247

249248
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
250249

@@ -262,7 +261,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
262261
//BOOST_CHECK(CheckFinalTx(tx2));
263262

264263
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
265-
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 2);
264+
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 3);
266265
delete pblocktemplate;
267266

268267
chainActive.Tip()->nHeight--;

0 commit comments

Comments
 (0)