Skip to content

Commit 472e3e6

Browse files
authored
Disk read resource (#4733)
# Description Adds support for p23 disk read resource in `checkValid`. Also changes `Resource` to use disk read entries in p23. # Checklist - [x] Reviewed the [contributing](https://github.com/stellar/stellar-core/blob/master/CONTRIBUTING.md#submitting-changes) document - [x] Rebased on top of master (no merge commits) - [x] Ran `clang-format` v8.0.0 (via `make format` or the Visual Studio extension) - [x] Compiles - [ ] Ran all tests - [ ] If change impacts performance, include supporting evidence per the [performance document](https://github.com/stellar/stellar-core/blob/master/performance-eval/performance-eval.md)
2 parents 88cd5b9 + 0abae9a commit 472e3e6

File tree

53 files changed

+5009
-4465
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+5009
-4465
lines changed

src/herder/ParallelTxSetBuilder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ buildSurgePricedParallelSorobanPhase(
348348
TxFrameList const& txFrames, Config const& cfg,
349349
SorobanNetworkConfig const& sorobanCfg,
350350
std::shared_ptr<SurgePricingLaneConfig> laneConfig,
351-
std::vector<bool>& hadTxNotFittingLane)
351+
std::vector<bool>& hadTxNotFittingLane, uint32_t ledgerVersion)
352352
{
353353
ZoneScoped;
354354
// Simplify the transactions to the minimum necessary amount of data.
@@ -431,7 +431,7 @@ buildSurgePricedParallelSorobanPhase(
431431
stellar::rand_uniform<size_t>(0, std::numeric_limits<size_t>::max()));
432432
for (auto const& tx : txFrames)
433433
{
434-
queue.add(tx);
434+
queue.add(tx, ledgerVersion);
435435
}
436436

437437
ParallelPartitionConfig partitionCfg(cfg, sorobanCfg);
@@ -466,7 +466,7 @@ buildSurgePricedParallelSorobanPhase(
466466

467467
std::vector<Resource> laneLeftUntilLimitUnused;
468468
queue.popTopTxs(/* allowGaps */ true, visitor, laneLeftUntilLimitUnused,
469-
hadTxNotFittingLane);
469+
hadTxNotFittingLane, ledgerVersion);
470470
// There is only a single fee lane for Soroban, so there is only a single
471471
// flag that indicates whether there was a transaction that didn't fit into
472472
// lane (and thus all transactions are surge priced at once).

src/herder/ParallelTxSetBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ TxStageFrameList buildSurgePricedParallelSorobanPhase(
2424
TxFrameList const& txFrames, Config const& cfg,
2525
SorobanNetworkConfig const& sorobanCfg,
2626
std::shared_ptr<SurgePricingLaneConfig> laneConfig,
27-
std::vector<bool>& hadTxNotFittingLane);
27+
std::vector<bool>& hadTxNotFittingLane, uint32_t ledgerVersion);
2828

2929
} // namespace stellar

src/herder/SurgePricingUtils.cpp

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ std::vector<TransactionFrameBasePtr>
150150
SurgePricingPriorityQueue::getMostTopTxsWithinLimits(
151151
std::vector<TransactionFrameBasePtr> const& txs,
152152
std::shared_ptr<SurgePricingLaneConfig> laneConfig,
153-
std::vector<bool>& hadTxNotFittingLane)
153+
std::vector<bool>& hadTxNotFittingLane, uint32_t ledgerVersion)
154154
{
155155
ZoneScoped;
156156

@@ -159,7 +159,7 @@ SurgePricingPriorityQueue::getMostTopTxsWithinLimits(
159159
stellar::rand_uniform<size_t>(0, std::numeric_limits<size_t>::max()));
160160
for (auto const& tx : txs)
161161
{
162-
queue.add(tx);
162+
queue.add(tx, ledgerVersion);
163163
}
164164
std::vector<TransactionFrameBasePtr> outTxs;
165165
auto visitor = [&outTxs](TransactionFrameBasePtr const& tx) {
@@ -168,63 +168,67 @@ SurgePricingPriorityQueue::getMostTopTxsWithinLimits(
168168
};
169169
std::vector<Resource> laneLeftUntilLimit;
170170
queue.popTopTxs(/* allowGaps */ true, visitor, laneLeftUntilLimit,
171-
hadTxNotFittingLane);
171+
hadTxNotFittingLane, ledgerVersion);
172172
return outTxs;
173173
}
174174

