Skip to content

Commit e25e42f

Browse files
committed
[p2p] Reattempt initial send of unbroadcast transactions
Every 10-15 minutes, the scheduler kicks off a job that queues unbroadcast transactions onto each node.
1 parent 7e93eec commit e25e42f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/net_processing.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,19 @@ void PeerLogicValidation::InitializeNode(CNode *pnode) {
779779
PushNodeVersion(pnode, connman, GetTime());
780780
}
781781

782+
void PeerLogicValidation::ReattemptInitialBroadcast(CScheduler& scheduler) const
783+
{
784+
std::set<uint256> unbroadcast_txids = m_mempool.GetUnbroadcastTxs();
785+
786+
for (const uint256& txid : unbroadcast_txids) {
787+
RelayTransaction(txid, *connman);
788+
}
789+
790+
// schedule next run for 10-15 minutes in the future
791+
const std::chrono::milliseconds delta = std::chrono::minutes{10} + GetRandMillis(std::chrono::minutes{5});
792+
scheduler.scheduleFromNow([&] { ReattemptInitialBroadcast(scheduler); }, delta);
793+
}
794+
782795
void PeerLogicValidation::FinalizeNode(NodeId nodeid, bool& fUpdateConnectionTime) {
783796
fUpdateConnectionTime = false;
784797
LOCK(cs_main);
@@ -1128,6 +1141,10 @@ PeerLogicValidation::PeerLogicValidation(CConnman* connmanIn, BanMan* banman, CS
11281141
// timer.
11291142
static_assert(EXTRA_PEER_CHECK_INTERVAL < STALE_CHECK_INTERVAL, "peer eviction timer should be less than stale tip check timer");
11301143
scheduler.scheduleEvery([this, consensusParams] { this->CheckForStaleTipAndEvictPeers(consensusParams); }, std::chrono::seconds{EXTRA_PEER_CHECK_INTERVAL});
1144+
1145+
// schedule next run for 10-15 minutes in the future
1146+
const std::chrono::milliseconds delta = std::chrono::minutes{10} + GetRandMillis(std::chrono::minutes{5});
1147+
scheduler.scheduleFromNow([&] { ReattemptInitialBroadcast(scheduler); }, delta);
11311148
}
11321149

11331150
/**

src/net_processing.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ class PeerLogicValidation final : public CValidationInterface, public NetEventsI
7575
void CheckForStaleTipAndEvictPeers(const Consensus::Params &consensusParams);
7676
/** If we have extra outbound peers, try to disconnect the one with the oldest block announcement */
7777
void EvictExtraOutboundPeers(int64_t time_in_seconds) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
78+
/** Retrieve unbroadcast transactions from the mempool and reattempt sending to peers */
79+
void ReattemptInitialBroadcast(CScheduler& scheduler) const;
7880

7981
private:
8082
int64_t m_stale_tip_check_time; //!< Next time to check for stale tip

0 commit comments

Comments
 (0)