Skip to content

Commit

Permalink
Automatic Checkpointing
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushstar committed Jun 26, 2014
1 parent 646a38c commit 43413fa
Show file tree
Hide file tree
Showing 17 changed files with 814 additions and 29 deletions.
3 changes: 2 additions & 1 deletion deepcoin-qt.pro
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ SOURCES += src/qt/bitcoin.cpp \
src/cubehash.c \
src/shavite.c \
src/echo.c \
src/simd.c
src/simd.c \
src/checkpointsync.cpp

RESOURCES += src/qt/bitcoin.qrc

Expand Down
4 changes: 4 additions & 0 deletions src/bitcoinrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ static const CRPCCommand vRPCCommands[] =
{ "getworkex", &getworkex, true, false, true },
{ "listaccounts", &listaccounts, false, false, true },
{ "makekeypair", &makekeypair, true, false, false },
{ "getcheckpoint", &getcheckpoint, true, false, false },
{ "sendcheckpoint", &sendcheckpoint, true, false, false },
{ "enforcecheckpoint", &enforcecheckpoint, true, false, false },
{ "sendalert", &sendalert, true, false, false },
{ "settxfee", &settxfee, false, false, true },
{ "getblocktemplate", &getblocktemplate, true, false, false },
Expand Down Expand Up @@ -1204,6 +1207,7 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri
if (strMethod == "sendalert" && n > 4) ConvertTo<boost::int64_t>(params[4]);
if (strMethod == "sendalert" && n > 5) ConvertTo<boost::int64_t>(params[5]);
if (strMethod == "sendalert" && n > 6) ConvertTo<boost::int64_t>(params[6]);
if (strMethod == "enforcecheckpoint" && n > 0) ConvertTo<bool>(params[0]);

return params;
}
Expand Down
3 changes: 3 additions & 0 deletions src/bitcoinrpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ extern json_spirit::Value listtransactions(const json_spirit::Array& params, boo
extern json_spirit::Value listaddressgroupings(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value listaccounts(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value makekeypair(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getcheckpoint(const json_spirit::Array& params, bool fHelp); // in checkpointsync.cpp
extern json_spirit::Value sendcheckpoint(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value enforcecheckpoint(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value sendalert(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value listsinceblock(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value gettransaction(const json_spirit::Array& params, bool fHelp);
Expand Down
17 changes: 17 additions & 0 deletions src/checkpoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,21 @@ namespace Checkpoints
}
return NULL;
}

uint256 GetLastAvailableCheckpoint() {
const MapCheckpoints& checkpoints = (fTestNet ? mapCheckpointsTestnet : mapCheckpoints);

BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, checkpoints) {
const uint256& hash = i.second;
if(mapBlockIndex.count(hash) && mapBlockIndex[hash]->IsInMainChain())
return(hash);
}
return(hashGenesisBlock);
}

uint256 GetLatestHardenedCheckpoint()
{
const MapCheckpoints& checkpoints = *Checkpoints().mapCheckpoints;
return (checkpoints.rbegin()->second);
}
}
6 changes: 6 additions & 0 deletions src/checkpoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ namespace Checkpoints
// Returns last CBlockIndex* in mapBlockIndex that is a checkpoint
CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex);

/* Returns the last available checkpoint in the main chain */
uint256 GetLastAvailableCheckpoint();

// Returns the block hash of latest hardened checkpoint
uint256 GetLatestHardenedCheckpoint();

double GuessVerificationProgress(CBlockIndex *pindex);
}

Expand Down
Loading

0 comments on commit 43413fa

Please sign in to comment.