20 #include <ripple/ledger/detail/ApplyStateTable.h>
21 #include <ripple/basics/Log.h>
22 #include <ripple/json/to_string.h>
23 #include <ripple/protocol/Feature.h>
24 #include <ripple/protocol/st.h>
34 for (
auto const& item :
items_)
38 switch(item.second.first)
61 switch (item.second.first)
84 switch (item.second.first)
87 func (item.first,
true,
92 func (item.first,
false,
93 nullptr, item.second.second);
97 func (item.first,
false,
110 boost::optional<STAmount>
const& deliver,
115 std::make_shared<Serializer>();
129 switch (item.second.first)
144 auto const origNode =
146 auto curNode = item.second.second;
155 assert (origNode && curNode);
159 for (
auto const& obj : *origNode)
163 if (obj.getFName().shouldMeta(
165 ! curNode->hasMatchingEntry (obj))
173 for (
auto const& obj : *curNode)
176 if (obj.getFName().shouldMeta(
181 if (!finals.
empty ())
186 assert (curNode && origNode);
188 if (curNode->isThreadedType ())
192 for (
auto const& obj : *origNode)
203 for (
auto const& obj : *curNode)
210 if (!finals.
empty ())
215 assert (curNode && !origNode);
218 if (curNode->isThreadedType ())
222 for (
auto const& obj : *curNode)
225 if (!obj.isDefault () &&
226 obj.getFName().shouldMeta(
241 for (
auto& mod : newMod)
244 sMeta = std::make_shared<Serializer>();
267 auto const& item = iter->second;
268 auto const& sle = item.second;
285 key_type const& key, boost::optional<
287 boost::optional<key_type>
289 boost::optional<key_type> next = key;
290 items_t::const_iterator iter;
295 next = base.succ(*next, last);
298 iter = items_.find(*next);
300 while (iter != items_.end() &&
301 iter->second.first == Action::erase);
303 for (iter = items_.upper_bound(key);
304 iter != items_.end (); ++iter)
306 if (iter->second.first != Action::erase)
309 if (! next || next > iter->first)
316 if (last && next >= last)
328 auto const& item = iter->second;
329 auto const& sle = item.second;
350 iter->first != k.
key)
352 auto const sle = base.
read(k);
361 make_shared<SLE>(*sle)));
362 return iter->second.second;
364 auto const& item = iter->second;
365 auto const& sle = item.second;
388 LogicError(
"ApplyStateTable::erase: missing key");
389 auto& item = iter->second;
390 if (item.second != sle)
391 LogicError(
"ApplyStateTable::erase: unknown SLE");
395 LogicError(
"ApplyStateTable::erase: double erase");
418 auto& item = result.first->second;
422 LogicError(
"ApplyStateTable::rawErase: double erase");
442 iter->first != sle->key())
451 auto& item = iter->second;
455 LogicError(
"ApplyStateTable::insert: already cached");
457 LogicError(
"ApplyStateTable::insert: already inserted");
459 LogicError(
"ApplyStateTable::insert: already modified");
474 iter->first != sle->key())
482 auto& item = iter->second;
486 LogicError(
"ApplyStateTable::replace: already erased");
504 LogicError(
"ApplyStateTable::update: missing key");
505 auto& item = iter->second;
506 if (item.second != sle)
507 LogicError(
"ApplyStateTable::update: unknown SLE");
511 LogicError(
"ApplyStateTable::update: erased");
537 if (! sle->thread(meta.
getTxID(),
551 auto miter = mods.
find (key);
552 if (miter != mods.
end ())
554 assert (miter->second);
555 return miter->second;
562 auto const& item = iter->second;
568 JLOG(j.
warn()) <<
"Trying to thread to deleted node";
584 JLOG(j.
warn()) <<
"ApplyStateTable::getForMod: key not found";
587 auto sle = std::make_shared<SLE> (*c);
604 JLOG(j.
warn()) <<
"Threading to non-existent account: " <<
toBase58(to);
613 SLE const>
const& sle,
Mods& mods,
633 if (
auto const optSleAcct {(*sle)[~
sfAccount]})
634 threadTx (base, meta, *optSleAcct, mods, j);
642 threadTx (base, meta, *optSleDest, mods, j);
std::size_t txCount() const
Return the number of tx inserted since creation.
A pair of SHAMap key and LedgerEntryType.
const SField sfPreviousFields(access, STI_OBJECT, 6, "PreviousFields")
Stream trace() const
Severity stream access functions.
const SF_U16 sfLedgerEntryType(access, STI_UINT16, 1, "LedgerEntryType", SField::sMD_Never)
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.
const SF_Account sfAccount(access, STI_ACCOUNT, 1, "Account")
const SField sfNewFields(access, STI_OBJECT, 8, "NewFields")
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
bool exists(ReadView const &base, Keylet const &k) const
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 sfFinalFields(access, STI_OBJECT, 7, "FinalFields")
const SField sfModifiedNode(access, STI_OBJECT, 5, "ModifiedNode")
const SF_Amount sfHighLimit(access, STI_AMOUNT, 7, "HighLimit")
void destroyXRP(XRPAmount const &fee)
const SF_Amount sfLowLimit(access, STI_AMOUNT, 6, "LowLimit")
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.
Interface for ledger entry changes.
T emplace_hint(T... args)
void apply(RawView &to) const
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.
static const account_t account
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.
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.
bool enabled(uint256 const &id) const
Returns true if a feature is enabled.
T forward_as_tuple(T... args)
const SField sfCreatedNode(access, STI_OBJECT, 3, "CreatedNode")
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.
Keylet unchecked(uint256 const &key)
Any ledger entry.
void rawErase(ReadView const &base, std::shared_ptr< SLE > const &sle)
uint256 getTransactionID() const
std::shared_ptr< SLE > getForMod(ReadView const &base, key_type const &key, Mods &mods, beast::Journal j)
std::size_t emplace_back(Args &&... args)
boost::optional< key_type > succ(ReadView const &base, key_type const &key, boost::optional< key_type > const &last) const
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
virtual void add(Serializer &s) const override
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
Ledger entry types.
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.
void update(ReadView const &base, std::shared_ptr< SLE > const &sle)
std::shared_ptr< SLE const > read(Keylet const &k) const override
Return the state item associated with a key.
const SF_Account sfDestination(access, STI_ACCOUNT, 3, "Destination")
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 SField sfDeletedNode(access, STI_OBJECT, 4, "DeletedNode")
std::shared_ptr< SLE > peek(ReadView const &base, Keylet const &k)