Skip to content

Commit

Permalink
Strip unneeded MTP data (#1089)
Browse files Browse the repository at this point in the history
* Allow stripping of MTP data

* Added arguments for MTP data srtipping testing

* Remove one MTP test

* Lifting strict rules preventing connection of older nodes

* Version bump to 0.14.9.2

* MTP data strip time is set on testnet

* Set date for MTP data stripping
  • Loading branch information
psolstice authored Nov 30, 2021
1 parent f8fd1a8 commit 7de8050
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 160 deletions.
1 change: 0 additions & 1 deletion src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ BITCOIN_TESTS = \
test/merkle_tests.cpp \
test/miner_tests.cpp \
test/mtp_halving_tests.cpp \
test/mtp_malformed_tests.cpp \
test/mtp_tests.cpp \
test/mtp_trans_tests.cpp \
test/firopow_tests.cpp \
Expand Down
7 changes: 7 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ class CMainParams : public CChainParams {
consensus.nMTPSwitchTime = SWITCH_TO_MTP_BLOCK_HEADER;
consensus.nMTPStartBlock = 117564;
consensus.nMTPFiveMinutesStartBlock = SWITCH_TO_MTP_5MIN_BLOCK;
consensus.nMTPStripDataTime = 1638954000; // December 08, 2021 09:00 UTC

consensus.nDifficultyAdjustStartBlock = 0;
consensus.nFixedDifficulty = 0x2000ffff;
Expand Down Expand Up @@ -567,6 +568,8 @@ class CTestNetParams : public CChainParams {
consensus.nMTPSwitchTime = 1539172800;
consensus.nMTPStartBlock = 1;
consensus.nMTPFiveMinutesStartBlock = 0;
consensus.nMTPStripDataTime = 1636362000; // November 08 2021, 09:00 UTC

consensus.nDifficultyAdjustStartBlock = 100;
consensus.nFixedDifficulty = 0x2000ffff;
consensus.nPowTargetSpacingMTP = 5*60;
Expand Down Expand Up @@ -807,6 +810,8 @@ class CDevNetParams : public CChainParams {
consensus.nMTPSwitchTime = 0;
consensus.nMTPStartBlock = 1;
consensus.nMTPFiveMinutesStartBlock = 0;
consensus.nMTPStripDataTime = INT_MAX;

consensus.nDifficultyAdjustStartBlock = 800;
consensus.nFixedDifficulty = 0x2000ffff;
consensus.nPowTargetSpacingMTP = 5*60;
Expand Down Expand Up @@ -1012,6 +1017,8 @@ class CRegTestParams : public CChainParams {
consensus.nMTPSwitchTime = INT_MAX;
consensus.nMTPStartBlock = 0;
consensus.nMTPFiveMinutesStartBlock = 0;
consensus.nMTPStripDataTime = INT_MAX;

consensus.nDifficultyAdjustStartBlock = 5000;
consensus.nFixedDifficulty = 0x207fffff;
consensus.nPowTargetSpacingMTP = 5*60;
Expand Down
3 changes: 3 additions & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ struct Params {
/** reduction coefficient for rewards after MTP kicks in */
int nMTPRewardReduction;

/** after this time MTP data is stripped from all the outgoing blocks */
uint32_t nMTPStripDataTime;

/** block number to disable zerocoin on consensus level */
int nDisableZerocoinStartBlock;

Expand Down
14 changes: 12 additions & 2 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1688,16 +1688,26 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
nMaxOutboundLimit = GetArg("-maxuploadtarget", DEFAULT_MAX_UPLOAD_TARGET)*1024*1024;
}

// ********************************************************* Prepare ProgPow test in regtest mode
// ********************************************************* Prepare ProgPow/MTP tests

Consensus::Params &mutableParams = const_cast<Consensus::Params &>(Params().GetConsensus());
if (Params().GetConsensus().IsRegtest()) {
Consensus::Params &mutableParams = const_cast<Consensus::Params &>(Params().GetConsensus());
if (IsArgSet("-ppswitchtime"))
mutableParams.nPPSwitchTime = GetArg("-ppswitchtime", INT_MAX);
else if (IsArgSet("-ppswitchtimefromnow"))
mutableParams.nPPSwitchTime = GetArg("-ppswitchtimefromnow", 0) + (uint32_t)GetTime();

if (IsArgSet("-mtpswitchtime"))
mutableParams.nMTPSwitchTime = GetArg("-mtpswitchtime", INT_MAX);
else if (IsArgSet("-mtpswitchtimefromnow"))
mutableParams.nMTPSwitchTime = GetArg("-mtpswitchtimefromnow", 0) + (uint32_t)GetTime();
}

if (IsArgSet("-mtpstripdatatime"))
mutableParams.nMTPStripDataTime = GetArg("-mtpstripdatatime", INT_MAX);
else if (IsArgSet("-mtpstripdatatimefromnow"))
mutableParams.nMTPStripDataTime = GetArg("-mtpstripdatatimefromnow", 0) + (uint32_t)GetTime();

// ********************************************************* Step 7a: check lite mode

// lite mode disables all Dash-specific functionality
Expand Down
20 changes: 20 additions & 0 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,20 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
CBlock block;
if (!ReadBlockFromDisk(block, (*mi).second, consensusParams))
assert(!"cannot load block from disk");
// Strip MTP data if past specific point of time
if (!block.IsProgPow() && block.IsMTP() && GetTime() >= consensusParams.nMTPStripDataTime) {
if (pfrom->nVersion >= MTPDATA_STRIPPED_VERSION) {
if (block.mtpHashData)
block.mtpHashData->StripMTPData();
}
else {
// node is not ready for a block with stripped MTP data. Skip the block if MTP
// data has already been stripped locally
if (!block.mtpHashData || block.mtpHashData->IsMTPDataStripped())
continue;
}
}

if (inv.type == MSG_BLOCK)
connman.PushMessage(pfrom, msgMaker.Make(SERIALIZE_TRANSACTION_NO_WITNESS, NetMsgType::BLOCK, block));
else if (inv.type == MSG_WITNESS_BLOCK)
Expand Down Expand Up @@ -2710,6 +2724,12 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>();
vRecv >> *pblock;

if (pblock->IsMTP() && !pblock->IsProgPow() && pblock->mtpHashData && GetTime() >= chainparams.GetConsensus().nMTPStripDataTime)
{
// we don't need MTP data anymore
pblock->mtpHashData->StripMTPData();
}

LogPrint("net", "received block %s peer=%d\n", pblock->GetHash().ToString(), pfrom->id);

// Process all blocks from whitelisted peers, even if not requested,
Expand Down
5 changes: 3 additions & 2 deletions src/pow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ bool CheckMerkleTreeProof(const CBlockHeader &block, const Consensus::Params &pa
if (!block.IsMTP() || block.IsProgPow())
return true;

if (!block.mtpHashData)
return false;
if (!block.mtpHashData || block.mtpHashData->IsMTPDataStripped())
// MTP data was stripped from the block, can't verify. Return true
return true;

uint256 calculatedMtpHashValue;
bool isVerified = mtp::verify(block.nNonce, block, Params().GetConsensus().powLimit, &calculatedMtpHashValue) &&
Expand Down
17 changes: 17 additions & 0 deletions src/primitives/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,19 @@ class CMTPHashData {
std::deque<std::vector<uint8_t>> nProofMTP[mtp::MTP_L*3];

CMTPHashData() {
memset(hashRootMTP, 0, sizeof(hashRootMTP));
memset(nBlockMTP, 0, sizeof(nBlockMTP));
}

bool IsMTPDataStripped() const {
// if MTP data is stripped for this block hashRootMTP is all zeroes
return std::all_of(hashRootMTP, hashRootMTP+16, [](uint8_t b) {return b==0;});
}

void StripMTPData() {
memset(hashRootMTP, 0, sizeof(hashRootMTP));
}

ADD_SERIALIZE_METHODS;

/**
Expand All @@ -65,6 +75,9 @@ class CMTPHashData {
template <typename Stream, typename Operation, typename = typename std::enable_if<!std::is_base_of<CSerActionUnserialize, Operation>::value>::type>
inline void SerializationOp(Stream &s, Operation ser_action) {
READWRITE(hashRootMTP);
if (IsMTPDataStripped())
return;

READWRITE(nBlockMTP);
for (int i = 0; i < mtp::MTP_L*3; i++) {
assert(nProofMTP[i].size() < 256);
Expand All @@ -82,6 +95,10 @@ class CMTPHashData {
template <typename Stream>
inline void SerializationOp(Stream &s, CSerActionUnserialize ser_action) {
READWRITE(hashRootMTP);

if (IsMTPDataStripped())
return;

READWRITE(nBlockMTP);
for (int i = 0; i < mtp::MTP_L*3; i++) {
uint8_t numberOfProofBlocks;
Expand Down
154 changes: 0 additions & 154 deletions src/test/mtp_malformed_tests.cpp

This file was deleted.

5 changes: 4 additions & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* network protocol versioning
*/

static const int PROTOCOL_VERSION = 90030;
static const int PROTOCOL_VERSION = 90031;

//! legacy znode protocol version
static const int LEGACY_ZNODES_PROTOCOL_VERSION = 90026;
Expand Down Expand Up @@ -60,4 +60,7 @@ static const int DMN_PROTO_VERSION = 90030;
//! introduction of LLMQs
static const int LLMQS_PROTO_VERSION = 90030;

//! introducing blocks with stripped MTP data
static const int MTPDATA_STRIPPED_VERSION = 90031;

#endif // BITCOIN_VERSION_H

0 comments on commit 7de8050

Please sign in to comment.