increase max ping

This commit is contained in:
Valentin Balaschenko
2025-04-17 10:54:03 +01:00
parent 4008662fd5
commit cdb9f8c21f
2 changed files with 24 additions and 9 deletions

View File

@@ -57,7 +57,10 @@ namespace {
std::chrono::milliseconds constexpr peerHighLatency{300}; std::chrono::milliseconds constexpr peerHighLatency{300};
/** How often we PING the peer to check for latency and sendq probe */ /** How often we PING the peer to check for latency and sendq probe */
std::chrono::seconds constexpr peerTimerInterval{300}; std::chrono::seconds constexpr peerTimerInterval{60};
uint16_t constexpr maxPingNumber = 5;
} // namespace } // namespace
// TODO: Remove this exclusion once unit tests are added after the hotfix // TODO: Remove this exclusion once unit tests are added after the hotfix
@@ -604,7 +607,7 @@ PeerImp::fail(std::string const& reason)
return post( return post(
strand_, strand_,
std::bind( std::bind(
(void(Peer::*)(std::string const&)) & PeerImp::fail, (void (Peer::*)(std::string const&))&PeerImp::fail,
shared_from_this(), shared_from_this(),
reason)); reason));
if (journal_.active(beast::severities::kWarning) && socket_.is_open()) if (journal_.active(beast::severities::kWarning) && socket_.is_open())
@@ -730,7 +733,13 @@ PeerImp::onTimer(error_code const& ec)
} }
// Already waiting for PONG // Already waiting for PONG
if (lastPingSeq_) if (lastPingSeq_ && (pingAttempts_ < maxPingNumber))
{
pingAttempts_++;
JLOG(journal_.info()) << "Missing PONG, sending PING, attempt "
<< pingAttempts_ << " of " << maxPingNumber;
}
else if (lastPingSeq_)
{ {
fail("Ping Timeout"); fail("Ping Timeout");
return; return;
@@ -738,6 +747,7 @@ PeerImp::onTimer(error_code const& ec)
lastPingTime_ = clock_type::now(); lastPingTime_ = clock_type::now();
lastPingSeq_ = rand_int<std::uint32_t>(); lastPingSeq_ = rand_int<std::uint32_t>();
pingAttempts_ = 0;
protocol::TMPing message; protocol::TMPing message;
message.set_type(protocol::TMPing::ptPING); message.set_type(protocol::TMPing::ptPING);
@@ -1105,6 +1115,7 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMPing> const& m)
if (m->seq() == lastPingSeq_) if (m->seq() == lastPingSeq_)
{ {
lastPingSeq_.reset(); lastPingSeq_.reset();
pingAttempts_ = 0;
// Update latency estimate // Update latency estimate
auto const rtt = std::chrono::round<std::chrono::milliseconds>( auto const rtt = std::chrono::round<std::chrono::milliseconds>(
@@ -1488,8 +1499,9 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMProofPathRequest> const& m)
} }
else else
{ {
peer->send(std::make_shared<Message>( peer->send(
reply, protocol::mtPROOF_PATH_RESPONSE)); std::make_shared<Message>(
reply, protocol::mtPROOF_PATH_RESPONSE));
} }
} }
}); });
@@ -1543,8 +1555,9 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMReplayDeltaRequest> const& m)
} }
else else
{ {
peer->send(std::make_shared<Message>( peer->send(
reply, protocol::mtREPLAY_DELTA_RESPONSE)); std::make_shared<Message>(
reply, protocol::mtREPLAY_DELTA_RESPONSE));
} }
} }
}); });

View File

@@ -112,6 +112,7 @@ private:
std::optional<std::chrono::milliseconds> latency_; std::optional<std::chrono::milliseconds> latency_;
std::optional<std::uint32_t> lastPingSeq_; std::optional<std::uint32_t> lastPingSeq_;
uint16_t pingAttempts_ = 0;
clock_type::time_point lastPingTime_; clock_type::time_point lastPingTime_;
clock_type::time_point const creationTime_; clock_type::time_point const creationTime_;
@@ -715,8 +716,9 @@ PeerImp::PeerImp(
app_.config().LEDGER_REPLAY)) app_.config().LEDGER_REPLAY))
, ledgerReplayMsgHandler_(app, app.getLedgerReplayer()) , ledgerReplayMsgHandler_(app, app.getLedgerReplayer())
{ {
read_buffer_.commit(boost::asio::buffer_copy( read_buffer_.commit(
read_buffer_.prepare(boost::asio::buffer_size(buffers)), buffers)); boost::asio::buffer_copy(
read_buffer_.prepare(boost::asio::buffer_size(buffers)), buffers));
JLOG(journal_.info()) << "compression enabled " JLOG(journal_.info()) << "compression enabled "
<< (compressionEnabled_ == Compressed::On) << (compressionEnabled_ == Compressed::On)
<< " vp reduce-relay enabled " << " vp reduce-relay enabled "