xrpld
Loading...
Searching...
No Matches
tx/transactors/system/TicketCreate.h
1#pragma once
2
3#include <xrpl/beast/utility/Journal.h>
4#include <xrpl/core/ServiceRegistry.h>
5#include <xrpl/ledger/ReadView.h>
6#include <xrpl/protocol/STTx.h>
7#include <xrpl/protocol/TER.h>
8#include <xrpl/protocol/XRPAmount.h>
9#include <xrpl/tx/ApplyContext.h>
10#include <xrpl/tx/Transactor.h>
11
12#include <cstdint>
13
14namespace xrpl {
15
17{
18public:
20
21 static constexpr std::uint32_t kMinValidCount = 1;
22
23 // A note on how the maxValidCount was determined. The goal is for
24 // a single TicketCreate transaction to not use more compute power than
25 // a single compute-intensive Payment.
26 //
27 // Timing was performed using a MacBook Pro laptop and a release build
28 // with asserts off. 20 measurements were taken of each of the Payment
29 // and TicketCreate transactions and averaged to get timings.
30 //
31 // For the example compute-intensive Payment a Discrepancy unit test
32 // unit test Payment with 3 paths was chosen. With all the latest
33 // amendments enabled, that Payment::doApply() operation took, on
34 // average, 1.25 ms.
35 //
36 // Using that same test set up creating 250 Tickets in a single
37 // TicketCreate::doApply() in a unit test took, on average, 1.21 ms.
38 //
39 // So, for the moment, a single transaction creating 250 Tickets takes
40 // about the same compute time as a single compute-intensive payment.
41 //
42 // October 2018.
43 static constexpr std::uint32_t kMaxValidCount = 250;
44
45 // The maximum number of Tickets an account may hold. If a
46 // TicketCreate would cause an account to own more than this many
47 // tickets, then the TicketCreate will fail.
48 //
49 // The number was chosen arbitrarily and is an effort toward avoiding
50 // ledger-stuffing with Tickets.
51 static constexpr std::uint32_t kMaxTicketThreshold = 250;
52
53 explicit TicketCreate(ApplyContext& ctx) : Transactor(ctx)
54 {
55 }
56
57 static TxConsequences
59
63 static NotTEC
64 preflight(PreflightContext const& ctx);
65
69 static TER
70 preclaim(PreclaimContext const& ctx);
71
75 TER
76 doApply() override;
77
78 void
79 visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override;
80
81 [[nodiscard]] bool
83 STTx const& tx,
84 TER result,
85 XRPAmount fee,
86 ReadView const& view,
87 beast::Journal const& j) override;
88};
89
90} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
State information when applying a tx.
A view into a ledger.
Definition ReadView.h:41
std::shared_ptr< STLedgerEntry const > const & const_ref
void visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override
Inspect a single ledger entry modified by this transaction.
static constexpr std::uint32_t kMinValidCount
static NotTEC preflight(PreflightContext const &ctx)
Enforce constraints beyond those of the Transactor base class.
static constexpr std::uint32_t kMaxTicketThreshold
TER doApply() override
Precondition: fee collection is likely.
static TER preclaim(PreclaimContext const &ctx)
Enforce constraints beyond those of the Transactor base class.
bool finalizeInvariants(STTx const &tx, TER result, XRPAmount fee, ReadView const &view, beast::Journal const &j) override
Check transaction-specific post-conditions after all entries have been visited.
static constexpr auto kConsequencesFactory
static TxConsequences makeTxConsequences(PreflightContext const &ctx)
static constexpr std::uint32_t kMaxValidCount
ApplyView & view()
Definition Transactor.h:175
Transactor(Transactor const &)=delete
Class describing the consequences to the account of applying a transaction if the transaction consume...
Definition applySteps.h:52
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:607
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition View.cpp:572
TERSubset< CanCvtToTER > TER
Definition TER.h:647
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:83
State information when preflighting a tx.
Definition Transactor.h:38