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