175175
void
176176
SurgePricingPriorityQueue::visitTopTxs(
177177
std::vector<TransactionFrameBasePtr> const& txs,
178178
std::function<VisitTxResult(TransactionFrameBasePtr const&)> const& visitor,
179-
std::vector<Resource>& laneLeftUntilLimit)
179+
std::vector<Resource>& laneLeftUntilLimit, uint32_t ledgerVersion)
180180
{
181181
ZoneScoped;
182182

183183
for (auto const& tx : txs)
184184
{
185-
add(tx);
185+
add(tx, ledgerVersion);
186186
}
187187
std::vector<bool> hadTxNotFittingLane;
188188
popTopTxs(/* allowGaps */ false, visitor, laneLeftUntilLimit,
189-
hadTxNotFittingLane);
189+
hadTxNotFittingLane, ledgerVersion);
190190
}
191191

192192
void
193-
SurgePricingPriorityQueue::add(TransactionFrameBasePtr tx)
193+
SurgePricingPriorityQueue::add(TransactionFrameBasePtr tx,
194+
uint32_t ledgerVersion)
194195
{
195196
releaseAssert(tx != nullptr);
196197
auto lane = mLaneConfig->getLane(*tx);
197198
bool inserted = mTxSortedSets[lane].insert(tx).second;
198199
if (inserted)
199200
{
200-
mLaneCurrentCount[lane] += mLaneConfig->getTxResources(*tx);
201+
mLaneCurrentCount[lane] +=
202+
mLaneConfig->getTxResources(*tx, ledgerVersion);
201203
}
202204
}
203205

204206
void
205-
SurgePricingPriorityQueue::erase(TransactionFrameBasePtr tx)
207+
SurgePricingPriorityQueue::erase(TransactionFrameBasePtr tx,
208+
uint32_t ledgerVersion)
206209
{
207210
releaseAssert(tx != nullptr);
208211
auto lane = mLaneConfig->getLane(*tx);
209212
auto it = mTxSortedSets[lane].find(tx);
210213
if (it != mTxSortedSets[lane].end())
211214
{
212-
erase(lane, it);
215+
erase(lane, it, ledgerVersion);
213216
}
214217
}
215218

216219
void
217-
SurgePricingPriorityQueue::erase(Iterator const& it)
220+
SurgePricingPriorityQueue::erase(Iterator const& it, uint32_t ledgerVersion)
218221
{
219222
auto innerIt = it.getInnerIter();
220-
erase(innerIt.first, innerIt.second);
223+
erase(innerIt.first, innerIt.second, ledgerVersion);
221224
}
222225

