MCPcopy Create free account
hub / github.com/ElementsProject/elements / NewTxHash

Method NewTxHash

src/test/txrequest_tests.cpp:196–219  ·  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

194 * are within the same preferredness class.
195 */
196 uint256 NewTxHash(const std::vector<std::vector<NodeId>>& orders = {})
197 {
198 uint256 ret;
199 bool ok;
200 do {
201 ret = InsecureRand256();
202 ok = true;
203 for (const auto& order : orders) {
204 for (size_t pos = 1; pos < order.size(); ++pos) {
205 uint64_t prio_prev = m_runner.txrequest.ComputePriority(ret, order[pos - 1], true);
206 uint64_t prio_cur = m_runner.txrequest.ComputePriority(ret, order[pos], true);
207 if (prio_prev <= prio_cur) {
208 ok = false;
209 break;
210 }
211 }
212 if (!ok) break;
213 }
214 if (ok) {
215 ok = m_runner.txhashset.insert(ret).second;
216 }
217 } while(!ok);
218 return ret;
219 }
220
221 /** Generate a random GenTxid; the txhash follows NewTxHash; the is_wtxid flag is random. */
222 GenTxid NewGTxid(const std::vector<std::vector<NodeId>>& orders = {})

Callers 1

BuildWtxidTestFunction · 0.80

Calls 4

InsecureRand256Function · 0.85
sizeMethod · 0.45
ComputePriorityMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected