xrpld
Loading...
Searching...
No Matches
MPTInvariant.h
1#pragma once
2
3#include <xrpl/basics/UnorderedContainers.h>
4#include <xrpl/basics/base_uint.h>
5#include <xrpl/beast/utility/Journal.h>
6#include <xrpl/ledger/ReadView.h>
7#include <xrpl/protocol/AccountID.h>
8#include <xrpl/protocol/STLedgerEntry.h>
9#include <xrpl/protocol/STTx.h>
10#include <xrpl/protocol/TER.h>
11#include <xrpl/protocol/UintTypes.h>
12#include <xrpl/protocol/XRPAmount.h>
13
14#include <array>
15#include <cstdint>
16#include <map>
17#include <memory>
18#include <optional>
19#include <vector>
20
21namespace xrpl {
22
24{
27
30 // non-MPT transactions may attempt to create
31 // MPToken by an issuer
32 bool mptCreatedByIssuer_ = false;
33
39
44
52
62
63public:
72 void
73 visitEntry(bool isDelete, SLE::ConstRef before, SLE::ConstRef after);
74
85 [[nodiscard]] bool
87 STTx const& tx,
88 TER const result,
89 XRPAmount const fee,
90 ReadView const& view,
91 beast::Journal const& j) const;
92};
93
102{
103 enum class Order { Before = 0, After = 1 };
104 struct MPTData
105 {
107 // sum (MPT after - MPT before)
109 };
110
111 // true if OutstandingAmount > MaximumAmount in after for any MPT
112 bool overflow_{false};
113 // mptid:MPTData
115
116public:
124 void
125 visitEntry(bool isDelete, SLE::ConstRef before, SLE::ConstRef after);
126
137 bool
138 finalize(
139 STTx const& tx,
140 TER const result,
141 XRPAmount const fee,
142 ReadView const& view,
143 beast::Journal const& j);
144};
145
169{
170 struct Changes
171 {
177 // True when an erased MPToken had a non-zero pre-tx public balance.
179 bool badConsistency = false;
180 bool badCOA = false;
182 bool badVersion = false;
183 };
185
186public:
194 void
196 bool isDelete,
197 std::shared_ptr<SLE const> const& before,
199
211 bool
212 finalize(
213 STTx const& tx,
214 TER const result,
215 XRPAmount const fee,
216 ReadView const& view,
217 beast::Journal const& j);
218};
219
221{
227 // MPTID: {holder: Value}
229 // Deleted MPToken
230 // MPToken key: true if MPTAuthorized is set
232 // Every touched AccountRoot (not only pseudos):
233 // AccountID -> whether it was a pseudo-account BEFORE this transaction
234 // applied. Needed because a transaction may erase a pseudo-account and
235 // move MPT out of it in the same transaction; by finalize() time the
236 // view no longer shows it as a pseudo-account (or as existing at all).
237 // False entries freeze the pre-tx classification for touched non-pseudos.
239
240public:
248 void
250 bool isDelete,
251 std::shared_ptr<SLE const> const& before,
253
264 bool
265 finalize(
266 STTx const& tx,
267 TER const result,
268 XRPAmount const fee,
269 ReadView const& view,
270 beast::Journal const& j);
271
272private:
288 [[nodiscard]] bool
290 ReadView const& view,
291 MPTID const& mptid,
292 AccountID const& holder,
293 bool requireAuth) const;
294};
295
296} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
A view into a ledger.
Definition ReadView.h:41
std::shared_ptr< STLedgerEntry const > const & ConstRef
std::shared_ptr< STLedgerEntry const > const_pointer
Invariants: Confidential MPToken consistency.
void visitEntry(bool isDelete, std::shared_ptr< SLE const > const &before, std::shared_ptr< SLE const > const &after)
Track confidential MPT balance, issuance, and version changes.
bool finalize(STTx const &tx, TER const result, XRPAmount const fee, ReadView const &view, beast::Journal const &j)
Verify confidential MPT accounting and encrypted-field invariants.
std::map< UInt192, Changes > changes_
Verify public MPT amount and outstanding amount accounting.
void visitEntry(bool isDelete, SLE::ConstRef before, SLE::ConstRef after)
Track MPT amount and outstanding amount changes.
HashMap< UInt192, MPTData > data_
bool finalize(STTx const &tx, TER const result, XRPAmount const fee, ReadView const &view, beast::Journal const &j)
Verify public MPT payment accounting invariants.
std::uint32_t mptokensCreated_
bool referenceHoldingSetOnCreate_
sfReferenceHolding is intended to be set exactly once at vault creation and immutable thereafter; tru...
std::uint32_t mptokensDeleted_
bool finalize(STTx const &tx, TER const result, XRPAmount const fee, ReadView const &view, beast::Journal const &j) const
Verify MPT issuance invariants after transaction application.
void visitEntry(bool isDelete, SLE::ConstRef before, SLE::ConstRef after)
Track MPT issuance and holding creations, deletions, and mutations.
bool referenceHoldingMutated_
True when sfReferenceHolding was mutated on an existing MPTokenIssuance.
std::uint32_t mptIssuancesCreated_
std::vector< std::shared_ptr< SLE const > > deletedHoldings_
MPTokens and RippleStates deleted during apply.
std::uint32_t issuanceFlagsCleared_
Flags cleared on an existing MPTokenIssuance, except lsfMPTLocked, which tfMPTUnlock clears legitimat...
std::uint32_t mptIssuancesDeleted_
HashMap< AccountID, bool > pseudoAccountsBefore_
bool isAuthorized(ReadView const &view, MPTID const &mptid, AccountID const &holder, bool requireAuth) const
Check whether a holder is authorized to send or receive an MPToken.
void visitEntry(bool isDelete, std::shared_ptr< SLE const > const &before, std::shared_ptr< SLE const > const &after)
Track MPT balance changes and deleted authorization state.
HashMap< UInt192, HashMap< AccountID, Value > > amount_
HashMap< UInt256, bool > deletedAuthorized_
bool finalize(STTx const &tx, TER const result, XRPAmount const fee, ReadView const &view, beast::Journal const &j)
Verify MPT transfer authorization invariants.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
BaseUInt< 192 > MPTID
MPTID is a 192-bit value representing MPT Issuance ID, which is a concatenation of a 32-bit sequence ...
Definition UintTypes.h:54
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition View.cpp:644
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
TERSubset< CanCvtToTER > TER
Definition TER.h:654
TER requireAuth(ReadView const &view, MPTIssue const &mptIssue, AccountID const &account, AuthType authType=AuthType::Legacy, std::uint8_t depth=0)
Check if the account lacks required authorization for MPT.
std::unordered_map< Key, Value, Hash, Pred, Allocator > HashMap
std::array< std::int64_t, 2 > outstanding
std::optional< std::uint64_t > amtAfter
std::optional< std::uint64_t > amtBefore