rippled
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
xrpl::ManifestCache Class Reference

Remembers manifests with the highest sequence number. More...

#include <Manifest.h>

Collaboration diagram for xrpl::ManifestCache:
Collaboration graph
[legend]

Public Member Functions

 ManifestCache (beast::Journal j=beast::Journal(beast::Journal::getNullSink()))
 
std::uint32_t sequence () const
 A monotonically increasing number used to detect new manifests.
 
std::optional< PublicKeygetSigningKey (PublicKey const &pk) const
 Returns master key's current signing key.
 
PublicKey getMasterKey (PublicKey const &pk) const
 Returns ephemeral signing key's master public key.
 
std::optional< std::uint32_tgetSequence (PublicKey const &pk) const
 Returns master key's current manifest sequence.
 
std::optional< std::stringgetDomain (PublicKey const &pk) const
 Returns domain claimed by a given public key.
 
std::optional< std::stringgetManifest (PublicKey const &pk) const
 Returns manifest corresponding to a given public key.
 
bool revoked (PublicKey const &pk) const
 Returns true if master key has been revoked in a manifest.
 
ManifestDisposition applyManifest (Manifest m)
 Add manifest to cache.
 
bool load (DatabaseCon &dbCon, std::string const &dbTable, std::string const &configManifest, std::vector< std::string > const &configRevocation)
 Populate manifest cache with manifests in database and config.
 
void load (DatabaseCon &dbCon, std::string const &dbTable)
 Populate manifest cache with manifests in database.
 
void save (DatabaseCon &dbCon, std::string const &dbTable, std::function< bool(PublicKey const &)> const &isTrusted)
 Save cached manifests to database.
 
template<class Function >
void for_each_manifest (Function &&f) const
 Invokes the callback once for every populated manifest.
 
template<class PreFun , class EachFun >
void for_each_manifest (PreFun &&pf, EachFun &&f) const
 Invokes the callback once for every populated manifest.
 

Private Attributes

beast::Journal j_
 
std::shared_mutex mutex_
 
hash_map< PublicKey, Manifestmap_
 Active manifests stored by master public key.
 
hash_map< PublicKey, PublicKeysigningToMasterKeys_
 Master public keys stored by current ephemeral public key.
 
std::atomic< std::uint32_tseq_ {0}
 

Detailed Description

Remembers manifests with the highest sequence number.

Definition at line 236 of file Manifest.h.

Constructor & Destructor Documentation

◆ ManifestCache()

xrpl::ManifestCache::ManifestCache ( beast::Journal  j = beast::Journal(beast::Journal::getNullSink()))
explicit

Definition at line 251 of file Manifest.h.

Member Function Documentation

◆ sequence()

std::uint32_t xrpl::ManifestCache::sequence ( ) const

A monotonically increasing number used to detect new manifests.

Definition at line 259 of file Manifest.h.

◆ getSigningKey()

std::optional< PublicKey > xrpl::ManifestCache::getSigningKey ( PublicKey const &  pk) const

Returns master key's current signing key.

Parameters
pkMaster public key
Returns
pk if no known signing key from a manifest
Thread Safety

May be called concurrently

Definition at line 291 of file Manifest.cpp.

◆ getMasterKey()

PublicKey xrpl::ManifestCache::getMasterKey ( PublicKey const &  pk) const

Returns ephemeral signing key's master public key.

Parameters
pkEphemeral signing public key
Returns
pk if signing key is not in a valid manifest
Thread Safety

May be called concurrently

Definition at line 303 of file Manifest.cpp.

◆ getSequence()

std::optional< std::uint32_t > xrpl::ManifestCache::getSequence ( PublicKey const &  pk) const

Returns master key's current manifest sequence.

Returns
sequence corresponding to Master public key if configured or std::nullopt otherwise

Definition at line 315 of file Manifest.cpp.

◆ getDomain()

std::optional< std::string > xrpl::ManifestCache::getDomain ( PublicKey const &  pk) const

Returns domain claimed by a given public key.

Returns
domain corresponding to Master public key if present, otherwise std::nullopt

Definition at line 327 of file Manifest.cpp.

◆ getManifest()

