Skip to content

Commit 3f1fd47

Browse files
committed
Log the caller / reason for server state changes:
* Also log as warning when the state lowers
1 parent 424517c commit 3f1fd47

File tree

8 files changed

+42
-24
lines changed

8 files changed

+42
-24
lines changed

src/ripple/app/consensus/RCLConsensus.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,8 @@ void
10621062
RCLConsensus::Adaptor::updateOperatingMode(std::size_t const positions) const
10631063
{
10641064
if (!positions && app_.getOPs().isFull())
1065-
app_.getOPs().setMode(OperatingMode::CONNECTED);
1065+
app_.getOPs().setMode(
1066+
OperatingMode::CONNECTED, "updateOperatingMode: no positions");
10661067
}
10671068

10681069
void

src/ripple/app/ledger/impl/InboundLedger.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -538,15 +538,17 @@ InboundLedger::trigger(std::shared_ptr<Peer> const& peer, TriggerReason reason)
538538

539539
if (auto stream = journal_.debug())
540540
{
541-
stream << "Trigger acquiring ledger " << hash_;
541+
std::stringstream ss;
542+
ss << "Trigger acquiring ledger " << hash_;
542543
if (peer)
543-
stream << " from " << peer;
544+
ss << " from " << peer;
544545

545546
if (complete_ || failed_)
546-
stream << "complete=" << complete_ << " failed=" << failed_;
547+
ss << " complete=" << complete_ << " failed=" << failed_;
547548
else
548-
stream << "header=" << mHaveHeader << " tx=" << mHaveTransactions
549-
<< " as=" << mHaveState;
549+
ss << " header=" << mHaveHeader << " tx=" << mHaveTransactions
550+
<< " as=" << mHaveState;
551+
stream << ss.str();
550552
}
551553

552554
if (!mHaveHeader)

src/ripple/app/ledger/impl/TimeoutCounter.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ TimeoutCounter::TimeoutCounter(
3333
QueueJobParameter&& jobParameter,
3434
beast::Journal journal)
3535
: app_(app)
36-
, journal_(journal)
36+
, sink_(journal, to_short_string(hash) + " ")
37+
, journal_(sink_)
3738
, hash_(hash)
3839
, timeouts_(0)
3940
, complete_(false)

src/ripple/app/ledger/impl/TimeoutCounter.h

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <ripple/app/main/Application.h>
2424
#include <ripple/beast/clock/abstract_clock.h>
2525
#include <ripple/beast/utility/Journal.h>
26+
#include <ripple/beast/utility/WrappedSink.h>
2627
#include <ripple/core/Job.h>
2728
#include <boost/asio/basic_waitable_timer.hpp>
2829
#include <mutex>
@@ -121,6 +122,7 @@ class TimeoutCounter
121122
// Used in this class for access to boost::asio::io_service and
122123
// ripple::Overlay. Used in subtypes for the kitchen sink.
123124
Application& app_;
125+
beast::WrappedSink sink_;
124126
beast::Journal journal_;
125127
mutable std::recursive_mutex mtx_;
126128

src/ripple/app/misc/NetworkOPs.cpp

+19-16
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ class NetworkOPsImp final : public NetworkOPs
401401
isFull() override;
402402

403403
void
404-
setMode(OperatingMode om) override;
404+
setMode(OperatingMode om, std::string const& reason) override;
405405

406406
bool
407407
isBlocked() override;
@@ -881,7 +881,7 @@ NetworkOPsImp::strOperatingMode(bool const admin /* = false */) const
881881
inline void
882882
NetworkOPsImp::setStandAlone()
883883
{
884-
setMode(OperatingMode::FULL);
884+
setMode(OperatingMode::FULL, "setStandAlone");
885885
}
886886

