Skip to content

Commit 91cba1a

Browse files
committed
Merge pull request #5969
f14e687 Chainparams: Decouple CAlert from CChainParams (Jorge Timón)
2 parents a0bfc69 + f14e687 commit 91cba1a

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

src/alert.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include "alert.h"
77

8-
#include "chainparams.h"
98
#include "clientversion.h"
109
#include "net.h"
1110
#include "pubkey.h"
@@ -145,9 +144,9 @@ bool CAlert::RelayTo(CNode* pnode) const
145144
return false;
146145
}
147146

148-
bool CAlert::CheckSignature() const
147+
bool CAlert::CheckSignature(const std::vector<unsigned char>& alertKey) const
149148
{
150-
CPubKey key(Params().AlertKey());
149+
CPubKey key(alertKey);
151150
if (!key.Verify(Hash(vchMsg.begin(), vchMsg.end()), vchSig))
152151
return error("CAlert::CheckSignature(): verify signature failed");
153152

@@ -169,9 +168,9 @@ CAlert CAlert::getAlertByHash(const uint256 &hash)
169168
return retval;
170169
}
171170

172-
bool CAlert::ProcessAlert(bool fThread)
171+
bool CAlert::ProcessAlert(const std::vector<unsigned char>& alertKey, bool fThread)
173172
{
174-
if (!CheckSignature())
173+
if (!CheckSignature(alertKey))
175174
return false;
176175
if (!IsInEffect())
177176
return false;

src/alert.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ class CAlert : public CUnsignedAlert
100100
bool AppliesTo(int nVersion, std::string strSubVerIn) const;
101101
bool AppliesToMe() const;
102102
bool RelayTo(CNode* pnode) const;
103-
bool CheckSignature() const;
104-
bool ProcessAlert(bool fThread = true); // fThread means run -alertnotify in a free-running thread
103+
bool CheckSignature(const std::vector<unsigned char>& alertKey) const;
104+
bool ProcessAlert(const std::vector<unsigned char>& alertKey, bool fThread = true); // fThread means run -alertnotify in a free-running thread
105105
static void Notify(const std::string& strMessage, bool fThread);
106106

107107
/*

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4270,7 +4270,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
42704270
uint256 alertHash = alert.GetHash();
42714271
if (pfrom->setKnown.count(alertHash) == 0)
42724272
{
4273-
if (alert.ProcessAlert())
4273+
if (alert.ProcessAlert(Params().AlertKey()))
42744274
{
42754275
// Relay
42764276
pfrom->setKnown.insert(alertHash);

src/test/alert_tests.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "clientversion.h"
1111
#include "data/alertTests.raw.h"
1212

13+
#include "chainparams.h"
1314
#include "serialize.h"
1415
#include "streams.h"
1516
#include "util.h"
@@ -119,10 +120,11 @@ BOOST_FIXTURE_TEST_SUITE(Alert_tests, ReadAlerts)
119120
BOOST_AUTO_TEST_CASE(AlertApplies)
120121
{
121122
SetMockTime(11);
123+
const std::vector<unsigned char>& alertKey = Params(CBaseChainParams::MAIN).AlertKey();
122124

123125
BOOST_FOREACH(const CAlert& alert, alerts)
124126
{
125-
BOOST_CHECK(alert.CheckSignature());
127+
BOOST_CHECK(alert.CheckSignature(alertKey));
126128
}
127129

128130
BOOST_CHECK(alerts.size() >= 3);
@@ -159,14 +161,15 @@ BOOST_AUTO_TEST_CASE(AlertApplies)
159161
BOOST_AUTO_TEST_CASE(AlertNotify)
160162
{
161163
SetMockTime(11);
164+
const std::vector<unsigned char>& alertKey = Params(CBaseChainParams::MAIN).AlertKey();
162165

163166
boost::filesystem::path temp = GetTempPath() / "alertnotify.txt";
164167
boost::filesystem::remove(temp);
165168

166169
mapArgs["-alertnotify"] = std::string("echo %s >> ") + temp.string();
167170

168171
BOOST_FOREACH(CAlert alert, alerts)
169-
alert.ProcessAlert(false);
172+
alert.ProcessAlert(alertKey, false);
170173

171174
std::vector<std::string> r = read_lines(temp);
172175
BOOST_CHECK_EQUAL(r.size(), 4u);

0 commit comments

Comments
 (0)