Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -392,29 +392,26 @@ BITCOIN_CORE_H = \
util/bytevectorhash.h \
util/check.h \
util/edge.h \
util/enumerate.h \
util/epochguard.h \
util/error.h \
util/fastrange.h \
util/fees.h \
util/golombrice.h \
util/hasher.h \
util/hash_type.h \
util/irange.h \
util/helpers.h \
util/asmap.h \
util/getuniquepath.h \
util/macros.h \
util/message.h \
util/moneystr.h \
util/overflow.h \
util/overloaded.h \
util/pointer.h \
util/ranges.h \
util/readwritefile.h \
util/result.h \
util/underlying.h \
util/serfloat.h \
util/settings.h \
util/std23.h \
util/ranges_set.h \
util/sock.h \
util/string.h \
Expand Down
16 changes: 9 additions & 7 deletions src/active/dkgsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <llmq/options.h>
#include <llmq/utils.h>
#include <masternode/meta.h>
#include <util/helpers.h>
#include <util/std23.h>

#include <chain.h>
#include <deploymentstatus.h>
Expand Down Expand Up @@ -81,7 +83,7 @@ void ActiveDKGSession::SendContributions(CDKGPendingMessages& pendingMessages, P
qc.contributions = std::make_shared<CBLSIESMultiRecipientObjects<CBLSSecretKey>>();
qc.contributions->InitEncrypt(members.size());

for (const auto i : irange::range(members.size())) {
for (const auto i : util::irange(members.size())) {
const auto& m = members[i];
CBLSSecretKey skContrib = m_sk_contributions[i];

Expand Down Expand Up @@ -150,7 +152,7 @@ void ActiveDKGSession::VerifyPendingContributions()
return;
}

for (const auto i : irange::range(memberIndexes.size())) {
for (const auto i : util::irange(memberIndexes.size())) {
if (!result[i]) {
const auto& m = members[memberIndexes[i]];
logger.Batch("invalid contribution from %s. will complain later", m->dmn->proTxHash.ToString());
Expand Down Expand Up @@ -267,7 +269,7 @@ void ActiveDKGSession::SendComplaint(CDKGPendingMessages& pendingMessages, PeerM

int badCount = 0;
int complaintCount = 0;
for (const auto i : irange::range(members.size())) {
for (const auto i : util::irange(members.size())) {
const auto& m = members[i];
if (m->bad || m->badConnection) {
qc.badMembers[i] = true;
Expand Down Expand Up @@ -352,9 +354,9 @@ void ActiveDKGSession::SendJustification(CDKGPendingMessages& pendingMessages, P
qj.proTxHash = myProTxHash;
qj.contributions.reserve(forMembers.size());

for (const uint32_t i : irange::range(members.size())) {
for (const uint32_t i : util::irange(members.size())) {
const auto& m = members[i];
if (forMembers.count(m->dmn->proTxHash) == 0) {
if (!std23::ranges::contains(forMembers, m->dmn->proTxHash)) {
continue;
}
logger.Batch("justifying for %s", m->dmn->proTxHash.ToString());
Expand Down Expand Up @@ -444,7 +446,7 @@ void ActiveDKGSession::SendCommitment(CDKGPendingMessages& pendingMessages, Peer
qc.quorumHash = m_quorum_base_block_index->GetBlockHash();
qc.proTxHash = myProTxHash;

for (const auto i : irange::range(members.size())) {
for (const auto i : util::irange(members.size())) {
const auto& m = members[i];
if (!m->bad) {
qc.validMembers[i] = true;
Expand Down Expand Up @@ -559,7 +561,7 @@ std::vector<CFinalCommitment> ActiveDKGSession::FinalizeCommitments()

for (const auto& p : prematureCommitments) {
const auto& qc = p.second;
if (validCommitments.count(p.first) == 0) {
if (!std23::ranges::contains(validCommitments, p.first)) {
continue;
}

Expand Down
20 changes: 10 additions & 10 deletions src/active/dkgsessionhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ void ActiveDKGSessionHandler::UpdatedBlockTip(const CBlockIndex* pindexNew)
bool fNewPhase = (quorumStageInt % params.dkgPhaseBlocks) == 0;
int phaseInt = quorumStageInt / params.dkgPhaseBlocks + 1;
QuorumPhase oldPhase = phase;
if (fNewPhase && phaseInt >= ToUnderlying(QuorumPhase::Initialized) && phaseInt <= ToUnderlying(QuorumPhase::Idle)) {
if (fNewPhase && phaseInt >= std23::to_underlying(QuorumPhase::Initialized) && phaseInt <= std23::to_underlying(QuorumPhase::Idle)) {
phase = static_cast<QuorumPhase>(phaseInt);
}

LogPrint(BCLog::LLMQ_DKG, "ActiveDKGSessionHandler::%s -- %s qi[%d] currentHeight=%d, pQuorumBaseBlockIndex->nHeight=%d, oldPhase=%d, newPhase=%d\n", __func__,
params.name, quorumIndex, currentHeight, pQuorumBaseBlockIndex->nHeight, ToUnderlying(oldPhase), ToUnderlying(phase));
params.name, quorumIndex, currentHeight, pQuorumBaseBlockIndex->nHeight, std23::to_underlying(oldPhase), std23::to_underlying(phase));
}

void ActiveDKGSessionHandler::StartThread(CConnman& connman, PeerManager& peerman)
Expand All @@ -75,7 +75,7 @@ void ActiveDKGSessionHandler::StartThread(CConnman& connman, PeerManager& peerma
throw std::runtime_error("Tried to start an already started ActiveDKGSessionHandler thread.");
}

m_thread_name = strprintf("llmq-%d-%d", ToUnderlying(params.type), quorumIndex);
m_thread_name = strprintf("llmq-%d-%d", std23::to_underlying(params.type), quorumIndex);
phaseHandlerThread = std::thread(&util::TraceThread, m_thread_name.c_str(),
[this, &connman, &peerman] { PhaseHandlerThread(connman, peerman); });
}
Expand Down Expand Up @@ -120,7 +120,7 @@ class AbortPhaseException : public std::exception {
void ActiveDKGSessionHandler::WaitForNextPhase(std::optional<QuorumPhase> curPhase, QuorumPhase nextPhase,
const uint256& expectedQuorumHash, const WhileWaitFunc& shouldNotWait) const
{
LogPrint(BCLog::LLMQ_DKG, "ActiveDKGSessionHandler::%s -- %s qi[%d] - starting, curPhase=%d, nextPhase=%d\n", __func__, params.name, quorumIndex, curPhase.has_value() ? ToUnderlying(*curPhase) : -1, ToUnderlying(nextPhase));
LogPrint(BCLog::LLMQ_DKG, "ActiveDKGSessionHandler::%s -- %s qi[%d] - starting, curPhase=%d, nextPhase=%d\n", __func__, params.name, quorumIndex, curPhase.has_value() ? std23::to_underlying(*curPhase) : -1, std23::to_underlying(nextPhase));

while (true) {
if (stopRequested) {
Expand All @@ -136,15 +136,15 @@ void ActiveDKGSessionHandler::WaitForNextPhase(std::optional<QuorumPhase> curPha
break;
}
if (curPhase.has_value() && _phase != curPhase) {
LogPrint(BCLog::LLMQ_DKG, "ActiveDKGSessionHandler::%s -- %s qi[%d] - aborting due unexpected phase change, _phase=%d, curPhase=%d\n", __func__, params.name, quorumIndex, ToUnderlying(_phase), curPhase.has_value() ? ToUnderlying(*curPhase) : -1);
LogPrint(BCLog::LLMQ_DKG, "ActiveDKGSessionHandler::%s -- %s qi[%d] - aborting due unexpected phase change, _phase=%d, curPhase=%d\n", __func__, params.name, quorumIndex, std23::to_underlying(_phase), curPhase.has_value() ? std23::to_underlying(*curPhase) : -1);
throw AbortPhaseException();
}
if (!shouldNotWait()) {
UninterruptibleSleep(std::chrono::milliseconds{100});
}
}

LogPrint(BCLog::LLMQ_DKG, "ActiveDKGSessionHandler::%s -- %s qi[%d] - done, curPhase=%d, nextPhase=%d\n", __func__, params.name, quorumIndex, curPhase.has_value() ? ToUnderlying(*curPhase) : -1, ToUnderlying(nextPhase));
LogPrint(BCLog::LLMQ_DKG, "ActiveDKGSessionHandler::%s -- %s qi[%d] - done, curPhase=%d, nextPhase=%d\n", __func__, params.name, quorumIndex, curPhase.has_value() ? std23::to_underlying(*curPhase) : -1, std23::to_underlying(nextPhase));

if (nextPhase == QuorumPhase::Initialized) {
m_dkgdbgman.ResetLocalSessionStatus(params.type, quorumIndex);
Expand Down Expand Up @@ -206,7 +206,7 @@ void ActiveDKGSessionHandler::SleepBeforePhase(QuorumPhase curPhase, const uint2
int heightTmp{currentHeight.load()};
int heightStart{heightTmp};

LogPrint(BCLog::LLMQ_DKG, "ActiveDKGSessionHandler::%s -- %s qi[%d] - starting sleep for %d ms, curPhase=%d\n", __func__, params.name, quorumIndex, sleepTime, ToUnderlying(curPhase));
LogPrint(BCLog::LLMQ_DKG, "ActiveDKGSessionHandler::%s -- %s qi[%d] - starting sleep for %d ms, curPhase=%d\n", __func__, params.name, quorumIndex, sleepTime, std23::to_underlying(curPhase));

while (TicksSinceEpoch<std::chrono::milliseconds>(SystemClock::now()) < endTime) {
if (stopRequested) {
Expand All @@ -233,20 +233,20 @@ void ActiveDKGSessionHandler::SleepBeforePhase(QuorumPhase curPhase, const uint2
}
}

LogPrint(BCLog::LLMQ_DKG, "ActiveDKGSessionHandler::%s -- %s qi[%d] - done, curPhase=%d\n", __func__, params.name, quorumIndex, ToUnderlying(curPhase));
LogPrint(BCLog::LLMQ_DKG, "ActiveDKGSessionHandler::%s -- %s qi[%d] - done, curPhase=%d\n", __func__, params.name, quorumIndex, std23::to_underlying(curPhase));
}

void ActiveDKGSessionHandler::HandlePhase(QuorumPhase curPhase, QuorumPhase nextPhase,
const uint256& expectedQuorumHash, double randomSleepFactor,
const StartPhaseFunc& startPhaseFunc, const WhileWaitFunc& runWhileWaiting)
{
LogPrint(BCLog::LLMQ_DKG, "ActiveDKGSessionHandler::%s -- %s qi[%d] - starting, curPhase=%d, nextPhase=%d\n", __func__, params.name, quorumIndex, ToUnderlying(curPhase), ToUnderlying(nextPhase));
LogPrint(BCLog::LLMQ_DKG, "ActiveDKGSessionHandler::%s -- %s qi[%d] - starting, curPhase=%d, nextPhase=%d\n", __func__, params.name, quorumIndex, std23::to_underlying(curPhase), std23::to_underlying(nextPhase));

SleepBeforePhase(curPhase, expectedQuorumHash, randomSleepFactor, runWhileWaiting);
startPhaseFunc();
WaitForNextPhase(curPhase, nextPhase, expectedQuorumHash, runWhileWaiting);

LogPrint(BCLog::LLMQ_DKG, "ActiveDKGSessionHandler::%s -- %s qi[%d] - done, curPhase=%d, nextPhase=%d\n", __func__, params.name, quorumIndex, ToUnderlying(curPhase), ToUnderlying(nextPhase));
LogPrint(BCLog::LLMQ_DKG, "ActiveDKGSessionHandler::%s -- %s qi[%d] - done, curPhase=%d, nextPhase=%d\n", __func__, params.name, quorumIndex, std23::to_underlying(curPhase), std23::to_underlying(nextPhase));
}

// returns a set of NodeIds which sent invalid messages
Expand Down
23 changes: 15 additions & 8 deletions src/active/quorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <llmq/quorums.h>
#include <llmq/utils.h>
#include <masternode/sync.h>
#include <util/helpers.h>

#include <chain.h>
#include <chainparams.h>
Expand All @@ -24,6 +25,8 @@

#include <cxxtimer.hpp>

#include <ranges>

namespace llmq {
QuorumParticipant::QuorumParticipant(CBLSWorker& bls_worker, CConnman& connman, CDeterministicMNManager& dmnman,
QuorumObserverParent& qman, CQuorumSnapshotManager& qsnapman,
Expand All @@ -47,13 +50,15 @@ void QuorumParticipant::CheckQuorumConnections(const Consensus::LLMQParams& llmq

const uint256 proTxHash = m_mn_activeman.GetProTxHash();
const bool watchOtherISQuorums = llmqParams.type == Params().GetConsensus().llmqTypeDIP0024InstantSend &&
ranges::any_of(lastQuorums, [&proTxHash](const auto& old_quorum){ return old_quorum->IsMember(proTxHash); });
std::ranges::any_of(lastQuorums, [&proTxHash](const auto& old_quorum) {
return old_quorum->IsMember(proTxHash);
});

for (const auto& quorum : lastQuorums) {
if (utils::EnsureQuorumConnections(llmqParams, m_connman, m_sporkman, {m_dmnman, m_qsnapman, m_chainman, quorum->m_quorum_base_block_index},
m_dmnman.GetListAtChainTip(), proTxHash, /*is_masternode=*/true, m_quorums_watch)) {
if (deletableQuorums.erase(quorum->qc->quorumHash) > 0) {
LogPrint(BCLog::LLMQ, "QuorumParticipant::%s -- llmqType[%d] h[%d] keeping mn quorum connections for quorum: [%d:%s]\n", __func__, ToUnderlying(llmqParams.type), pindexNew->nHeight, quorum->m_quorum_base_block_index->nHeight, quorum->m_quorum_base_block_index->GetBlockHash().ToString());
LogPrint(BCLog::LLMQ, "QuorumParticipant::%s -- llmqType[%d] h[%d] keeping mn quorum connections for quorum: [%d:%s]\n", __func__, std23::to_underlying(llmqParams.type), pindexNew->nHeight, quorum->m_quorum_base_block_index->nHeight, quorum->m_quorum_base_block_index->GetBlockHash().ToString());
}
} else if (watchOtherISQuorums && !quorum->IsMember(proTxHash)) {
Uint256HashSet connections;
Expand All @@ -63,12 +68,12 @@ void QuorumParticipant::CheckQuorumConnections(const Consensus::LLMQParams& llmq
}
if (!connections.empty()) {
if (!m_connman.HasMasternodeQuorumNodes(llmqParams.type, quorum->m_quorum_base_block_index->GetBlockHash())) {
LogPrint(BCLog::LLMQ, "QuorumParticipant::%s -- llmqType[%d] h[%d] adding mn inter-quorum connections for quorum: [%d:%s]\n", __func__, ToUnderlying(llmqParams.type), pindexNew->nHeight, quorum->m_quorum_base_block_index->nHeight, quorum->m_quorum_base_block_index->GetBlockHash().ToString());
LogPrint(BCLog::LLMQ, "QuorumParticipant::%s -- llmqType[%d] h[%d] adding mn inter-quorum connections for quorum: [%d:%s]\n", __func__, std23::to_underlying(llmqParams.type), pindexNew->nHeight, quorum->m_quorum_base_block_index->nHeight, quorum->m_quorum_base_block_index->GetBlockHash().ToString());
m_connman.SetMasternodeQuorumNodes(llmqParams.type, quorum->m_quorum_base_block_index->GetBlockHash(), connections);
m_connman.SetMasternodeQuorumRelayMembers(llmqParams.type, quorum->m_quorum_base_block_index->GetBlockHash(), connections);
}
if (deletableQuorums.erase(quorum->qc->quorumHash) > 0) {
LogPrint(BCLog::LLMQ, "QuorumParticipant::%s -- llmqType[%d] h[%d] keeping mn inter-quorum connections for quorum: [%d:%s]\n", __func__, ToUnderlying(llmqParams.type), pindexNew->nHeight, quorum->m_quorum_base_block_index->nHeight, quorum->m_quorum_base_block_index->GetBlockHash().ToString());
LogPrint(BCLog::LLMQ, "QuorumParticipant::%s -- llmqType[%d] h[%d] keeping mn inter-quorum connections for quorum: [%d:%s]\n", __func__, std23::to_underlying(llmqParams.type), pindexNew->nHeight, quorum->m_quorum_base_block_index->nHeight, quorum->m_quorum_base_block_index->GetBlockHash().ToString());
}
}
}
Expand Down Expand Up @@ -96,7 +101,7 @@ size_t QuorumParticipant::GetQuorumRecoveryStartOffset(const CQuorum& quorum, gs
size_t nIndex{0};
{
auto my_protx_hash = m_mn_activeman.GetProTxHash();
for (const auto i : irange::range(vecProTxHashes.size())) {
for (const auto i : util::irange(vecProTxHashes.size())) {
// cppcheck-suppress useStlAlgorithm
if (my_protx_hash == vecProTxHashes[i]) {
nIndex = i;
Expand Down Expand Up @@ -156,7 +161,7 @@ MessageProcessingResult QuorumParticipant::ProcessContribQDATA(CNode& pfrom, CDa

std::vector<CBLSSecretKey> vecSecretKeys;
vecSecretKeys.resize(vecEncrypted.size());
for (const auto i : irange::range(vecEncrypted.size())) {
for (const auto i : util::irange(vecEncrypted.size())) {
if (!m_mn_activeman.Decrypt(vecEncrypted[i], memberIdx, vecSecretKeys[i], PROTOCOL_VERSION)) {
return MisbehavingError{10, "failed to decrypt"};
}
Expand Down Expand Up @@ -209,7 +214,9 @@ void QuorumParticipant::TriggerQuorumDataRecoveryThreads(gsl::not_null<const CBl

for (const auto& params : Params().GetConsensus().llmqs) {
auto vecQuorums = m_qman.ScanQuorums(params.type, block_index, params.keepOldConnections);
const bool fWeAreQuorumTypeMember = ranges::any_of(vecQuorums, [&proTxHash](const auto& pQuorum) { return pQuorum->IsValidMember(proTxHash); });
const bool fWeAreQuorumTypeMember = std::ranges::any_of(vecQuorums, [&proTxHash](const auto& pQuorum) {
return pQuorum->IsValidMember(proTxHash);
});

for (auto& pQuorum : vecQuorums) {
if (pQuorum->IsValidMember(proTxHash)) {
Expand All @@ -224,7 +231,7 @@ void QuorumParticipant::TriggerQuorumDataRecoveryThreads(gsl::not_null<const CBl
StartDataRecoveryThread(block_index, std::move(pQuorum), nDataMask);
} else {
LogPrint(BCLog::LLMQ, "QuorumParticipant::%s -- No data needed from (%d, %s) at height %d\n", __func__,
ToUnderlying(pQuorum->qc->llmqType), pQuorum->qc->quorumHash.ToString(), block_index->nHeight);
std23::to_underlying(pQuorum->qc->llmqType), pQuorum->qc->quorumHash.ToString(), block_index->nHeight);
}
} else {
TryStartVvecSyncThread(block_index, std::move(pQuorum), fWeAreQuorumTypeMember);
Expand Down
8 changes: 4 additions & 4 deletions src/addressindex.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <consensus/amount.h>
#include <serialize.h>
#include <uint256.h>
#include <util/underlying.h>
#include <util/std23.h>

#include <chrono>
#include <tuple>
Expand Down Expand Up @@ -122,7 +122,7 @@ struct CAddressIndexKey {

template<typename Stream>
void Serialize(Stream& s) const {
ser_writedata8(s, ToUnderlying(m_address_type));
ser_writedata8(s, std23::to_underlying(m_address_type));
m_address_bytes.Serialize(s);
// Heights are stored big-endian for key sorting in LevelDB
ser_writedata32be(s, m_block_height);
Expand Down Expand Up @@ -169,7 +169,7 @@ struct CAddressIndexIteratorKey {

template<typename Stream>
void Serialize(Stream& s) const {
ser_writedata8(s, ToUnderlying(m_address_type));
ser_writedata8(s, std23::to_underlying(m_address_type));
m_address_bytes.Serialize(s);
}

Expand Down Expand Up @@ -207,7 +207,7 @@ struct CAddressIndexIteratorHeightKey {

template<typename Stream>
void Serialize(Stream& s) const {
ser_writedata8(s, ToUnderlying(m_address_type));
ser_writedata8(s, std23::to_underlying(m_address_type));
m_address_bytes.Serialize(s);
ser_writedata32be(s, m_block_height);
}
Expand Down
12 changes: 7 additions & 5 deletions src/bench/bls_dkg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <bench/bench.h>

#include <bls/bls_worker.h>
#include <util/helpers.h>

#include <random.h>
#include <util/irange.h>

struct Member {
CBLSId id;
Expand Down Expand Up @@ -45,7 +47,7 @@ class DKG
void VerifyContributionShares(size_t whoAmI, const std::set<size_t>& invalidIndexes, bool aggregated)
{
auto result = blsWorker.VerifyContributionShares(members[whoAmI].id, receivedVvecs, receivedSkShares, aggregated);
for (const size_t i : irange::range(receivedVvecs.size())) {
for (const size_t i : util::irange(receivedVvecs.size())) {
if (invalidIndexes.count(i)) {
assert(!result[i]);
} else {
Expand All @@ -60,7 +62,7 @@ class DKG
members.reserve(quorumSize);
ids.reserve(quorumSize);

for (const int i : irange::range(quorumSize)) {
for (const int i : util::irange(quorumSize)) {
uint256 id;
WriteLE64(id.begin(), i + 1);
members.push_back({CBLSId(id), {}, {}});
Expand Down Expand Up @@ -94,7 +96,7 @@ class DKG
ReceiveShares(memberIdx);

std::set<size_t> invalidIndexes;
for ([[maybe_unused]] const auto _ : irange::range(invalidCount)) {
for ([[maybe_unused]] const auto _ : util::irange(invalidCount)) {
size_t shareIdx = GetRand<size_t>(receivedSkShares.size());
receivedSkShares[shareIdx].MakeNewKey();
invalidIndexes.emplace(shareIdx);
Expand All @@ -117,7 +119,7 @@ static void BLSDKG_GenerateContributions(benchmark::Bench& bench, uint32_t epoch
epoch_iters = 1;
quorumSize = 1;
}
for (const int i : irange::range(quorumSize)) {
for (const int i : util::irange(quorumSize)) {
uint256 id;
WriteLE64(id.begin(), i + 1);
members.push_back({CBLSId(id), {}, {}});
Expand Down
Loading
Loading