Skip to content

account/NodeType.hpp

Deployment node role shared across the node, transaction, and migration layers. More...

Namespaces

Name
sgns

Classes

Name
struct fmt::formatter< sgns::NodeType >
Lets a NodeType be passed straight to any spdlog/fmt call: logger->info( "role={}", node_type_ ).

Types

Name
enum class uint8_t NodeType { Full = 0, Light = 1, Archive = 2}
Deployment node role, read from sgns_config.json ("node_type").

Functions

Name
constexpr bool ReplicatesAllAccounts(NodeType type)
Whether this role replicates network-wide data rather than just its own account.
constexpr bool ParticipatesInConsensus(NodeType type)
Whether this role actively participates in consensus and result handling.
constexpr std::string_view NodeTypeToString(NodeType type)
Canonical lowercase name of a role, as accepted in sgns_config.json.
std::optional< NodeType > NodeTypeFromString(std::string_view s)
Parses a node role name, case-insensitively (Phase-2 D-02).

Detailed Description

Deployment node role shared across the node, transaction, and migration layers.

Date: 2026-08-17

Lives in its own header (rather than nested in GeniusNode) so that lower layers — TransactionManager, MigrationManager — can take a NodeType without including the GeniusNode facade that owns them.

Types Documentation

enum NodeType

Enumerator Value Description
Full 0 Full node: replicates everything and participates in consensus.
Light 1 Light node: own account only. Default on missing/unknown key.
Archive 2 Archive node: replicates everything, participates in nothing.

Deployment node role, read from sgns_config.json ("node_type").

  • Full participates in everything: replicates all accounts, proposes, votes, mirrors results.
  • Light replicates only its own account's data.
  • Archive replicates everything like Full, but performs no consensus or result work. It is a passive replica: it stores, it does not act.

Functions Documentation

function ReplicatesAllAccounts

constexpr bool ReplicatesAllAccounts(
    NodeType type
)

Whether this role replicates network-wide data rather than just its own account.

Return: True for Full and Archive, false for Light.

Gates the full-node topic subscription, network-wide UTXO roots, and full-node blockchain mode — i.e. everything on the "store it" side of the split.

function ParticipatesInConsensus

constexpr bool ParticipatesInConsensus(
    NodeType type
)

Whether this role actively participates in consensus and result handling.

Return: True for Full and Light, false for Archive.

Archive is a passive replica, so it declines the work-generating side of full-node behavior (proposals, certificate authorship, result mirroring) while keeping replication.

function NodeTypeToString

constexpr std::string_view NodeTypeToString(
    NodeType type
)

Canonical lowercase name of a role, as accepted in sgns_config.json.

function NodeTypeFromString

inline std::optional< NodeType > NodeTypeFromString(
    std::string_view s
)

Parses a node role name, case-insensitively (Phase-2 D-02).

Return: The matching role, or std::nullopt if the string is not a known role.

Source code

#ifndef _SGNS_NODE_TYPE_HPP_
#define _SGNS_NODE_TYPE_HPP_

#include <cctype>
#include <cstdint>
#include <optional>
#include <string>
#include <string_view>

#include <fmt/format.h>

namespace sgns
{
    enum class NodeType : uint8_t
    {
        Full    = 0, 
        Light   = 1, 
        Archive = 2, 
    };

    constexpr bool ReplicatesAllAccounts( NodeType type ) noexcept
    {
        return type != NodeType::Light;
    }

    constexpr bool ParticipatesInConsensus( NodeType type ) noexcept
    {
        return type != NodeType::Archive;
    }

    constexpr std::string_view NodeTypeToString( NodeType type ) noexcept
    {
        switch ( type )
        {
            case NodeType::Full:
                return "full";
            case NodeType::Light:
                return "light";
            case NodeType::Archive:
                return "archive";
        }
        return "light";
    }

    inline std::optional<NodeType> NodeTypeFromString( std::string_view s )
    {
        std::string lower;
        lower.reserve( s.size() );
        for ( char c : s )
        {
            lower.push_back( static_cast<char>( std::tolower( static_cast<unsigned char>( c ) ) ) );
        }
        if ( lower == "full" )
        {
            return NodeType::Full;
        }
        if ( lower == "light" )
        {
            return NodeType::Light;
        }
        if ( lower == "archive" )
        {
            return NodeType::Archive;
        }
        return std::nullopt;
    }
}

template <>
struct fmt::formatter<sgns::NodeType> : formatter<std::string_view>
{
    format_context::iterator format( sgns::NodeType type, format_context &ctx ) const
    {
        return formatter<string_view>::format( sgns::NodeTypeToString( type ), ctx );
    }
};

#endif

Updated on 2026-08-26 at 01:52:50 +0000