MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / NewTxHash

Method NewTxHash

src/test/txrequest_tests.cpp:213–236  ·  view source on GitHub ↗

Generate a random txhash, whose priorities for certain peers are constrained. * * For example, NewTxHash({{p1,p2,p3},{p2,p4,p5}}) will generate a txhash T such that both: * - priority(p1,T) > priority(p2,T) > priority(p3,T) * - priority(p2,T) > priority(p4,T) > priority(p5,T) * where priority is the predicted internal TxRequestTracker's priority, assuming all announcemen

Source from the content-addressed store, hash-verified

211 * are within the same preferredness class.
212 */
213 uint256 NewTxHash(const std::vector<std::vector<NodeId>>& orders = {})
214 {
215 uint256 ret;
216 bool ok;
217 do {
218 ret = m_rng.rand256();
219 ok = true;
220 for (const auto& order : orders) {
221 for (size_t pos = 1; pos < order.size(); ++pos) {
222 uint64_t prio_prev = m_runner.txrequest.ComputePriority(ret, order[pos - 1], true);
223 uint64_t prio_cur = m_runner.txrequest.ComputePriority(ret, order[pos], true);
224 if (prio_prev <= prio_cur) {
225 ok = false;
226 break;
227 }
228 }
229 if (!ok) break;
230 }
231 if (ok) {
232 ok = m_runner.txhashset.insert(ret).second;
233 }
234 } while(!ok);
235 return ret;
236 }
237
238 /** Generate a random GenTxid; the txhash follows NewTxHash; the transaction identifier is random. */
239 GenTxid NewGTxid(const std::vector<std::vector<NodeId>>& orders = {})

Callers 1

BuildWtxidTestMethod · 0.80

Calls 4

rand256Method · 0.80
sizeMethod · 0.45
ComputePriorityMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected