1#include <xrpl/basics/Log.h>
2#include <xrpl/beast/utility/instrumentation.h>
3#include <xrpl/json/to_string.h>
4#include <xrpl/ledger/detail/ApplyStateTable.h>
5#include <xrpl/protocol/Feature.h>
6#include <xrpl/protocol/st.h>
15 for (
auto const& item :
items_)
17 auto const& sle = item.second.second;
18 switch (item.second.first)
41 switch (item.second.first)
65 switch (item.second.first)
72 func(item.first,
false,
nullptr, item.second.second);
100 if (!to.
open() || isDryRun)
111 switch (item.second.first)
117 type = &sfDeletedNode;
120 type = &sfCreatedNode;
123 type = &sfModifiedNode;
127 auto curNode = item.second.second;
128 if ((type == &sfModifiedNode) && (*curNode == *origNode))
131 curNode ? curNode->getFieldU16(sfLedgerEntryType) : origNode->getFieldU16(sfLedgerEntryType);
133 if (type == &sfDeletedNode)
137 "xrpl::detail::ApplyStateTable::apply : valid nodes for "
142 for (
auto const& obj : *origNode)
154 for (
auto const& obj : *curNode)
164 else if (type == &sfModifiedNode)
168 "xrpl::detail::ApplyStateTable::apply : valid nodes for "
171 if (curNode->isThreadedType(to.
rules()))
176 for (
auto const& obj : *origNode)
187 for (
auto const& obj : *curNode)
197 else if (type == &sfCreatedNode)
200 curNode && !origNode,
201 "xrpl::detail::ApplyStateTable::apply : valid nodes for "
205 if (curNode->isThreadedType(to.
rules()))
209 for (
auto const& obj : *curNode)
223 "xrpl::detail::ApplyStateTable::apply : unsupported "
232 for (
auto const& mod : newMod)
262 auto const& item = iter->second;
263 auto const& sle = item.second;
283 items_t::const_iterator iter;
288 next = base.succ(*next, last);
291 iter = items_.find(*next);
292 }
while (iter != items_.end() && iter->second.first == Action::erase);
294 for (iter = items_.upper_bound(key); iter != items_.end(); ++iter)
296 if (iter->second.first != Action::erase)
299 if (!next || next > iter->first)
306 if (last && next >= last)
317 auto const& item = iter->second;
318 auto const& sle = item.second;
339 auto const sle = base.
read(k);
347 forward_as_tuple(sle->key()),
349 return iter->
second.second;
351 auto const& item = iter->second;
352 auto const& sle = item.second;
372 LogicError(
"ApplyStateTable::erase: missing key");
373 auto& item = iter->second;
374 if (item.second != sle)
375 LogicError(
"ApplyStateTable::erase: unknown SLE");
379 LogicError(
"ApplyStateTable::erase: double erase");
399 auto& item = result.
first->second;
403 LogicError(
"ApplyStateTable::rawErase: double erase");
424 iter, piecewise_construct, forward_as_tuple(sle->key()), forward_as_tuple(
Action::insert, sle));
427 auto& item = iter->
second;
431 LogicError(
"ApplyStateTable::insert: already cached");
433 LogicError(
"ApplyStateTable::insert: already inserted");
435 LogicError(
"ApplyStateTable::insert: already modified");
451 iter, piecewise_construct, forward_as_tuple(sle->key()), forward_as_tuple(
Action::modify, sle));
454 auto& item = iter->
second;
458 LogicError(
"ApplyStateTable::replace: already erased");
474 LogicError(
"ApplyStateTable::update: missing key");
475 auto& item = iter->second;
476 if (item.second != sle)
477 LogicError(
"ApplyStateTable::update: unknown SLE");
481 LogicError(
"ApplyStateTable::update: erased");
514 if (node.getFieldIndex(sfPreviousTxnID) == -1)
517 node.getFieldIndex(sfPreviousTxnLgrSeq) == -1,
518 "xrpl::ApplyStateTable::threadItem : previous ledger is not "
520 node.setFieldH256(sfPreviousTxnID, prevTxID);
521 node.setFieldU32(sfPreviousTxnLgrSeq, prevLgrID);
525 node.getFieldH256(sfPreviousTxnID) == prevTxID,
526 "xrpl::ApplyStateTable::threadItem : previous transaction is a "
529 node.getFieldU32(sfPreviousTxnLgrSeq) == prevLgrID,
530 "xrpl::ApplyStateTable::threadItem : previous ledger is a match");
538 auto miter = mods.
find(key);
539 if (miter != mods.
end())
541 XRPL_ASSERT(miter->second,
"xrpl::ApplyStateTable::getForMod : non-null result");
542 return miter->second;
549 auto const& item = iter->
second;
555 JLOG(j.
warn()) <<
"Trying to thread to deleted node";
571 JLOG(j.
warn()) <<
"ApplyStateTable::getForMod: key not found";
588 JLOG(j.
warn()) <<
"Threading to non-existent account: " <<
toBase58(to);
592 XRPL_ASSERT(sle->isThreadedType(base.
rules()),
"xrpl::ApplyStateTable::threadTx : SLE is threaded");
607 case ltACCOUNT_ROOT: {
611 case ltRIPPLE_STATE: {
612 threadTx(base, meta, (*sle)[sfLowLimit].getIssuer(), mods, j);
613 threadTx(base, meta, (*sle)[sfHighLimit].getIssuer(), mods, j);
618 if (
auto const optSleAcct{(*sle)[~sfAccount]})
619 threadTx(base, meta, *optSleAcct, mods, j);
622 if (
auto const optSleDest{(*sle)[~sfDestination]})
623 threadTx(base, meta, *optSleDest, mods, j);
A generic endpoint for log messages.
Stream trace() const
Severity stream access functions.
Writable ledger view that accumulates state and tx changes.
std::size_t txCount() const
Return the number of tx inserted since creation.
void rawReplace(std::shared_ptr< SLE > const &sle) override
Unconditionally replace a state item.
bool open() const override
Returns true if this reflects an open ledger.
void rawTxInsert(key_type const &key, std::shared_ptr< Serializer const > const &txn, std::shared_ptr< Serializer const > const &metaData) override
Add a transaction to the tx map.
std::shared_ptr< SLE const > read(Keylet const &k) const override
Return the state item associated with a key.
Rules const & rules() const override
Returns the tx processing rules.
Interface for ledger entry changes.
virtual void rawReplace(std::shared_ptr< SLE > const &sle)=0
Unconditionally replace a state item.
virtual void rawErase(std::shared_ptr< SLE > const &sle)=0
Delete an existing state item.
virtual void rawInsert(std::shared_ptr< SLE > const &sle)=0
Unconditionally insert a state item.
virtual void rawDestroyXRP(XRPAmount const &fee)=0
Destroy XRP.
virtual Rules const & rules() const =0
Returns the tx processing rules.
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
LedgerIndex seq() const
Returns the sequence number of the base ledger.
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
std::size_t emplace_back(Args &&... args)
void add(Serializer &s) const override
uint256 getTransactionID() const
void destroyXRP(XRPAmount const &fee)
bool exists(ReadView const &base, Keylet const &k) const
void visit(ReadView const &base, std::function< void(uint256 const &key, bool isDelete, std::shared_ptr< SLE const > const &before, std::shared_ptr< SLE const > const &after)> const &func) const
std::shared_ptr< SLE > peek(ReadView const &base, Keylet const &k)
void replace(ReadView const &base, std::shared_ptr< SLE > const &sle)
static void threadItem(TxMeta &meta, std::shared_ptr< SLE > const &to)
std::optional< key_type > succ(ReadView const &base, key_type const &key, std::optional< key_type > const &last) const
void rawErase(ReadView const &base, std::shared_ptr< SLE > const &sle)
void threadTx(ReadView const &base, TxMeta &meta, AccountID const &to, Mods &mods, beast::Journal j)
void threadOwners(ReadView const &base, TxMeta &meta, std::shared_ptr< SLE const > const &sle, Mods &mods, beast::Journal j)
std::shared_ptr< SLE > getForMod(ReadView const &base, key_type const &key, Mods &mods, beast::Journal j)
std::shared_ptr< SLE const > read(ReadView const &base, Keylet const &k) const
void apply(RawView &to) const
void update(ReadView const &base, std::shared_ptr< SLE > const &sle)
XRPAmount dropsDestroyed_
T emplace_hint(T... args)
Keylet unchecked(uint256 const &key) noexcept
Any ledger entry.
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
LedgerEntryType
Identifiers for on-ledger objects.
A pair of SHAMap key and LedgerEntryType.
bool check(STLedgerEntry const &) const
Returns true if the SLE matches the type.