223226
void
224227
SurgePricingPriorityQueue::erase(
225-
size_t lane, SurgePricingPriorityQueue::TxSortedSet::iterator iter)
228+
size_t lane, SurgePricingPriorityQueue::TxSortedSet::iterator iter,
229+
uint32_t ledgerVersion)
226230
{
227-
auto res = mLaneConfig->getTxResources(*(*iter));
231+
auto res = mLaneConfig->getTxResources(*(*iter), ledgerVersion);
228232
releaseAssert(res <= mLaneCurrentCount[lane]);
229233
mLaneCurrentCount[lane] -= res;
230234
mTxSortedSets[lane].erase(iter);
@@ -235,7 +239,7 @@ SurgePricingPriorityQueue::popTopTxs(
235239
bool allowGaps,
236240
std::function<VisitTxResult(TransactionFrameBasePtr const&)> const& visitor,
237241
std::vector<Resource>& laneLeftUntilLimit,
238-
std::vector<bool>& hadTxNotFittingLane)
242+
std::vector<bool>& hadTxNotFittingLane, uint32_t ledgerVersion)
239243
{
240244
ZoneScoped;
241245

@@ -251,7 +255,7 @@ SurgePricingPriorityQueue::popTopTxs(
251255
while (!currIt.isEnd())
252256
{
253257
auto const& currTx = *(*currIt);
254-
auto curr = mLaneConfig->getTxResources(currTx);
258+
auto curr = mLaneConfig->getTxResources(currTx, ledgerVersion);
255259
auto lane = mLaneConfig->getLane(currTx);
256260
if (anyGreater(curr, laneLeftUntilLimit[lane]) ||
257261
anyGreater(curr, laneLeftUntilLimit[GENERIC_LANE]))
@@ -261,7 +265,7 @@ SurgePricingPriorityQueue::popTopTxs(
261265
// If gaps are allowed we just erase the iterator and
262266
// continue in the main loop.
263267
gapSkipped = true;
264-
erase(currIt);
268+
erase(currIt, ledgerVersion);
265269
if (anyGreater(curr, laneLeftUntilLimit[lane]))
266270
{
267271
hadTxNotFittingLane[lane] = true;
@@ -311,7 +315,7 @@ SurgePricingPriorityQueue::popTopTxs(
311315
// we can visit it and remove it from the queue.
312316
auto const& tx = *currIt;
313317
auto visitRes = visitor(tx);
314-
auto res = mLaneConfig->getTxResources(*tx);
318+
auto res = mLaneConfig->getTxResources(*tx, ledgerVersion);
315319
auto lane = mLaneConfig->getLane(*tx);
316320
// Only account for resource counts when transaction was actually
317321
// processed by the visitor.
@@ -333,22 +337,23 @@ SurgePricingPriorityQueue::popTopTxs(
333337
hadTxNotFittingLane[GENERIC_LANE] = true;
334338
hadTxNotFittingLane[lane] = true;
335339
}
336-
erase(currIt);
340+
erase(currIt, ledgerVersion);
337341
}
338342
}
339343

340344
std::pair<bool, int64_t>
341345
SurgePricingPriorityQueue::canFitWithEviction(
342346
TransactionFrameBase const& tx, std::optional<Resource> txDiscount,
343-
std::vector<std::pair<TransactionFrameBasePtr, bool>>& txsToEvict) const
347+
std::vector<std::pair<TransactionFrameBasePtr, bool>>& txsToEvict,
348+
uint32_t ledgerVersion) const
344349
{
345350
ZoneScoped;
346351

347352
// This only makes sense when the lowest fee rate tx is on top.
348353
releaseAssert(!mComparator.isGreater());
349354

350355
auto lane = mLaneConfig->getLane(tx);
351-
auto txNewResources = mLaneConfig->getTxResources(tx);
356+
auto txNewResources = mLaneConfig->getTxResources(tx, ledgerVersion);
352357
if (txDiscount)
353358
{
354359
txNewResources = subtractNonNegative(txNewResources, *txDiscount);
@@ -442,7 +447,7 @@ SurgePricingPriorityQueue::canFitWithEviction(
442447
// the transaction by evicting some transactions.
443448
releaseAssert(!iter.isEnd());
444449
auto const& evictTx = *(*iter);
445-
auto evict = mLaneConfig->getTxResources(evictTx);
450+
auto evict = mLaneConfig->getTxResources(evictTx, ledgerVersion);
446451
auto evictLane = mLaneConfig->getLane(evictTx);
447452

448453
// Evicted tx must have a strictly lower fee than the new tx.
@@ -596,10 +601,11 @@ DexLimitingLaneConfig::updateGenericLaneLimit(Resource const& limit)
596601
}
597602

598603
Resource
599-
DexLimitingLaneConfig::getTxResources(TransactionFrameBase const& tx)
604+
DexLimitingLaneConfig::getTxResources(TransactionFrameBase const& tx,
605+
uint32_t ledgerVersion)
600606
{
601607
releaseAssert(!tx.isSoroban());
602-
return tx.getResources(mUseByteLimit);
608+
return tx.getResources(mUseByteLimit, ledgerVersion);
603609
}
604610

605611
size_t
@@ -645,9 +651,10 @@ SorobanGenericLaneConfig::updateGenericLaneLimit(Resource const& limit)
645651
}
646652

647653
Resource
648-
SorobanGenericLaneConfig::getTxResources(TransactionFrameBase const& tx)
654+
SorobanGenericLaneConfig::getTxResources(TransactionFrameBase const& tx,
655+
uint32_t ledgerVersion)
649656
{
650657
releaseAssert(tx.isSoroban());
651-
return tx.getResources(/* useByteLimitInClassic */ false);
658+
return tx.getResources(/* useByteLimitInClassic */ false, ledgerVersion);
652659
}
653660
} // namespace stellar

src/herder/SurgePricingUtils.h

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ class SurgePricingLaneConfig
5555
// configuration).
5656
virtual void updateGenericLaneLimit(Resource const& limit) = 0;
5757

58-
virtual Resource getTxResources(TransactionFrameBase const& tx) = 0;
58+
virtual Resource getTxResources(TransactionFrameBase const& tx,
59+
uint32_t ledgerVersion) = 0;
5960

6061
virtual ~SurgePricingLaneConfig() = default;
6162
};
@@ -76,7 +77,8 @@ class DexLimitingLaneConfig : public SurgePricingLaneConfig
7677
size_t getLane(TransactionFrameBase const& tx) const override;
7778
std::vector<Resource> const& getLaneLimits() const override;
7879
virtual void updateGenericLaneLimit(Resource const& limit) override;
79-
virtual Resource getTxResources(TransactionFrameBase const& tx) override;
80+
virtual Resource getTxResources(TransactionFrameBase const& tx,
81+
uint32_t ledgerVersion) override;
8082

8183
private:
8284
std::vector<Resource> mLaneLimits;
@@ -91,7 +93,8 @@ class SorobanGenericLaneConfig : public SurgePricingLaneConfig
9193
size_t getLane(TransactionFrameBase const& tx) const override;
9294
std::vector<Resource> const& getLaneLimits() const override;
9395
virtual void updateGenericLaneLimit(Resource const& limit) override;
94-
virtual Resource getTxResources(TransactionFrameBase const& tx) override;
96+
virtual Resource getTxResources(TransactionFrameBase const& tx,
97+
uint32_t ledgerVersion) override;
9598

9699
private:
97100
std::vector<Resource> mLaneLimits;
@@ -117,7 +120,7 @@ class SurgePricingPriorityQueue
117120
static std::vector<TransactionFrameBasePtr> getMostTopTxsWithinLimits(
118121
std::vector<TransactionFrameBasePtr> const& txs,
119122
std::shared_ptr<SurgePricingLaneConfig> laneConfig,
120-
std::vector<bool>& hadTxNotFittingLane);
123+
std::vector<bool>& hadTxNotFittingLane, uint32_t ledgerVersion);
121124

122125
// Returns total amount of resources in all the transactions in this queue.
123126
Resource totalResources() const;
@@ -154,7 +157,8 @@ class SurgePricingPriorityQueue
154157
std::vector<TransactionFrameBasePtr> const& txs,
155158
std::function<VisitTxResult(TransactionFrameBasePtr const&)> const&
156159
visitor,
157-
std::vector<Resource>& laneResourcesLeftUntilLimit);
160+
std::vector<Resource>& laneResourcesLeftUntilLimit,
161+
uint32_t ledgerVersion);
158162