887887
inline void
@@ -1029,7 +1029,9 @@ NetworkOPsImp::processHeartbeatTimer()
10291029
{
10301030
if (mMode != OperatingMode::DISCONNECTED)
10311031
{
1032-
setMode(OperatingMode::DISCONNECTED);
1032+
setMode(
1033+
OperatingMode::DISCONNECTED,
1034+
"Heartbeat: insufficient peers");
10331035
JLOG(m_journal.warn())
10341036
<< "Node count (" << numPeers << ") has fallen "
10351037
<< "below required minimum (" << minPeerCount_ << ").";
@@ -1045,17 +1047,17 @@ NetworkOPsImp::processHeartbeatTimer()
10451047

10461048
if (mMode == OperatingMode::DISCONNECTED)
10471049
{
1048-
setMode(OperatingMode::CONNECTED);
1050+
setMode(OperatingMode::CONNECTED, "Heartbeat: sufficient peers");
10491051
JLOG(m_journal.info())
10501052
<< "Node count (" << numPeers << ") is sufficient.";
10511053
}
10521054

10531055
// Check if the last validated ledger forces a change between these
10541056
// states.
10551057
if (mMode == OperatingMode::SYNCING)
1056-
setMode(OperatingMode::SYNCING);
1058+
setMode(OperatingMode::SYNCING, "Heartbeat: check syncing");
10571059
else if (mMode == OperatingMode::CONNECTED)
1058-
setMode(OperatingMode::CONNECTED);
1060+
setMode(OperatingMode::CONNECTED, "Heartbeat: check connected");
10591061
}
10601062

10611063
mConsensus.timerEntry(app_.timeKeeper().closeTime());
@@ -1609,7 +1611,7 @@ void
16091611
NetworkOPsImp::setAmendmentBlocked()
16101612
{
16111613
amendmentBlocked_ = true;
1612-
setMode(OperatingMode::CONNECTED);
1614+
setMode(OperatingMode::CONNECTED, "setAmendmentBlocked");
16131615
}
16141616

16151617
inline bool
@@ -1640,7 +1642,7 @@ void
16401642
NetworkOPsImp::setUNLBlocked()
16411643
{
16421644
unlBlocked_ = true;
1643-
setMode(OperatingMode::CONNECTED);
1645+
setMode(OperatingMode::CONNECTED, "setUNLBlocked");
16441646
}
16451647

16461648
inline void
@@ -1741,7 +1743,7 @@ NetworkOPsImp::checkLastClosedLedger(
17411743

17421744
if ((mMode == OperatingMode::TRACKING) || (mMode == OperatingMode::FULL))
17431745
{
1744-
setMode(OperatingMode::CONNECTED);
1746+
setMode(OperatingMode::CONNECTED, "check LCL: not on consensus ledger");
17451747
}
17461748

17471749
if (consensus)
@@ -1826,8 +1828,9 @@ NetworkOPsImp::beginConsensus(uint256 const& networkClosed)
18261828
// this shouldn't happen unless we jump ledgers
18271829
if (mMode == OperatingMode::FULL)
18281830
{
1829-
JLOG(m_journal.warn()) << "Don't have LCL, going to tracking";
1830-
setMode(OperatingMode::TRACKING);
1831+
JLOG(m_journal.warn())
1832+
<< "beginConsensus Don't have LCL, going to tracking";
1833+
setMode(OperatingMode::TRACKING, "beginConsensus: No LCL");
18311834
}
18321835

18331836
return false;
@@ -1933,7 +1936,7 @@ NetworkOPsImp::endConsensus()
19331936
// validations we have for LCL. If the ledger is good enough, go to
19341937
// TRACKING - TODO
19351938
if (!needNetworkLedger_)
1936-
setMode(OperatingMode::TRACKING);
1939+
setMode(OperatingMode::TRACKING, "endConsensus: check tracking");
19371940
}
19381941

19391942
if (((mMode == OperatingMode::CONNECTED) ||
@@ -1947,7 +1950,7 @@ NetworkOPsImp::endConsensus()
19471950
if (app_.timeKeeper().now() < (current->info().parentCloseTime +
19481951
2 * current->info().closeTimeResolution))
19491952
{
1950-
setMode(OperatingMode::FULL);
1953+
setMode(OperatingMode::FULL, "endConsensus: check full");
19511954
}
19521955
}
19531956

@@ -1959,7 +1962,7 @@ NetworkOPsImp::consensusViewChange()
19591962
{
19601963
if ((mMode == OperatingMode::FULL) || (mMode == OperatingMode::TRACKING))
19611964
{
1962-
setMode(OperatingMode::CONNECTED);
1965+
setMode(OperatingMode::CONNECTED, "consensusViewChange");
19631966
}
19641967
}
19651968

@@ -2277,7 +2280,7 @@ NetworkOPsImp::pubPeerStatus(std::function<Json::Value(void)> const& func)
22772280
}
22782281

22792282
void
2280-
NetworkOPsImp::setMode(OperatingMode om)
2283+
NetworkOPsImp::setMode(OperatingMode om, std::string const& reason)
22812284
{
22822285
using namespace std::chrono_literals;
22832286
if (om == OperatingMode::CONNECTED)
@@ -2301,7 +2304,7 @@ NetworkOPsImp::setMode(OperatingMode om)
23012304

23022305
accounting_.mode(om);
23032306

2304-
JLOG(m_journal.info()) << "STATE->" << strOperatingMode();
2307+
JLOG(m_journal.info()) << "STATE->" << strOperatingMode() << " " << reason;
23052308
pubServer();
23062309
}
23072310

src/ripple/app/misc/NetworkOPs.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class NetworkOPs : public InfoSub::Source
197197
virtual bool
198198
isFull() = 0;
199199
virtual void
200-
setMode(OperatingMode om) = 0;
200+
setMode(OperatingMode om, std::string const& reason) = 0;
201201
virtual bool
202202
isBlocked() = 0;
203203
virtual bool

src/ripple/basics/base_uint.h

+7
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,13 @@ to_string(base_uint<Bits, Tag> const& a)
623623
return strHex(a.cbegin(), a.cend());
624624
}
625625

626+
template <std::size_t Bits, class Tag>
627+
inline std::string
628+
to_short_string(base_uint<Bits, Tag> const& a)
629+
{
630+
return strHex(a.cbegin(), a.cend()).substr(0, 8) + "...";
631+
}
632+
626633
template <std::size_t Bits, class Tag>
627634
inline std::ostream&
628635
operator<<(std::ostream& out, base_uint<Bits, Tag> const& u)

src/ripple/protocol/LedgerHeader.h

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ struct LedgerHeader
5555

5656
// If validated is false, it means "not yet validated."
5757
// Once validated is true, it will never be set false at a later time.
58+
// NOTE: If you are accessing this directly, you are probably doing it
59+
// wrong. Use LedgerMaster::isValidated().
5860
// VFALCO TODO Make this not mutable
5961
bool mutable validated = false;
6062
bool accepted = false;

0 commit comments

Comments
 (0)