3#include <xrpl/basics/Blob.h>
4#include <xrpl/basics/Slice.h>
5#include <xrpl/basics/UnorderedContainers.h>
6#include <xrpl/basics/base64.h>
7#include <xrpl/basics/base_uint.h>
8#include <xrpl/beast/utility/Journal.h>
9#include <xrpl/protocol/PublicKey.h>
10#include <xrpl/protocol/SecretKey.h>
344 return "badMasterKey";
346 return "badEphemeralKey";
350 return "untrustedCapacity";
626 template <
class Function>
631 for (
auto const& [_, manifest] :
map_)
655 template <
class PreFun,
class EachFun>
661 for (
auto const& [_, manifest] :
map_)
A generic endpoint for log messages.
static Sink & getNullSink()
Returns a Sink which does nothing.
void forEachManifest(Function &&f) const
Invokes the callback once for every populated manifest.
std::size_t const maxUntrustedCount_
Maximum number of untrusted master keys kept in the cache.
std::atomic< std::uint32_t > seq_
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.
std::optional< PublicKey > getSigningKey(PublicKey const &pk) const
Returns master key's current signing key.
ManifestDisposition applyManifest(Manifest m, ManifestRateLimitCapPolicy cap)
Add manifest to cache.
static constexpr std::uint64_t kUntrustedRejectCount
Number of cap rejections between summary warnings.
hash_set< PublicKey > untrustedKeys_
Master keys of cached manifests for validators this node does not list.
std::optional< std::string > getDomain(PublicKey const &pk) const
Returns domain claimed by a given public key.
ManifestCache(beast::Journal j=beast::Journal(beast::Journal::getNullSink()), std::size_t maxUntrustedCount=kMaxUntrustedCount)
PublicKey getMasterKey(PublicKey const &pk) const
Returns ephemeral signing key's master public key.
std::uint32_t sequence() const
A monotonically increasing number used to detect new manifests.
hash_map< PublicKey, PublicKey > signingToMasterKeys_
Master public keys stored by current ephemeral public key.
std::optional< std::string > getManifest(PublicKey const &pk) const
Returns manifest corresponding to a given public key.
hash_map< PublicKey, Manifest > map_
Active manifests stored by master public key.
std::optional< std::uint32_t > getSequence(PublicKey const &pk) const
Returns master key's current manifest sequence.
void save(DatabaseCon &dbCon, std::string const &dbTable, std::function< bool(PublicKey const &)> const &isTrusted)
Save cached manifests to database.
std::atomic< std::uint64_t > untrustedRejectCount_
Running count of manifests rejected because the untrusted cap was full.
void forEachManifest(PreFun &&pf, EachFun &&f) const
Invokes the callback once for every populated manifest.
void promoteToTrusted(PublicKey const &pk)
Stop counting a master key against the untrusted cap.
bool revoked(PublicKey const &pk) const
Returns true if master key has been revoked in a manifest.
constexpr std::size_t encodedSize(std::size_t const nBytes)
Returns the maximum number of characters needed to base64-encode nBytes bytes.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr std::size_t kMaxTrustedCount
Default number of trusted manifests allowed in a Manifest message.
constexpr bool operator==(BaseUInt< Bits, Tag > const &lhs, BaseUInt< Bits, Tag > const &rhs)
constexpr std::size_t kMaxManifestBytes
Largest a valid manifest can be, in decoded bytes.
std::unordered_set< Value, Hash, Pred, Allocator > hash_set
constexpr std::size_t kMaxManifestBase64
Largest a valid manifest can be, in base64 characters.
constexpr std::size_t kMaxUntrustedCount
Default number of untrusted manifests to store in cache and allowed in one Manifest message.
std::string to_string(BaseUInt< Bits, Tag > const &a)
@ Stale
Not current or was older than current from this node.
std::optional< Manifest > deserializeManifest(Slice s, beast::Journal journal)
Constructs Manifest from serialized string.
ManifestRateLimitCapPolicy
Whether a manifest counts against the 'untrusted' cache cap.
@ Uncapped
Bypasses the cap (listed/trusted or config manifests).
@ Capped
Subject to the untrusted cap (unlisted peer gossip).
Slice makeSlice(std::array< T, N > const &a)
@ Accepted
We have accepted a new last closed ledger and are waiting on a call to startRound to begin the next c...
constexpr std::size_t trustedManifestCount(std::optional< std::size_t > const &configured)
Number of trusted manifests allowed in a Manifest message.
std::unordered_map< Key, Value, Hash, Pred, Allocator > hash_map
constexpr std::size_t untrustedManifestCount(std::optional< std::size_t > const &configured)
Number of untrusted manifests to store in cache and allowed in one Manifest message.
std::vector< unsigned char > Blob
Storage for linear binary data.
std::optional< ValidatorToken > loadValidatorToken(std::vector< std::string > const &blob, beast::Journal journal=beast::Journal(beast::Journal::getNullSink()))
@ BadMasterKey
The master key is not acceptable to us.
@ Accepted
Manifest is valid.
@ Invalid
Timely, but invalid signature.
@ BadEphemeralKey
The ephemeral key is not acceptable to us.
@ Stale
Sequence is too old.
@ UntrustedCapacity
Unlisted and limit reached.
Manifest(Manifest const &other)=delete
Manifest(std::string serialized, PublicKey const &masterKey, std::optional< PublicKey > const &signingKey, std::uint32_t seq, std::string domain)
Manifest & operator=(Manifest const &other)=delete
PublicKey masterKey
The master key associated with this manifest.
Manifest(Manifest &&other)=default
std::string serialized
The manifest in serialized form.
Blob getMasterSignature() const
Returns manifest master key signature.
std::string domain
The domain, if one was specified in the manifest; empty otherwise.
std::optional< Blob > getSignature() const
Returns manifest signature.
std::optional< PublicKey > signingKey
The ephemeral key associated with this manifest.
std::uint32_t sequence
The sequence number of this manifest.
bool revoked() const
Returns true if manifest revokes master key.
uint256 hash() const
Returns hash of serialized manifest data.
bool verify() const
Returns true if manifest signature is valid.
Manifest & operator=(Manifest &&other)=default
SecretKey validationSecret