Skip to content

Commit 31de241

Browse files
committed
Merge pull request #7011
6531f17 Add mediantime field to getblock and getblockheader (Peter Todd) 7259769 Document new mediantime field in getblockchaininfo (Peter Todd) c277a63 Clarify nLockTime-by-time comment in CheckFinalTx() (Peter Todd) 748321e Add mediantime field to getblockchaininfo RPC call (Peter Todd)
2 parents 616d61b + 6531f17 commit 31de241

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/main.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -670,10 +670,11 @@ bool CheckFinalTx(const CTransaction &tx, int flags)
670670
// IsFinalTx() with one more than chainActive.Height().
671671
const int nBlockHeight = chainActive.Height() + 1;
672672

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:
673+
// BIP113 will require that time-locked transactions have nLockTime set to
674+
// less than the median time of the previous block they're contained in.
675+
// When the next block is created its previous block will be the current
676+
// chain tip, so we use that to calculate the median time passed to
677+
// IsFinalTx() if LOCKTIME_MEDIAN_TIME_PAST is set.
677678
const int64_t nBlockTime = (flags & LOCKTIME_MEDIAN_TIME_PAST)
678679
? chainActive.Tip()->GetMedianTimePast()
679680
: GetAdjustedTime();

src/rpcblockchain.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ UniValue blockheaderToJSON(const CBlockIndex* blockindex)
7171
result.push_back(Pair("version", blockindex->nVersion));
7272
result.push_back(Pair("merkleroot", blockindex->hashMerkleRoot.GetHex()));
7373
result.push_back(Pair("time", (int64_t)blockindex->nTime));
74+
result.push_back(Pair("mediantime", (int64_t)blockindex->GetMedianTimePast()));
7475
result.push_back(Pair("nonce", (uint64_t)blockindex->nNonce));
7576
result.push_back(Pair("bits", strprintf("%08x", blockindex->nBits)));
7677
result.push_back(Pair("difficulty", GetDifficulty(blockindex)));
@@ -111,6 +112,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx
111112
}
112113
result.push_back(Pair("tx", txs));
113114
result.push_back(Pair("time", block.GetBlockTime()));
115+
result.push_back(Pair("mediantime", (int64_t)blockindex->GetMedianTimePast()));
114116
result.push_back(Pair("nonce", (uint64_t)block.nNonce));
115117
result.push_back(Pair("bits", strprintf("%08x", block.nBits)));
116118
result.push_back(Pair("difficulty", GetDifficulty(blockindex)));
@@ -313,6 +315,7 @@ UniValue getblockheader(const UniValue& params, bool fHelp)
313315
" \"version\" : n, (numeric) The block version\n"
314316
" \"merkleroot\" : \"xxxx\", (string) The merkle root\n"
315317
" \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
318+
" \"mediantime\" : ttt, (numeric) The median block time in seconds since epoch (Jan 1 1970 GMT)\n"
316319
" \"nonce\" : n, (numeric) The nonce\n"
317320
" \"bits\" : \"1d00ffff\", (string) The bits\n"
318321
" \"difficulty\" : x.xxx, (numeric) The difficulty\n"
@@ -374,6 +377,7 @@ UniValue getblock(const UniValue& params, bool fHelp)
374377
" ,...\n"
375378
" ],\n"
376379
" \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
380+
" \"mediantime\" : ttt, (numeric) The median block time in seconds since epoch (Jan 1 1970 GMT)\n"
377381
" \"nonce\" : n, (numeric) The nonce\n"
378382
" \"bits\" : \"1d00ffff\", (string) The bits\n"
379383
" \"difficulty\" : x.xxx, (numeric) The difficulty\n"
@@ -608,6 +612,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
608612
" \"headers\": xxxxxx, (numeric) the current number of headers we have validated\n"
609613
" \"bestblockhash\": \"...\", (string) the hash of the currently best block\n"
610614
" \"difficulty\": xxxxxx, (numeric) the current difficulty\n"
615+
" \"mediantime\": xxxxxx, (numeric) median time for the current best block\n"
611616
" \"verificationprogress\": xxxx, (numeric) estimate of verification progress [0..1]\n"
612617
" \"chainwork\": \"xxxx\" (string) total amount of work in active chain, in hexadecimal\n"
613618
" \"pruned\": xx, (boolean) if the blocks are subject to pruning\n"
@@ -639,6 +644,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
639644
obj.push_back(Pair("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1));
640645
obj.push_back(Pair("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex()));
641646
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
647+
obj.push_back(Pair("mediantime", (int64_t)chainActive.Tip()->GetMedianTimePast()));
642648
obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(Params().Checkpoints(), chainActive.Tip())));
643649
obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex()));
644650
obj.push_back(Pair("pruned", fPruneMode));

0 commit comments

Comments
 (0)