Skip to content

Commit 0082f6a

Browse files
committed
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.
1 parent 79d45b1 commit 0082f6a

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/rpc/mining.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
using interfaces::BlockTemplate;
5050
using interfaces::Mining;
5151
using node::BlockAssembler;
52+
using node::GetMinimumTime;
5253
using node::NodeContext;
5354
using node::RegenerateCommitments;
5455
using node::UpdateTime;
@@ -674,7 +675,7 @@ static RPCHelpMan getblocktemplate()
674675
{RPCResult::Type::NUM, "coinbasevalue", "maximum allowable input to coinbase transaction, including the generation award and transaction fees (in satoshis)"},
675676
{RPCResult::Type::STR, "longpollid", "an id to include with a request to longpoll on an update to this template"},
676677
{RPCResult::Type::STR, "target", "The hash target"},
677-
{RPCResult::Type::NUM_TIME, "mintime", "The minimum timestamp appropriate for the next block time, expressed in " + UNIX_EPOCH_TIME},
678+
{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."},
678679
{RPCResult::Type::ARR, "mutable", "list of ways the block template may be changed",
679680
{
680681
{RPCResult::Type::STR, "value", "A way the block template may be changed, e.g. 'time', 'transactions', 'prevblock'"},
@@ -977,7 +978,7 @@ static RPCHelpMan getblocktemplate()
977978
result.pushKV("coinbasevalue", (int64_t)block.vtx[0]->vout[0].nValue);
978979
result.pushKV("longpollid", tip.GetHex() + ToString(nTransactionsUpdatedLast));
979980
result.pushKV("target", hashTarget.GetHex());
980-
result.pushKV("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1);
981+
result.pushKV("mintime", GetMinimumTime(pindexPrev, consensusParams.DifficultyAdjustmentInterval()));
981982
result.pushKV("mutable", std::move(aMutable));
982983
result.pushKV("noncerange", "00000000ffffffff");
983984
int64_t nSigOpLimit = MAX_BLOCK_SIGOPS_COST;

test/functional/mining_basic.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ def test_timewarp(self):
153153
# The template will have an adjusted timestamp, which we then modify
154154
tmpl = node.getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
155155
assert_greater_than_or_equal(tmpl['curtime'], t + MAX_FUTURE_BLOCK_TIME - MAX_TIMEWARP)
156+
# mintime and curtime should match
157+
assert_equal(tmpl['mintime'], tmpl['curtime'])
156158

157159
block = CBlock()
158160
block.nVersion = tmpl["version"]

0 commit comments

Comments
 (0)