mirror of
https://github.com/XRPLF/rippled.git
synced 2026-10-02 01:38:27 +00:00
Review of the preceding commits found a clang-tidy failure and a convention break, both rooted in the same place: the enum-to-label helpers were put in ConsensusSpanNames.h, which pulled two domain headers into it. misc-include-cleaner rejected the new test: it used xrpl::LedgerCloseReason without directly including ConsensusTypes.h, relying on the transitive include. misc-* is enabled and this path is not in IgnoreHeaders, so it would have failed CI. ConsensusSpanNames.h had also become the only one of the eight *SpanNames.h headers to include anything beyond SpanNames.h. That cost is paid by every consumer: PeerImp.cpp, ConsensusReceiveTracing.h and RCLConsensus.cpp want only name and key constants, but were newly compiling ConsensusTypes.h and DisputedTx.h through it. Move both helpers to a new ConsensusSpanLabels.h, which owns the domain includes. ConsensusSpanNames.h is dependency-free again like its siblings, and the labels reach their only production caller, Consensus.h, directly. Also from the review: - phaseOpen() had grown to 81 lines, over the 80-line limit. Extract annotateOpenStart() and annotateOpenClose(), which also removes the repeated span guards. phaseOpen is 72 lines; startRoundInternal drops 103 to 93, still over the limit but it was 99 before this work began. - Note at the CLOG why the log text keeps the shouldCloseLedger name: existing consumers match on it. - whyCloseLedger's doc claimed "both log identically", implying the wrapper logs too. It delegates, so the logging happens once either way. - Cross-reference proposers_validated and proposers_finished, which sit eight lines apart and count different things: validators of the previous ledger versus those already past it. - The two static_asserts no longer sit inside TEST bodies with SUCCEED(); they fire at compile time regardless. Also "consteval-safe" was wrong; they are constexpr. - SpanGuardFactory.cpp claimed a libxrpl test cannot include the consensus span-name header. The new test in the same directory does exactly that, so the claim is corrected to name the real constraint: the rpc_* constants it needs live in an xrpld-level header.
86 lines
2.7 KiB
C++
86 lines
2.7 KiB
C++
#pragma once
|
|
|
|
/**
|
|
* Enum-to-label mappings for consensus span attribute values.
|
|
*
|
|
* Split from ConsensusSpanNames.h so that header stays dependency-free like
|
|
* its siblings: the span-name and attribute-key constants are included by
|
|
* overlay and app translation units that have no use for the consensus
|
|
* enums, while these mappings are needed only by Consensus.h.
|
|
*
|
|
* ConsensusSpanNames.h (constants only, no domain deps)
|
|
* ^
|
|
* | includes
|
|
* ConsensusSpanLabels.h --includes--> ConsensusParms.h, ConsensusTypes.h
|
|
* ^
|
|
* | includes
|
|
* Consensus.h
|
|
*/
|
|
|
|
#include <xrpl/consensus/ConsensusParms.h>
|
|
#include <xrpl/consensus/ConsensusSpanNames.h>
|
|
#include <xrpl/consensus/ConsensusTypes.h>
|
|
|
|
#include <string_view>
|
|
|
|
namespace xrpl::telemetry::consensus::span {
|
|
|
|
/**
|
|
* Map a close-time avalanche state to its `avalanche_state` label.
|
|
*
|
|
* The regime escalates Init -> Mid -> Late -> Stuck, raising the close-time
|
|
* agreement threshold at each step.
|
|
*
|
|
* @param state The state held by Consensus::closeTimeAvalancheState_.
|
|
* @return The wire label; one of val::avalanche*.
|
|
*
|
|
* @note No default arm, so a new enumerator is a -Wswitch warning; the
|
|
* fall-through returns "unknown" rather than a plausible-looking regime.
|
|
*/
|
|
[[nodiscard]] constexpr std::string_view
|
|
avalancheStateLabel(ConsensusParms::AvalancheState const state)
|
|
{
|
|
switch (state)
|
|
{
|
|
case ConsensusParms::AvalancheState::Init:
|
|
return val::avalancheInit;
|
|
case ConsensusParms::AvalancheState::Mid:
|
|
return val::avalancheMid;
|
|
case ConsensusParms::AvalancheState::Late:
|
|
return val::avalancheLate;
|
|
case ConsensusParms::AvalancheState::Stuck:
|
|
return val::avalancheStuck;
|
|
}
|
|
return val::unknown;
|
|
}
|
|
|
|
/**
|
|
* Map a ledger-close decision to its `close_reason` label.
|
|
*
|
|
* @param reason The value returned by whyCloseLedger().
|
|
* @return The wire label; one of val::close*.
|
|
*
|
|
* @note No default arm, so a new enumerator is a -Wswitch warning; the
|
|
* fall-through returns "unknown". `keep_open` is mapped but never emitted.
|
|
*/
|
|
[[nodiscard]] constexpr std::string_view
|
|
closeReasonLabel(LedgerCloseReason const reason)
|
|
{
|
|
switch (reason)
|
|
{
|
|
case LedgerCloseReason::KeepOpen:
|
|
return val::closeKeepOpen;
|
|
case LedgerCloseReason::Anomaly:
|
|
return val::closeAnomaly;
|
|
case LedgerCloseReason::OthersClosed:
|
|
return val::closeOthersClosed;
|
|
case LedgerCloseReason::Idle:
|
|
return val::closeIdle;
|
|
case LedgerCloseReason::Normal:
|
|
return val::closeNormal;
|
|
}
|
|
return val::unknown;
|
|
}
|
|
|
|
} // namespace xrpl::telemetry::consensus::span
|