1 // Copyright (c) 2016 The Zcash developers
2 // Original code from: https://gist.github.com/laanwj/0e689cfa37b52bcbbb44
6 To set up a new alert system
7 ----------------------------
9 Create a new alert key pair:
10 openssl ecparam -name secp256k1 -genkey -param_enc explicit -outform PEM -out data.pem
12 Get the private key in hex:
13 openssl ec -in data.pem -outform DER | tail -c 279 | xxd -p -c 279
15 Get the public key in hex:
16 openssl ec -in data.pem -pubout -outform DER | tail -c 65 | xxd -p -c 65
18 Update the public keys found in chainparams.cpp.
21 To send an alert message
22 ------------------------
24 Copy the private keys into alertkeys.h.
26 Modify the alert parameters, id and message found in this file.
28 Build and run with -sendalert or -printalert.
30 ./zcashd -printtoconsole -sendalert
32 One minute after starting up, the alert will be broadcast. It is then
33 flooded through the network until the nRelayUntil time, and will be
34 active until nExpiration OR the alert is cancelled.
36 If you make a mistake, send another alert with nCancel set to cancel
49 #include "clientversion.h"
50 #include "chainparams.h"
52 #include "alertkeys.h"
55 static const int64_t DAYS = 24 * 60 * 60;
57 void ThreadSendAlert()
59 if (!mapArgs.count("-sendalert") && !mapArgs.count("-printalert"))
62 MilliSleep(60*1000); // Wait a minute so we get connected
65 // Alerts are relayed around the network until nRelayUntil, flood
66 // filling to every node.
67 // After the relay time is past, new nodes are told about alerts
68 // when they connect to peers, until either nExpiration or
69 // the alert is cancelled by a newer alert.
70 // Nodes never save alerts to disk, they are in-memory-only.
73 alert.nRelayUntil = GetTime() + 15 * 60;
74 alert.nExpiration = GetTime() + 10 * 365 * 24 * 60 * 60;
75 alert.nID = 1005; // use https://github.com/zcash/zcash/wiki/specification#assigned-numbers to keep track of alert IDs
76 alert.nCancel = 1004; // cancels previous messages up to this ID number
78 // These versions are protocol versions
80 alert.nMinVer = 170002;
81 alert.nMaxVer = 170004;
85 // 1000 for Misc warnings like out of disk space and clock is wrong
86 // 2000 for longer invalid proof-of-work chain
87 // Higher numbers mean higher priority
88 // 4000 or higher will put the RPC into safe mode
89 alert.nPriority = 4000;
90 alert.strComment = "";
91 alert.strStatusBar = "Your client is out of date and incompatible with the Overwinter network upgrade. Please update to a recent version of Zcash (1.1.0 or later).";
92 alert.strRPCError = alert.strStatusBar;
94 // Set specific client version/versions here. If setSubVer is empty, no filtering on subver is done:
95 // alert.setSubVer.insert(std::string("/MagicBean:0.7.2/"));
96 const std::vector<std::string> useragents = {}; //{"MagicBean", "BeanStalk", "AppleSeed", "EleosZcash"};
98 BOOST_FOREACH(const std::string& useragent, useragents) {
102 assert(alert.strComment.length() <= 65536); // max length in alert.h
103 assert(alert.strStatusBar.length() <= 256);
104 assert(alert.strRPCError.length() <= 256);
107 const CChainParams& chainparams = Params();
108 std::string networkID = chainparams.NetworkIDString();
109 bool fIsTestNet = networkID.compare("test") == 0;
110 std::vector<unsigned char> vchTmp(ParseHex(fIsTestNet ? pszTestNetPrivKey : pszPrivKey));
111 CPrivKey vchPrivKey(vchTmp.begin(), vchTmp.end());
113 CDataStream sMsg(SER_NETWORK, CLIENT_VERSION);
114 sMsg << *(CUnsignedAlert*)&alert;
115 alert.vchMsg = std::vector<unsigned char>(sMsg.begin(), sMsg.end());
117 if (!key.SetPrivKey(vchPrivKey, false))
119 printf("ThreadSendAlert() : key.SetPrivKey failed\n");
122 if (!key.Sign(Hash(alert.vchMsg.begin(), alert.vchMsg.end()), alert.vchSig))
124 printf("ThreadSendAlert() : key.Sign failed\n");
129 CDataStream sBuffer(SER_NETWORK, CLIENT_VERSION);
133 if (!alert2.CheckSignature(chainparams.AlertKey()))
135 printf("ThreadSendAlert() : CheckSignature failed\n");
138 assert(alert2.vchMsg == alert.vchMsg);
139 assert(alert2.vchSig == alert.vchSig);
141 printf("\nThreadSendAlert:\n");
142 printf("hash=%s\n", alert2.GetHash().ToString().c_str());
143 printf("%s\n", alert2.ToString().c_str());
144 printf("vchMsg=%s\n", HexStr(alert2.vchMsg).c_str());
145 printf("vchSig=%s\n", HexStr(alert2.vchSig).c_str());
148 if (!mapArgs.count("-sendalert"))
150 while (vNodes.size() < 1 && !ShutdownRequested())
152 if (ShutdownRequested())
156 printf("ThreadSendAlert() : Sending alert\n");
160 BOOST_FOREACH(CNode* pnode, vNodes)
162 if (alert2.RelayTo(pnode))
164 printf("ThreadSendAlert() : Sent alert to %s\n", pnode->addr.ToString().c_str());
169 printf("ThreadSendAlert() : Alert sent to %d nodes\n", nSent);