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