return Write(string("nBestInvalidTrust"), nBestInvalidTrust);
}
-bool CTxDB::ReadAutoCheckpoint(int& nAutoCheckpoint)
+bool CTxDB::ReadSyncCheckpoint(uint256& hashCheckpoint)
{
- return Read(string("nAutoCheckpoint"), nAutoCheckpoint);
+ return Read(string("hashSyncCheckpoint"), hashCheckpoint);
}
-bool CTxDB::WriteAutoCheckpoint(int nCheckpoint, bool fReset)
+bool CTxDB::WriteSyncCheckpoint(uint256 hashCheckpoint)
{
- nCheckpoint = fReset? nCheckpoint : max(Checkpoints::nAutoCheckpoint, nCheckpoint);
- return Write(string("nAutoCheckpoint"), nCheckpoint);
+ return Write(string("hashSyncCheckpoint"), hashCheckpoint);
}
-bool CTxDB::ReadSyncCheckpoint(uint256& hashCheckpoint)
+bool CTxDB::ReadCheckpointPubKey(string& strPubKey)
{
- return Read(string("hashSyncCheckpoint"), hashCheckpoint);
+ return Read(string("strCheckpointPubKey"), strPubKey);
}
-bool CTxDB::WriteSyncCheckpoint(uint256 hashCheckpoint)
+bool CTxDB::WriteCheckpointPubKey(const string& strPubKey)
{
- return Write(string("hashSyncCheckpoint"), hashCheckpoint);
+ return Write(string("strCheckpointPubKey"), strPubKey);
}
CBlockIndex static * InsertBlockIndex(uint256 hash)
pindexNew->nBlockPos = diskindex.nBlockPos;
pindexNew->nChainTrust = diskindex.nChainTrust;
pindexNew->nHeight = diskindex.nHeight;
- pindexNew->nCheckpoint = diskindex.nCheckpoint;
pindexNew->fProofOfStake = diskindex.fProofOfStake;
pindexNew->prevoutStake = diskindex.prevoutStake;
pindexNew->nVersion = diskindex.nVersion;
nBestChainTrust = pindexBest->nChainTrust;
printf("LoadBlockIndex(): hashBestChain=%s height=%d trust=%d\n", hashBestChain.ToString().substr(0,20).c_str(), nBestHeight, nBestChainTrust);
- // ppcoin: load nAutoCheckpoint
- if (!ReadAutoCheckpoint(Checkpoints::nAutoCheckpoint))
- return error("CTxDB::LoadBlockIndex() : nAutoCheckpoint not loaded");
- printf("LoadBlockIndex(): automatic checkpoint at height=%d\n", Checkpoints::nAutoCheckpoint);
-
// ppcoin: load hashSyncCheckpoint
if (!ReadSyncCheckpoint(Checkpoints::hashSyncCheckpoint))
return error("CTxDB::LoadBlockIndex() : hashSyncCheckpoint not loaded");
printf("LoadBlockIndex(): synchronized checkpoint %s\n", Checkpoints::hashSyncCheckpoint.ToString().c_str());
+ // ppcoin: if checkpoint master key changed must reset sync-checkpoint
+ string strPubKey = "";
+ if (!ReadCheckpointPubKey(strPubKey) || strPubKey != CSyncCheckpoint::strMasterPubKey)
+ {
+ // write checkpoint master key to db
+ TxnBegin();
+ WriteCheckpointPubKey(CSyncCheckpoint::strMasterPubKey);
+ if (!TxnCommit())
+ return error("CTxDB::LoadBlockIndex() : failed to write new checkpoint master key");
+ if (!Checkpoints::ResetSyncCheckpoint())
+ return error("CTxDB::LoadBlockIndex() : failed to reset sync-checkpoint");
+ }
+
// Load nBestInvalidTrust, OK if it doesn't exist
ReadBestInvalidTrust(nBestInvalidTrust);