From ef1b4a70c20eda6ac5e544fe26f76a08255cff42 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Sat, 10 Jan 2026 20:34:24 +0530 Subject: [PATCH 01/16] refactor: rename `ToUnderlying()` to match C++23 convention We have a multitude of C++23 polyfills across the codebase and the current naming convention makes it painful to switch to the standard library when the time eventually comes. --- src/Makefile.am | 2 +- src/active/dkgsessionhandler.cpp | 20 +++++++++--------- src/active/quorums.cpp | 8 ++++---- src/addressindex.h | 8 ++++---- src/chainlock/chainlock.cpp | 4 ++-- src/chainparams.cpp | 4 ++-- src/evo/core_write.cpp | 10 ++++----- src/evo/providertx.cpp | 6 +++--- src/evo/providertx.h | 2 +- src/evo/simplifiedmns.cpp | 10 +++++---- src/evo/smldiff.cpp | 2 +- src/governance/classes.cpp | 7 ++++--- src/governance/governance.cpp | 6 +++--- src/governance/object.cpp | 4 ++-- src/governance/validators.cpp | 7 ++++--- src/llmq/blockprocessor.cpp | 34 +++++++++++++++---------------- src/llmq/commitment.cpp | 14 ++++++------- src/llmq/commitment.h | 10 ++++----- src/llmq/core_write.cpp | 6 +++--- src/llmq/debug.cpp | 14 ++++++------- src/llmq/dkgsession.cpp | 10 ++++----- src/llmq/dkgsession.h | 4 ++-- src/llmq/dkgsessionmgr.cpp | 21 ++++++++++--------- src/llmq/observer/quorums.cpp | 10 ++++----- src/llmq/options.cpp | 4 ++-- src/llmq/quorumsman.cpp | 16 +++++++-------- src/llmq/signing_shares.cpp | 10 ++++----- src/llmq/utils.cpp | 4 ++-- src/net_processing.cpp | 4 ++-- src/qt/optionsdialog.cpp | 4 ++-- src/qt/rpcconsole.cpp | 8 ++++---- src/spentindex.h | 2 +- src/test/llmq_dkg_tests.cpp | 4 ++-- src/util/std23.h | 28 +++++++++++++++++++++++++ src/util/underlying.h | 14 ------------- src/validation.cpp | 2 +- src/zmq/zmqpublishnotifier.cpp | 2 +- test/util/data/non-backported.txt | 1 + 38 files changed, 173 insertions(+), 153 deletions(-) create mode 100644 src/util/std23.h delete mode 100644 src/util/underlying.h diff --git a/src/Makefile.am b/src/Makefile.am index 1c5fd1936399..7b4960beb3ce 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -412,9 +412,9 @@ BITCOIN_CORE_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 \ diff --git a/src/active/dkgsessionhandler.cpp b/src/active/dkgsessionhandler.cpp index c0ed65b75402..ad795befc498 100644 --- a/src/active/dkgsessionhandler.cpp +++ b/src/active/dkgsessionhandler.cpp @@ -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(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) @@ -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); }); } @@ -120,7 +120,7 @@ class AbortPhaseException : public std::exception { void ActiveDKGSessionHandler::WaitForNextPhase(std::optional 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) { @@ -136,7 +136,7 @@ void ActiveDKGSessionHandler::WaitForNextPhase(std::optional 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()) { @@ -144,7 +144,7 @@ void ActiveDKGSessionHandler::WaitForNextPhase(std::optional curPha } } - 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); @@ -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(SystemClock::now()) < endTime) { if (stopRequested) { @@ -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 diff --git a/src/active/quorums.cpp b/src/active/quorums.cpp index 1885022d9c35..b293a99030c7 100644 --- a/src/active/quorums.cpp +++ b/src/active/quorums.cpp @@ -53,7 +53,7 @@ void QuorumParticipant::CheckQuorumConnections(const Consensus::LLMQParams& llmq 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; @@ -63,12 +63,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()); } } } @@ -224,7 +224,7 @@ void QuorumParticipant::TriggerQuorumDataRecoveryThreads(gsl::not_nullqc->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); diff --git a/src/addressindex.h b/src/addressindex.h index 55dbc8284a58..6ef68d473d80 100644 --- a/src/addressindex.h +++ b/src/addressindex.h @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include @@ -122,7 +122,7 @@ struct CAddressIndexKey { template 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); @@ -169,7 +169,7 @@ struct CAddressIndexIteratorKey { template 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); } @@ -207,7 +207,7 @@ struct CAddressIndexIteratorHeightKey { template 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); } diff --git a/src/chainlock/chainlock.cpp b/src/chainlock/chainlock.cpp index bbfb3c9f83af..e5a62a43c54b 100644 --- a/src/chainlock/chainlock.cpp +++ b/src/chainlock/chainlock.cpp @@ -10,9 +10,9 @@ #include #include #include +#include #include #include -#include #include #include @@ -135,7 +135,7 @@ MessageProcessingResult CChainLocksHandler::ProcessNewChainLock(const NodeId fro if (const auto ret = VerifyChainLock(clsig); ret != VerifyRecSigStatus::Valid) { LogPrint(BCLog::CHAINLOCKS, "CChainLocksHandler::%s -- invalid CLSIG (%s), status=%d peer=%d\n", __func__, - clsig.ToString(), ToUnderlying(ret), from); + clsig.ToString(), std23::to_underlying(ret), from); if (from != -1) { return MisbehavingError{10}; } diff --git a/src/chainparams.cpp b/src/chainparams.cpp index bf6e74023579..df1eb452ad53 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -11,8 +11,8 @@ #include #include #include +#include #include -#include #include #include @@ -1192,7 +1192,7 @@ void CRegTestParams::UpdateLLMQInstantSendDIP0024FromArgs(const ArgsManager& arg if (llmqType == Consensus::LLMQType::LLMQ_NONE) { throw std::runtime_error("Invalid LLMQ type specified for -llmqtestinstantsenddip0024."); } - LogPrintf("Setting llmqtestinstantsenddip0024 to %ld\n", ToUnderlying(llmqType)); + LogPrintf("Setting llmqtestinstantsenddip0024 to %ld\n", std23::to_underlying(llmqType)); UpdateLLMQDIP0024InstantSend(llmqType); } diff --git a/src/evo/core_write.cpp b/src/evo/core_write.cpp index b3e414d7c779..72b3cb0b32b8 100644 --- a/src/evo/core_write.cpp +++ b/src/evo/core_write.cpp @@ -13,11 +13,11 @@ #include #include #include +#include #include #include #include -#include #include @@ -163,7 +163,7 @@ RPCResult CCbTx::GetJsonHelp(const std::string& key, bool optional) UniValue CCbTx::ToJson() const { UniValue ret(UniValue::VOBJ); - ret.pushKV("version", ToUnderlying(nVersion)); + ret.pushKV("version", std23::to_underlying(nVersion)); ret.pushKV("height", nHeight); ret.pushKV("merkleRootMNList", merkleRootMNList.ToString()); if (nVersion >= CCbTx::Version::MERKLE_ROOT_QUORUMS) { @@ -301,7 +301,7 @@ UniValue CProRegTx::ToJson() const { UniValue ret(UniValue::VOBJ); ret.pushKV("version", nVersion); - ret.pushKV("type", ToUnderlying(nType)); + ret.pushKV("type", std23::to_underlying(nType)); ret.pushKV("collateralHash", collateralOutpoint.hash.ToString()); ret.pushKV("collateralIndex", collateralOutpoint.n); ret.pushKV("service", netInfo->GetPrimary().ToStringAddrPort()); @@ -391,7 +391,7 @@ UniValue CProUpServTx::ToJson() const { UniValue ret(UniValue::VOBJ); ret.pushKV("version", nVersion); - ret.pushKV("type", ToUnderlying(nType)); + ret.pushKV("type", std23::to_underlying(nType)); ret.pushKV("proTxHash", proTxHash.ToString()); ret.pushKV("service", netInfo->GetPrimary().ToStringAddrPort()); ret.pushKV("addresses", GetNetInfoWithLegacyFields(*this, nType)); @@ -524,7 +524,7 @@ UniValue CSimplifiedMNListEntry::ToJson(bool extended) const { UniValue obj(UniValue::VOBJ); obj.pushKV("nVersion", nVersion); - obj.pushKV("nType", ToUnderlying(nType)); + obj.pushKV("nType", std23::to_underlying(nType)); obj.pushKV("proRegTxHash", proRegTxHash.ToString()); obj.pushKV("confirmedHash", confirmedHash.ToString()); obj.pushKV("service", netInfo->GetPrimary().ToStringAddrPort()); diff --git a/src/evo/providertx.cpp b/src/evo/providertx.cpp index 9f5d38a50a3e..bbdc009bb197 100644 --- a/src/evo/providertx.cpp +++ b/src/evo/providertx.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -12,7 +13,6 @@ #include #include