trustedpeer/TrustedPeerRegistry.hpp¶
Genesis-seeded, quorum-updatable trusted-peer set built entirely on top of Phase 9's SecureCrdt/SecureCrdtRegistry/ISignedCRDTData machinery. This is the first real (non-test) consumer of the SecureCRDT layer, and the signer-set-source dependency Phase 11 (BURN_BASIS_POINTS) will build on (TPR-01, TPR-02, TPR-03). More...
Namespaces¶
| Name |
|---|
| sgns |
| sgns::trustedpeer |
Classes¶
| Name | |
|---|---|
| class | sgns::trustedpeer::TrustedPeerListPayload ISignedCRDTData payload type carrying the trusted-peer list. Serialization is a newline-joined encoding of the peer address list (addresses are 128-char hex strings and never contain ' '). Verify() performs structural validation ONLY (non-empty, no duplicates, each entry exactly 128 lowercase-hex characters) – it never diffs against any cached/mutable state (Pitfall 4). |
| class | sgns::trustedpeer::TrustedPeerRegistry Genesis-seeded, in-memory-cached, quorum-updatable trusted-peer set. Delegates ALL signature/quorum logic to SecureCrdt / SecureCrdtRegistry – no bespoke signature/quorum logic exists here (TPR-03). |
Detailed Description¶
Genesis-seeded, quorum-updatable trusted-peer set built entirely on top of Phase 9's SecureCrdt/SecureCrdtRegistry/ISignedCRDTData machinery. This is the first real (non-test) consumer of the SecureCRDT layer, and the signer-set-source dependency Phase 11 (BURN_BASIS_POINTS) will build on (TPR-01, TPR-02, TPR-03).
Date: 2026-07-24 Henrique A. Klein ([email protected])
Source code¶
#ifndef SGNS_TRUSTEDPEER_TRUSTEDPEERREGISTRY_HPP
#define SGNS_TRUSTEDPEER_TRUSTEDPEERREGISTRY_HPP
#include <cstdint>
#include <memory>
#include <optional>
#include <shared_mutex>
#include <string>
#include <vector>
#include "base/logger.hpp"
#include "crdt/hierarchical_key.hpp"
#include "outcome/outcome.hpp"
#include "securecrdt/ISignedCRDTData.hpp"
#include "securecrdt/SecureCrdt.hpp"
#include "securecrdt/SecureCrdtRegistry.hpp"
namespace sgns::trustedpeer
{
class TrustedPeerListPayload : public sgns::securecrdt::ISignedCRDTData
{
public:
TrustedPeerListPayload() = default;
explicit TrustedPeerListPayload( std::vector<std::string> peers );
static std::optional<TrustedPeerListPayload> FromBytes( const std::vector<uint8_t> &bytes );
std::vector<uint8_t> SerializeToBytes() const override;
bool DeserializeFromBytes( const std::vector<uint8_t> &bytes ) override;
bool Verify( const std::vector<uint8_t> &payload ) const override;
void Apply() override;
const std::vector<std::string> &GetPeers() const
{
return peers_;
}
private:
std::vector<std::string> peers_;
};
class TrustedPeerRegistry : public std::enable_shared_from_this<TrustedPeerRegistry>
{
public:
TrustedPeerRegistry( std::shared_ptr<sgns::securecrdt::SecureCrdt> secure_crdt,
std::vector<std::string> genesis_peers,
std::string bootstrapper_address,
uint64_t quorum_threshold,
sgns::crdt::HierarchicalKey base_key );
~TrustedPeerRegistry();
static outcome::result<std::shared_ptr<TrustedPeerRegistry>> New(
std::shared_ptr<sgns::securecrdt::SecureCrdt> secure_crdt,
std::vector<std::string> genesis_peers,
std::string bootstrapper_address,
uint64_t quorum_threshold,
sgns::crdt::HierarchicalKey base_key = sgns::crdt::HierarchicalKey( "trusted-peer-registry" ) );
outcome::result<void> SeedGenesis( const std::vector<std::string> &genesis_peers,
const std::vector<uint8_t> &ephemeral_signature );
outcome::result<void> ProposeMembershipChange( const std::vector<std::string> &new_peers );
outcome::result<void> SignMembershipChange( const std::string &signer_address,
const std::vector<uint8_t> &signature );
outcome::result<bool> TryConfirm();
std::vector<std::string> GetCurrentPeers() const;
bool IsGenesisConfirmed() const;
void Unregister();
private:
void RegisterSignerSetSource();
outcome::result<sgns::securecrdt::SignerSetSnapshot> ResolveSignerSet() const;
std::shared_ptr<sgns::securecrdt::SecureCrdt> secure_crdt_;
sgns::crdt::HierarchicalKey base_key_;
std::string bootstrapper_address_;
uint64_t quorum_threshold_;
mutable std::shared_mutex cache_mutex_;
std::vector<std::string> cached_peers_;
bool genesis_confirmed_ = false;
int registry_token_ = 0;
sgns::base::Logger logger_ = sgns::base::createLogger( "TrustedPeerRegistry" );
};
} // namespace sgns::trustedpeer
#endif // SGNS_TRUSTEDPEER_TRUSTEDPEERREGISTRY_HPP
Updated on 2026-08-07 at 17:48:05 +0000