Skip to content

Commit

Permalink
Merge pull request #678 from denravonska/remove-checkpoint-relaying
Browse files Browse the repository at this point in the history
Remove checkpoint relaying.
  • Loading branch information
denravonska committed Oct 12, 2017
2 parents 9b9c180 + c949a02 commit be801a3
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 808 deletions.
465 changes: 15 additions & 450 deletions src/checkpoints.cpp
100644 → 100755

Large diffs are not rendered by default.

141 changes: 2 additions & 139 deletions src/checkpoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,14 @@
#include "net.h"
#include "util.h"

#ifdef WIN32
#undef STRICT
#undef PERMISSIVE
#undef ADVISORY
#endif

class uint256;
class CBlockIndex;
class CSyncCheckpoint;


/** Block-chain checkpoints are compiled-in sanity checks.
* They are updated every release or three.
*/
namespace Checkpoints
{
/** Checkpointing mode */
enum CPMode
{
// Scrict checkpoints policy, perform conflicts verification and resolve conflicts
STRICT = 0,
// Advisory checkpoints policy, perform conflicts verification but don't try to resolve them
ADVISORY = 1,
// Permissive checkpoints policy, don't perform any checking
PERMISSIVE = 2
};

// Returns true if block passes checkpoint checks
bool CheckHardened(int nHeight, const uint256& hash);

Expand All @@ -44,126 +25,8 @@ namespace Checkpoints
// Returns last CBlockIndex* in mapBlockIndex that is a checkpoint
CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex);

extern uint256 hashSyncCheckpoint;
extern CSyncCheckpoint checkpointMessage;
extern uint256 hashInvalidCheckpoint;
extern CCriticalSection cs_hashSyncCheckpoint;

CBlockIndex* GetLastSyncCheckpoint();
bool WriteSyncCheckpoint(const uint256& hashCheckpoint);
bool AcceptPendingSyncCheckpoint();
uint256 AutoSelectSyncCheckpoint();
bool CheckSync(const uint256& hashBlock, const CBlockIndex* pindexPrev);
bool WantedByPendingSyncCheckpoint(uint256 hashBlock);
bool ResetSyncCheckpoint();
void AskForPendingSyncCheckpoint(CNode* pfrom);
bool SetCheckpointPrivKey(std::string strPrivKey);
bool SendSyncCheckpoint(uint256 hashCheckpoint);
bool SendSyncCheckpointWithBalance(uint256 hashCheckpoint, double nBalance, std::string SendingWalletAddress);
bool SendSyncHashCheckpoint(uint256 hash1, std::string SendingWalletAddress);

bool IsMatureSyncCheckpoint();
const CBlockIndex* AutoSelectSyncCheckpoint();
bool CheckSync(int nHeight);
}

// ppcoin: synchronized checkpoint
class CUnsignedSyncCheckpoint
{
public:
int nVersion;
uint256 hashCheckpoint; // checkpoint block
double balance;
std::string SendingWalletAddress;
std::string SendersWalletAddress;
uint256 hashCheckpointGlobal;

IMPLEMENT_SERIALIZE
(
READWRITE(this->nVersion);
nVersion = this->nVersion;
READWRITE(hashCheckpoint);
READWRITE(balance);
READWRITE(SendingWalletAddress);
READWRITE(hashCheckpointGlobal);
)

void SetNull()
{
nVersion = 1;
hashCheckpoint = 0;
}

std::string ToString() const
{
return strprintf(
"CSyncCheckpoint(\n"
" nVersion = %d\n"
" hashCheckpoint = %s\n"
")\n",
nVersion,
hashCheckpoint.ToString().c_str());
}

void print() const
{
printf("%s", ToString().c_str());
}
};

