Feathercoin  0.5.0
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
checkpointsync.cpp
Go to the documentation of this file.
1 // Copyright (c) 2012-2013 PPCoin developers
2 // Copyright (c) 2013 Primecoin developers
3 // Distributed under conditional MIT/X11 software license,
4 // see the accompanying file COPYING
5 //
6 // The synchronized checkpoint system is first developed by Sunny King for
7 // ppcoin network in 2012, giving cryptocurrency developers a tool to gain
8 // additional network protection against 51% attack.
9 //
10 // Primecoin also adopts this security mechanism, and the enforcement of
11 // checkpoints is explicitly granted by user, thus granting only temporary
12 // consensual central control to developer at the threats of 51% attack.
13 //
14 // Concepts
15 //
16 // In the network there can be a privileged node known as 'checkpoint master'.
17 // This node can send out checkpoint messages signed by the checkpoint master
18 // key. Each checkpoint is a block hash, representing a block on the blockchain
19 // that the network should reach consensus on.
20 //
21 // Besides verifying signatures of checkpoint messages, each node also verifies
22 // the consistency of the checkpoints. If a conflicting checkpoint is received,
23 // it means either the checkpoint master key is compromised, or there is an
24 // operator mistake. In this situation the node would discard the conflicting
25 // checkpoint message and display a warning message. This precaution controls
26 // the damage to network caused by operator mistake or compromised key.
27 //
28 // Operations
29 //
30 // Checkpoint master key can be established by using the 'makekeypair' command
31 // The public key in source code should then be updated and private key kept
32 // in a safe place.
33 //
34 // Any node can be turned into checkpoint master by setting the 'checkpointkey'
35 // configuration parameter with the private key of the checkpoint master key.
36 // Operator should exercise caution such that at any moment there is at most
37 // one node operating as checkpoint master. When switching master node, the
38 // recommended procedure is to shutdown the master node and restart as
39 // regular node, note down the current checkpoint by 'getcheckpoint', then
40 // compare to the checkpoint at the new node to be upgraded to master node.
41 // When the checkpoint on both nodes match then it is safe to switch the new
42 // node to checkpoint master.
43 //
44 // The configuration parameter 'checkpointdepth' specifies how many blocks
45 // should the checkpoints lag behind the latest block in auto checkpoint mode.
46 // A depth of 0 is the strongest auto checkpoint policy and offers the greatest
47 // protection against 51% attack. A negative depth means that the checkpoints
48 // should not be automatically generated by the checkpoint master, but instead
49 // be manually entered by operator via the 'sendcheckpoint' command. The manual
50 // mode is also the default mode (default value -1 for checkpointdepth).
51 //
52 // Command 'enforcecheckpoint' and configuration parameter 'checkpointenforce'
53 // are for the users to explicitly consent to enforce the checkpoints issued
54 // from checkpoint master. To enforce checkpoint, user needs to either issue
55 // command 'enforcecheckpoint true', or set configuration parameter
56 // checkpointenforce=1. The current enforcement setting can be queried via
57 // command 'getcheckpoint', where 'subscribemode' displays either 'enforce'
58 // or 'advisory'. The 'enforce' mode of subscribemode means checkpoints are
59 // enforced. The 'advisory' mode of subscribemode means checkpoints are not
60 // enforced but a warning message would be displayed if the node is on a
61 // different blockchain fork from the checkpoint, and this is the default mode.
62 //
63 
64 #include <boost/foreach.hpp>
65 
66 #include "checkpoints.h"
67 #include "checkpointsync.h"
68 
69 #include "base58.h"
70 #include "bitcoinrpc.h"
71 #include "main.h"
72 #include "txdb.h"
73 #include "uint256.h"
74 
75 using namespace json_spirit;
76 using namespace std;
77 
78 
79 // ppcoin: sync-checkpoint master key
80 const std::string CSyncCheckpoint::strMainPubKey = "04b9ff17f2865bc685456429defb94fcb1ffc44a98703f0d62513fa47e7b76e4c6ab10b59e2c068d45f6a04b47bcee8b0fa50b33bfa53ff279a02863dbf1da6128";
81 const std::string CSyncCheckpoint::strTestPubKey = "04db371d2b99df9e7962b2ce2369ada9821261e7f943a57a7ff3494d7d6c87939d3632fcaa2878bd5e45cfea0ea435fd6ee049a28ccbd0998ea3aadeb7abeed065";
82 std::string CSyncCheckpoint::strMasterPrivKey = "";
83 
84 
85 // ppcoin: synchronized checkpoint (centrally broadcasted)
93 
94 // ppcoin: get last synchronized checkpoint
96 {
97  LOCK(cs_hashSyncCheckpoint);
98  if (!mapBlockIndex.count(hashSyncCheckpoint))
99  error("GetSyncCheckpoint: block index missing for current sync-checkpoint %s", hashSyncCheckpoint.ToString().c_str());
100  else
102  return NULL;
103 }
104 
105 // ppcoin: only descendant of current sync-checkpoint is allowed
106 bool ValidateSyncCheckpoint(uint256 hashCheckpoint)
107 {
108  if (!mapBlockIndex.count(hashSyncCheckpoint))
109  return error("ValidateSyncCheckpoint: block index missing for current sync-checkpoint %s", hashSyncCheckpoint.ToString().c_str());
110  if (!mapBlockIndex.count(hashCheckpoint))
111  return error("ValidateSyncCheckpoint: block index missing for received sync-checkpoint %s", hashCheckpoint.ToString().c_str());
112 
113  CBlockIndex* pindexSyncCheckpoint = mapBlockIndex[hashSyncCheckpoint];
114  CBlockIndex* pindexCheckpointRecv = mapBlockIndex[hashCheckpoint];
115 
116  if (pindexCheckpointRecv->nHeight <= pindexSyncCheckpoint->nHeight)
117  {
118  // Received an older checkpoint, trace back from current checkpoint
119  // to the same height of the received checkpoint to verify
120  // that current checkpoint should be a descendant block
121  CBlockIndex* pindex = pindexSyncCheckpoint;
122  while (pindex->nHeight > pindexCheckpointRecv->nHeight)
123  if (!(pindex = pindex->pprev))
124  return error("ValidateSyncCheckpoint: pprev1 null - block index structure failure");
125  if (pindex->GetBlockHash() != hashCheckpoint)
126  {
127  hashInvalidCheckpoint = hashCheckpoint;
128  return error("ValidateSyncCheckpoint: new sync-checkpoint %s is conflicting with current sync-checkpoint %s", hashCheckpoint.ToString().c_str(), hashSyncCheckpoint.ToString().c_str());
129  }
130  return false; // ignore older checkpoint
131  }
132 
133  // Received checkpoint should be a descendant block of the current
134  // checkpoint. Trace back to the same height of current checkpoint
135  // to verify.
136  CBlockIndex* pindex = pindexCheckpointRecv;
137  while (pindex->nHeight > pindexSyncCheckpoint->nHeight)
138  if (!(pindex = pindex->pprev))
139  return error("ValidateSyncCheckpoint: pprev2 null - block index structure failure");
140  if (pindex->GetBlockHash() != hashSyncCheckpoint)
141  {
142  hashInvalidCheckpoint = hashCheckpoint;
143  return error("ValidateSyncCheckpoint: new sync-checkpoint %s is not a descendant of current sync-checkpoint %s", hashCheckpoint.ToString().c_str(), hashSyncCheckpoint.ToString().c_str());
144  }
145  return true;
146 }
147 
148 bool WriteSyncCheckpoint(const uint256& hashCheckpoint)
149 {
150  if (!pblocktree->WriteSyncCheckpoint(hashCheckpoint))
151  {
152  return error("WriteSyncCheckpoint(): failed to write to txdb sync checkpoint %s", hashCheckpoint.ToString().c_str());
153  }
154  if (!pblocktree->Sync())
155  return error("WriteSyncCheckpoint(): failed to commit to txdb sync checkpoint %s", hashCheckpoint.ToString().c_str());
156 
157  hashSyncCheckpoint = hashCheckpoint;
158  return true;
159 }
160 
162 {
163  return (GetBoolArg("-checkpointenforce", true) || mapArgs.count("-checkpointkey")); // checkpoint master node is always enforced
164 }
165 
167 {
168  LOCK(cs_hashSyncCheckpoint);
169  if (hashPendingCheckpoint != 0 && mapBlockIndex.count(hashPendingCheckpoint))
170  {
171  if (!ValidateSyncCheckpoint(hashPendingCheckpoint))
172  {
173  hashPendingCheckpoint = 0;
174  checkpointMessagePending.SetNull();
175  return false;
176  }
177 
178  CBlockIndex* pindexCheckpoint = mapBlockIndex[hashPendingCheckpoint];
179  if (IsSyncCheckpointEnforced() && !pindexCheckpoint->IsInMainChain())
180  {
182  if (!SetBestChain(state, pindexCheckpoint))
183  {
184  hashInvalidCheckpoint = hashPendingCheckpoint;
185  return error("AcceptPendingSyncCheckpoint: SetBestChain failed for sync checkpoint %s", hashPendingCheckpoint.ToString().c_str());
186  }
187  }
188 
189  if (!WriteSyncCheckpoint(hashPendingCheckpoint))
190  return error("AcceptPendingSyncCheckpoint(): failed to write sync checkpoint %s", hashPendingCheckpoint.ToString().c_str());
191  hashPendingCheckpoint = 0;
192  checkpointMessage = checkpointMessagePending;
193  checkpointMessagePending.SetNull();
194  printf("AcceptPendingSyncCheckpoint : sync-checkpoint at %s\n", hashSyncCheckpoint.ToString().c_str());
195  // relay the checkpoint
196  if (!checkpointMessage.IsNull())
197  {
198  BOOST_FOREACH(CNode* pnode, vNodes)
199  checkpointMessage.RelayTo(pnode);
200  }
201  return true;
202  }
203  return false;
204 }
205 
206 // Automatically select a suitable sync-checkpoint
208 {
209  // Search backward for a block with specified depth policy
210  const CBlockIndex *pindex = pindexBest;
211  while (pindex->pprev && pindex->nHeight + (int)GetArg("-checkpointdepth", -1) > pindexBest->nHeight)
212  pindex = pindex->pprev;
213  return pindex->GetBlockHash();
214 }
215 
216 // Check against synchronized checkpoint
217 bool CheckSyncCheckpoint(const uint256& hashBlock, const CBlockIndex* pindexPrev)
218 {
219  int nHeight = pindexPrev->nHeight + 1;
220 
221  LOCK(cs_hashSyncCheckpoint);
222  // sync-checkpoint should always be accepted block
223  assert(mapBlockIndex.count(hashSyncCheckpoint));
224  const CBlockIndex* pindexSync = mapBlockIndex[hashSyncCheckpoint];
225 
226  if (nHeight > pindexSync->nHeight)
227  {
228  // trace back to same height as sync-checkpoint
229  const CBlockIndex* pindex = pindexPrev;
230  while (pindex->nHeight > pindexSync->nHeight)
231  if (!(pindex = pindex->pprev))
232  return error("CheckSyncCheckpoint: pprev null - block index structure failure");
233  if (pindex->nHeight < pindexSync->nHeight || pindex->GetBlockHash() != hashSyncCheckpoint)
234  return false; // only descendant of sync-checkpoint can pass check
235  }
236  if (nHeight == pindexSync->nHeight && hashBlock != hashSyncCheckpoint)
237  return false; // same height with sync-checkpoint
238  if (nHeight < pindexSync->nHeight && !mapBlockIndex.count(hashBlock))
239  return false; // lower height than sync-checkpoint
240  return true;
241 }
242 
244 {
245  LOCK(cs_hashSyncCheckpoint);
246  if (hashPendingCheckpoint == 0)
247  return false;
248  if (hashBlock == hashPendingCheckpoint)
249  return true;
250  if (mapOrphanBlocks.count(hashPendingCheckpoint)
251  && hashBlock == WantedByOrphan(mapOrphanBlocks[hashPendingCheckpoint]))
252  return true;
253  return false;
254 }
255 
256 // ppcoin: reset synchronized checkpoint to last hardened checkpoint
258 {
259  LOCK(cs_hashSyncCheckpoint);
261  if (mapBlockIndex.count(hash) && !mapBlockIndex[hash]->IsInMainChain())
262  {
263  // checkpoint block accepted but not yet in main chain
264  printf("ResetSyncCheckpoint: SetBestChain to hardened checkpoint %s\n", hash.ToString().c_str());
266  if (!SetBestChain(state, mapBlockIndex[hash]))
267  {
268  return error("ResetSyncCheckpoint: SetBestChain failed for hardened checkpoint %s", hash.ToString().c_str());
269  }
270  }
271  else if(!mapBlockIndex.count(hash))
272  {
273  // checkpoint block not yet accepted
274  hashPendingCheckpoint = hash;
275  checkpointMessagePending.SetNull();
276  printf("ResetSyncCheckpoint: pending for sync-checkpoint %s\n", hashPendingCheckpoint.ToString().c_str());
277  }
278 
279  if (!WriteSyncCheckpoint((mapBlockIndex.count(hash) && mapBlockIndex[hash]->IsInMainChain())? hash : hashGenesisBlock))
280  return error("ResetSyncCheckpoint: failed to write sync checkpoint %s", hash.ToString().c_str());
281  printf("ResetSyncCheckpoint: sync-checkpoint reset to %s\n", hashSyncCheckpoint.ToString().c_str());
282  return true;
283 }
284 
286 {
287  LOCK(cs_hashSyncCheckpoint);
288  if (pfrom && hashPendingCheckpoint != 0 && (!mapBlockIndex.count(hashPendingCheckpoint)) && (!mapOrphanBlocks.count(hashPendingCheckpoint)))
289  pfrom->AskFor(CInv(MSG_BLOCK, hashPendingCheckpoint));
290 }
291 
292 // Verify sync checkpoint master pubkey and reset sync checkpoint if changed
294 {
295  std::string strPubKey = "";
297  if (!pblocktree->ReadCheckpointPubKey(strPubKey) || strPubKey != strMasterPubKey)
298  {
299  // write checkpoint master key to db
300  if (!pblocktree->WriteCheckpointPubKey(strMasterPubKey))
301  return error("CheckCheckpointPubKey() : failed to write new checkpoint master key to db");
302  if (!pblocktree->Sync())
303  return error("CheckCheckpointPubKey() : failed to commit new checkpoint master key to db");
304  if (!ResetSyncCheckpoint())
305  return error("CheckCheckpointPubKey() : failed to reset sync-checkpoint");
306  }
307  return true;
308 }
309 
310 bool SetCheckpointPrivKey(std::string strPrivKey)
311 {
312  // Test signing a sync-checkpoint with genesis block
313  CSyncCheckpoint checkpoint;
314  checkpoint.hashCheckpoint = hashGenesisBlock;
315  CDataStream sMsg(SER_NETWORK, PROTOCOL_VERSION);
316  sMsg << (CUnsignedSyncCheckpoint)checkpoint;
317  checkpoint.vchMsg = std::vector<unsigned char>(sMsg.begin(), sMsg.end());
318 
319  CBitcoinSecret vchSecret;
320  if (!vchSecret.SetString(strPrivKey))
321  return error("SendSyncCheckpoint: Checkpoint master key invalid");
322  CKey key = vchSecret.GetKey(); // if key is not correct openssl may crash
323  if (!key.Sign(Hash(checkpoint.vchMsg.begin(), checkpoint.vchMsg.end()), checkpoint.vchSig))
324  return false;
325 
326  // Test signing successful, proceed
328  return true;
329 }
330 
331 bool SendSyncCheckpoint(uint256 hashCheckpoint)
332 {
333  CSyncCheckpoint checkpoint;
334  checkpoint.hashCheckpoint = hashCheckpoint;
335  CDataStream sMsg(SER_NETWORK, PROTOCOL_VERSION);
336  sMsg << (CUnsignedSyncCheckpoint)checkpoint;
337  checkpoint.vchMsg = std::vector<unsigned char>(sMsg.begin(), sMsg.end());
338 
340  return error("SendSyncCheckpoint: Checkpoint master key unavailable.");
341  CBitcoinSecret vchSecret;
343  return error("SendSyncCheckpoint: Checkpoint master key invalid");
344  CKey key = vchSecret.GetKey(); // if key is not correct openssl may crash
345  if (!key.Sign(Hash(checkpoint.vchMsg.begin(), checkpoint.vchMsg.end()), checkpoint.vchSig))
346  return error("SendSyncCheckpoint: Unable to sign checkpoint, check private key?");
347 
348  if(!checkpoint.ProcessSyncCheckpoint(NULL))
349  {
350  printf("WARNING: SendSyncCheckpoint: Failed to process checkpoint.\n");
351  return false;
352  }
353 
354  // Relay checkpoint
355  {
356  LOCK(cs_vNodes);
357  BOOST_FOREACH(CNode* pnode, vNodes)
358  checkpoint.RelayTo(pnode);
359  }
360  return true;
361 }
362 
363 // Is the sync-checkpoint outside maturity window?
365 {
366  LOCK(cs_hashSyncCheckpoint);
367  // sync-checkpoint should always be accepted block
368  assert(mapBlockIndex.count(hashSyncCheckpoint));
369  const CBlockIndex* pindexSync = mapBlockIndex[hashSyncCheckpoint];
370  return (nBestHeight >= pindexSync->nHeight + COINBASE_MATURITY);
371 }
372 
373 // Is the sync-checkpoint too old?
374 bool IsSyncCheckpointTooOld(unsigned int nSeconds)
375 {
376  LOCK(cs_hashSyncCheckpoint);
377  // sync-checkpoint should always be accepted block
378  assert(mapBlockIndex.count(hashSyncCheckpoint));
379  const CBlockIndex* pindexSync = mapBlockIndex[hashSyncCheckpoint];
380  return (pindexSync->GetBlockTime() + nSeconds < GetAdjustedTime());
381 }
382 
383 // ppcoin: find block wanted by given orphan block
384 uint256 WantedByOrphan(const CBlock* pblockOrphan)
385 {
386  // Work back to the first block in the orphan chain
387  while (mapOrphanBlocks.count(pblockOrphan->hashPrevBlock))
388  pblockOrphan = mapOrphanBlocks[pblockOrphan->hashPrevBlock];
389  return pblockOrphan->hashPrevBlock;
390 }
391 
392 // ppcoin: verify signature of sync-checkpoint message
394 {
396  CPubKey key(ParseHex(strMasterPubKey));
397  if (!key.Verify(Hash(vchMsg.begin(), vchMsg.end()), vchSig))
398  return error("CSyncCheckpoint::CheckSignature() : verify signature failed");
399 
400  // Now unserialize the data
401  CDataStream sMsg(vchMsg, SER_NETWORK, PROTOCOL_VERSION);
402  sMsg >> *(CUnsignedSyncCheckpoint*)this;
403  return true;
404 }
405 
406 // ppcoin: process synchronized checkpoint
408 {
409  if (!CheckSignature())
410  return false;
411 
412  LOCK(cs_hashSyncCheckpoint);
413  if (!mapBlockIndex.count(hashCheckpoint))
414  {
415  // We haven't received the checkpoint chain, keep the checkpoint as pending
416  hashPendingCheckpoint = hashCheckpoint;
417  checkpointMessagePending = *this;
418  printf("ProcessSyncCheckpoint: pending for sync-checkpoint %s\n", hashCheckpoint.ToString().c_str());
419  // Ask this guy to fill in what we're missing
420  if (pfrom)
421  {
422  pfrom->PushGetBlocks(pindexBest, hashCheckpoint);
423  // ask directly as well in case rejected earlier by duplicate
424  // proof-of-stake because getblocks may not get it this time
425  pfrom->AskFor(CInv(MSG_BLOCK, mapOrphanBlocks.count(hashCheckpoint)? WantedByOrphan(mapOrphanBlocks[hashCheckpoint]) : hashCheckpoint));
426  }
427  return false;
428  }
429 
430  if (!ValidateSyncCheckpoint(hashCheckpoint))
431  return false;
432 
433  CBlockIndex* pindexCheckpoint = mapBlockIndex[hashCheckpoint];
434  if (IsSyncCheckpointEnforced() && !pindexCheckpoint->IsInMainChain())
435  {
436  // checkpoint chain received but not yet main chain
438  if (!SetBestChain(state, pindexCheckpoint))
439  {
440  hashInvalidCheckpoint = hashCheckpoint;
441  return error("ProcessSyncCheckpoint: SetBestChain failed for sync checkpoint %s", hashCheckpoint.ToString().c_str());
442  }
443  }
444 
445  if (!WriteSyncCheckpoint(hashCheckpoint))
446  return error("ProcessSyncCheckpoint(): failed to write sync checkpoint %s", hashCheckpoint.ToString().c_str());
447  checkpointMessage = *this;
448  hashPendingCheckpoint = 0;
449  checkpointMessagePending.SetNull();
450  printf("ProcessSyncCheckpoint: sync-checkpoint at %s\n", hashCheckpoint.ToString().c_str());
451  return true;
452 }
453 
454 
455 // RPC commands related to sync checkpoints
456 // get information of sync-checkpoint (first introduced in ppcoin)
457 Value getcheckpoint(const Array& params, bool fHelp)
458 {
459  if (fHelp || params.size() != 0)
460  throw runtime_error(
461  "getcheckpoint\n"
462  "Show info of synchronized checkpoint.\n");
463 
464  Object result;
465  CBlockIndex* pindexCheckpoint;
466 
467  result.push_back(Pair("synccheckpoint", hashSyncCheckpoint.ToString().c_str()));
468  if (mapBlockIndex.count(hashSyncCheckpoint))
469  {
470  pindexCheckpoint = mapBlockIndex[hashSyncCheckpoint];
471  result.push_back(Pair("height", pindexCheckpoint->nHeight));
472  result.push_back(Pair("timestamp", (boost::int64_t) pindexCheckpoint->GetBlockTime()));
473  }
474  result.push_back(Pair("subscribemode", IsSyncCheckpointEnforced()? "enforce" : "advisory"));
475  if (mapArgs.count("-checkpointkey"))
476  result.push_back(Pair("checkpointmaster", true));
477 
478  return result;
479 }
480 
481 Value sendcheckpoint(const Array& params, bool fHelp)
482 {
483  if (fHelp || params.size() != 1)
484  throw runtime_error(
485  "sendcheckpoint <blockhash>\n"
486  "Send a synchronized checkpoint.\n");
487 
488  if (!mapArgs.count("-checkpointkey") || CSyncCheckpoint::strMasterPrivKey.empty())
489  throw runtime_error("Not a checkpointmaster node, first set checkpointkey in configuration and restart client. ");
490 
491  std::string strHash = params[0].get_str();
492  uint256 hash(strHash);
493 
494  if (!SendSyncCheckpoint(hash))
495  throw runtime_error("Failed to send checkpoint, check log. ");
496 
497  Object result;
498  CBlockIndex* pindexCheckpoint;
499 
500  result.push_back(Pair("synccheckpoint", hashSyncCheckpoint.ToString().c_str()));
501  if (mapBlockIndex.count(hashSyncCheckpoint))
502  {
503  pindexCheckpoint = mapBlockIndex[hashSyncCheckpoint];
504  result.push_back(Pair("height", pindexCheckpoint->nHeight));
505  result.push_back(Pair("timestamp", (boost::int64_t) pindexCheckpoint->GetBlockTime()));
506  }
507  result.push_back(Pair("subscribemode", IsSyncCheckpointEnforced()? "enforce" : "advisory"));
508  if (mapArgs.count("-checkpointkey"))
509  result.push_back(Pair("checkpointmaster", true));
510 
511  return result;
512 }
513 
514 Value enforcecheckpoint(const Array& params, bool fHelp)
515 {
516  if (fHelp || params.size() != 1)
517  throw runtime_error(
518  "enforcecheckpoint <enforce>\n"
519  "<enforce> is true or false to enable or disable enforcement of broadcasted checkpoints by developer.");
520 
521  bool fEnforceCheckpoint = params[0].get_bool();
522  if (mapArgs.count("-checkpointkey") && !fEnforceCheckpoint)
523  throw runtime_error(
524  "checkpoint master node must enforce synchronized checkpoints.");
525  if (fEnforceCheckpoint)
527  mapArgs["-checkpointenforce"] = (fEnforceCheckpoint ? "1" : "0");
528  return Value::null;
529 }
530 
bool error(const char *format,...)
Definition: util.cpp:358
Value sendcheckpoint(const Array &params, bool fHelp)
std::vector< unsigned char > vchSig
const_iterator begin() const
Definition: serialize.h:884
CBlockIndex * pprev
Definition: main.h:1633
CKey GetKey()
Definition: base58.h:415
Definition: main.h:1334
bool ReadCheckpointPubKey(std::string &strPubKey)
Definition: txdb.cpp:258
uint256 WantedByOrphan(const CBlock *pblockOrphan)
bool WriteSyncCheckpoint(uint256 hashCheckpoint)
Definition: txdb.cpp:253
inv message data
Definition: protocol.h:113
int64 GetBlockTime() const
Definition: main.h:1749
void AskFor(const CInv &inv)
Definition: net.h:360
bool RelayTo(CNode *pnode) const
bool Sign(const uint256 &hash, std::vector< unsigned char > &vchSig) const
Definition: key.cpp:321
bool Sync()
Definition: leveldb.h:142
bool ProcessSyncCheckpoint(CNode *pfrom)
bool ResetSyncCheckpoint()
Double ended buffer combining vector and stream-like interfaces.
Definition: serialize.h:799
Value enforcecheckpoint(const Array &params, bool fHelp)
map< uint256, CBlock * > mapOrphanBlocks
Definition: main.cpp:69
Value getcheckpoint(const Array &params, bool fHelp)
uint256 hashGenesisBlock("0x12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2")
Config::Object_type Object
CSyncCheckpoint checkpointMessage
bool CheckCheckpointPubKey()
uint256 hashPendingCheckpoint
static std::string strMasterPrivKey
vector< CNode * > vNodes
Definition: net.cpp:56
bool SetString(const char *pszSecret)
Definition: base58.h:440
bool WriteSyncCheckpoint(const uint256 &hashCheckpoint)
std::vector< unsigned char > vchMsg
bool CheckSyncCheckpoint(const uint256 &hashBlock, const CBlockIndex *pindexPrev)
CCriticalSection cs_hashSyncCheckpoint
uint256 hashInvalidCheckpoint
CBlockTreeDB * pblocktree
Global variable that points to the active block tree (protected by cs_main)
Definition: main.cpp:290
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
Definition: util.cpp:600
bool fTestNet
Definition: util.cpp:81
void AskForPendingSyncCheckpoint(CNode *pfrom)
bool SetBestChain(CValidationState &state, CBlockIndex *pindexNew)
Connect/disconnect blocks until pindexNew is the new tip of the active block chain.
Definition: main.cpp:1832
#define printf
Definition: rpcdump.cpp:12
#define LOCK(cs)
Definition: sync.h:108
static const std::string strTestPubKey
bool WantedByPendingSyncCheckpoint(uint256 hashBlock)
A base58-encoded secret key.
Definition: base58.h:398
An encapsulated public key.
Definition: key.h:40
uint256 AutoSelectSyncCheckpoint()
static const Value_impl null
bool IsInMainChain() const
Definition: main.h:1763
uint256 hashPrevBlock
Definition: main.h:1284
int64 GetAdjustedTime()
Definition: util.cpp:1317
MTState * state
Definition: db_test.cc:1708
uint256 hashSyncCheckpoint
bool ValidateSyncCheckpoint(uint256 hashCheckpoint)
std::string strCheckpointWarning
Config::Array_type Array
uint256 Hash(const T1 pbegin, const T1 pend)
Definition: hash.h:16
const String_type & get_str() const
uint256 GetLatestHardenedCheckpoint()
bool IsMatureSyncCheckpoint()
bool IsSyncCheckpointEnforced()
Capture information about block/transaction validation.
Definition: main.h:1907
256-bit unsigned integer
Definition: uint256.h:537
static const std::string strMainPubKey
bool SendSyncCheckpoint(uint256 hashCheckpoint)
bool IsNull() const
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: main.h:1626
std::string ToString() const
Definition: uint256.h:343
CSyncCheckpoint checkpointMessagePending
bool AcceptPendingSyncCheckpoint()
bool IsSyncCheckpointTooOld(unsigned int nSeconds)
signed long long int64_t
Definition: stdint.h:18
CBlockIndex * pindexBest
Definition: main.cpp:45
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
Definition: util.cpp:586
An encapsulated private key.
Definition: key.h:172
int nHeight
Definition: main.h:1639
Information about a peer.
Definition: net.h:154
int nBestHeight
Definition: main.cpp:41
bool Verify(const uint256 &hash, const std::vector< unsigned char > &vchSig) const
Definition: key.cpp:343
bool WriteCheckpointPubKey(const std::string &strPubKey)
Definition: txdb.cpp:263
CBlockIndex * GetLastSyncCheckpoint()
Config::Pair_type Pair
void PushGetBlocks(CBlockIndex *pindexBegin, uint256 hashEnd)
Definition: net.cpp:85
map< uint256, CBlockIndex * > mapBlockIndex
Definition: main.cpp:37
vector< unsigned char > ParseHex(const char *psz)
Definition: util.cpp:500
uint32_t hash
Definition: cache.cc:34
CCriticalSection cs_vNodes
Definition: net.cpp:57
map< string, string > mapArgs
Definition: util.cpp:71
uint256 GetBlockHash() const
Definition: main.h:1744
bool SetCheckpointPrivKey(std::string strPrivKey)
const_iterator end() const
Definition: serialize.h:886