Skip to content

Commit 7585554

Browse files
committed
[FOLD] Add comments and tweak log messages
1 parent 8b89ea1 commit 7585554

File tree

1 file changed

+49
-6
lines changed

1 file changed

+49
-6
lines changed

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

+49-6
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,59 @@ class InboundLedgersImp : public InboundLedgers
8787
reason != InboundLedger::Reason::SHARD ||
8888
(seq != 0 && app_.getShardStore()));
8989

90+
// If the node is not in "full" state, it needs to sync to the network,
91+
// and doesn't have the necessary tx's and ledger entries to build the
92+
// ledger.
9093
bool const isFull = app_.getOPs().isFull();
94+
// fallingBehind means the last closed ledger is at least 2 behind the
95+
// validated ledger. If the node is falling behind the network, it
96+
// probably needs information from the network to catch up.
97+
//
98+
// The reason this should not simply be only at least 1 behind the
99+
// validated ledger is that a slight lag is normal case because some
100+
// nodes get there slightly later than others. A difference of 2 means
101+
// that at least a full ledger interval has passed, so the node is
102+
// beginning to fall behind.
91103
bool const fallingBehind = app_.getOPs().isFallingBehind();
104+
// If everything else is ok, don't try to acquire the ledger if the
105+
// requested seq is in the near future relative to the validated ledger.
106+
// If the requested ledger is between 1 and 19 inclusive ledgers ahead
107+
// of the valid ledger this node has not built it yet, but it's
108+
// possible/likely it has the tx's necessary to build it and get caught
109+
// up. Plus it might not become validated. On the other hand, if it's
110+
// more than 20 in the future, this node should request it so that it
111+
// can jump ahead and get caught up.
92112
LedgerIndex const validSeq =
93113
app_.getLedgerMaster().getValidLedgerIndex();
94114
constexpr std::size_t lagLeeway = 20;
95115
bool const nearFuture =
96116
(seq > validSeq) && (seq < validSeq + lagLeeway);
117+
// If everything else is ok, don't try to acquire the ledger if the
118+
// request is related to consensus. (Note that consensus calls usually
119+
// pass a seq of 0, so nearFuture will be false other than on a brand
120+
// new network.)
97121
bool const consensus = reason == InboundLedger::Reason::CONSENSUS;
98-
bool const shouldAcquire =
99-
!(isFull && !fallingBehind && (nearFuture || consensus));
122+
123+
bool const shouldAcquire = [&]() {
124+
// If the node is not synced, try to get the ledger.
125+
if (!isFull)
126+
return true;
127+
// If the node is falling behind, try to get the ledger.
128+
if (fallingBehind)
129+
return true;
130+
// If the ledger is in the near future, do NOT get the ledger. This
131+
// node is probably about to build it.
132+
if (nearFuture)
133+
return false;
134+
// If the request is because of consensus, do NOT get the ledger.
135+
// This node is probably about to build it.
136+
if (consensus)
137+
return false;
138+
return true;
139+
}();
140+
assert(
141+
shouldAcquire ==
142+
!(isFull && !fallingBehind && (nearFuture || consensus)));
100143
ss << " Evaluating whether to acquire ledger " << hash
101144
<< ". full: " << (isFull ? "true" : "false")
102145
<< ". falling behind: " << (fallingBehind ? "true" : "false")
@@ -113,7 +156,7 @@ class InboundLedgersImp : public InboundLedgers
113156
ScopedLockType sl(mLock);
114157
if (stopping_)
115158
{
116-
JLOG(j_.debug()) << "Abort (stopping): " << ss.str();
159+
JLOG(j_.debug()) << "Abort(stopping): " << ss.str();
117160
return {};
118161
}
119162

@@ -140,7 +183,7 @@ class InboundLedgersImp : public InboundLedgers
140183

141184
if (inbound->isFailed())
142185
{
143-
JLOG(j_.debug()) << "Abort (failed): " << ss.str();
186+
JLOG(j_.debug()) << "Abort(failed): " << ss.str();
144187
return {};
145188
}
146189

@@ -149,7 +192,7 @@ class InboundLedgersImp : public InboundLedgers
149192

150193
if (!inbound->isComplete())
151194
{
152-
JLOG(j_.debug()) << "Abort (incomplete): " << ss.str();
195+
JLOG(j_.debug()) << "Abort(incomplete): " << ss.str();
153196
return {};
154197
}
155198

@@ -198,7 +241,7 @@ class InboundLedgersImp : public InboundLedgers
198241
{
199242
// This check should be before the others because it's cheaper, but
200243
// it's at the end for now to test the effectiveness of the change
201-
JLOG(j_.debug()) << "Abort (rule): " << ss.str();
244+
JLOG(j_.debug()) << "Abort(rule): " << ss.str();
202245
return {};
203246
}
204247

0 commit comments

Comments
 (0)