aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2014-10-09 10:33:05 -0400
committerGavin Andresen <gavinandresen@gmail.com>2014-10-09 10:39:29 -0400
commit3222802ea11053f0dd69c99fc2f33edff554dc17 (patch)
tree8db1800655df86b016a4a5ef042a855f321bde02 /src
parentdec58922d07241f0b502c96f8e5131abccbd5dc1 (diff)
parentdbca89b74b76610331d21656cd6747f5bf8375d6 (diff)
Merge pull request #5059
dbca89b Trigger -alertnotify if network is upgrading without you (Gavin Andresen) e01a793 Refactor -alertnotify code (Gavin Andresen) Signed-off-by: Gavin Andresen <gavinandresen@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/alert.cpp37
-rw-r--r--src/alert.h3
-rw-r--r--src/main.cpp18
-rw-r--r--src/miner.cpp5
4 files changed, 37 insertions, 26 deletions
diff --git a/src/alert.cpp b/src/alert.cpp
index 3271ecfbfd..d495849206 100644
--- a/src/alert.cpp
+++ b/src/alert.cpp
@@ -233,25 +233,30 @@ bool CAlert::ProcessAlert(bool fThread)
if(AppliesToMe())
{
uiInterface.NotifyAlertChanged(GetHash(), CT_NEW);
- std::string strCmd = GetArg("-alertnotify", "");
- if (!strCmd.empty())
- {
- // Alert text should be plain ascii coming from a trusted source, but to
- // be safe we first strip anything not in safeChars, then add single quotes around
- // the whole string before passing it to the shell:
- std::string singleQuote("'");
- std::string safeStatus = SanitizeString(strStatusBar);
- safeStatus = singleQuote+safeStatus+singleQuote;
- boost::replace_all(strCmd, "%s", safeStatus);
-
- if (fThread)
- boost::thread t(runCommand, strCmd); // thread runs free
- else
- runCommand(strCmd);
- }
+ Notify(strStatusBar, fThread);
}
}
LogPrint("alert", "accepted alert %d, AppliesToMe()=%d\n", nID, AppliesToMe());
return true;
}
+
+void
+CAlert::Notify(const std::string& strMessage, bool fThread)
+{
+ std::string strCmd = GetArg("-alertnotify", "");
+ if (strCmd.empty()) return;
+
+ // Alert text should be plain ascii coming from a trusted source, but to
+ // be safe we first strip anything not in safeChars, then add single quotes around
+ // the whole string before passing it to the shell:
+ std::string singleQuote("'");
+ std::string safeStatus = SanitizeString(strMessage);
+ safeStatus = singleQuote+safeStatus+singleQuote;
+ boost::replace_all(strCmd, "%s", safeStatus);
+
+ if (fThread)
+ boost::thread t(runCommand, strCmd); // thread runs free
+ else
+ runCommand(strCmd);
+}
diff --git a/src/alert.h b/src/alert.h
index 5ecf94cea8..ba3235858d 100644
--- a/src/alert.h
+++ b/src/alert.h
@@ -101,7 +101,8 @@ public:
bool AppliesToMe() const;
bool RelayTo(CNode* pnode) const;
bool CheckSignature() const;
- bool ProcessAlert(bool fThread = true);
+ bool ProcessAlert(bool fThread = true); // fThread means run -alertnotify in a free-running thread
+ static void Notify(const std::string& strMessage, bool fThread);
/*
* Get copy of (active) alert object by hash. Returns a null alert if it is not found.
diff --git a/src/main.cpp b/src/main.cpp
index de3876944e..fc8167e40e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1178,14 +1178,9 @@ void CheckForkWarningConditions()
{
if (!fLargeWorkForkFound)
{
- std::string strCmd = GetArg("-alertnotify", "");
- if (!strCmd.empty())
- {
- std::string warning = std::string("'Warning: Large-work fork detected, forking after block ") +
- pindexBestForkBase->phashBlock->ToString() + std::string("'");
- boost::replace_all(strCmd, "%s", warning);
- boost::thread t(runCommand, strCmd); // thread runs free
- }
+ std::string warning = std::string("'Warning: Large-work fork detected, forking after block ") +
+ pindexBestForkBase->phashBlock->ToString() + std::string("'");
+ CAlert::Notify(warning, true);
}
if (pindexBestForkTip)
{
@@ -1753,7 +1748,8 @@ void static UpdateTip(CBlockIndex *pindexNew) {
cvBlockChange.notify_all();
// Check the version of the last 100 blocks to see if we need to upgrade:
- if (!IsInitialBlockDownload())
+ static bool fWarned = false;
+ if (!IsInitialBlockDownload() && !fWarned)
{
int nUpgraded = 0;
const CBlockIndex* pindex = chainActive.Tip();
@@ -1766,8 +1762,12 @@ void static UpdateTip(CBlockIndex *pindexNew) {
if (nUpgraded > 0)
LogPrintf("SetBestChain: %d of last 100 blocks above version %d\n", nUpgraded, (int)CBlock::CURRENT_VERSION);
if (nUpgraded > 100/2)
+ {
// strMiscWarning is read by GetWarnings(), called by Qt and the JSON-RPC code to warn the user:
strMiscWarning = _("Warning: This version is obsolete, upgrade required!");
+ CAlert::Notify(strMiscWarning, true);
+ fWarned = true;
+ }
}
}
diff --git a/src/miner.cpp b/src/miner.cpp
index fd6c52ca69..c2762bf44e 100644
--- a/src/miner.cpp
+++ b/src/miner.cpp
@@ -83,6 +83,11 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
return NULL;
CBlock *pblock = &pblocktemplate->block; // pointer for convenience
+ // -regtest only: allow overriding block.nVersion with
+ // -blockversion=N to test forking scenarios
+ if (Params().MineBlocksOnDemand())
+ pblock->nVersion = GetArg("-blockversion", pblock->nVersion);
+
// Create coinbase tx
CMutableTransaction txNew;
txNew.vin.resize(1);