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/JobQueue.h>
8#include <xrpld/core/TimeKeeper.h>
9#include <xrpld/perflog/PerfLog.h>
11#include <xrpl/basics/Log.h>
12#include <xrpl/basics/chrono.h>
19 : ledgerID_{0}, ledgerSeq_{0}, j_{
beast::Journal::getNullSink()}
26 : ledgerID_{ledger->info().hash}, ledgerSeq_{ledger->seq()}, j_{j}
32 hashIndex->getFieldU32(sfLastLedgerSequence) == (
seq() - 1),
33 "ripple::RCLValidatedLedger::RCLValidatedLedger(Ledger) : valid "
34 "last ledger sequence");
35 ancestors_ = hashIndex->getFieldV256(sfHashes).value();
39 <<
" missing recent ancestor hashes";
62 if (s >= minSeq() && s <= seq())
66 Seq const diff = seq() - s;
67 return ancestors_[ancestors_.size() - diff];
70 JLOG(j_.
warn()) <<
"Unable to determine hash of ancestor seq=" << s
71 <<
" from ledger hash=" << ledgerID_
72 <<
" seq=" << ledgerSeq_ <<
" (available: " << minSeq()
73 <<
"-" << seq() <<
")";
89 while (curr !=
Seq{0} && a[curr] != b[curr] && curr >= lower)
94 return (curr < lower) ?
Seq{1} : (curr +
Seq{1});
111 using namespace std::chrono_literals;
121 <<
"Need validated ledger for preferred ledger analysis " << hash;
126 jtADVANCE,
"getConsensusLedger2", [pApp, hash,
this]() {
128 <<
"JOB advanceLedger getConsensusLedger2 started";
136 !ledger->open() && ledger->isImmutable(),
137 "ripple::RCLValidationsAdaptor::acquire : valid ledger state");
139 ledger->info().hash == hash,
140 "ripple::RCLValidationsAdaptor::acquire : ledger hash match");
153 auto const& signingKey = val->getSignerPublic();
154 auto const& hash = val->getLedgerHash();
155 auto const seq = val->getFieldU32(sfLedgerSequence);
160 if (!val->isTrusted() && masterKey)
171 validations.
add(
calcNodeID(masterKey.value_or(signingKey)), val);
175 if (val->isTrusted())
180 j,
"ripple::handleNewValidation : journal is available");
183 JLOG(j->trace()) <<
"Bypassing checkAccept for validation "
184 << val->getLedgerHash();
203 if (
auto const ls = val->isTrusted()
204 ? validations.adaptor().journal().error()
205 : validations.adaptor().journal().info();
208 auto const id = [&masterKey, &signingKey]() {
211 if (masterKey && masterKey != signingKey)
218 ls <<
"Byzantine Behavior Detector: "
219 << (val->isTrusted() ?
"trusted " :
"untrusted ") <<
id
220 <<
": Conflicting validation for " << seq <<
"!\n["
221 << val->getSerializer().slice() <<
"]";
224 ls <<
"Byzantine Behavior Detector: "
225 << (val->isTrusted() ?
"trusted " :
"untrusted ") <<
id
226 <<
": Multiple validations for " << seq <<
"/" << hash <<
"!\n["
227 << val->getSerializer().slice() <<
"]";
A generic endpoint for log messages.
virtual RCLValidations & getValidations()=0
virtual TimeKeeper & timeKeeper()=0
virtual JobQueue & getJobQueue()=0
virtual InboundLedgers & getInboundLedgers()=0
virtual ValidatorList & validators()=0
virtual LedgerMaster & getLedgerMaster()=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.
ID id() const
The ID (hash) of the ledger.
ID operator[](Seq const &s) const
Lookup the ID of the ancestor ledger.
RCLValidatedLedger(MakeGenesis)
std::vector< uint256 > ancestors_
Seq seq() const
The sequence (index) of the ledger.
std::optional< RCLValidatedLedger > acquire(LedgerHash const &id)
Attempt to acquire the ledger with given id from the network.
RCLValidationsAdaptor(Application &app, beast::Journal j)
NetClock::time_point now() const
Current time used to determine if validations are stale.
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 > getTrustedKey(PublicKey const &identity) const
Returns master public key if public key is trusted.
std::optional< PublicKey > getListedKey(PublicKey const &identity) const
Returns listed master public if public key is included on any lists.
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.
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.
RCLValidatedLedger::Seq mismatch(RCLValidatedLedger const &a, RCLValidatedLedger const &b)
@ 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.