Implement BIP 9 GBT changes
- BIP9DeploymentInfo struct for static deployment info - VersionBitsDeploymentInfo: Avoid C++11ism by commenting parameter names - getblocktemplate: Make sure to set deployments in the version if it is LOCKED_IN - In this commit, all rules are considered required for clients to support
This commit is contained in:
parent
71527a0f31
commit
d3df40e51a
6 changed files with 70 additions and 3 deletions
|
@ -16,6 +16,7 @@ enum DeploymentPos
|
|||
{
|
||||
DEPLOYMENT_TESTDUMMY,
|
||||
DEPLOYMENT_CSV, // Deployment of BIP68, BIP112, and BIP113.
|
||||
// NOTE: Also add new deployments to VersionBitsDeploymentInfo in versionbits.cpp
|
||||
MAX_VERSION_BITS_DEPLOYMENTS
|
||||
};
|
||||
|
||||
|
|
|
@ -2122,7 +2122,7 @@ void PartitionCheck(bool (*initialDownloadCheck)(), CCriticalSection& cs, const
|
|||
}
|
||||
|
||||
// Protected by cs_main
|
||||
static VersionBitsCache versionbitscache;
|
||||
VersionBitsCache versionbitscache;
|
||||
|
||||
int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Params& params)
|
||||
{
|
||||
|
|
|
@ -551,6 +551,8 @@ extern CBlockTreeDB *pblocktree;
|
|||
*/
|
||||
int GetSpendHeight(const CCoinsViewCache& inputs);
|
||||
|
||||
extern VersionBitsCache versionbitscache;
|
||||
|
||||
/**
|
||||
* Determine what nVersion a new block should use.
|
||||
*/
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "chain.h"
|
||||
#include "chainparams.h"
|
||||
#include "consensus/consensus.h"
|
||||
#include "consensus/params.h"
|
||||
#include "consensus/validation.h"
|
||||
#include "core_io.h"
|
||||
#include "init.h"
|
||||
|
@ -260,6 +261,13 @@ static UniValue BIP22ValidationResult(const CValidationState& state)
|
|||
return "valid?";
|
||||
}
|
||||
|
||||
std::string gbt_vb_name(const Consensus::DeploymentPos pos) {
|
||||
const struct BIP9DeploymentInfo& vbinfo = VersionBitsDeploymentInfo[pos];
|
||||
std::string s = vbinfo.name;
|
||||
s.insert(s.begin(), '!');
|
||||
return s;
|
||||
}
|
||||
|
||||
UniValue getblocktemplate(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() > 1)
|
||||
|
@ -267,7 +275,9 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
|
|||
"getblocktemplate ( \"jsonrequestobject\" )\n"
|
||||
"\nIf the request parameters include a 'mode' key, that is used to explicitly select between the default 'template' request or a 'proposal'.\n"
|
||||
"It returns data needed to construct a block to work on.\n"
|
||||
"See https://en.bitcoin.it/wiki/BIP_0022 for full specification.\n"
|
||||
"For full specification, see BIPs 22 and 9:\n"
|
||||
" https://github.com/bitcoin/bips/blob/master/bip-0022.mediawiki\n"
|
||||
" https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki#getblocktemplate_changes\n"
|
||||
|
||||
"\nArguments:\n"
|
||||
"1. \"jsonrequestobject\" (string, optional) A json object in the following spec\n"
|
||||
|
@ -283,6 +293,12 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
|
|||
"\nResult:\n"
|
||||
"{\n"
|
||||
" \"version\" : n, (numeric) The block version\n"
|
||||
" \"rules\" : [ \"rulename\", ... ], (array of strings) specific block rules that are to be enforced\n"
|
||||
" \"vbavailable\" : { (json object) set of pending, supported versionbit (BIP 9) softfork deployments\n"
|
||||
" \"rulename\" : bitnumber (numeric) identifies the bit number as indicating acceptance and readiness for the named softfork rule\n"
|
||||
" ,...\n"
|
||||
" },\n"
|
||||
" \"vbrequired\" : n, (numeric) bit mask of versionbits the server requires set in submissions\n"
|
||||
" \"previousblockhash\" : \"xxxx\", (string) The hash of current highest block\n"
|
||||
" \"transactions\" : [ (array) contents of non-coinbase transactions that should be included in the next block\n"
|
||||
" {\n"
|
||||
|
@ -458,9 +474,10 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
|
|||
pindexPrev = pindexPrevNew;
|
||||
}
|
||||
CBlock* pblock = &pblocktemplate->block; // pointer for convenience
|
||||
const Consensus::Params& consensusParams = Params().GetConsensus();
|
||||
|
||||
// Update nTime
|
||||
UpdateTime(pblock, Params().GetConsensus(), pindexPrev);
|
||||
UpdateTime(pblock, consensusParams, pindexPrev);
|
||||
pblock->nNonce = 0;
|
||||
|
||||
UniValue aCaps(UniValue::VARR); aCaps.push_back("proposal");
|
||||
|
@ -511,7 +528,36 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
|
|||
|
||||
UniValue result(UniValue::VOBJ);
|
||||
result.push_back(Pair("capabilities", aCaps));
|
||||
|
||||
UniValue aRules(UniValue::VARR);
|
||||
UniValue vbavailable(UniValue::VOBJ);
|
||||
for (int i = 0; i < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++i) {
|
||||
Consensus::DeploymentPos pos = Consensus::DeploymentPos(i);
|
||||
ThresholdState state = VersionBitsState(pindexPrev, consensusParams, pos, versionbitscache);
|
||||
switch (state) {
|
||||
case THRESHOLD_DEFINED:
|
||||
case THRESHOLD_FAILED:
|
||||
// Not exposed to GBT at all
|
||||
break;
|
||||
case THRESHOLD_LOCKED_IN:
|
||||
// Ensure bit is set in block version
|
||||
pblock->nVersion |= VersionBitsMask(consensusParams, pos);
|
||||
// FALL THROUGH to get vbavailable set...
|
||||
case THRESHOLD_STARTED:
|
||||
// Add to vbavailable (and it's presumably in version already)
|
||||
vbavailable.push_back(Pair(gbt_vb_name(pos), consensusParams.vDeployments[pos].bit));
|
||||
break;
|
||||
case THRESHOLD_ACTIVE:
|
||||
// Add to rules only
|
||||
aRules.push_back(gbt_vb_name(pos));
|
||||
break;
|
||||
}
|
||||
}
|
||||
result.push_back(Pair("version", pblock->nVersion));
|
||||
result.push_back(Pair("rules", aRules));
|
||||
result.push_back(Pair("vbavailable", vbavailable));
|
||||
result.push_back(Pair("vbrequired", int(0)));
|
||||
|
||||
result.push_back(Pair("previousblockhash", pblock->hashPrevBlock.GetHex()));
|
||||
result.push_back(Pair("transactions", transactions));
|
||||
result.push_back(Pair("coinbaseaux", aux));
|
||||
|
|
|
@ -4,6 +4,17 @@
|
|||
|
||||
#include "versionbits.h"
|
||||
|
||||
#include "consensus/params.h"
|
||||
|
||||
const struct BIP9DeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION_BITS_DEPLOYMENTS] = {
|
||||
{
|
||||
/*.name =*/ "testdummy",
|
||||
},
|
||||
{
|
||||
/*.name =*/ "csv",
|
||||
}
|
||||
};
|
||||
|
||||
ThresholdState AbstractThresholdConditionChecker::GetStateFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const
|
||||
{
|
||||
int nPeriod = Period(params);
|
||||
|
|
|
@ -30,6 +30,13 @@ enum ThresholdState {
|
|||
// will either be NULL or a block with (height + 1) % Period() == 0.
|
||||
typedef std::map<const CBlockIndex*, ThresholdState> ThresholdConditionCache;
|
||||
|
||||
struct BIP9DeploymentInfo {
|
||||
/** Deployment name */
|
||||
const char *name;
|
||||
};
|
||||
|
||||
extern const struct BIP9DeploymentInfo VersionBitsDeploymentInfo[];
|
||||
|
||||
/**
|
||||
* Abstract class that implements BIP9-style threshold logic, and caches results.
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue