Changeset View
Changeset View
Standalone View
Standalone View
src/test/pmt_tests.cpp
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | for (int i = 0; i < 12; i++) { | ||||
// unique | // unique | ||||
tx.nLockTime = j; | tx.nLockTime = j; | ||||
block.vtx.push_back(MakeTransactionRef(std::move(tx))); | block.vtx.push_back(MakeTransactionRef(std::move(tx))); | ||||
} | } | ||||
// calculate actual merkle root and height | // calculate actual merkle root and height | ||||
uint256 merkleRoot1 = BlockMerkleRoot(block); | uint256 merkleRoot1 = BlockMerkleRoot(block); | ||||
std::vector<uint256> vTxid(nTx, uint256()); | std::vector<uint256> vTxid(nTx, uint256()); | ||||
for (unsigned int j = 0; j < nTx; j++) | for (unsigned int j = 0; j < nTx; j++) { | ||||
vTxid[j] = block.vtx[j]->GetId(); | vTxid[j] = block.vtx[j]->GetId(); | ||||
} | |||||
int nHeight = 1, nTx_ = nTx; | int nHeight = 1, nTx_ = nTx; | ||||
while (nTx_ > 1) { | while (nTx_ > 1) { | ||||
nTx_ = (nTx_ + 1) / 2; | nTx_ = (nTx_ + 1) / 2; | ||||
nHeight++; | nHeight++; | ||||
} | } | ||||
// check with random subsets with inclusion chances 1, 1/2, 1/4, ..., | // check with random subsets with inclusion chances 1, 1/2, 1/4, ..., | ||||
// 1/128 | // 1/128 | ||||
for (int att = 1; att < 15; att++) { | for (int att = 1; att < 15; att++) { | ||||
// build random subset of txid's | // build random subset of txid's | ||||
std::vector<bool> vMatch(nTx, false); | std::vector<bool> vMatch(nTx, false); | ||||
std::vector<uint256> vMatchTxid1; | std::vector<uint256> vMatchTxid1; | ||||
for (unsigned int j = 0; j < nTx; j++) { | for (unsigned int j = 0; j < nTx; j++) { | ||||
bool fInclude = InsecureRandBits(att / 2) == 0; | bool fInclude = InsecureRandBits(att / 2) == 0; | ||||
vMatch[j] = fInclude; | vMatch[j] = fInclude; | ||||
if (fInclude) vMatchTxid1.push_back(vTxid[j]); | if (fInclude) { | ||||
vMatchTxid1.push_back(vTxid[j]); | |||||
} | |||||
} | } | ||||
// build the partial merkle tree | // build the partial merkle tree | ||||
CPartialMerkleTree pmt1(vTxid, vMatch); | CPartialMerkleTree pmt1(vTxid, vMatch); | ||||
// serialize | // serialize | ||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); | CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); | ||||
ss << pmt1; | ss << pmt1; | ||||
▲ Show 20 Lines • Show All 51 Lines • Show Last 20 Lines |