aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rpcmining.cpp27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp
index 5275148870..18c3b3a511 100644
--- a/src/rpcmining.cpp
+++ b/src/rpcmining.cpp
@@ -405,6 +405,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
std::string strMode = "template";
UniValue lpval = NullUniValue;
std::set<std::string> setClientRules;
+ int64_t nMaxVersionPreVB = -1;
if (params.size() > 0)
{
const UniValue& oparam = params[0].get_obj();
@@ -455,6 +456,12 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
const UniValue& v = aClientRules[i];
setClientRules.insert(v.get_str());
}
+ } else {
+ // NOTE: It is important that this NOT be read if versionbits is supported
+ const UniValue& uvMaxVersion = find_value(oparam, "maxversion");
+ if (uvMaxVersion.isNum()) {
+ nMaxVersionPreVB = uvMaxVersion.get_int64();
+ }
}
}
@@ -589,13 +596,10 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits);
- static UniValue aMutable(UniValue::VARR);
- if (aMutable.empty())
- {
- aMutable.push_back("time");
- aMutable.push_back("transactions");
- aMutable.push_back("prevblock");
- }
+ UniValue aMutable(UniValue::VARR);
+ aMutable.push_back("time");
+ aMutable.push_back("transactions");
+ aMutable.push_back("prevblock");
UniValue result(UniValue::VOBJ);
result.push_back(Pair("capabilities", aCaps));
@@ -634,6 +638,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
if (setClientRules.find(vbinfo.name) == setClientRules.end()) {
// Not supported by the client; make sure it's safe to proceed
if (!vbinfo.gbt_force) {
+ // If we do anything other than throw an exception here, be sure version/force isn't sent to old clients
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Support for '%s' rule requires explicit client support", vbinfo.name));
}
}
@@ -646,6 +651,14 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
result.push_back(Pair("vbavailable", vbavailable));
result.push_back(Pair("vbrequired", int(0)));
+ if (nMaxVersionPreVB >= 2) {
+ // If VB is supported by the client, nMaxVersionPreVB is -1, so we won't get here
+ // Because BIP 34 changed how the generation transaction is serialised, we can only use version/force back to v2 blocks
+ // This is safe to do [otherwise-]unconditionally only because we are throwing an exception above if a non-force deployment gets activated
+ // Note that this can probably also be removed entirely after the first BIP9 non-force deployment (ie, probably segwit) gets activated
+ aMutable.push_back("version/force");
+ }
+
result.push_back(Pair("previousblockhash", pblock->hashPrevBlock.GetHex()));
result.push_back(Pair("transactions", transactions));
result.push_back(Pair("coinbaseaux", aux));