#include "db.h"
#include "net.h"
#include "init.h"
+#include "checkpoints.h"
#undef printf
#include <boost/asio.hpp>
#include <boost/iostreams/concepts.hpp>
}
+// ppcoin: reset auto checkpoint
+Value resetcheckpoint(const Array& params, bool fHelp)
+{
+ if (fHelp || params.size() < 1 || params.size() > 1)
+ throw runtime_error(
+ "resetcheckpoint <checkpointheight>\n"
+ "Reset automatic checkpoint to specified height.\n"
+ "<checkpointheight> is the height of the new checkpoint block.\n");
+
+ int nCheckpoint = params[0].get_int();
+ if (nCheckpoint <= 0 || nCheckpoint >= nBestHeight)
+ throw runtime_error(
+ "invalid checkpoint height.\n"
+ );
+ if (nCheckpoint >= Checkpoints::nAutoCheckpoint)
+ throw runtime_error(
+ "new checkpoint must be earlier than current auto checkpoint.\n"
+ );
+ if (!Checkpoints::ResetAutoCheckpoint(nCheckpoint))
+ throw runtime_error(
+ "internal error - reset checkpoint failed.\n"
+ );
+
+ return Value::null;
+}
+
+
+// ppcoin: get branch point of alternative branch
+Value getbranchpoint(const Array& params, bool fHelp)
+{
+ if (fHelp || params.size() != 0)
+ throw runtime_error(
+ "getbranchpoint\n"
+ "Returns height of branch point of alternative branch.\n");
+ Object result;
+ if (Checkpoints::nBranchPoint > 0)
+ result.push_back(Pair("branchpoint", Checkpoints::nBranchPoint));
+ else
+ result.push_back(Pair("branchpoint", "none"));
+ result.push_back(Pair("checkpoint", Checkpoints::nAutoCheckpoint));
+ return result;
+}
make_pair("settxfee", &settxfee),
make_pair("getmemorypool", &getmemorypool),
make_pair("listsinceblock", &listsinceblock),
+ make_pair("resetcheckpoint", &resetcheckpoint),
+ make_pair("getbranchpoint", &getbranchpoint),
};
map<string, rpcfn_type> mapCallTable(pCallTable, pCallTable + sizeof(pCallTable)/sizeof(pCallTable[0]));
params[1] = v.get_obj();
}
if (strMethod == "sendmany" && n > 2) ConvertTo<boost::int64_t>(params[2]);
+ if (strMethod == "resetcheckpoint" && n > 0) ConvertTo<boost::int64_t>(params[0]);
// Execute
Object reply = CallRPC(strMethod, params);
// Copyright (c) 2011 The Bitcoin developers
-// Copyright (c) 2011 The PPCoin developers
+// Copyright (c) 2011-2012 The PPCoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
// ppcoin: automatic checkpoint (represented by height of checkpoint)
int nAutoCheckpoint = 0;
+ int nBranchPoint = 0; // branch point to alternative branch
bool CheckHardened(int nHeight, const uint256& hash)
{
if (pindex->nHeight >= nAutoCheckpoint)
return true;
else
+ {
+ nBranchPoint = pindex->nHeight;
return error("Checkpoints: new block on alternative branch at height=%d before auto checkpoint at height=%d", pindex->nHeight, nAutoCheckpoint);
+ }
}
else
pindex = pindex->pprev;
return mapCheckpoints.rbegin()->first;
}
+ // ppcoin: reset auto checkpoint
+ bool ResetAutoCheckpoint(int nCheckpoint)
+ {
+ if (nCheckpoint <= 0 || nCheckpoint > nBestHeight)
+ return error("ResetAutoCheckpoint() : new checkpoint invalid");
+ if (nCheckpoint >= nAutoCheckpoint)
+ return error("ResetAutoCheckpoint() : new checkpoint not earlier than current auto checkpoint");
+ CTxDB txdb;
+ txdb.TxnBegin();
+ if (!txdb.WriteAutoCheckpoint(nCheckpoint, true))
+ return error("ResetAutoCheckpoint() : database write failed");
+ if (!txdb.TxnCommit())
+ return error("ResetAutoCheckpoint() : database commit failed");
+ nAutoCheckpoint = nCheckpoint;
+ nBranchPoint = 0; // clear branch point
+
+ // clear ban list to accept alternative branches
+ CRITICAL_BLOCK(cs_vNodes)
+ {
+ BOOST_FOREACH(CNode* pnode, vNodes)
+ pnode->ClearBanned();
+ }
+
+ return true;
+ }
+
CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex)
{
if (fTestNet) return NULL;
// Copyright (c) 2011 The Bitcoin developers
-// Copyright (c) 2011 The PPCoin developers
+// Copyright (c) 2011-2012 The PPCoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_CHECKPOINT_H
namespace Checkpoints
{
extern int nAutoCheckpoint;
+ extern int nBranchPoint;
// Returns true if block passes checkpoint checks
bool CheckHardened(int nHeight, const uint256& hash);
int GetNextChainCheckpoint(const CBlockIndex *pindex);
int GetNextAutoCheckpoint(int nCheckpoint);
void AdvanceAutoCheckpoint(int nCheckpoint);
+ bool ResetAutoCheckpoint(int nCheckpoint);
// Return conservative estimate of total number of blocks, 0 if unknown
int GetTotalBlocksEstimate();
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2011 The Bitcoin developers
-// Copyright (c) 2011 The PPCoin developers
+// Copyright (c) 2011-2012 The PPCoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
return Read(string("nAutoCheckpoint"), nAutoCheckpoint);
}
-bool CTxDB::WriteAutoCheckpoint(int nCheckpoint)
+bool CTxDB::WriteAutoCheckpoint(int nCheckpoint, bool fReset)
{
- return Write(string("nAutoCheckpoint"), max(Checkpoints::nAutoCheckpoint, nCheckpoint));
+ nCheckpoint = fReset? nCheckpoint : max(Checkpoints::nAutoCheckpoint, nCheckpoint);
+ return Write(string("nAutoCheckpoint"), nCheckpoint);
}
CBlockIndex static * InsertBlockIndex(uint256 hash)
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2011 The Bitcoin developers
-// Copyright (c) 2011 The PPCoin developers
+// Copyright (c) 2011-2012 The PPCoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_DB_H
bool ReadBestInvalidTrust(uint64& nBestInvalidTrust);
bool WriteBestInvalidTrust(uint64 nBestInvalidTrust);
bool ReadAutoCheckpoint(int& nAutoCheckpoint);
- bool WriteAutoCheckpoint(int nCheckpoint);
+ bool WriteAutoCheckpoint(int nCheckpoint, bool fReset=false);
bool LoadBlockIndex();
};