1#include <xrpld/app/consensus/RCLValidations.h>
2#include <xrpld/app/ledger/InboundLedger.h>
3#include <xrpld/app/ledger/InboundLedgers.h>
4#include <xrpld/app/ledger/LedgerMaster.h>
5#include <xrpld/app/main/Application.h>
6#include <xrpld/app/misc/ValidatorList.h>
7#include <xrpld/core/TimeKeeper.h>
9#include <xrpl/basics/Log.h>
10#include <xrpl/basics/chrono.h>
11#include <xrpl/core/JobQueue.h>
12#include <xrpl/core/PerfLog.h>
23 : ledgerID_{ledger->header().hash}, ledgerSeq_{ledger->seq()}, j_{j}
29 hashIndex->getFieldU32(sfLastLedgerSequence) == (
seq() - 1),
30 "xrpl::RCLValidatedLedger::RCLValidatedLedger(Ledger) : valid "
31 "last ledger sequence");
32 ancestors_ = hashIndex->getFieldV256(sfHashes).value();
58 if (s >= minSeq() && s <= seq())
62 Seq const diff = seq() - s;
63 return ancestors_[ancestors_.size() - diff];
66 JLOG(j_.warn()) <<
"Unable to determine hash of ancestor seq=" << s <<
" from ledger hash=" << ledgerID_
67 <<
" seq=" << ledgerSeq_ <<
" (available: " << minSeq() <<
"-" << seq() <<
")";
83 while (curr !=
Seq{0} && a[curr] != b[curr] && curr >= lower)
88 return (curr < lower) ?
Seq{1} : (curr +
Seq{1});
104 using namespace std::chrono_literals;
110 JLOG(
j_.
warn()) <<
"Need validated ledger for preferred ledger analysis " << hash;
115 JLOG(
j_.
debug()) <<
"JOB advanceLedger getConsensusLedger2 started";
121 XRPL_ASSERT(!ledger->open() && ledger->isImmutable(),
"xrpl::RCLValidationsAdaptor::acquire : valid ledger state");
122 XRPL_ASSERT(ledger->header().hash == hash,
"xrpl::RCLValidationsAdaptor::acquire : ledger hash match");
135 auto const& signingKey = val->getSignerPublic();
136 auto const& hash = val->getLedgerHash();
137 auto const seq = val->getFieldU32(sfLedgerSequence);
142 if (!val->isTrusted() && masterKey)
152 auto const outcome = validations.
add(
calcNodeID(masterKey.value_or(signingKey)), val);
156 if (val->isTrusted())
160 XRPL_ASSERT(j,
"xrpl::handleNewValidation : journal is available");
163 JLOG(j->trace()) <<
"Bypassing checkAccept for validation " << val->getLedgerHash();
183 val->isTrusted() ? validations.adaptor().journal().error() : validations.adaptor().journal().info();
186 auto const id = [&masterKey, &signingKey]() {
189 if (masterKey && masterKey != signingKey)
196 ls <<
"Byzantine Behavior Detector: " << (val->isTrusted() ?
"trusted " :
"untrusted ") <<
id
197 <<
": Conflicting validation for " << seq <<
"!\n[" << val->getSerializer().slice() <<
"]";
200 ls <<
"Byzantine Behavior Detector: " << (val->isTrusted() ?
"trusted " :
"untrusted ") <<
id
201 <<
": Multiple validations for " << seq <<
"/" << hash <<
"!\n[" << val->getSerializer().slice() <<
"]";
A generic endpoint for log messages.
virtual InboundLedgers & getInboundLedgers()=0
virtual LedgerMaster & getLedgerMaster()=0
virtual TimeKeeper & timeKeeper()=0
virtual RCLValidations & getValidations()=0
virtual JobQueue & getJobQueue()=0
virtual ValidatorList & validators()=0
virtual void acquireAsync(uint256 const &hash, std::uint32_t seq, InboundLedger::Reason reason)=0
bool addJob(JobType type, std::string const &name, JobHandler &&jobHandler)
Adds a job to the JobQueue.
void checkAccept(std::shared_ptr< Ledger const > const &ledger)
Wraps a ledger instance for use in generic Validations LedgerTrie.
RCLValidatedLedger(MakeGenesis)
Seq seq() const
The sequence (index) of the ledger.
ID id() const
The ID (hash) of the ledger.
ID operator[](Seq const &s) const
Lookup the ID of the ancestor ledger.
std::vector< uint256 > ancestors_
std::optional< RCLValidatedLedger > acquire(LedgerHash const &id)
Attempt to acquire the ledger with given id from the network.
NetClock::time_point now() const
Current time used to determine if validations are stale.
RCLValidationsAdaptor(Application &app, beast::Journal j)
time_point closeTime() const
Returns the predicted close time, in network time.
ValStatus add(NodeID const &nodeID, Validation const &val)
Add a new validation.
std::optional< PublicKey > getListedKey(PublicKey const &identity) const
Returns listed master public if public key is included on any lists.
std::optional< PublicKey > getTrustedKey(PublicKey const &identity) const
Returns master public key if public key is trusted.
Keylet const & skip() noexcept
The index of the "short" skip list.
auto measureDurationAndLog(Func &&func, std::string const &actionDescription, std::chrono::duration< Rep, Period > maxDelay, beast::Journal const &journal)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
@ current
This was a new validation and was added.
@ conflicting
Multiple validations by a validator for different ledgers.
@ multiple
Multiple validations by a validator for the same ledger.
NodeID calcNodeID(PublicKey const &)
Calculate the 160-bit node ID from a node public key.
RCLValidatedLedger::Seq mismatch(RCLValidatedLedger const &a, RCLValidatedLedger const &b)
void handleNewValidation(Application &app, std::shared_ptr< STValidation > const &val, std::string const &source, BypassAccept const bypassAccept, std::optional< beast::Journal > j)
Handle a new validation.