rippled
Loading...
Searching...
No Matches
OpenView.cpp
1#include <xrpl/basics/contract.h>
2#include <xrpl/ledger/OpenView.h>
3
4namespace ripple {
5
6class OpenView::txs_iter_impl : public txs_type::iter_base
7{
8private:
10 txs_map::const_iterator iter_;
11
12public:
13 explicit txs_iter_impl(bool metadata, txs_map::const_iterator iter)
14 : metadata_(metadata), iter_(iter)
15 {
16 }
17
19 copy() const override
20 {
22 }
23
24 bool
25 equal(base_type const& impl) const override
26 {
27 if (auto const p = dynamic_cast<txs_iter_impl const*>(&impl))
28 return iter_ == p->iter_;
29 return false;
30 }
31
32 void
33 increment() override
34 {
35 ++iter_;
36 }
37
38 value_type
39 dereference() const override
40 {
41 value_type result;
42 {
43 SerialIter sit(iter_->second.txn->slice());
44 result.first = std::make_shared<STTx const>(sit);
45 }
46 if (metadata_)
47 {
48 SerialIter sit(iter_->second.meta->slice());
49 result.second = std::make_shared<STObject const>(sit, sfMetadata);
50 }
51 return result;
52 }
53};
54
55//------------------------------------------------------------------------------
56
58 : ReadView(rhs)
59 , TxsRawView(rhs)
60 , monotonic_resource_{std::make_unique<
61 boost::container::pmr::monotonic_buffer_resource>(initialBufferSize)}
62 , txs_{rhs.txs_, monotonic_resource_.get()}
63 , rules_{rhs.rules_}
64 , info_{rhs.info_}
65 , base_{rhs.base_}
66 , items_{rhs.items_}
67 , hold_{rhs.hold_}
68 , open_{rhs.open_} {};
69
72 ReadView const* base,
73 Rules const& rules,
75 : monotonic_resource_{std::make_unique<
76 boost::container::pmr::monotonic_buffer_resource>(initialBufferSize)}
77 , txs_{monotonic_resource_.get()}
78 , rules_(rules)
79 , info_(base->info())
80 , base_(base)
81 , hold_(std::move(hold))
82{
83 info_.validated = false;
84 info_.accepted = false;
85 info_.seq = base_->info().seq + 1;
88}
89
91 : monotonic_resource_{std::make_unique<
92 boost::container::pmr::monotonic_buffer_resource>(initialBufferSize)}
93 , txs_{monotonic_resource_.get()}
94 , rules_(base->rules())
95 , info_(base->info())
96 , base_(base)
97 , hold_(std::move(hold))
98 , open_(base->open())
99{
100}
101
104{
105 return baseTxCount_ + txs_.size();
106}
107
108void
110{
111 items_.apply(to);
112 for (auto const& item : txs_)
113 to.rawTxInsert(item.first, item.second.txn, item.second.meta);
114}
115
116//---
117
118LedgerInfo const&
120{
121 return info_;
122}
123
124Fees const&
126{
127 return base_->fees();
128}
129
130Rules const&
132{
133 return rules_;
134}
135
136bool
138{
139 return items_.exists(*base_, k);
140}
141
142auto
143OpenView::succ(key_type const& key, std::optional<key_type> const& last) const
145{
146 return items_.succ(*base_, key, last);
147}
148
150OpenView::read(Keylet const& k) const
151{
152 return items_.read(*base_, k);
153}
154
155auto
156OpenView::slesBegin() const -> std::unique_ptr<sles_type::iter_base>
157{
158 return items_.slesBegin(*base_);
159}
160
161auto
162OpenView::slesEnd() const -> std::unique_ptr<sles_type::iter_base>
163{
164 return items_.slesEnd(*base_);
165}
166
167auto
170{
171 return items_.slesUpperBound(*base_, key);
172}
173
174auto
175OpenView::txsBegin() const -> std::unique_ptr<txs_type::iter_base>
176{
178}
179
180auto
181OpenView::txsEnd() const -> std::unique_ptr<txs_type::iter_base>
182{
184}
185
186bool
188{
189 return txs_.find(key) != txs_.end();
190}
191
192auto
194{
195 auto const iter = txs_.find(key);
196 if (iter == txs_.end())
197 return base_->txRead(key);
198 auto const& item = iter->second;
199 auto stx = std::make_shared<STTx const>(SerialIter{item.txn->slice()});
200 decltype(tx_type::second) sto;
201 if (item.meta)
203 SerialIter{item.meta->slice()}, sfMetadata);
204 else
205 sto = nullptr;
206 return {std::move(stx), std::move(sto)};
207}
208
209//---
210
211void
213{
214 items_.erase(sle);
215}
216
217void
222
223void
228
229void
231{
232 items_.destroyXRP(fee);
233 // VFALCO Deduct from info_.totalDrops ?
234 // What about child views?
235}
236
237//---
238
239void
241 key_type const& key,
243 std::shared_ptr<Serializer const> const& metaData)
244{
245 auto const result = txs_.emplace(
248 std::forward_as_tuple(txn, metaData));
249 if (!result.second)
250 LogicError("rawTxInsert: duplicate TX id: " + to_string(key));
251}
252
253} // namespace ripple
T cbegin(T... args)
std::unique_ptr< base_type > copy() const override
Definition OpenView.cpp:19
txs_iter_impl(bool metadata, txs_map::const_iterator iter)
Definition OpenView.cpp:13
bool equal(base_type const &impl) const override
Definition OpenView.cpp:25
value_type dereference() const override
Definition OpenView.cpp:39
txs_map::const_iterator iter_
Definition OpenView.cpp:10
Writable ledger view that accumulates state and tx changes.
Definition OpenView.h:46
std::size_t txCount() const
Return the number of tx inserted since creation.
Definition OpenView.cpp:103
std::unique_ptr< sles_type::iter_base > slesUpperBound(uint256 const &key) const override
Definition OpenView.cpp:168
tx_type txRead(key_type const &key) const override
Read a transaction from the tx map.
Definition OpenView.cpp:193
bool txExists(key_type const &key) const override
Returns true if a tx exists in the tx map.
Definition OpenView.cpp:187
ReadView const * base_
Definition OpenView.h:86
LedgerInfo const & info() const override
Returns information about the ledger.
Definition OpenView.cpp:119
std::unique_ptr< sles_type::iter_base > slesEnd() const override
Definition OpenView.cpp:162
detail::RawStateTable items_
Definition OpenView.h:87
std::optional< key_type > succ(key_type const &key, std::optional< key_type > const &last=std::nullopt) const override
Return the key of the next state item.
Definition OpenView.cpp:143
LedgerInfo info_
Definition OpenView.h:85
void rawDestroyXRP(XRPAmount const &fee) override
Destroy XRP.
Definition OpenView.cpp:230
bool exists(Keylet const &k) const override
Determine if a state item exists.
Definition OpenView.cpp:137
Rules const & rules() const override
Returns the tx processing rules.
Definition OpenView.cpp:131
std::shared_ptr< SLE const > read(Keylet const &k) const override
Return the state item associated with a key.
Definition OpenView.cpp:150
std::unique_ptr< sles_type::iter_base > slesBegin() const override
Definition OpenView.cpp:156
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.
Definition OpenView.cpp:240
void rawErase(std::shared_ptr< SLE > const &sle) override
Delete an existing state item.
Definition OpenView.cpp:212
std::size_t baseTxCount_
In batch mode, the number of transactions already executed.
Definition OpenView.h:91
void rawReplace(std::shared_ptr< SLE > const &sle) override
Unconditionally replace a state item.
Definition OpenView.cpp:224
void rawInsert(std::shared_ptr< SLE > const &sle) override
Unconditionally insert a state item.
Definition OpenView.cpp:218
bool open() const override
Returns true if this reflects an open ledger.
Definition OpenView.h:172
std::unique_ptr< txs_type::iter_base > txsBegin() const override
Definition OpenView.cpp:175
Fees const & fees() const override
Returns the fees for the base ledger.
Definition OpenView.cpp:125
void apply(TxsRawView &to) const
Apply changes.
Definition OpenView.cpp:109
std::unique_ptr< txs_type::iter_base > txsEnd() const override
Definition OpenView.cpp:181
A view into a ledger.
Definition ReadView.h:32
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
virtual LedgerInfo const & info() const =0
Returns information about the ledger.
Rules controlling protocol behavior.
Definition Rules.h:19
Interface for changing ledger entries with transactions.
Definition RawView.h:76
virtual void rawTxInsert(ReadView::key_type const &key, std::shared_ptr< Serializer const > const &txn, std::shared_ptr< Serializer const > const &metaData)=0
Add a transaction to the tx map.
void destroyXRP(XRPAmount const &fee)
bool exists(ReadView const &base, Keylet const &k) const
void apply(RawView &to) const
void insert(std::shared_ptr< SLE > const &sle)
void erase(std::shared_ptr< SLE > const &sle)
std::shared_ptr< SLE const > read(ReadView const &base, Keylet const &k) const
std::unique_ptr< ReadView::sles_type::iter_base > slesBegin(ReadView const &base) const
void replace(std::shared_ptr< SLE > const &sle)
std::unique_ptr< ReadView::sles_type::iter_base > slesEnd(ReadView const &base) const
T emplace(T... args)
T cend(T... args)
T find(T... args)
T forward_as_tuple(T... args)
T is_same_v
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
@ open
We haven't closed our ledger yet, but others might have.
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:611
T get(Section const &section, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
STL namespace.
T piecewise_construct
T size(T... args)
Reflects the fee settings for a particular ledger.
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:20
Information about the notional ledger backing the view.
NetClock::time_point closeTime
NetClock::time_point parentCloseTime
Open ledger construction tag.
Definition OpenView.h:25