20#include <xrpld/ledger/detail/ApplyStateTable.h>
21#include <xrpl/basics/Log.h>
22#include <xrpl/beast/utility/instrumentation.h>
23#include <xrpl/json/to_string.h>
24#include <xrpl/protocol/Feature.h>
25#include <xrpl/protocol/st.h>
34 for (
auto const& item :
items_)
36 auto const& sle = item.second.second;
37 switch (item.second.first)
60 switch (item.second.first)
84 switch (item.second.first)
95 func(item.first,
false,
nullptr, item.second.second);
121 auto const sTx = std::make_shared<Serializer>();
133 switch (item.second.first)
139 type = &sfDeletedNode;
142 type = &sfCreatedNode;
145 type = &sfModifiedNode;
149 auto curNode = item.second.second;
150 if ((type == &sfModifiedNode) && (*curNode == *origNode))
153 ? curNode->getFieldU16(sfLedgerEntryType)
154 : origNode->getFieldU16(sfLedgerEntryType);
156 if (type == &sfDeletedNode)
160 "ripple::detail::ApplyStateTable::apply : valid nodes for "
165 for (
auto const& obj : *origNode)
170 !curNode->hasMatchingEntry(obj))
179 for (
auto const& obj : *curNode)
182 if (obj.getFName().shouldMeta(
191 else if (type == &sfModifiedNode)
195 "ripple::detail::ApplyStateTable::apply : valid nodes for "
198 if (curNode->isThreadedType(
204 for (
auto const& obj : *origNode)
208 !curNode->hasMatchingEntry(obj))
217 for (
auto const& obj : *curNode)
220 if (obj.getFName().shouldMeta(
229 else if (type == &sfCreatedNode)
232 curNode && !origNode,
233 "ripple::detail::ApplyStateTable::apply : valid nodes for "
237 if (curNode->isThreadedType(
242 for (
auto const& obj : *curNode)
245 if (!obj.isDefault() &&
246 obj.getFName().shouldMeta(
258 "ripple::detail::ApplyStateTable::apply : unsupported "
264 for (
auto& mod : newMod)
267 sMeta = std::make_shared<Serializer>();
286 auto const& item = iter->second;
287 auto const& sle = item.second;
309 items_t::const_iterator iter;
314 next = base.succ(*next, last);
317 iter = items_.find(*next);
318 }
while (iter != items_.end() && iter->second.first == Action::erase);
320 for (iter = items_.upper_bound(key); iter != items_.end(); ++iter)
322 if (iter->second.first != Action::erase)
325 if (!next || next > iter->first)
332 if (last && next >= last)
343 auto const& item = iter->second;
344 auto const& sle = item.second;
365 auto const sle = base.
read(k);
373 forward_as_tuple(sle->key()),
375 return iter->
second.second;
377 auto const& item = iter->second;
378 auto const& sle = item.second;
398 LogicError(
"ApplyStateTable::erase: missing key");
399 auto& item = iter->second;
400 if (item.second != sle)
401 LogicError(
"ApplyStateTable::erase: unknown SLE");
405 LogicError(
"ApplyStateTable::erase: double erase");
423 forward_as_tuple(sle->key()),
427 auto& item = result.
first->second;
431 LogicError(
"ApplyStateTable::rawErase: double erase");
454 forward_as_tuple(sle->key()),
458 auto& item = iter->
second;
462 LogicError(
"ApplyStateTable::insert: already cached");
464 LogicError(
"ApplyStateTable::insert: already inserted");
466 LogicError(
"ApplyStateTable::insert: already modified");
484 forward_as_tuple(sle->key()),
488 auto& item = iter->
second;
492 LogicError(
"ApplyStateTable::replace: already erased");
508 LogicError(
"ApplyStateTable::update: missing key");
509 auto& item = iter->second;
510 if (item.second != sle)
511 LogicError(
"ApplyStateTable::update: unknown SLE");
515 LogicError(
"ApplyStateTable::update: erased");
548 if (node.getFieldIndex(sfPreviousTxnID) == -1)
551 node.getFieldIndex(sfPreviousTxnLgrSeq) == -1,
552 "ripple::ApplyStateTable::threadItem : previous ledger is not "
554 node.setFieldH256(sfPreviousTxnID, prevTxID);
555 node.setFieldU32(sfPreviousTxnLgrSeq, prevLgrID);
559 node.getFieldH256(sfPreviousTxnID) == prevTxID,
560 "ripple::ApplyStateTable::threadItem : previous transaction is a "
563 node.getFieldU32(sfPreviousTxnLgrSeq) == prevLgrID,
564 "ripple::ApplyStateTable::threadItem : previous ledger is a match");
576 auto miter = mods.
find(key);
577 if (miter != mods.
end())
581 "ripple::ApplyStateTable::getForMod : non-null result");
582 return miter->second;
589 auto const& item = iter->
second;
595 JLOG(j.
warn()) <<
"Trying to thread to deleted node";
611 JLOG(j.
warn()) <<
"ApplyStateTable::getForMod: key not found";
614 auto sle = std::make_shared<SLE>(*c);
633 JLOG(j.
warn()) <<
"Threading to non-existent account: " <<
toBase58(to);
638 sle->isThreadedType(base.
rules()),
639 "ripple::ApplyStateTable::threadTx : SLE is threaded");
654 case ltACCOUNT_ROOT: {
658 case ltRIPPLE_STATE: {
659 threadTx(base, meta, (*sle)[sfLowLimit].getIssuer(), mods, j);
660 threadTx(base, meta, (*sle)[sfHighLimit].getIssuer(), mods, j);
665 if (
auto const optSleAcct{(*sle)[~sfAccount]})
666 threadTx(base, meta, *optSleAcct, mods, j);
670 if (ledgerType == ltCHECK &&
675 if (
auto const optSleDest{(*sle)[~sfDestination]})
676 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.
Rules const & rules() const override
Returns the tx processing rules.
std::shared_ptr< SLE const > read(Keylet const &k) const override
Return the state item associated with a key.
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.
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.
Interface for ledger entry changes.
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 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 std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
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 Rules const & rules() const =0
Returns the tx processing rules.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
void add(Serializer &s) const override
std::size_t emplace_back(Args &&... args)
uint256 getTransactionID() const
std::shared_ptr< SLE > peek(ReadView const &base, Keylet const &k)
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)
std::shared_ptr< SLE const > read(ReadView const &base, Keylet const &k) const
void update(ReadView const &base, std::shared_ptr< SLE > const &sle)
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
static void threadItem(TxMeta &meta, std::shared_ptr< SLE > const &to)
std::shared_ptr< SLE > getForMod(ReadView const &base, key_type const &key, Mods &mods, beast::Journal j)
void threadOwners(ReadView const &base, TxMeta &meta, std::shared_ptr< SLE const > const &sle, Mods &mods, beast::Journal j)
void apply(RawView &to) const
std::optional< key_type > succ(ReadView const &base, key_type const &key, std::optional< key_type > const &last) const
void replace(ReadView const &base, std::shared_ptr< SLE > const &sle)
void destroyXRP(XRPAmount const &fee)
XRPAmount dropsDestroyed_
T emplace_hint(T... args)
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet unchecked(uint256 const &key) noexcept
Any ledger entry.
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.
LedgerEntryType
Identifiers for on-ledger objects.
static bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
A pair of SHAMap key and LedgerEntryType.
bool check(STLedgerEntry const &) const
Returns true if the SLE matches the type.