From 0082f6acc1dc6c99007e232fc8f849ed8147fc9f Mon Sep 17 00:00:00 2001 From: Sjors Provoost Date: Wed, 29 Jan 2025 09:27:09 +0100 Subject: [PATCH] rpc: have mintime account for timewarp rule Previously in getblocktemplate only curtime took the timewarp rule into account. Mining pool software could use either, though in general it should use curtime. --- src/rpc/mining.cpp | 5 +++-- test/functional/mining_basic.py | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 3843e8b18ebac..fbfa7b8637fba 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -49,6 +49,7 @@ using interfaces::BlockTemplate; using interfaces::Mining; using node::BlockAssembler; +using node::GetMinimumTime; using node::NodeContext; using node::RegenerateCommitments; using node::UpdateTime; @@ -674,7 +675,7 @@ static RPCHelpMan getblocktemplate() {RPCResult::Type::NUM, "coinbasevalue", "maximum allowable input to coinbase transaction, including the generation award and transaction fees (in satoshis)"}, {RPCResult::Type::STR, "longpollid", "an id to include with a request to longpoll on an update to this template"}, {RPCResult::Type::STR, "target", "The hash target"}, - {RPCResult::Type::NUM_TIME, "mintime", "The minimum timestamp appropriate for the next block time, expressed in " + UNIX_EPOCH_TIME}, + {RPCResult::Type::NUM_TIME, "mintime", "The minimum timestamp appropriate for the next block time, expressed in " + UNIX_EPOCH_TIME + ". Adjusted for the proposed BIP94 timewarp rule."}, {RPCResult::Type::ARR, "mutable", "list of ways the block template may be changed", { {RPCResult::Type::STR, "value", "A way the block template may be changed, e.g. 'time', 'transactions', 'prevblock'"}, @@ -977,7 +978,7 @@ static RPCHelpMan getblocktemplate() result.pushKV("coinbasevalue", (int64_t)block.vtx[0]->vout[0].nValue); result.pushKV("longpollid", tip.GetHex() + ToString(nTransactionsUpdatedLast)); result.pushKV("target", hashTarget.GetHex()); - result.pushKV("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1); + result.pushKV("mintime", GetMinimumTime(pindexPrev, consensusParams.DifficultyAdjustmentInterval())); result.pushKV("mutable", std::move(aMutable)); result.pushKV("noncerange", "00000000ffffffff"); int64_t nSigOpLimit = MAX_BLOCK_SIGOPS_COST; diff --git a/test/functional/mining_basic.py b/test/functional/mining_basic.py index 979eda7d04218..827e05dcfed24 100755 --- a/test/functional/mining_basic.py +++ b/test/functional/mining_basic.py @@ -153,6 +153,8 @@ def test_timewarp(self): # The template will have an adjusted timestamp, which we then modify tmpl = node.getblocktemplate(NORMAL_GBT_REQUEST_PARAMS) assert_greater_than_or_equal(tmpl['curtime'], t + MAX_FUTURE_BLOCK_TIME - MAX_TIMEWARP) + # mintime and curtime should match + assert_equal(tmpl['mintime'], tmpl['curtime']) block = CBlock() block.nVersion = tmpl["version"]