std::optional< std::string > xrpl::ManifestCache::getManifest ( PublicKey const &  pk) const

Returns manifest corresponding to a given public key.

Returns
manifest corresponding to Master public key if present, otherwise std::nullopt

Definition at line 339 of file Manifest.cpp.

◆ revoked()

bool xrpl::ManifestCache::revoked ( PublicKey const &  pk) const

Returns true if master key has been revoked in a manifest.

Parameters
pkMaster public key
Thread Safety

May be called concurrently

Definition at line 351 of file Manifest.cpp.

◆ applyManifest()

ManifestDisposition xrpl::ManifestCache::applyManifest ( Manifest  m)

Add manifest to cache.

Parameters
mManifest to add
Returns
ManifestDisposition::accepted if successful, or stale or invalid otherwise
Thread Safety

May be called concurrently

Definition at line 363 of file Manifest.cpp.

◆ load() [1/2]

bool xrpl::ManifestCache::load ( DatabaseCon dbCon,
std::string const &  dbTable,
std::string const &  configManifest,
std::vector< std::string > const &  configRevocation 
)

Populate manifest cache with manifests in database and config.

Parameters
dbConDatabase connection with dbTable
dbTableDatabase table
configManifestBase64 encoded manifest for local node's validator keys
configRevocationBase64 encoded validator key revocation from the config
Thread Safety

May be called concurrently

Definition at line 531 of file Manifest.cpp.

◆ load() [2/2]

void xrpl::ManifestCache::load ( DatabaseCon dbCon,
std::string const &  dbTable 
)

Populate manifest cache with manifests in database.

Parameters
dbConDatabase connection with dbTable
dbTableDatabase table
Thread Safety

May be called concurrently

Definition at line 524 of file Manifest.cpp.

◆ save()

void xrpl::ManifestCache::save ( DatabaseCon dbCon,
std::string const &  dbTable,
std::function< bool(PublicKey const &)> const &  isTrusted 
)

Save cached manifests to database.

Parameters
dbConDatabase connection with ValidatorManifests table
isTrustedFunction that returns true if manifest is trusted
Thread Safety

May be called concurrently

Definition at line 588 of file Manifest.cpp.

◆ for_each_manifest() [1/2]

template<class Function >
void xrpl::ManifestCache::for_each_manifest ( Function &&  f) const

Invokes the callback once for every populated manifest.

Note
Do not call ManifestCache member functions from within the callback. This can re-lock the mutex from the same thread, which is UB.
Do not write ManifestCache member variables from within the callback. This can lead to data races.
Parameters
fFunction called for each manifest
Thread Safety

May be called concurrently

Definition at line 406 of file Manifest.h.

◆ for_each_manifest() [2/2]

template<class PreFun , class EachFun >
void xrpl::ManifestCache::for_each_manifest ( PreFun &&  pf,
EachFun &&  f 
) const

Invokes the callback once for every populated manifest.

Note
Do not call ManifestCache member functions from within the callback. This can re-lock the mutex from the same thread, which is UB.
Do not write ManifestCache member variables from within the callback. This can lead to data races.
Parameters
pfPre-function called with the maximum number of times f will be called (useful for memory allocations)
fFunction called for each manifest
Thread Safety

May be called concurrently

Definition at line 434 of file Manifest.h.

Member Data Documentation

◆ j_

beast::Journal xrpl::ManifestCache::j_
private

Definition at line 239 of file Manifest.h.

◆ mutex_

std::shared_mutex xrpl::ManifestCache::mutex_
mutableprivate

Definition at line 240 of file Manifest.h.

◆ map_

hash_map<PublicKey, Manifest> xrpl::ManifestCache::map_
private

Active manifests stored by master public key.

Definition at line 243 of file Manifest.h.

◆ signingToMasterKeys_

hash_map<PublicKey, PublicKey> xrpl::ManifestCache::signingToMasterKeys_
private

Master public keys stored by current ephemeral public key.

Definition at line 246 of file Manifest.h.

◆ seq_

std::atomic<std::uint32_t> xrpl::ManifestCache::seq_ {0}
private

Definition at line 248 of file Manifest.h.