20#include <xrpl/basics/Log.h>
21#include <xrpl/beast/utility/instrumentation.h>
22#include <xrpl/json/to_string.h>
23#include <xrpl/ledger/detail/ApplyStateTable.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);
127 if (!to.
open() || isDryRun)
138 switch (item.second.first)
144 type = &sfDeletedNode;
147 type = &sfCreatedNode;
150 type = &sfModifiedNode;
154 auto curNode = item.second.second;
155 if ((type == &sfModifiedNode) && (*curNode == *origNode))
158 ? curNode->getFieldU16(sfLedgerEntryType)
159 : origNode->getFieldU16(sfLedgerEntryType);
161 if (type == &sfDeletedNode)
165 "ripple::detail::ApplyStateTable::apply : valid nodes for "
170 for (
auto const& obj : *origNode)
175 !curNode->hasMatchingEntry(obj))
184 for (
auto const& obj : *curNode)
187 if (obj.getFName().shouldMeta(
196 else if (type == &sfModifiedNode)
200 "ripple::detail::ApplyStateTable::apply : valid nodes for "
203 if (curNode->isThreadedType(
209 for (
auto const& obj : *origNode)
213 !curNode->hasMatchingEntry(obj))
222 for (
auto const& obj : *curNode)
225 if (obj.getFName().shouldMeta(
234 else if (type == &sfCreatedNode)
237 curNode && !origNode,
238 "ripple::detail::ApplyStateTable::apply : valid nodes for "
242 if (curNode->isThreadedType(
247 for (
auto const& obj : *curNode)
250 if (!obj.isDefault() &&
251 obj.getFName().shouldMeta(
263 "ripple::detail::ApplyStateTable::apply : unsupported "
271 for (
auto const& mod : newMod)
301 auto const& item = iter->second;
302 auto const& sle = item.second;
324 items_t::const_iterator iter;
329 next = base.succ(*next, last);
332 iter = items_.find(*next);
333 }
while (iter != items_.end() && iter->second.first == Action::erase);
335 for (iter = items_.upper_bound(key); iter != items_.end(); ++iter)
337 if (iter->second.first != Action::erase)
340 if (!next || next > iter->first)
347 if (last && next >= last)
358 auto const& item = iter->second;
359 auto const& sle = item.second;
380 auto const sle = base.
read(k);
388 forward_as_tuple(sle->key()),
390 return iter->
second.second;
392 auto const& item = iter->second;
393 auto const& sle = item.second;
413 LogicError(
"ApplyStateTable::erase: missing key");
414 auto& item = iter->second;
415 if (item.second != sle)
416 LogicError(
"ApplyStateTable::erase: unknown SLE");
420 LogicError(
"ApplyStateTable::erase: double erase");
438 forward_as_tuple(sle->key()),
442 auto& item = result.
first->second;
446 LogicError(
"ApplyStateTable::rawErase: double erase");
469 forward_as_tuple(sle->key()),
473 auto& item = iter->
second;
477 LogicError(
"ApplyStateTable::insert: already cached");
479 LogicError(
"ApplyStateTable::insert: already inserted");
481 LogicError(
"ApplyStateTable::insert: already modified");
499 forward_as_tuple(sle->key()),
503 auto& item = iter->
second;
507 LogicError(
"ApplyStateTable::replace: already erased");
523 LogicError(
"ApplyStateTable::update: missing key");
524 auto& item = iter->second;
525 if (item.second != sle)
526 LogicError(
"ApplyStateTable::update: unknown SLE");
530 LogicError(
"ApplyStateTable::update: erased");
563 if (node.getFieldIndex(sfPreviousTxnID) == -1)
566 node.getFieldIndex(sfPreviousTxnLgrSeq) == -1,
567 "ripple::ApplyStateTable::threadItem : previous ledger is not "
569 node.setFieldH256(sfPreviousTxnID, prevTxID);
570 node.setFieldU32(sfPreviousTxnLgrSeq, prevLgrID);
574 node.getFieldH256(sfPreviousTxnID) == prevTxID,
575 "ripple::ApplyStateTable::threadItem : previous transaction is a "
578 node.getFieldU32(sfPreviousTxnLgrSeq) == prevLgrID,
579 "ripple::ApplyStateTable::threadItem : previous ledger is a match");
591 auto miter = mods.
find(key);
592 if (miter != mods.
end())
596 "ripple::ApplyStateTable::getForMod : non-null result");
597 return miter->second;
604 auto const& item = iter->
second;
610 JLOG(j.
warn()) <<
"Trying to thread to deleted node";
626 JLOG(j.
warn()) <<
"ApplyStateTable::getForMod: key not found";
648 JLOG(j.
warn()) <<
"Threading to non-existent account: " <<
toBase58(to);
653 sle->isThreadedType(base.
rules()),
654 "ripple::ApplyStateTable::threadTx : SLE is threaded");
669 case ltACCOUNT_ROOT: {
673 case ltRIPPLE_STATE: {
674 threadTx(base, meta, (*sle)[sfLowLimit].getIssuer(), mods, j);
675 threadTx(base, meta, (*sle)[sfHighLimit].getIssuer(), mods, j);
680 if (
auto const optSleAcct{(*sle)[~sfAccount]})
681 threadTx(base, meta, *optSleAcct, mods, j);
685 if (ledgerType == ltCHECK &&
690 if (
auto const optSleDest{(*sle)[~sfDestination]})
691 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.
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.