20#include <xrpld/ledger/detail/ApplyStateTable.h>
22#include <xrpl/basics/Log.h>
23#include <xrpl/beast/utility/instrumentation.h>
24#include <xrpl/json/to_string.h>
25#include <xrpl/protocol/Feature.h>
26#include <xrpl/protocol/st.h>
35 for (
auto const& item :
items_)
37 auto const& sle = item.second.second;
38 switch (item.second.first)
61 switch (item.second.first)
85 switch (item.second.first)
96 func(item.first,
false,
nullptr, item.second.second);
123 auto const sTx = std::make_shared<Serializer>();
127 if (!to.
open() || isDryRun)
136 switch (item.second.first)
142 type = &sfDeletedNode;
145 type = &sfCreatedNode;
148 type = &sfModifiedNode;
152 auto curNode = item.second.second;
153 if ((type == &sfModifiedNode) && (*curNode == *origNode))
156 ? curNode->getFieldU16(sfLedgerEntryType)
157 : origNode->getFieldU16(sfLedgerEntryType);
159 if (type == &sfDeletedNode)
163 "ripple::detail::ApplyStateTable::apply : valid nodes for "
168 for (
auto const& obj : *origNode)
173 !curNode->hasMatchingEntry(obj))
182 for (
auto const& obj : *curNode)
185 if (obj.getFName().shouldMeta(
194 else if (type == &sfModifiedNode)
198 "ripple::detail::ApplyStateTable::apply : valid nodes for "
201 if (curNode->isThreadedType(
207 for (
auto const& obj : *origNode)
211 !curNode->hasMatchingEntry(obj))
220 for (
auto const& obj : *curNode)
223 if (obj.getFName().shouldMeta(
232 else if (type == &sfCreatedNode)
235 curNode && !origNode,
236 "ripple::detail::ApplyStateTable::apply : valid nodes for "
240 if (curNode->isThreadedType(
245 for (
auto const& obj : *curNode)
248 if (!obj.isDefault() &&
249 obj.getFName().shouldMeta(
261 "ripple::detail::ApplyStateTable::apply : unsupported "
269 for (
auto const& mod : newMod)
273 sMeta = std::make_shared<Serializer>();
299 auto const& item = iter->second;
300 auto const& sle = item.second;
322 items_t::const_iterator iter;
327 next = base.succ(*next, last);
330 iter = items_.find(*next);
331 }
while (iter != items_.end() && iter->second.first == Action::erase);
333 for (iter = items_.upper_bound(key); iter != items_.end(); ++iter)
335 if (iter->second.first != Action::erase)
338 if (!next || next > iter->first)
345 if (last && next >= last)
356 auto const& item = iter->second;
357 auto const& sle = item.second;
378 auto const sle = base.
read(k);
386 forward_as_tuple(sle->key()),
388 return iter->
second.second;
390 auto const& item = iter->second;
391 auto const& sle = item.second;
411 LogicError(
"ApplyStateTable::erase: missing key");
412 auto& item = iter->second;
413 if (item.second != sle)
414 LogicError(
"ApplyStateTable::erase: unknown SLE");
418 LogicError(
"ApplyStateTable::erase: double erase");
436 forward_as_tuple(sle->key()),
440 auto& item = result.
first->second;
444 LogicError(
"ApplyStateTable::rawErase: double erase");
467 forward_as_tuple(sle->key()),
471 auto& item = iter->
second;
475 LogicError(
"ApplyStateTable::insert: already cached");
477 LogicError(
"ApplyStateTable::insert: already inserted");
479 LogicError(
"ApplyStateTable::insert: already modified");
497 forward_as_tuple(sle->key()),
501 auto& item = iter->
second;
505 LogicError(
"ApplyStateTable::replace: already erased");
521 LogicError(
"ApplyStateTable::update: missing key");
522 auto& item = iter->second;
523 if (item.second != sle)
524 LogicError(
"ApplyStateTable::update: unknown SLE");
528 LogicError(
"ApplyStateTable::update: erased");
561 if (node.getFieldIndex(sfPreviousTxnID) == -1)
564 node.getFieldIndex(sfPreviousTxnLgrSeq) == -1,
565 "ripple::ApplyStateTable::threadItem : previous ledger is not "
567 node.setFieldH256(sfPreviousTxnID, prevTxID);
568 node.setFieldU32(sfPreviousTxnLgrSeq, prevLgrID);
572 node.getFieldH256(sfPreviousTxnID) == prevTxID,
573 "ripple::ApplyStateTable::threadItem : previous transaction is a "
576 node.getFieldU32(sfPreviousTxnLgrSeq) == prevLgrID,
577 "ripple::ApplyStateTable::threadItem : previous ledger is a match");
589 auto miter = mods.
find(key);
590 if (miter != mods.
end())
594 "ripple::ApplyStateTable::getForMod : non-null result");
595 return miter->second;
602 auto const& item = iter->
second;
608 JLOG(j.
warn()) <<
"Trying to thread to deleted node";
624 JLOG(j.
warn()) <<
"ApplyStateTable::getForMod: key not found";
627 auto sle = std::make_shared<SLE>(*c);
646 JLOG(j.
warn()) <<
"Threading to non-existent account: " <<
toBase58(to);
651 sle->isThreadedType(base.
rules()),
652 "ripple::ApplyStateTable::threadTx : SLE is threaded");
667 case ltACCOUNT_ROOT: {
671 case ltRIPPLE_STATE: {
672 threadTx(base, meta, (*sle)[sfLowLimit].getIssuer(), mods, j);
673 threadTx(base, meta, (*sle)[sfHighLimit].getIssuer(), mods, j);
678 if (
auto const optSleAcct{(*sle)[~sfAccount]})
679 threadTx(base, meta, *optSleAcct, mods, j);
683 if (ledgerType == ltCHECK &&
688 if (
auto const optSleDest{(*sle)[~sfDestination]})
689 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.