Skip to content

Commit 31650b4

Browse files
committed
Merge bitcoin/bitcoin#32386: mining: rename gbt_force and gbt_force_name
0750249 mining: document gbt_rule_value helper (Sjors Provoost) 5e87c3e scripted-diff: rename gbt_force and gbt_force_name (Sjors Provoost) Pull request description: The term "force" is ambiguous and not used in [BIP9](https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki#getblocktemplate-changes) where there ! rule prefix is introduced. E.g. this code is hard to read: ```cpp if (!gbt_force) { s.insert(s.begin(), '!'); ``` Additionally, #29039 renamed `gbt_vb_name` to `gbt_force_name` which, at least for me, further increased the confusion. This is a pure (variable rename) refactor (plus documentation) and does not change behavior. Reminder of how to verify a scripted diff: ```sh test/lint/commit-script-check.sh origin/master..HEAD ``` ACKs for top commit: achow101: ACK 0750249 janb84: ACK [0750249](bitcoin/bitcoin@0750249) musaHaruna: ACK [0750249](bitcoin/bitcoin@0750249) glozow: ACK 0750249, seems sensible Tree-SHA512: 8c88a273a3b36040f6c641843bd20579d0065b051aad4b39fc14f0d2af2808690dff6772bd8b1a4d9699b72279a700d2661012651bc315433a123dcc8996adaa
2 parents bac43b9 + 0750249 commit 31650b4

File tree

5 files changed

+14
-13
lines changed

5 files changed

+14
-13
lines changed

src/deploymentinfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
const std::array<VBDeploymentInfo,Consensus::MAX_VERSION_BITS_DEPLOYMENTS> VersionBitsDeploymentInfo{
1212
VBDeploymentInfo{
1313
.name = "testdummy",
14-
.gbt_force = true,
14+
.gbt_optional_rule = true,
1515
},
1616
VBDeploymentInfo{
1717
.name = "taproot",
18-
.gbt_force = true,
18+
.gbt_optional_rule = true,
1919
},
2020
};
2121

src/deploymentinfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct VBDeploymentInfo {
1515
/** Deployment name */
1616
const char *name;
1717
/** Whether GBT clients can safely ignore this rule in simplified usage */
18-
bool gbt_force;
18+
bool gbt_optional_rule;
1919
};
2020

2121
extern const std::array<VBDeploymentInfo,Consensus::MAX_VERSION_BITS_DEPLOYMENTS> VersionBitsDeploymentInfo;

src/rpc/mining.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -596,10 +596,11 @@ static UniValue BIP22ValidationResult(const BlockValidationState& state)
596596
return "valid?";
597597
}
598598

599-
static std::string gbt_force_name(const std::string& name, bool gbt_force)
599+
// Prefix rule name with ! if not optional, see BIP9
600+
static std::string gbt_rule_value(const std::string& name, bool gbt_optional_rule)
600601
{
601602
std::string s{name};
602-
if (!gbt_force) {
603+
if (!gbt_optional_rule) {
603604
s.insert(s.begin(), '!');
604605
}
605606
return s;
@@ -955,25 +956,25 @@ static RPCHelpMan getblocktemplate()
955956
const auto gbtstatus = chainman.m_versionbitscache.GBTStatus(*pindexPrev, consensusParams);
956957

957958
for (const auto& [name, info] : gbtstatus.signalling) {
958-
vbavailable.pushKV(gbt_force_name(name, info.gbt_force), info.bit);
959-
if (!info.gbt_force && !setClientRules.count(name)) {
959+
vbavailable.pushKV(gbt_rule_value(name, info.gbt_optional_rule), info.bit);
960+
if (!info.gbt_optional_rule && !setClientRules.count(name)) {
960961
// If the client doesn't support this, don't indicate it in the [default] version
961962
block.nVersion &= ~info.mask;
962963
}
963964
}
964965

965966
for (const auto& [name, info] : gbtstatus.locked_in) {
966967
block.nVersion |= info.mask;
967-
vbavailable.pushKV(gbt_force_name(name, info.gbt_force), info.bit);
968-
if (!info.gbt_force && !setClientRules.count(name)) {
968+
vbavailable.pushKV(gbt_rule_value(name, info.gbt_optional_rule), info.bit);
969+
if (!info.gbt_optional_rule && !setClientRules.count(name)) {
969970
// If the client doesn't support this, don't indicate it in the [default] version
970971
block.nVersion &= ~info.mask;
971972
}
972973
}
973974

974975
for (const auto& [name, info] : gbtstatus.active) {
975-
aRules.push_back(gbt_force_name(name, info.gbt_force));
976-
if (!info.gbt_force && !setClientRules.count(name)) {
976+
aRules.push_back(gbt_rule_value(name, info.gbt_optional_rule));
977+
if (!info.gbt_optional_rule && !setClientRules.count(name)) {
977978
// Not supported by the client; make sure it's safe to proceed
978979
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Support for '%s' rule requires explicit client support", name));
979980
}

src/versionbits.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ BIP9GBTStatus VersionBitsCache::GBTStatus(const CBlockIndex& block_index, const
235235
VersionBitsConditionChecker checker(params, pos);
236236
ThresholdState state = checker.GetStateFor(&block_index, m_caches[pos]);
237237
const VBDeploymentInfo& vbdepinfo = VersionBitsDeploymentInfo[pos];
238-
BIP9GBTStatus::Info gbtinfo{.bit=params.vDeployments[pos].bit, .mask=checker.Mask(), .gbt_force=vbdepinfo.gbt_force};
238+
BIP9GBTStatus::Info gbtinfo{.bit=params.vDeployments[pos].bit, .mask=checker.Mask(), .gbt_optional_rule=vbdepinfo.gbt_optional_rule};
239239

240240
switch (state) {
241241
case DEFINED:

src/versionbits.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct BIP9GBTStatus {
6666
struct Info {
6767
int bit;
6868
uint32_t mask;
69-
bool gbt_force;
69+
bool gbt_optional_rule;
7070
};
7171
std::map<std::string, const Info, std::less<>> signalling, locked_in, active;
7272
};

0 commit comments

Comments
 (0)