Skip to content

Commit

Permalink
Add block blacklisting
Browse files Browse the repository at this point in the history
  • Loading branch information
yurykk committed Jul 31, 2022
1 parent 6d724fb commit a932f82
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,28 +123,45 @@ static Checkpoints::MapCheckpoints mapCheckpoints =
(550000, uint256("c6f21271fbdaec10dfee16d9cf4c4d073d78b1282d1aa4414001a4ec5fc05008"))
(650000, uint256("8942cf0b3850d448289ebe663e074c122bf0d36361bf6dd374aeeffa2b9c340b"))
(682400, uint256("89708f4d054771b2079854b415fb8d336d9f16c9b5cd1342d3b233229a35c97c")) // preparing update for 70926
(907970, uint256("3d9698bc000068035cebe5ed382ae5bb660b8debe271dffed70f914de22bc9aa"))
(907998, uint256("91ee7fb080b75f37cd96223134d52cccb9fdc19f2698c65a4343356a1421e0b0"))
// (, uint256(""))
;
//
// Blacklist
//
static Checkpoints::MapCheckpoints BadBlocks =
boost::assign::map_list_of
(907999, uint256("75759383da8f63daa3980f5b1767287a204124c317083780d457ebd6d15d4639")) // 29.7 - 908000
(908000, uint256("3a1daa15d6ab64d79d4f71e40dfde714fd5f0d181b12a4123d9e555b216fe358"))
;
static const Checkpoints::CCheckpointData data = {
&mapCheckpoints,
1630876592, // * UNIX timestamp of last checkpoint block
1762402, // * total number of transactions between genesis and last checkpoint
&BadBlocks,
1659113123, // * UNIX timestamp of last checkpoint block
2236602, // * total number of transactions between genesis and last checkpoint
// (the tx=... number in the SetBestChain debug.log lines)
0 // * estimated number of transactions per day after checkpoint
};

static Checkpoints::MapCheckpoints mapCheckpointsTestnet =
boost::assign::map_list_of(0, uint256("0x001"));
static Checkpoints::MapCheckpoints BadBlocksTestnet =
boost::assign::map_list_of(0, uint256("0x001"));
static const Checkpoints::CCheckpointData dataTestnet = {
&mapCheckpointsTestnet,
&BadBlocksTestnet,
1740710,
0,
250};

static Checkpoints::MapCheckpoints mapCheckpointsRegtest =
boost::assign::map_list_of(0, uint256("0x001"));
static Checkpoints::MapCheckpoints BadBlocksRegtest =
boost::assign::map_list_of(0, uint256("0x001"));
static const Checkpoints::CCheckpointData dataRegtest = {
&mapCheckpointsRegtest,
&BadBlocksRegtest,
1454124731,
0,
100};
Expand Down
5 changes: 5 additions & 0 deletions src/checkpoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ bool CheckBlock(int nHeight, const uint256& hash, bool fMatchesCheckpoint)
if (!fEnabled)
return true;

// Check if the block is Blacklisted
const MapCheckpoints& badblocks = *Params().Checkpoints().BadBlocks;
MapCheckpoints::const_iterator y = badblocks.find(nHeight);
if (y != badblocks.end()) return !(hash == y->second);

const MapCheckpoints& checkpoints = *Params().Checkpoints().mapCheckpoints;

MapCheckpoints::const_iterator i = checkpoints.find(nHeight);
Expand Down
1 change: 1 addition & 0 deletions src/checkpoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ typedef std::map<int, uint256> MapCheckpoints;

struct CCheckpointData {
MapCheckpoints* mapCheckpoints;
MapCheckpoints* BadBlocks;
int64_t nTimeLastCheckpoint;
int64_t nTransactionsLastCheckpoint;
double fTransactionsPerDay;
Expand Down
11 changes: 11 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5034,6 +5034,7 @@ bool CVerifyDB::VerifyDB(CCoinsView* coinsview, int nCheckLevel, int nCheckDepth
if (pindexFailure)
return error("VerifyDB() : *** coin database inconsistencies found (last %i blocks, %i good transactions before that)\n", chainActive.Height() - pindexFailure->nHeight + 1, nGoodTransactions);

CBlockIndex* invalidBlock = NULL;
// check level 4: try reconnecting blocks
if (nCheckLevel >= 4) {
CBlockIndex* pindex = pindexState;
Expand All @@ -5046,9 +5047,19 @@ bool CVerifyDB::VerifyDB(CCoinsView* coinsview, int nCheckLevel, int nCheckDepth
return error("VerifyDB() : *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
if (!ConnectBlock(block, state, pindex, coins, false))
return error("VerifyDB() : *** found unconnectable block at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
if ((invalidBlock == NULL) && !Checkpoints::CheckBlock(pindex->nHeight, pindex->GetBlockHash())) {
// return error("VerifyDB() : *** Checkpoint/Blacklist check fail at %d, hash=%s",pindex->nHeight, pindex->GetBlockHash().ToString());
LogPrintf("VerifyDB() : *** Checkpoint/Blacklist check fail at %d, hash=%s\n",pindex->nHeight, pindex->GetBlockHash().ToString());
invalidBlock = pindex;
// break;
}
}
}

// Invalidate blacklisted block (if found)
CValidationState inv_state;
if (invalidBlock != NULL) InvalidateBlock(inv_state, invalidBlock);

// Validate & Enforce last checkpoint

CBlockIndex* pindex = chainActive.Tip();
Expand Down

0 comments on commit a932f82

Please sign in to comment.