1#include <xrpld/app/consensus/RCLValidations.h>
3#include <xrpld/app/ledger/InboundLedger.h>
4#include <xrpld/app/ledger/InboundLedgers.h>
5#include <xrpld/app/ledger/LedgerMaster.h>
6#include <xrpld/app/main/Application.h>
7#include <xrpld/app/misc/ValidatorList.h>
8#include <xrpld/consensus/Validations.h>
9#include <xrpld/core/TimeKeeper.h>
11#include <xrpl/basics/Log.h>
12#include <xrpl/basics/chrono.h>
13#include <xrpl/beast/utility/instrumentation.h>
14#include <xrpl/core/Job.h>
15#include <xrpl/core/JobQueue.h>
16#include <xrpl/core/PerfLog.h>
17#include <xrpl/protocol/Indexes.h>
18#include <xrpl/protocol/PublicKey.h>
19#include <xrpl/protocol/RippleLedgerHash.h>
20#include <xrpl/protocol/SField.h>
21#include <xrpl/protocol/tokens.h>
43 hashIndex->getFieldU32(sfLastLedgerSequence) == (
seq() - 1),
44 "xrpl::RCLValidatedLedger::RCLValidatedLedger(Ledger) : valid "
45 "last ledger sequence");
46 ancestors_ = hashIndex->getFieldV256(sfHashes).value();
51 <<
" missing recent ancestor hashes";
79 Seq const diff =
seq() - s;
83 JLOG(
j_.warn()) <<
"Unable to determine hash of ancestor seq=" << s
85 <<
" (available: " <<
minSeq() <<
"-" <<
seq() <<
")";
101 while (curr !=
Seq{0} && a[curr] != b[curr] && curr >= lower)
106 return (curr < lower) ?
Seq{1} : (curr +
Seq{1});
116 return app_.getTimeKeeper().closeTime();
122 using namespace std::chrono_literals;
124 [&]() {
return app_.getLedgerMaster().getLedgerByHash(hash); },
131 JLOG(
j_.warn()) <<
"Need validated ledger for preferred ledger analysis " << hash;
135 app_.getJobQueue().addJob(
JtAdvance,
"GetConsL2", [pApp, hash,
this]() {
136 JLOG(
j_.debug()) <<
"JOB advanceLedger getConsensusLedger2 started";
143 !ledger->open() && ledger->isImmutable(),
144 "xrpl::RCLValidationsAdaptor::acquire : valid ledger state");
146 ledger->header().hash == hash,
"xrpl::RCLValidationsAdaptor::acquire : ledger hash match");
159 auto const& signingKey = val->getSignerPublic();
160 auto const& hash = val->getLedgerHash();
161 auto const seq = val->getFieldU32(sfLedgerSequence);
166 if (!val->isTrusted() && masterKey)
176 auto const outcome = validations.
add(
calcNodeID(masterKey.value_or(signingKey)), val);
180 if (val->isTrusted())
184 XRPL_ASSERT(j,
"xrpl::handleNewValidation : journal is available");
188 <<
"Bypassing checkAccept for validation " << val->getLedgerHash();
207 if (
auto const ls = val->isTrusted() ? validations.adaptor().journal().error()
208 : validations.adaptor().journal().info();
211 auto const id = [&masterKey, &signingKey]() {
214 if (masterKey && masterKey != signingKey)
222 ls <<
"Byzantine Behavior Detector: " << (val->isTrusted() ?
"trusted " :
"untrusted ")
223 <<
id <<
": Conflicting validation for " << seq <<
"!\n["
224 << val->getSerializer().slice() <<
"]";
229 ls <<
"Byzantine Behavior Detector: " << (val->isTrusted() ?
"trusted " :
"untrusted ")
230 <<
id <<
": Multiple validations for " << seq <<
"/" << hash <<
"!\n["
231 << val->getSerializer().slice() <<
"]";
A generic endpoint for log messages.
virtual void acquireAsync(uint256 const &hash, std::uint32_t seq, InboundLedger::Reason reason)=0
void checkAccept(std::shared_ptr< Ledger const > const &ledger)
std::chrono::time_point< NetClock > time_point
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)
virtual ValidatorList & getValidators()=0
virtual RCLValidations & getValidations()=0
virtual InboundLedgers & getInboundLedgers()=0
virtual LedgerMaster & getLedgerMaster()=0
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.
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.
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)