20#include <xrpld/app/consensus/RCLValidations.h>
21#include <xrpld/app/ledger/InboundLedger.h>
22#include <xrpld/app/ledger/InboundLedgers.h>
23#include <xrpld/app/ledger/LedgerMaster.h>
24#include <xrpld/app/main/Application.h>
25#include <xrpld/app/misc/NetworkOPs.h>
26#include <xrpld/app/misc/ValidatorList.h>
27#include <xrpld/consensus/LedgerTiming.h>
28#include <xrpld/core/JobQueue.h>
29#include <xrpld/core/TimeKeeper.h>
30#include <xrpld/perflog/PerfLog.h>
31#include <xrpl/basics/Log.h>
32#include <xrpl/basics/StringUtilities.h>
33#include <xrpl/basics/chrono.h>
41 : ledgerID_{0}, ledgerSeq_{0}, j_{
beast::Journal::getNullSink()}
48 : ledgerID_{ledger->info().hash}, ledgerSeq_{ledger->seq()}, j_{j}
54 hashIndex->getFieldU32(sfLastLedgerSequence) == (
seq() - 1),
55 "ripple::RCLValidatedLedger::RCLValidatedLedger(Ledger) : valid "
56 "last ledger sequence");
57 ancestors_ = hashIndex->getFieldV256(sfHashes).value();
61 <<
" missing recent ancestor hashes";
84 if (s >= minSeq() && s <= seq())
88 Seq const diff = seq() - s;
89 return ancestors_[ancestors_.size() - diff];
92 JLOG(j_.
warn()) <<
"Unable to determine hash of ancestor seq=" << s
93 <<
" from ledger hash=" << ledgerID_
94 <<
" seq=" << ledgerSeq_ <<
" (available: " << minSeq()
95 <<
"-" << seq() <<
")";
111 while (curr !=
Seq{0} && a[curr] != b[curr] && curr >= lower)
116 return (curr < lower) ?
Seq{1} : (curr +
Seq{1});
133 using namespace std::chrono_literals;
143 <<
"Need validated ledger for preferred ledger analysis " << hash;
148 jtADVANCE,
"getConsensusLedger2", [pApp, hash,
this]() {
150 <<
"JOB advanceLedger getConsensusLedger2 started";
158 !ledger->open() && ledger->isImmutable(),
159 "ripple::RCLValidationsAdaptor::acquire : valid ledger state");
161 ledger->info().hash == hash,
162 "ripple::RCLValidationsAdaptor::acquire : ledger hash match");
175 auto const& signingKey = val->getSignerPublic();
176 auto const& hash = val->getLedgerHash();
177 auto const seq = val->getFieldU32(sfLedgerSequence);
182 if (!val->isTrusted() && masterKey)
193 validations.
add(
calcNodeID(masterKey.value_or(signingKey)), val);
197 if (val->isTrusted())
202 j,
"ripple::handleNewValidation : journal is available");
205 JLOG(j->trace()) <<
"Bypassing checkAccept for validation "
206 << val->getLedgerHash();
225 if (
auto const ls = val->isTrusted()
226 ? validations.adaptor().journal().error()
227 : validations.adaptor().journal().info();
230 auto const id = [&masterKey, &signingKey]() {
233 if (masterKey && masterKey != signingKey)
240 ls <<
"Byzantine Behavior Detector: "
241 << (val->isTrusted() ?
"trusted " :
"untrusted ") <<
id
242 <<
": Conflicting validation for " << seq <<
"!\n["
243 << val->getSerializer().slice() <<
"]";
246 ls <<
"Byzantine Behavior Detector: "
247 << (val->isTrusted() ?
"trusted " :
"untrusted ") <<
id
248 <<
": Multiple validations for " << seq <<
"/" << hash <<
"!\n["
249 << 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, const std::string &actionDescription, std::chrono::duration< Rep, Period > maxDelay, const beast::Journal &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.