Skip to content

Commit

Permalink
Pop all transactions with sequential sequences, or tickets
Browse files Browse the repository at this point in the history
  • Loading branch information
ximinez committed Apr 10, 2024
1 parent b30ca00 commit 8590d37
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/ripple/app/misc/CanonicalTXSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,22 @@ CanonicalTXSet::popAcctTransaction(std::shared_ptr<STTx const> const& tx)
// 1. Prioritize transactions with Sequences over transactions with
// Tickets.
//
// 2. Don't worry about consecutive Sequence numbers. Creating Tickets
// can introduce a discontinuity in Sequence numbers.
// 2. For transactions not using Tickets, look for consecutive Sequence
// numbers. For transactions using Tickets, don't worry about
// consecutive Sequence numbers. Tickets can process out of order.
//
// 3. After handling all transactions with Sequences, return Tickets
// with the lowest Ticket ID first.
std::shared_ptr<STTx const> result;
uint256 const effectiveAccount{accountKey(tx->getAccountID(sfAccount))};

Key const after(effectiveAccount, tx->getSeqProxy(), beast::zero);
auto const seqProxy = tx->getSeqProxy();
Key const after(effectiveAccount, seqProxy, beast::zero);
auto const itrNext{map_.lower_bound(after)};
if (itrNext != map_.end() &&
itrNext->first.getAccount() == effectiveAccount)
itrNext->first.getAccount() == effectiveAccount &&
(!itrNext->second->getSeqProxy().isSeq() ||
itrNext->second->getSeqProxy().value() == seqProxy.value() + 1))
{
result = std::move(itrNext->second);
map_.erase(itrNext);
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/app/misc/HashRouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace ripple {
// TODO convert these macros to int constants or an enum
#define SF_BAD 0x02 // Temporarily bad
#define SF_SAVED 0x04
#define SF_HELD 0x08 // Held by LedgerMaster after potential processing failure
#define SF_HELD 0x08 // Held by LedgerMaster after potential processing failure
#define SF_TRUSTED 0x10 // comes from trusted source

// Private flags, used internally in apply.cpp.
Expand Down
9 changes: 7 additions & 2 deletions src/ripple/app/misc/NetworkOPs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1401,15 +1401,20 @@ NetworkOPsImp::apply(std::unique_lock<std::mutex>& batchLock)
<< "Transaction is now included in open ledger";
e.transaction->setStatus(INCLUDED);

// Pop as many "reasonable" transactions for this account as
// possible. "Reasonable" means they have sequential sequence
// numbers, or use tickets.
auto const& txCur = e.transaction->getSTransaction();
auto const txNext = m_ledgerMaster.popAcctTransaction(txCur);
if (txNext)
auto txNext = m_ledgerMaster.popAcctTransaction(txCur);
while (txNext)
{
std::string reason;
auto const trans = sterilize(*txNext);
auto t = std::make_shared<Transaction>(trans, reason, app_);
submit_held.emplace_back(t, false, false, FailHard::no);
t->setApplying();

txNext = m_ledgerMaster.popAcctTransaction(trans);
}
}
else if (e.result == tefPAST_SEQ)
Expand Down

0 comments on commit 8590d37

Please sign in to comment.