@@ -112,20 +112,29 @@ class InboundLedgersImp : public InboundLedgers
112
112
// the network, and doesn't have the necessary tx's and
113
113
// ledger entries to build the ledger.
114
114
bool const isFull = app_.getOPs ().isFull ();
115
+ // fallingBehind means the last closed ledger is at least 2
116
+ // behind the validated ledger. If the node is falling
117
+ // behind the network, it probably needs information from
118
+ // the network to catch up.
119
+ //
120
+ // The reason this should not simply be only at least 1
121
+ // behind the validated ledger is that a slight lag is
122
+ // normal case because some nodes get there slightly later
123
+ // than others. A difference of 2 means that at least a full
124
+ // ledger interval has passed, so the node is beginning to
125
+ // fall behind.
126
+ bool const fallingBehind = app_.getOPs ().isFallingBehind ();
115
127
// If everything else is ok, don't try to acquire the ledger
116
128
// if the requested seq is in the near future relative to
117
- // the validated ledger. If the requested ledger is between
118
- // 1 and 19 inclusive ledgers ahead of the valid ledger this
119
- // node has not built it yet, but it's possible/likely it
120
- // has the tx's necessary to build it and get caught up.
121
- // Plus it might not become validated. On the other hand, if
122
- // it's more than 20 in the future, this node should request
123
- // it so that it can jump ahead and get caught up.
129
+ // the validated ledger. Because validations lag behind
130
+ // consensus, if we get any further behind than this, we
131
+ // risk losing sync, because we don't have the preferred
132
+ // ledger available.
124
133
LedgerIndex const validSeq =
125
134
app_.getLedgerMaster ().getValidLedgerIndex ();
126
- constexpr std::size_t lagLeeway = 20 ;
127
- bool const nearFuture =
128
- (seq > validSeq) && (seq < validSeq + lagLeeway);
135
+ constexpr std::size_t lagLeeway = 2 ;
136
+ bool const nearFuture = (validSeq > 0 ) && (seq > validSeq) &&
137
+ (seq < validSeq + lagLeeway);
129
138
// If everything else is ok, don't try to acquire the ledger
130
139
// if the request is related to consensus. (Note that
131
140
// consensus calls usually pass a seq of 0, so nearFuture
@@ -134,6 +143,7 @@ class InboundLedgersImp : public InboundLedgers
134
143
reason == InboundLedger::Reason::CONSENSUS;
135
144
ss << " Evaluating whether to broadcast requests to peers"
136
145
<< " . full: " << (isFull ? " true" : " false" )
146
+ << " . falling behind: " << (fallingBehind ? " true" : " false" )
137
147
<< " . ledger sequence " << seq
138
148
<< " . Valid sequence: " << validSeq
139
149
<< " . Lag leeway: " << lagLeeway
@@ -144,6 +154,9 @@ class InboundLedgersImp : public InboundLedgers
144
154
// If the node is not synced, send requests.
145
155
if (!isFull)
146
156
return true ;
157
+ // If the node is falling behind, send requests.
158
+ if (fallingBehind)
159
+ return true ;
147
160
// If the ledger is in the near future, do NOT send requests.
148
161
// This node is probably about to build it.
149
162
if (nearFuture)
@@ -154,7 +167,7 @@ class InboundLedgersImp : public InboundLedgers
154
167
return false ;
155
168
return true ;
156
169
}();
157
- ss << " . Would broadcast to peers? "
170
+ ss << " . Broadcast to peers? "
158
171
<< (shouldBroadcast ? " true." : " false." );
159
172
160
173
if (!shouldAcquire)
@@ -189,7 +202,7 @@ class InboundLedgersImp : public InboundLedgers
189
202
std::ref (m_clock),
190
203
mPeerSetBuilder ->build ());
191
204
mLedgers .emplace (hash, inbound);
192
- inbound->init (sl);
205
+ inbound->init (sl, shouldBroadcast );
193
206
++mCounter ;
194
207
}
195
208
}
@@ -201,8 +214,12 @@ class InboundLedgersImp : public InboundLedgers
201
214
return {};
202
215
}
203
216
204
- if (!isNew)
205
- inbound->update (seq);
217
+ bool const didBroadcast = [&]() {
218
+ if (!isNew)
219
+ return inbound->update (seq, shouldBroadcast);
220
+ return shouldBroadcast;
221
+ }();
222
+ ss << " First broadcast: " << (didBroadcast ? " true" : " false" );
206
223
207
224
if (!inbound->isComplete ())
208
225
{
0 commit comments