20 #include <ripple/basics/Log.h>
21 #include <ripple/json/to_string.h>
22 #include <ripple/ledger/detail/ApplyStateTable.h>
23 #include <ripple/protocol/Feature.h>
24 #include <ripple/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)
149 auto curNode = item.second.second;
158 assert(origNode && curNode);
162 for (
auto const& obj : *origNode)
167 !curNode->hasMatchingEntry(obj))
176 for (
auto const& obj : *curNode)
179 if (obj.getFName().shouldMeta(
190 assert(curNode && origNode);
192 if (curNode->isThreadedType())
197 for (
auto const& obj : *origNode)
201 !curNode->hasMatchingEntry(obj))
210 for (
auto const& obj : *curNode)
213 if (obj.getFName().shouldMeta(
224 assert(curNode && !origNode);
227 if (curNode->isThreadedType())
231 for (
auto const& obj : *curNode)
234 if (!obj.isDefault() &&
235 obj.getFName().shouldMeta(
251 for (
auto& mod : newMod)
254 sMeta = std::make_shared<Serializer>();
273 auto const& item = iter->second;
274 auto const& sle = item.second;
296 items_t::const_iterator iter;
301 next = base.succ(*next, last);
304 iter = items_.find(*next);
305 }
while (iter != items_.end() && iter->second.first == Action::erase);
307 for (iter = items_.upper_bound(key); iter != items_.end(); ++iter)
309 if (iter->second.first != Action::erase)
312 if (!next || next > iter->first)
319 if (last && next >= last)
330 auto const& item = iter->second;
331 auto const& sle = item.second;
352 auto const sle = base.
read(k);
362 return iter->second.second;
364 auto const& item = iter->second;
365 auto const& sle = item.second;
385 LogicError(
"ApplyStateTable::erase: missing key");
386 auto& item = iter->second;
387 if (item.second != sle)
388 LogicError(
"ApplyStateTable::erase: unknown SLE");
392 LogicError(
"ApplyStateTable::erase: double erase");
414 auto& item = result.first->second;
418 LogicError(
"ApplyStateTable::rawErase: double erase");
435 if (iter ==
items_.
end() || iter->first != sle->key())
445 auto& item = iter->second;
449 LogicError(
"ApplyStateTable::insert: already cached");
451 LogicError(
"ApplyStateTable::insert: already inserted");
453 LogicError(
"ApplyStateTable::insert: already modified");
465 if (iter ==
items_.
end() || iter->first != sle->key())
475 auto& item = iter->second;
479 LogicError(
"ApplyStateTable::replace: already erased");
495 LogicError(
"ApplyStateTable::update: missing key");
496 auto& item = iter->second;
497 if (item.second != sle)
498 LogicError(
"ApplyStateTable::update: unknown SLE");
502 LogicError(
"ApplyStateTable::update: erased");
555 auto miter = mods.
find(key);
556 if (miter != mods.
end())
558 assert(miter->second);
559 return miter->second;
566 auto const& item = iter->second;
572 JLOG(j.
warn()) <<
"Trying to thread to deleted node";
588 JLOG(j.
warn()) <<
"ApplyStateTable::getForMod: key not found";
591 auto sle = std::make_shared<SLE>(*c);
610 JLOG(j.
warn()) <<
"Threading to non-existent account: " <<
toBase58(to);
638 if (
auto const optSleAcct{(*sle)[~
sfAccount]})
639 threadTx(base, meta, *optSleAcct, mods, j);
649 threadTx(base, meta, *optSleDest, mods, j);
const SF_UINT32 sfPreviousTxnLgrSeq
std::size_t txCount() const
Return the number of tx inserted since creation.
A pair of SHAMap key and LedgerEntryType.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Stream trace() const
Severity stream access functions.
const SF_ACCOUNT sfDestination
void insert(ReadView const &base, std::shared_ptr< SLE > const &sle)
Writable ledger view that accumulates state and tx changes.
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
virtual void rawDestroyXRP(XRPAmount const &fee)=0
Destroy XRP.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
const SField sfFinalFields
bool exists(ReadView const &base, Keylet const &k) const
@ ltCHECK
A ledger object which describes a check.
static void threadItem(TxMeta &meta, std::shared_ptr< SLE > const &to)
virtual void rawReplace(std::shared_ptr< SLE > const &sle)=0
Unconditionally replace a state item.
const SField sfDeletedNode
void destroyXRP(XRPAmount const &fee)
XRPAmount dropsDestroyed_
void replace(ReadView const &base, std::shared_ptr< SLE > const &sle)
virtual void rawErase(std::shared_ptr< SLE > const &sle)=0
Delete an existing state item.
const SF_AMOUNT sfLowLimit
Interface for ledger entry changes.
T emplace_hint(T... args)
void apply(RawView &to) const
Keylet account(AccountID const &id) noexcept
AccountID root.
void threadOwners(ReadView const &base, TxMeta &meta, std::shared_ptr< SLE const > const &sle, Mods &mods, beast::Journal j)
virtual void rawInsert(std::shared_ptr< SLE > const &sle)=0
Unconditionally insert a state item.
const uint256 fixCheckThreading
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.
const SField sfModifiedNode
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
void erase(ReadView const &base, std::shared_ptr< SLE > const &sle)
void threadTx(ReadView const &base, TxMeta &meta, AccountID const &to, Mods &mods, beast::Journal j)
A generic endpoint for log messages.
const SF_UINT256 sfPreviousTxnID
const SF_AMOUNT sfHighLimit
T forward_as_tuple(T... args)
Keylet unchecked(uint256 const &key) noexcept
Any ledger entry.
std::shared_ptr< SLE const > read(ReadView const &base, Keylet const &k) const
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
void rawErase(ReadView const &base, std::shared_ptr< SLE > const &sle)
uint256 getTransactionID() const
const SField sfPreviousFields
std::shared_ptr< SLE > getForMod(ReadView const &base, key_type const &key, Mods &mods, beast::Journal j)
std::size_t emplace_back(Args &&... args)
void add(Serializer &s) const override
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
const SF_UINT16 sfLedgerEntryType
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.
LedgerEntryType
Identifiers for on-ledger objects.
LedgerIndex seq() const
Returns the sequence number of the base ledger.
virtual Rules const & rules() const =0
Returns the tx processing rules.
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
@ ltACCOUNT_ROOT
A ledger object which describes an account.
const SField sfCreatedNode
void update(ReadView const &base, std::shared_ptr< SLE > const &sle)
std::optional< key_type > succ(ReadView const &base, key_type const &key, std::optional< key_type > const &last) const
std::shared_ptr< SLE const > read(Keylet const &k) const override
Return the state item associated with a key.
static bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
bool check(STLedgerEntry const &) const
Returns true if the SLE matches the type.
const SF_ACCOUNT sfAccount
@ ltRIPPLE_STATE
A ledger object which describes a bidirectional trust line.
std::shared_ptr< SLE > peek(ReadView const &base, Keylet const &k)