class CSyncCheckpoint : public CUnsignedSyncCheckpoint
{
public:
static const std::string strMasterPubKey;
static std::string strMasterPrivKey;

std::vector<unsigned char> vchMsg;
std::vector<unsigned char> vchSig;

CSyncCheckpoint()
{
SetNull();
}

IMPLEMENT_SERIALIZE
(
READWRITE(vchMsg);
READWRITE(vchSig);
READWRITE(balance);
READWRITE(SendingWalletAddress);
READWRITE(hashCheckpointGlobal);
)

void SetNull()
{
CUnsignedSyncCheckpoint::SetNull();
vchMsg.clear();
vchSig.clear();
}

bool IsNull() const
{
return (hashCheckpoint == 0);
}

uint256 GetHash() const
{
return SerializeHash(*this);
}

bool RelayTo(CNode* pnode) const
{
// returns true if wasn't already sent
if (pnode->hashCheckpointKnown != hashCheckpoint)
{
pnode->hashCheckpointKnown = hashCheckpoint;
pnode->PushMessage("checkpoint", *this);
return true;
}
return false;
}

bool CheckSignature();
bool CheckSignatureWithBalance();
bool ProcessSyncCheckpoint(CNode* pfrom);
};

#endif
24 changes: 0 additions & 24 deletions src/init.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "init.h"
#include "util.h"
#include "ui_interface.h"
#include "checkpoints.h"
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/filesystem/convenience.hpp>
Expand Down Expand Up @@ -46,7 +45,6 @@ extern unsigned int nNodeLifespan;
extern unsigned int nDerivationMethodIndex;
extern unsigned int nMinerSleep;
extern bool fUseFastIndex;
extern enum Checkpoints::CPMode CheckpointsMode;
void InitializeBoincProjects();


Expand Down Expand Up @@ -335,7 +333,6 @@ std::string HelpMessage()
" -bind=<addr> " + _("Bind to given address. Use [host]:port notation for IPv6") + "\n" +
" -dnsseed " + _("Find peers using DNS lookup (default: 1)") + "\n" +
" -synctime " + _("Sync time with other nodes. Disable if time on your system is precise e.g. syncing with NTP (default: 1)") + "\n" +
" -cppolicy " + _("Sync checkpoints policy (default: strict)") + "\n" +
" -banscore=<n> " + _("Threshold for disconnecting misbehaving peers (default: 100)") + "\n" +
" -bantime=<n> " + _("Number of seconds to keep misbehaving peers from reconnecting (default: 86400)") + "\n" +
" -maxreceivebuffer=<n> " + _("Maximum per-connection receive buffer, <n>*1000 bytes (default: 5000)") + "\n" +
Expand Down Expand Up @@ -506,21 +503,6 @@ bool AppInit2(boost::shared_ptr<ThreadHandler> threads)
fUseFastIndex = GetBoolArg("-fastindex", false);

nMinerSleep = GetArg("-minersleep", 8000);

CheckpointsMode = Checkpoints::STRICT;
//CheckpointsMode = Checkpoints::ADVISORY;

std::string strCpMode = GetArg("-cppolicy", "strict");

if(strCpMode == "strict")
CheckpointsMode = Checkpoints::STRICT;

if(strCpMode == "advisory")
CheckpointsMode = Checkpoints::ADVISORY;

if(strCpMode == "permissive")
CheckpointsMode = Checkpoints::PERMISSIVE;

nDerivationMethodIndex = 0;

fTestNet = GetBoolArg("-testnet");
Expand Down Expand Up @@ -845,12 +827,6 @@ bool AppInit2(boost::shared_ptr<ThreadHandler> threads)
}
}

if (mapArgs.count("-checkpointkey")) // ppcoin: checkpoint master priv key
{
if (!Checkpoints::SetCheckpointPrivKey(GetArg("-checkpointkey", "")))
InitError(_("Unable to sign checkpoint, wrong checkpointkey?\n"));
}

for (auto const& strDest : mapMultiArgs["-seednode"])
AddOneShot(strDest);

Expand Down
Loading

0 comments on commit be801a3

Please sign in to comment.