5 #ifndef PIVX_LLMQ_QUORUMS_UTILS_H
6 #define PIVX_LLMQ_QUORUMS_UTILS_H
30 std::string
ToHexStr(
const std::vector<bool>& vBits);
34 template <
typename NodesContainer,
typename Continue,
typename Callback>
35 static void IterateNodesRandom(NodesContainer& nodeStates, Continue&& cont, Callback&& callback,
FastRandomContext& rnd)
37 std::vector<typename NodesContainer::iterator> rndNodes;
38 rndNodes.reserve(nodeStates.size());
39 for (
auto it = nodeStates.begin(); it != nodeStates.end(); ++it) {
40 rndNodes.emplace_back(it);
42 if (rndNodes.empty()) {
45 Shuffle(rndNodes.begin(), rndNodes.end(), rnd);
48 while (!rndNodes.empty() && cont()) {
49 auto nodeId = rndNodes[idx]->first;
50 auto& ns = rndNodes[idx]->second;
52 if (callback(nodeId, ns)) {
53 idx = (idx + 1) % rndNodes.size();
55 rndNodes.erase(rndNodes.begin() + idx);
56 if (rndNodes.empty()) {
59 idx %= rndNodes.size();
64 template <
typename CacheType>
#define T(expected, seed, data)
std::string ToHexStr(const std::vector< bool > &vBits)
uint256 BuildSignHash(Consensus::LLMQType llmqType, const uint256 &quorumHash, const uint256 &id, const uint256 &msgHash)
bool IsQuorumActive(Consensus::LLMQType llmqType, const uint256 &quorumHash)
void InitQuorumsCache(CacheType &cache)
uint256 BuildCommitmentHash(Consensus::LLMQType llmqType, const uint256 &blockHash, const std::vector< bool > &validMembers, const CBLSPublicKey &pubKey, const uint256 &vvecHash)
void Shuffle(I first, I last, R &&rng)
More efficient than using std::shuffle on a FastRandomContext.