aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Dashjr <luke-jr+git@utopios.org>2016-06-01 16:47:36 +0000
committerLuke Dashjr <luke-jr+git@utopios.org>2016-06-08 18:42:17 +0000
commit65ee3324fbd6799241acada1320b684651bad892 (patch)
tree4efdc5d0fed8be6ebd9e40d5b28e207ca14f7eac
parent40e81f5f57a9f317b534b12ecb851845a91b3276 (diff)
downloadbitcoin-65ee3324fbd6799241acada1320b684651bad892.tar.xz
getblocktemplate: Explicitly handle the distinction between GBT-affecting softforks vs not
-rw-r--r--src/rpcmining.cpp32
-rw-r--r--src/versionbits.cpp2
-rw-r--r--src/versionbits.h2
3 files changed, 34 insertions, 2 deletions
diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp
index 6befd0a575..5275148870 100644
--- a/src/rpcmining.cpp
+++ b/src/rpcmining.cpp
@@ -324,7 +324,9 @@ static UniValue BIP22ValidationResult(const CValidationState& state)
std::string gbt_vb_name(const Consensus::DeploymentPos pos) {
const struct BIP9DeploymentInfo& vbinfo = VersionBitsDeploymentInfo[pos];
std::string s = vbinfo.name;
- s.insert(s.begin(), '!');
+ if (!vbinfo.gbt_force) {
+ s.insert(s.begin(), '!');
+ }
return s;
}
@@ -402,6 +404,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
std::string strMode = "template";
UniValue lpval = NullUniValue;
+ std::set<std::string> setClientRules;
if (params.size() > 0)
{
const UniValue& oparam = params[0].get_obj();
@@ -445,6 +448,14 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
TestBlockValidity(state, Params(), block, pindexPrev, false, true);
return BIP22ValidationResult(state);
}
+
+ const UniValue& aClientRules = find_value(oparam, "rules");
+ if (aClientRules.isArray()) {
+ for (unsigned int i = 0; i < aClientRules.size(); ++i) {
+ const UniValue& v = aClientRules[i];
+ setClientRules.insert(v.get_str());
+ }
+ }
}
if (strMode != "template")
@@ -604,13 +615,30 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
pblock->nVersion |= VersionBitsMask(consensusParams, pos);
// FALL THROUGH to get vbavailable set...
case THRESHOLD_STARTED:
- // Add to vbavailable (and it's presumably in version already)
+ {
+ const struct BIP9DeploymentInfo& vbinfo = VersionBitsDeploymentInfo[pos];
vbavailable.push_back(Pair(gbt_vb_name(pos), consensusParams.vDeployments[pos].bit));
+ if (setClientRules.find(vbinfo.name) == setClientRules.end()) {
+ if (!vbinfo.gbt_force) {
+ // If the client doesn't support this, don't indicate it in the [default] version
+ pblock->nVersion &= ~VersionBitsMask(consensusParams, pos);
+ }
+ }
break;
+ }
case THRESHOLD_ACTIVE:
+ {
// Add to rules only
+ const struct BIP9DeploymentInfo& vbinfo = VersionBitsDeploymentInfo[pos];
aRules.push_back(gbt_vb_name(pos));
+ if (setClientRules.find(vbinfo.name) == setClientRules.end()) {
+ // Not supported by the client; make sure it's safe to proceed
+ if (!vbinfo.gbt_force) {
+ throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Support for '%s' rule requires explicit client support", vbinfo.name));
+ }
+ }
break;
+ }
}
}
result.push_back(Pair("version", pblock->nVersion));
diff --git a/src/versionbits.cpp b/src/versionbits.cpp
index 041ca2adbc..c06c9907be 100644
--- a/src/versionbits.cpp
+++ b/src/versionbits.cpp
@@ -9,9 +9,11 @@
const struct BIP9DeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION_BITS_DEPLOYMENTS] = {
{
/*.name =*/ "testdummy",
+ /*.gbt_force =*/ true,
},
{
/*.name =*/ "csv",
+ /*.gbt_force =*/ true,
}
};
diff --git a/src/versionbits.h b/src/versionbits.h
index d805942028..ede2dcdda8 100644
--- a/src/versionbits.h
+++ b/src/versionbits.h
@@ -33,6 +33,8 @@ typedef std::map<const CBlockIndex*, ThresholdState> ThresholdConditionCache;
struct BIP9DeploymentInfo {
/** Deployment name */
const char *name;
+ /** Whether GBT clients can safely ignore this rule in simplified usage */
+ bool gbt_force;
};
extern const struct BIP9DeploymentInfo VersionBitsDeploymentInfo[];