159163
// Creates a `SurgePricingPriorityQueue` for the provided lane
160164
// configuration.
@@ -167,9 +171,9 @@ class SurgePricingPriorityQueue
167171
size_t comparisonSeed);
168172

169173
// Adds a transaction to this queue.
170-
void add(TransactionFrameBasePtr tx);
174+
void add(TransactionFrameBasePtr tx, uint32_t ledgerVersion);
171175
// Erases a transaction from this queue.
172-
void erase(TransactionFrameBasePtr tx);
176+
void erase(TransactionFrameBasePtr tx, uint32_t ledgerVersion);
173177

174178
// Checks whether a provided transaction could fit into this queue without
175179
// violating the `laneConfig` limits while evicting some lower fee rate
@@ -184,8 +188,8 @@ class SurgePricingPriorityQueue
184188
// limit (as opposed to 'generic' lane's limit).
185189
std::pair<bool, int64_t> canFitWithEviction(
186190
TransactionFrameBase const& tx, std::optional<Resource> txDiscount,
187-
std::vector<std::pair<TransactionFrameBasePtr, bool>>& txsToEvict)
188-
const;
191+
std::vector<std::pair<TransactionFrameBasePtr, bool>>& txsToEvict,
192+
uint32_t ledgerVersion) const;
189193

190194
// Generalized method for visiting and popping the top transactions in the
191195
// queue until the lane limits are reached.
@@ -196,7 +200,7 @@ class SurgePricingPriorityQueue
196200
std::function<VisitTxResult(TransactionFrameBasePtr const&)> const&
197201
visitor,
198202
std::vector<Resource>& laneResourcesLeftUntilLimit,
199-
std::vector<bool>& hadTxNotFittingLane);
203+
std::vector<bool>& hadTxNotFittingLane, uint32_t ledgerVersion);
200204

201205
private:
202206
class TxComparator
@@ -250,9 +254,10 @@ class SurgePricingPriorityQueue
250254
std::vector<LaneIter> mutable mIters;
251255
};
252256

253-
void erase(Iterator const& it);
257+
void erase(Iterator const& it, uint32_t ledgerVersion);
254258
void erase(size_t lane,
255-
SurgePricingPriorityQueue::TxSortedSet::iterator iter);
259+
SurgePricingPriorityQueue::TxSortedSet::iterator iter,
260+
uint32_t ledgerVersion);
256261

257262
Iterator getTop() const;
258263

0 commit comments

Comments
 (0)