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