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