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