Skip to content

Commit

Permalink
Unlocked compilation following merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
abi87 committed Apr 2, 2021
1 parent 9166f3a commit ed30eb7
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 228 deletions.
3 changes: 1 addition & 2 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ class CTestNetParams : public CMainParams {
(520000, uint256S("0x00052e65426a0ffbb90893208a6c89a82816abbed328fa2be5a647828609e61a"))
(595000, uint256S("0x0000da85ddc79fdd297e996d6b6b887fc5b345619b7a6726c496941dcf830966"))
(643000, uint256S("0x0000cabf39e3ac435d54b95c32e6173d6bb1b060066ecb7453d2146a0dd40947"))

//TODO: CONFLICT TO BE FIXED UPON RELEASE BY REPLACING CHECKPOINTS BELOW WITH A SINGLE ONE ON OFFICIAL TESTNET
//TODO: CONFLICT TO BE FIXED UPON RELEASE BY REPLACING CHECKPOINTS BELOW WITH A SINGLE ONE ON OFFICIAL TESTNET
//<<<<<<< HEAD
(655826, uint256S("0x00036f9e25a28763e6b5385988b2d36aec99a051854ab32bc0efff4ff65aa2f4")) // split from normal testnet
(657000, uint256S("0x013bbc2e60182c16479f082f9a0470183544fe11c572609c71a39e2588dd157d")), // sidechain testnet HF activation block
Expand Down
30 changes: 14 additions & 16 deletions src/gtest/test_checkblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,15 +489,14 @@ TEST(ContextualCheckBlock, CoinbaseCommunityReward) {

mtx.vin[0].scriptSig = CScript() << exceedHeight << OP_0;

mtx.vout.resize(3);
mtx.vout[0].scriptPubKey = CScript() << OP_HASH160 << ToByteVector(scriptID_found) << OP_EQUAL;
mtx.vout[0].nValue = 2.5 * COIN;
CTxOut out_0(CAmount(2.5 * COIN),CScript() << OP_HASH160 << ToByteVector(scriptID_found) << OP_EQUAL);
mtx.addOut(out_0);

mtx.vout[1].scriptPubKey = CScript() << OP_HASH160 << ToByteVector(scriptID_sec_node) << OP_EQUAL;
mtx.vout[1].nValue = 1.25 * COIN;
CTxOut out_1(CAmount(1.25 * COIN), CScript() << OP_HASH160 << ToByteVector(scriptID_sec_node) << OP_EQUAL);
mtx.addOut(out_1);

mtx.vout[2].scriptPubKey = CScript() << OP_HASH160 << ToByteVector(scriptID_sup_node) << OP_EQUAL;
mtx.vout[2].nValue = 1.25 * COIN;
CTxOut out_2(CAmount(1.25 * COIN), CScript() << OP_HASH160 << ToByteVector(scriptID_sup_node) << OP_EQUAL);
mtx.addOut(out_2);

indexPrev.nHeight = exceedHeight -1;
block.vtx[0] = CTransaction(mtx);
Expand All @@ -519,19 +518,18 @@ TEST(ContextualCheckBlock, CoinbaseCommunityReward) {

mtx.vin[0].scriptSig = CScript() << exceedHeight << OP_0;

mtx.vout.resize(4);
// add also miner subsidy quote, even if it is not checked by ContextualCheckBlock()
mtx.vout[0].scriptPubKey = CScript() << OP_HASH160 << ParseHex("28daa861e86d49694937c3ee6e637d50e8343e4b") << OP_EQUAL;
mtx.vout[0].nValue = 1.8755 * COIN;
CTxOut output_0(1.8755 * COIN,CScript() << OP_HASH160 << ParseHex("28daa861e86d49694937c3ee6e637d50e8343e4b") << OP_EQUAL);
mtx.addOut(output_0);

mtx.vout[1].scriptPubKey = CScript() << OP_HASH160 << ToByteVector(scriptID_found) << OP_EQUAL;
mtx.vout[1].nValue = 0.625 * COIN;
CTxOut output_1(1.0 * COIN, CScript() << OP_HASH160 << ToByteVector(scriptID_found) << OP_EQUAL);
mtx.addOut(output_1);

mtx.vout[2].scriptPubKey = CScript() << OP_HASH160 << ToByteVector(scriptID_sec_node) << OP_EQUAL;
mtx.vout[2].nValue = 0.3125 * COIN;
CTxOut output_2(0.3125 * COIN, CScript() << OP_HASH160 << ToByteVector(scriptID_sec_node) << OP_EQUAL);
mtx.addOut(output_2);

mtx.vout[3].scriptPubKey = CScript() << OP_HASH160 << ToByteVector(scriptID_sup_node) << OP_EQUAL;
mtx.vout[3].nValue = 0.3125 * COIN;
CTxOut output_3(0.3125 * COIN, CScript() << OP_HASH160 << ToByteVector(scriptID_sup_node) << OP_EQUAL);
mtx.addOut(output_3);

indexPrev.nHeight = exceedHeight -1;
block.vtx[0] = CTransaction(mtx);
Expand Down
209 changes: 2 additions & 207 deletions src/gtest/test_checktransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,7 @@ TEST(SidechainsCertificateManipulation, NonEmptyCertTransformationToMutableIsRev
CScript bwtScript = CScript() << OP_DUP << OP_HASH160 << ToByteVector(uint160()) << OP_EQUALVERIFY << OP_CHECKSIG;
for(unsigned int idx = 0; idx < bwtOut; ++idx)
helperMutCert.addBwt(CTxOut(CAmount(idx),bwtScript));

CScCertificate nonEmptyOriginalCert(helperMutCert);

// CopyCtor -> CopyCtor
Expand Down Expand Up @@ -747,212 +748,6 @@ TEST(SidechainsCertificateManipulation, NonEmptyCertTransformationToMutableIsRev
<<" revertedTxByAssignOp.GetHash() "<<revertedCertByAssignOp.GetHash().ToString();
}

extern const CBlockIndex* makeMain(int trunk_size);
extern void CleanUpAll();

TEST(checktransaction_tests, isStandardTransaction) {

/*
fDebug = true;
fPrintToConsole = true;
mapMultiArgs["-debug"].push_back("cbh");
mapArgs["-debug"] = "cbh";
*/

SelectParams(CBaseChainParams::REGTEST);
CMutableTransaction mtx = GetValidTransaction(TRANSPARENT_TX_VERSION);

mtx.vout.resize(9);

// a -1 value for height, minimally encoded
mtx.vout[0].nValue = 1;
mtx.vout[0].scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(uint160()) << OP_EQUALVERIFY << OP_CHECKSIG
<< ToByteVector(uint256()) << -1 << OP_CHECKBLOCKATHEIGHT;

// height and hash are swapped
mtx.vout[1].nValue = 1;
mtx.vout[1].scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(uint160()) << OP_EQUALVERIFY << OP_CHECKSIG
<< 2 << ToByteVector(uint256()) << OP_CHECKBLOCKATHEIGHT;

// an invalid op (0xFF) where height is expected
std::vector<unsigned char> data1(ParseHex("76a914f85d211e4175cd4b0f53284af6ddab6bbb3c5f0288ac20bf309c2d04f3fdd3cb6f4ccddb3985211d360e08e4f790c3d780d5c3f912e704ffb4"));
CScript bad_script1(data1.begin(), data1.end());
//std::cout << bad_script1.ToString() << std::endl;
mtx.vout[2].nValue = 1;
mtx.vout[2].scriptPubKey = bad_script1;

// an unknown op (0xBA) where height is expected
std::vector<unsigned char> data2(ParseHex("76a914f85d211e4175cd4b0f53284af6ddab6bbb3c5f0288ac20bf309c2d04f3fdd3cb6f4ccddb3985211d360e08e4f790c3d780d5c3f912e704bab4"));
CScript bad_script2(data2.begin(), data2.end());
//std::cout << bad_script2.ToString() << std::endl;
mtx.vout[3].nValue = 1;
mtx.vout[3].scriptPubKey = bad_script2;

// a non minimal height, caught by CScriptNum
std::vector<unsigned char> hnm1(ParseHex("01000000"));
mtx.vout[4].nValue = 1;
mtx.vout[4].scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(uint160()) << OP_EQUALVERIFY << OP_CHECKSIG
<< ToByteVector(uint256()) << hnm1 << OP_CHECKBLOCKATHEIGHT;
//std::cout << mtx.vout[4].scriptPubKey.ToString() << std::endl;
//std::string dumStr = HexStr(mtx.vout[4].begin(), mtx.vout[4].end());
//std::cout << dumStr << std::endl;

// another non minimal height
std::vector<unsigned char> hnm2(ParseHex("00"));
mtx.vout[5].nValue = 1;
mtx.vout[5].scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(uint160()) << OP_EQUALVERIFY << OP_CHECKSIG
<< ToByteVector(uint256()) << hnm2 << OP_CHECKBLOCKATHEIGHT;

// another non minimal height, not caught by CScriptNum but checking minimal pushing
std::vector<unsigned char> hnm3(ParseHex("10"));
mtx.vout[6].nValue = 1;
mtx.vout[6].scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(uint160()) << OP_EQUALVERIFY << OP_CHECKSIG
<< ToByteVector(uint256()) << hnm3 << OP_CHECKBLOCKATHEIGHT;

// minimal height, ok in both forks
std::vector<unsigned char> hnm4(ParseHex("11"));
mtx.vout[7].nValue = 1;
mtx.vout[7].scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(uint160()) << OP_EQUALVERIFY << OP_CHECKSIG
<< ToByteVector(uint256()) << hnm4 << OP_CHECKBLOCKATHEIGHT;

// an OP_0 op (0x00) where height is expected
std::vector<unsigned char> good_data(ParseHex("76a914f85d211e4175cd4b0f53284af6ddab6bbb3c5f0288ac20bf309c2d04f3fdd3cb6f4ccddb3985211d360e08e4f790c3d780d5c3f912e70400b4"));
CScript good_script(good_data.begin(), good_data.end());
//std::cout << good_script.ToString() << std::endl;
//std::string dumStr = HexStr(good_script.begin(), good_script.end());
//std::cout << dumStr << std::endl;
mtx.vout[8].nValue = 1;
mtx.vout[8].scriptPubKey = good_script;

CTransaction tx(mtx);

// these are expected to fail in both forks
CMutableTransaction mtx_bad_param = GetValidTransaction(TRANSPARENT_TX_VERSION);

mtx_bad_param.vout.resize(4);

// a hash representation shorter than 32 bytes
std::vector<unsigned char> data31NullBytes;
data31NullBytes.resize(31);
mtx_bad_param.vout[0].nValue = 1;
mtx_bad_param.vout[0].scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(uint160()) << OP_EQUALVERIFY << OP_CHECKSIG
<< data31NullBytes << 19 << OP_CHECKBLOCKATHEIGHT;

// a hash representation longer than 32 bytes
std::vector<unsigned char> data33NullBytes;
data33NullBytes.resize(33);
mtx_bad_param.vout[1].nValue = 1;
mtx_bad_param.vout[1].scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(uint160()) << OP_EQUALVERIFY << OP_CHECKSIG
<< data33NullBytes << 19 << OP_CHECKBLOCKATHEIGHT;

// a -1 height not minimally encoded, caught in different places before an after the fork
std::vector<unsigned char> hnm5(ParseHex("81"));
mtx_bad_param.vout[2].nValue = 1;
mtx_bad_param.vout[2].scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(uint160()) << OP_EQUALVERIFY << OP_CHECKSIG
<< ToByteVector(uint256()) << hnm5 << OP_CHECKBLOCKATHEIGHT;

// a height larger than 4 bytes
std::vector<unsigned char> hnm6(ParseHex("aabbccddee"));
mtx_bad_param.vout[3].nValue = 1;
mtx_bad_param.vout[3].scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(uint160()) << OP_EQUALVERIFY << OP_CHECKSIG
<< ToByteVector(uint256()) << hnm6 << OP_CHECKBLOCKATHEIGHT;

CTransaction tx_bad_param(mtx_bad_param);

ReplayProtectionAttributes rpAttributes;
txnouttype whichType;
std::string reason;


// ------------------ before rp fix
static const int H_PRE_FORK = 220;
CleanUpAll();
makeMain(H_PRE_FORK);

// This is useful only for the tests of pre-rp-fix fork.
// This is for avoiding checking blockheight against blockhash in scripts, because hashes are fake
// in this simple test environment, and it would always make IsStandard() return false even when scripts parse ok.
mapArgs["-cbhsafedepth"] = "10";

EXPECT_TRUE(IsStandardTx(tx, reason, H_PRE_FORK));

EXPECT_TRUE(IsStandard(tx.vout[0].scriptPubKey, whichType, rpAttributes));
EXPECT_TRUE(whichType == TX_PUBKEYHASH_REPLAY);
EXPECT_TRUE(IsStandard(tx.vout[1].scriptPubKey, whichType, rpAttributes));
EXPECT_TRUE(whichType == TX_PUBKEYHASH_REPLAY);
EXPECT_TRUE(IsStandard(tx.vout[2].scriptPubKey, whichType, rpAttributes));
EXPECT_TRUE(whichType == TX_PUBKEYHASH_REPLAY);
EXPECT_TRUE(IsStandard(tx.vout[3].scriptPubKey, whichType, rpAttributes));
EXPECT_TRUE(whichType == TX_PUBKEYHASH_REPLAY);
EXPECT_TRUE(IsStandard(tx.vout[4].scriptPubKey, whichType, rpAttributes));
EXPECT_TRUE(whichType == TX_PUBKEYHASH_REPLAY);
EXPECT_TRUE(IsStandard(tx.vout[5].scriptPubKey, whichType, rpAttributes));
EXPECT_TRUE(whichType == TX_PUBKEYHASH_REPLAY);
EXPECT_TRUE(IsStandard(tx.vout[6].scriptPubKey, whichType, rpAttributes));
EXPECT_TRUE(whichType == TX_PUBKEYHASH_REPLAY);
EXPECT_TRUE(IsStandard(tx.vout[7].scriptPubKey, whichType, rpAttributes));
EXPECT_TRUE(whichType == TX_PUBKEYHASH_REPLAY);
EXPECT_TRUE(IsStandard(tx.vout[8].scriptPubKey, whichType, rpAttributes));
EXPECT_TRUE(whichType == TX_PUBKEYHASH_REPLAY);

// expecting to fail before and after the fork
EXPECT_FALSE(IsStandardTx(tx_bad_param, reason, H_PRE_FORK));
EXPECT_TRUE(reason == "scriptpubkey");

EXPECT_FALSE(IsStandard(tx_bad_param.vout[0].scriptPubKey, whichType, rpAttributes));
EXPECT_TRUE(whichType == TX_NONSTANDARD);
EXPECT_FALSE(IsStandard(tx_bad_param.vout[1].scriptPubKey, whichType, rpAttributes));
EXPECT_TRUE(whichType == TX_NONSTANDARD);
EXPECT_FALSE(IsStandard(tx_bad_param.vout[2].scriptPubKey, whichType, rpAttributes));
EXPECT_TRUE(whichType == TX_NONSTANDARD);
EXPECT_FALSE(IsStandard(tx_bad_param.vout[3].scriptPubKey, whichType, rpAttributes));
EXPECT_TRUE(whichType == TX_NONSTANDARD);



// ------------------ after rp fix
static const int H_POST_FORK = 500;
CleanUpAll();
makeMain(H_POST_FORK);

EXPECT_FALSE(IsStandardTx(tx, reason, H_POST_FORK));
EXPECT_TRUE(reason == "scriptpubkey");

EXPECT_FALSE(IsStandard(tx.vout[0].scriptPubKey, whichType, rpAttributes));
EXPECT_TRUE(whichType == TX_NONSTANDARD);
EXPECT_FALSE(IsStandard(tx.vout[1].scriptPubKey, whichType, rpAttributes));
EXPECT_TRUE(whichType == TX_NONSTANDARD);
EXPECT_FALSE(IsStandard(tx.vout[2].scriptPubKey, whichType, rpAttributes));
EXPECT_TRUE(whichType == TX_NONSTANDARD);
EXPECT_FALSE(IsStandard(tx.vout[3].scriptPubKey, whichType, rpAttributes));
EXPECT_TRUE(whichType == TX_NONSTANDARD);

// non minimal height encodings are not legal anymore
EXPECT_FALSE(IsStandard(tx.vout[4].scriptPubKey, whichType, rpAttributes));
EXPECT_FALSE(IsStandard(tx.vout[5].scriptPubKey, whichType, rpAttributes));
EXPECT_FALSE(IsStandard(tx.vout[6].scriptPubKey, whichType, rpAttributes));

// legal height encodings
EXPECT_TRUE(IsStandard(tx.vout[7].scriptPubKey, whichType, rpAttributes));
EXPECT_TRUE(whichType == TX_PUBKEYHASH_REPLAY);

EXPECT_TRUE(IsStandard(tx.vout[8].scriptPubKey, whichType, rpAttributes));
EXPECT_TRUE(whichType == TX_PUBKEYHASH_REPLAY);

// expecting to fail before and after the fork
EXPECT_FALSE(IsStandardTx(tx_bad_param, reason, H_PRE_FORK));
EXPECT_TRUE(reason == "scriptpubkey");

EXPECT_FALSE(IsStandard(tx_bad_param.vout[0].scriptPubKey, whichType, rpAttributes));
EXPECT_TRUE(whichType == TX_NONSTANDARD);
EXPECT_FALSE(IsStandard(tx_bad_param.vout[1].scriptPubKey, whichType, rpAttributes));
EXPECT_TRUE(whichType == TX_NONSTANDARD);
EXPECT_FALSE(IsStandard(tx_bad_param.vout[2].scriptPubKey, whichType, rpAttributes));
EXPECT_TRUE(whichType == TX_NONSTANDARD);
EXPECT_FALSE(IsStandard(tx_bad_param.vout[3].scriptPubKey, whichType, rpAttributes));
EXPECT_TRUE(whichType == TX_NONSTANDARD);
}

TEST(SidechainsCertificateManipulation, ExtendingCertificateOutsAndBwts) {
CMutableScCertificate mutCert;
EXPECT_TRUE(mutCert.getVout().size() == 0);
Expand Down Expand Up @@ -1238,7 +1033,7 @@ TEST(checktransaction_tests, isStandardTransaction) {



// ------------------ after rp fix
// ------------------ after rp fix
static const int H_POST_FORK = 500;
CleanUpAll();
makeMain(H_POST_FORK);
Expand Down
5 changes: 3 additions & 2 deletions src/gtest/test_reindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ CBlockHeader ReindexTestSuite::createCoinBaseOnlyBlockHeader(const uint256& prev
res.nVersion = MIN_BLOCK_VERSION;
res.hashPrevBlock = prevBlockHash;
res.hashMerkleRoot = uint256();
res.hashReserved.SetNull();
res.hashScTxsCommitment.SetNull();

static unsigned int runCounter = 0;
SetMockTime(time(nullptr) + ++runCounter);
Expand All @@ -563,7 +563,8 @@ CBlockHeader ReindexTestSuite::createCoinBaseOnlyBlockHeader(const uint256& prev

CBlock ReindexTestSuite::createCoinBaseOnlyBlock(const uint256& prevBlockHash, unsigned int blockHeight)
{
CBlock res = createCoinBaseOnlyBlockHeader(prevBlockHash);
CBlock res;
res.SetBlockHeader(createCoinBaseOnlyBlockHeader(prevBlockHash));

CScript coinbaseScript = CScript() << OP_DUP << OP_HASH160
<< ToByteVector(uint160()) << OP_EQUALVERIFY << OP_CHECKSIG;
Expand Down
4 changes: 3 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6204,7 +6204,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
pindex = chainActive.Next(pindex);
}

// we must use CBlocks, as CBlockHeaders won't include the 0x00 nTx count at the end
// we cannot use CBlockHeaders since it won't include the 0x00 nTx count at the end
// we cannot use CBlock, since we added Certificates and its serialization is not backward compatible
// We must use CBlockHeaderForNetwork, and ad-hoc class for this task
vector<CBlockHeaderForNetwork> vHeaders;
int nLimit = MAX_HEADERS_RESULTS;
LogPrint("net", "getheaders from h(%d) to %s from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString(), pfrom->id);
Expand Down
5 changes: 5 additions & 0 deletions src/primitives/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ class CBlock : public CBlockHeader
SetNull();
}

void SetBlockHeader(const CBlockHeader &header)
{
*static_cast<CBlockHeader*>(this) = header;
}

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
Expand Down

0 comments on commit ed30eb7

Please sign in to comment.