Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve transaction relay logic #4985

Open
wants to merge 77 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
c3805a7
Decrease `shouldRelay` limit to 30s:
ximinez Dec 21, 2023
36dddfa
Give a transaction more chances to be retried:
ximinez Jan 25, 2024
99a63a0
Pop all transactions with sequential sequences, or tickets
ximinez Jan 25, 2024
e048a41
Process held transactions through existing NetworkOPs batching:
ximinez Jan 25, 2024
3c0dbeb
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Apr 19, 2024
88c0074
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Apr 19, 2024
029d64c
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Apr 24, 2024
a1218af
Merge branch 'develop' into relay
ximinez Apr 26, 2024
f67f346
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Apr 26, 2024
3863b01
Merge remote-tracking branch 'upstream/develop' into relay
ximinez May 1, 2024
8b43ea8
Merge remote-tracking branch 'upstream/develop' into relay
ximinez May 7, 2024
23636d1
Merge commit 'c706926' into relay
ximinez Jul 2, 2024
7096d0a
Merge commit 'f6879da' into relay
ximinez Jul 2, 2024
643ca1a
Move CMake directory
Jul 2, 2024
f0170d3
Rearrange sources
Jul 2, 2024
8742e3b
Rewrite includes
Jul 2, 2024
e6f2597
Recompute loops
Jul 2, 2024
0f71e1c
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Jul 2, 2024
31a18f8
Fix formatting
ximinez Jul 2, 2024
58a5797
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Jul 5, 2024
05e4164
[FOLD] Review feedback from @scottschurr:
ximinez Jul 9, 2024
ff27e9e
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Jul 10, 2024
5d1ab36
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Jul 19, 2024
43d8ab1
fixup! [FOLD] Review feedback from @scottschurr:
ximinez Jul 21, 2024
c7e08bc
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Jul 24, 2024
3054f5a
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Jul 25, 2024
c9eed68
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Jul 29, 2024
3ac1a8a
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Aug 2, 2024
0940acd
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Aug 6, 2024
00e1945
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Aug 8, 2024
77138fc
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Aug 19, 2024
c2f600c
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Sep 5, 2024
29dbd50
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Sep 11, 2024
3d741e1
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Sep 11, 2024
fb0e201
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Sep 25, 2024
f982d93
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Oct 15, 2024
284399b
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Oct 18, 2024
03f9d0f
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Oct 31, 2024
31e982a
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Oct 31, 2024
0641f77
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Nov 4, 2024
01bd73b
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Nov 5, 2024
f3e3199
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Nov 8, 2024
b056f25
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Nov 13, 2024
0bbb61a
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Nov 13, 2024
b008dbc
Add UNDOCUMENTED configuration section for HashRouter timeouts
ximinez Nov 13, 2024
022142f
Document why a lock is not used for Transaction::mApplying
ximinez Nov 14, 2024
be52629
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Nov 27, 2024
12af9f1
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Dec 3, 2024
c1866d1
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Dec 5, 2024
79fb1cc
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Dec 16, 2024
b5624fe
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Dec 20, 2024
a35aab0
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Jan 7, 2025
9595d8c
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Jan 9, 2025
eeb1277
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Jan 24, 2025
91d0867
fixup! Add UNDOCUMENTED configuration section for HashRouter timeouts
ximinez Jan 28, 2025
3c5e9cf
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Jan 28, 2025
2ca015e
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Jan 30, 2025
65303b3
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Feb 4, 2025
e5233f2
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Feb 6, 2025
8f48d64
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Feb 7, 2025
d5ba2c6
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Feb 8, 2025
dcc3ca5
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Feb 11, 2025
d3a9522
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Feb 12, 2025
9082414
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Feb 13, 2025
96f9219
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Feb 14, 2025
c94bf7d
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Feb 20, 2025
9fe23dc
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Feb 20, 2025
e96745f
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Feb 25, 2025
1cd33b8
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Feb 25, 2025
158c285
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Feb 27, 2025
5b09745
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Feb 27, 2025
e8c0d7b
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Feb 28, 2025
76dd4e1
Address review feedback from @Bronek:
ximinez Feb 28, 2025
47da138
Add missing include
ximinez Mar 1, 2025
93b9a6d
Get rid of some unused variables
ximinez Mar 1, 2025
0855726
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Mar 11, 2025
1fed810
Merge remote-tracking branch 'upstream/develop' into relay
ximinez Mar 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/ripple/app/ledger/LocalTxs.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ namespace ripple {
class LocalTxs
{
public:
// The number of ledgers to hold a transaction is essentially
// arbitrary. It should be sufficient to allow the transaction to
// get into a fully-validated ledger.
static constexpr int holdLedgers = 5;

virtual ~LocalTxs() = default;

// Add a new local transaction
Expand Down
29 changes: 10 additions & 19 deletions src/ripple/app/ledger/impl/LedgerMaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,26 +548,17 @@ LedgerMaster::storeLedger(std::shared_ptr<Ledger const> ledger)
void
LedgerMaster::applyHeldTransactions()
{
std::lock_guard sl(m_mutex);
CanonicalTXSet const set = [this]() {
std::lock_guard sl(m_mutex);
// VFALCO NOTE The hash for an open ledger is undefined so we use
// something that is a reasonable substitute.
CanonicalTXSet set(app_.openLedger().current()->info().parentHash);
std::swap(mHeldTransactions, set);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great way to minimize processing while the lock is held. Good spotting!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

return set;
}();

app_.openLedger().modify([&](OpenView& view, beast::Journal j) {
bool any = false;
for (auto const& it : mHeldTransactions)
{
ApplyFlags flags = tapNONE;
auto const result =
app_.getTxQ().apply(app_, view, it.second, flags, j);
if (result.second)
any = true;
}
return any;
});

// VFALCO TODO recreate the CanonicalTxSet object instead of resetting
// it.
// VFALCO NOTE The hash for an open ledger is undefined so we use
// something that is a reasonable substitute.
mHeldTransactions.reset(app_.openLedger().current()->info().parentHash);
if (!set.empty())
app_.getOPs().processTransactionSet(set);
}

std::shared_ptr<STTx const>
Expand Down
7 changes: 1 addition & 6 deletions src/ripple/app/ledger/impl/LocalTxs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,9 @@ namespace ripple {
class LocalTx
{
public:
// The number of ledgers to hold a transaction is essentially
// arbitrary. It should be sufficient to allow the transaction to
// get into a fully-validated ledger.
static int const holdLedgers = 5;

LocalTx(LedgerIndex index, std::shared_ptr<STTx const> const& txn)
: m_txn(txn)
, m_expire(index + holdLedgers)
, m_expire(index + LocalTxs::holdLedgers)
, m_id(txn->getTransactionID())
, m_account(txn->getAccountID(sfAccount))
, m_seqProxy(txn->getSeqProxy())
Expand Down
3 changes: 2 additions & 1 deletion src/ripple/app/main/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,8 @@ class ApplicationImp : public Application, public BasicApp

, hashRouter_(std::make_unique<HashRouter>(
stopwatch(),
HashRouter::getDefaultHoldTime()))
HashRouter::getDefaultHoldTime(),
HashRouter::getDefaultRelayTime()))

, mValidations(
ValidationParms(),
Expand Down
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))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! This takes full advantage of the "unusual" sort order of SeqProxy, that all sequence numbers sort in front of all tickets.

{
result = std::move(itrNext->second);
map_.erase(itrNext);
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/app/misc/HashRouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ HashRouter::shouldRelay(uint256 const& key)

auto& s = emplace(key).first;

if (!s.shouldRelay(suppressionMap_.clock().now(), holdTime_))
if (!s.shouldRelay(suppressionMap_.clock().now(), relayTime_))
return {};

return s.releasePeerSet();
Expand Down
23 changes: 19 additions & 4 deletions src/ripple/app/misc/HashRouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +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_TRUSTED 0x10 // comes from trusted source

// Private flags, used internally in apply.cpp.
Expand Down Expand Up @@ -143,8 +144,21 @@ class HashRouter
return 300s;
}

HashRouter(Stopwatch& clock, std::chrono::seconds entryHoldTimeInSeconds)
: suppressionMap_(clock), holdTime_(entryHoldTimeInSeconds)
static inline std::chrono::seconds
getDefaultRelayTime()
{
using namespace std::chrono;

return 30s;
}

HashRouter(
Stopwatch& clock,
std::chrono::seconds entryHoldTime,
std::chrono::seconds entryRelayTime)
: suppressionMap_(clock)
, holdTime_(entryHoldTime)
, relayTime_(entryRelayTime)
{
}

Expand Down Expand Up @@ -195,11 +209,11 @@ class HashRouter
Effects:

If the item should be relayed, this function will not
return `true` again until the hold time has expired.
return a seated optional again until the relay time has expired.
The internal set of peers will also be reset.

@return A `std::optional` set of peers which do not need to be
relayed to. If the result is uninitialized, the item should
relayed to. If the result is unseated, the item should
_not_ be relayed.
*/
std::optional<std::set<PeerShortID>>
Expand All @@ -221,6 +235,7 @@ class HashRouter
suppressionMap_;

std::chrono::seconds const holdTime_;
std::chrono::seconds const relayTime_;
};

} // namespace ripple
Expand Down
Loading
Loading