Skip to content

Commit

Permalink
txQueue: ban transactions when we drop them late in the pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
MonsieurNicolas committed Dec 9, 2021
1 parent 6faafcc commit 577bef4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
40 changes: 25 additions & 15 deletions src/herder/TransactionQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -844,12 +844,12 @@ TransactionQueue::getMaxOpsToFloodThisPeriod() const
return static_cast<size_t>(opsToFlood);
}

bool
TransactionQueue::BroadcastStatus
TransactionQueue::broadcastTx(AccountState& state, TimestampedTx& tx)
{
if (tx.mBroadcasted)
{
return false;
return BroadcastStatus::BROADCAST_STATUS_ALREADY;
}

bool allowTx{true};
Expand Down Expand Up @@ -933,10 +933,11 @@ TransactionQueue::broadcastTx(AccountState& state, TimestampedTx& tx)
// false to our caller so that they will not count this tx against the
// per-timeslice counters -- we want to allow the caller to try useful
// work from other sources.
return false;
return BroadcastStatus::BROADCAST_STATUS_SKIPPED;
}
return mApp.getOverlayManager().broadcastMessage(
tx.mTx->toStellarMessage());
return mApp.getOverlayManager().broadcastMessage(tx.mTx->toStellarMessage())
? BroadcastStatus::BROADCAST_STATUS_SUCCESS
: BroadcastStatus::BROADCAST_STATUS_ALREADY;
}

struct TxQueueTracker
Expand Down Expand Up @@ -1012,6 +1013,7 @@ TransactionQueue::broadcastSome()
}
}

std::vector<TransactionFrameBasePtr> banningTxs;
while (opsToFlood != 0 && !iters.empty())
{
auto curTracker = iters.top();
Expand All @@ -1027,22 +1029,30 @@ TransactionQueue::broadcastSome()
// accumulate more flooding credit
break;
}
auto bStatus = broadcastTx(*curTracker.mAccountState, *cur);
if (bStatus == BroadcastStatus::BROADCAST_STATUS_SUCCESS)
{
auto ops = tx->getNumOperations();
opsToFlood -= ops;
totalOpsToFlood -= ops;
}
// when skipping, we ban the transaction and skip the remainder of the
// queue
if (bStatus == BroadcastStatus::BROADCAST_STATUS_SKIPPED)
{
banningTxs.emplace_back(tx);
}
else
{
if (broadcastTx(*curTracker.mAccountState, *cur))
cur++;
// if we're not done with this account, add the tracker back
if (curTracker.skipToFirstNotBroadcasted())
{
auto ops = tx->getNumOperations();
opsToFlood -= ops;
totalOpsToFlood -= ops;
iters.push(curTracker);
}
cur++;
}
// if we're not done with this account, add the tracker back
if (curTracker.skipToFirstNotBroadcasted())
{
iters.push(curTracker);
}
}
ban(banningTxs);
// carry over remainder, up to MAX_OPS_PER_TX ops
// reason is that if we add 1 next round, we can flood a "worst case fee
// bump" tx
Expand Down
8 changes: 7 additions & 1 deletion src/herder/TransactionQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,13 @@ class TransactionQueue
bool broadcastSome();
void broadcast(bool fromCallback);
// broadcasts a single transaction
bool broadcastTx(AccountState& state, TimestampedTx& tx);
enum class BroadcastStatus
{
BROADCAST_STATUS_ALREADY,
BROADCAST_STATUS_SUCCESS,
BROADCAST_STATUS_SKIPPED
};
BroadcastStatus broadcastTx(AccountState& state, TimestampedTx& tx);

AddResult canAdd(TransactionFrameBasePtr tx,
AccountStates::iterator& stateIter,
Expand Down

5 comments on commit 577bef4

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

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

saw approval from graydon
at MonsieurNicolas@577bef4

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

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

merging MonsieurNicolas/stellar-core/banDropped = 577bef4 into auto

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

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

MonsieurNicolas/stellar-core/banDropped = 577bef4 merged ok, testing candidate = b63c162

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

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

fast-forwarding master to auto = b63c162

Please sign in to comment.