Skip to content

Commit

Permalink
Disable mining by default on development branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeShark committed May 26, 2016
1 parent 5b0cd48 commit 34ec9e8
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions share/genbuild.sh
Expand Up @@ -15,6 +15,7 @@ fi

DESC=""
SUFFIX=""
BRANCH_NAME=""
LAST_COMMIT_DATE=""
if [ -e "$(which git 2>/dev/null)" -a "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then
# clean 'dirty' status of touched files that haven't been modified
Expand All @@ -30,6 +31,9 @@ if [ -e "$(which git 2>/dev/null)" -a "$(git rev-parse --is-inside-work-tree 2>/
SUFFIX=$(git rev-parse --short HEAD)
git diff-index --quiet HEAD -- || SUFFIX="$SUFFIX-dirty"

# get branch name
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)

# get a string like "2012-04-10 16:27:19 +0200"
LAST_COMMIT_DATE="$(git log -n 1 --format="%ci")"
fi
Expand All @@ -45,6 +49,9 @@ fi
# only update build.h if necessary
if [ "$INFO" != "$NEWINFO" ]; then
echo "$NEWINFO" >"$FILE"
if [ -n "$BRANCH_NAME" ]; then
echo "#define BRANCH_NAME \"$BRANCH_NAME\"" >> "$FILE"
fi
if [ -n "$LAST_COMMIT_DATE" ]; then
echo "#define BUILD_DATE \"$LAST_COMMIT_DATE\"" >> "$FILE"
fi
Expand Down
4 changes: 4 additions & 0 deletions src/chainparams.cpp
Expand Up @@ -135,6 +135,7 @@ class CMainParams : public CChainParams {
fRequireStandard = true;
fMineBlocksOnDemand = false;
fTestnetToBeDeprecatedFieldRPC = false;
fMineOnDevelopmentBranch = false;

checkpointData = (CCheckpointData) {
boost::assign::map_list_of
Expand Down Expand Up @@ -225,6 +226,7 @@ class CTestNetParams : public CChainParams {
fRequireStandard = false;
fMineBlocksOnDemand = false;
fTestnetToBeDeprecatedFieldRPC = true;
fMineOnDevelopmentBranch = true;

checkpointData = (CCheckpointData) {
boost::assign::map_list_of
Expand Down Expand Up @@ -294,6 +296,7 @@ class CSegNetParams : public CChainParams {
fRequireStandard = false;
fMineBlocksOnDemand = false;
fTestnetToBeDeprecatedFieldRPC = true;
fMineOnDevelopmentBranch = true;

// checkpointData is empty
}
Expand Down Expand Up @@ -350,6 +353,7 @@ class CRegTestParams : public CChainParams {
fRequireStandard = false;
fMineBlocksOnDemand = true;
fTestnetToBeDeprecatedFieldRPC = false;
fMineOnDevelopmentBranch = true;

checkpointData = (CCheckpointData){
boost::assign::map_list_of
Expand Down
3 changes: 3 additions & 0 deletions src/chainparams.h
Expand Up @@ -68,6 +68,8 @@ class CChainParams
bool MineBlocksOnDemand() const { return fMineBlocksOnDemand; }
/** In the future use NetworkIDString() for RPC fields */
bool TestnetToBeDeprecatedFieldRPC() const { return fTestnetToBeDeprecatedFieldRPC; }
/** Allow mining on master branch by default. **/
bool MineOnDevelopmentBranch() const { return fMineOnDevelopmentBranch; }
/** Return the BIP70 network string (main, test or regtest) */
std::string NetworkIDString() const { return strNetworkID; }
const std::vector<CDNSSeedData>& DNSSeeds() const { return vSeeds; }
Expand All @@ -91,6 +93,7 @@ class CChainParams
bool fRequireStandard;
bool fMineBlocksOnDemand;
bool fTestnetToBeDeprecatedFieldRPC;
bool fMineOnDevelopmentBranch;
CCheckpointData checkpointData;
};

Expand Down
5 changes: 5 additions & 0 deletions src/clientversion.cpp
Expand Up @@ -110,3 +110,8 @@ std::string FormatSubVersion(const std::string& name, int nClientVersion, const
ss << "/";
return ss.str();
}

bool IsDevelopmentBranch()
{
return std::string(BRANCH_NAME) == "master";
}
2 changes: 2 additions & 0 deletions src/clientversion.h
Expand Up @@ -65,6 +65,8 @@ extern const std::string CLIENT_DATE;
std::string FormatFullVersion();
std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments);

bool IsDevelopmentBranch();

#endif // WINDRES_PREPROC

#endif // BITCOIN_CLIENTVERSION_H
5 changes: 5 additions & 0 deletions src/rpc/mining.cpp
Expand Up @@ -7,6 +7,7 @@
#include "amount.h"
#include "chain.h"
#include "chainparams.h"
#include "clientversion.h"
#include "consensus/consensus.h"
#include "consensus/validation.h"
#include "core_io.h"
Expand Down Expand Up @@ -372,6 +373,10 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
+ HelpExampleRpc("getblocktemplate", "")
);

const CChainParams& chainParams = Params();
if (!chainParams.MineOnDevelopmentBranch() && IsDevelopmentBranch())
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");

LOCK(cs_main);

std::string strMode = "template";
Expand Down

0 comments on commit 34ec9e8

Please sign in to comment.