| 66 | } // anon namespace |
| 67 | |
| 68 | static void BlockEncodingBench(benchmark::Bench& bench, size_t n_pool, size_t n_extra) |
| 69 | { |
| 70 | const auto testing_setup = MakeNoLogFileContext<const ChainTestingSetup>(ChainType::MAIN); |
| 71 | CTxMemPool& pool = *Assert(testing_setup->m_node.mempool); |
| 72 | InsecureRandomContext rng(11); |
| 73 | |
| 74 | LOCK2(cs_main, pool.cs); |
| 75 | |
| 76 | std::vector<std::pair<Wtxid, CTransactionRef>> extratxn; |
| 77 | extratxn.reserve(n_extra); |
| 78 | |
| 79 | // bump up the size of txs |
| 80 | std::array<std::byte,200> sigspam; |
| 81 | sigspam.fill(std::byte(42)); |
| 82 | |
| 83 | // a reasonably large mempool of 50k txs, ~10MB total |
| 84 | std::vector<CTransactionRef> refs; |
| 85 | refs.reserve(n_pool + n_extra); |
| 86 | for (size_t i = 0; i < n_pool + n_extra; ++i) { |
| 87 | CMutableTransaction tx = CMutableTransaction(); |
| 88 | tx.vin.resize(1); |
| 89 | tx.vin[0].scriptSig = CScript() << sigspam; |
| 90 | tx.vin[0].scriptWitness.stack.push_back({1}); |
| 91 | tx.vout.resize(1); |
| 92 | tx.vout[0].scriptPubKey = CScript() << OP_1 << OP_EQUAL; |
| 93 | tx.vout[0].nValue = i; |
| 94 | refs.push_back(MakeTransactionRef(tx)); |
| 95 | } |
| 96 | |
| 97 | // ensure mempool ordering is different to memory ordering of transactions, |
| 98 | // to simulate a mempool that has changed over time |
| 99 | std::shuffle(refs.begin(), refs.end(), rng); |
| 100 | |
| 101 | for (size_t i = 0; i < n_pool; ++i) { |
| 102 | AddTx(refs[i], /*fee=*/refs[i]->vout[0].nValue, pool); |
| 103 | } |
| 104 | for (size_t i = n_pool; i < n_pool + n_extra; ++i) { |
| 105 | extratxn.emplace_back(refs[i]->GetWitnessHash(), refs[i]); |
| 106 | } |
| 107 | |
| 108 | BenchCBHAST cmpctblock{rng, 3000}; |
| 109 | |
| 110 | bench.run([&] { |
| 111 | PartiallyDownloadedBlock pdb{&pool}; |
| 112 | auto res = pdb.InitData(cmpctblock, extratxn); |
| 113 | |
| 114 | // if there were duplicates the benchmark will be invalid |
| 115 | // (eg, extra txns will be skipped) and we will receive |
| 116 | // READ_STATUS_FAILED |
| 117 | assert(res == READ_STATUS_OK); |
| 118 | }); |
| 119 | } |
| 120 | |
| 121 | static void BlockEncodingNoExtra(benchmark::Bench& bench) |
| 122 | { |
no test coverage detected