Skip to content

Commit

Permalink
finished refactoring relay
Browse files Browse the repository at this point in the history
  • Loading branch information
vlntb committed Jan 25, 2025
1 parent 13974f4 commit 59820e3
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/xrpld/overlay/detail/OverlayImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1212,28 +1212,30 @@ OverlayImpl::relay(
relay = !isPseudoTx(STTx{sit});
}

if (!relay) {
Overlay::PeerSequence peers = {};
std::size_t total = 0;
std::size_t disabled = 0;
std::size_t enabledInSkip = 0;

if (!relay)
{
if (!app_.config().TX_REDUCE_RELAY_ENABLE)
return;

Check warning on line 1223 in src/xrpld/overlay/detail/OverlayImpl.cpp

View check run for this annotation

Codecov / codecov/patch

src/xrpld/overlay/detail/OverlayImpl.cpp#L1223

Added line #L1223 was not covered by tests
auto peers = getActivePeers(toSkip, 0, 0, 0)
JLOG(journal_.trace()) << "not relaying tx, total peers " << peers.size();

peers = getActivePeers(toSkip, total, disabled, enabledInSkip);
JLOG(journal_.trace())
<< "not relaying tx, total peers " << peers.size();
for (auto const& p : peers)
p->addTxQueue(hash);
return;

Check warning on line 1230 in src/xrpld/overlay/detail/OverlayImpl.cpp

View check run for this annotation

Codecov / codecov/patch

src/xrpld/overlay/detail/OverlayImpl.cpp#L1230

Added line #L1230 was not covered by tests
}
}

auto& txn = tx->get();
sm = std::make_shared<Message>(txn, protocol::mtTRANSACTION);

std::size_t total = 0;
std::size_t disabled = 0;
std::size_t enabledInSkip = 0;

// total peers excluding peers in toSkip
auto peers = getActivePeers(toSkip, total, disabled, enabledInSkip);
peers = getActivePeers(toSkip, total, disabled, enabledInSkip);
auto const minRelay = app_.config().TX_REDUCE_RELAY_MIN_PEERS + disabled;

if (relay && (!app_.config().TX_REDUCE_RELAY_ENABLE || total <= minRelay))
if (!app_.config().TX_REDUCE_RELAY_ENABLE || total <= minRelay)
{
for (auto const& p : peers)
p->send(sm);
Expand Down Expand Up @@ -1268,12 +1270,10 @@ OverlayImpl::relay(
// always relay to a peer with the disabled feature
if (!p->txReduceRelayEnabled())
{
if (relay)
p->send(sm);
p->send(sm);
}
else if (enabledAndRelayed < enabledTarget)
{
assert(relay);
enabledAndRelayed++;
p->send(sm);
}
Expand Down

0 comments on commit 59820e3

Please sign in to comment.