You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 25, 2025. It is now read-only.
[FABG-698] Event client reconn bug fix and enhancements
Fixed a bug where the threshold subtracted from the max height
resulted in a very high uint64 number (due to overflow).
Check the height of the current peer from discovery as well
as the number of blocks received. This prevents the client from
disconnecting prematurely.
Change-Id: I79c9168bc3447fc6e84b90879d451bf6af65b3bd
Signed-off-by: Bob Stasyszyn <Bob.Stasyszyn@securekey.com>
logger.Debugf("Starting block height monitor. Lag threshold: %d", ed.reconnectBlockHeightLagThreshold)
287
+
logger.Debugf("Starting block height monitor on channel [%s]. Lag threshold: %d", ed.chConfig.ID(), ed.reconnectBlockHeightLagThreshold)
288
+
279
289
for {
280
290
if_, ok:=<-ed.ticker.C; !ok {
281
-
logger.Debugf("Stopping block height monitor")
291
+
logger.Debugf("Stopping block height monitor on channel [%s]", ed.chConfig.ID())
292
+
return
293
+
}
294
+
if!ed.checkBlockHeight() {
295
+
// Disconnected
296
+
logger.Debugf("Client on channel [%s] has disconnected - stopping block height monitor", ed.chConfig.ID())
282
297
return
283
298
}
284
-
ed.checkBlockHeight()
285
299
}
286
300
}
287
301
288
-
func (ed*Dispatcher) checkBlockHeight() {
289
-
logger.Debugf("Checking block heights...")
302
+
// checkBlockHeight checks the current peer's block height relative to the block heights of the
303
+
// other peers in the channel and disconnects the peer if the configured threshold is reached.
304
+
// Returns true if the block height is acceptable; false if the client has been disconnected from the peer
305
+
func (ed*Dispatcher) checkBlockHeight() bool {
306
+
logger.Debugf("Checking block heights on channel [%s]...", ed.chConfig.ID())
290
307
291
-
lastBlockReceived:=ed.LastBlockNum()
292
-
iflastBlockReceived==math.MaxUint64 {
293
-
logger.Debugf("No blocks have been received yet")
294
-
return
308
+
connectedPeer:=ed.connectedPeer()
309
+
ifconnectedPeer==nil {
310
+
logger.Debugf("Not connected yet")
311
+
returntrue
295
312
}
296
313
314
+
peerState, ok:=connectedPeer.(fab.PeerState)
315
+
if!ok {
316
+
logger.Debugf("Peer does not contain state")
317
+
returntrue
318
+
}
319
+
320
+
lastBlockReceived:=ed.LastBlockNum()
321
+
connectedPeerBlockHeight:=peerState.BlockHeight()
322
+
297
323
peers, err:=ed.discoveryService.GetPeers()
298
324
iferr!=nil {
299
325
logger.Warnf("Error checking block height on peers: %s", err)
300
-
return
326
+
returntrue
301
327
}
302
328
303
-
connectedPeerBlockHeight:=lastBlockReceived+1
304
329
maxHeight:=getMaxBlockHeight(peers)
305
330
306
-
logger.Debugf("Block height from blocks received: %d, Max block height from Discovery: %d", connectedPeerBlockHeight, maxHeight)
331
+
logger.Debugf("Block height on channel [%s] of connected peer [%s] from Discovery: %d, Last block received: %d, Max block height from Discovery: %d", ed.chConfig.ID(), connectedPeer.URL(), connectedPeerBlockHeight, lastBlockReceived, maxHeight)
logger.Debugf("Max block height on channel [%s] of peers is %d and reconnect lag threshold is %d so event client will not be disconnected from peer", ed.chConfig.ID(), maxHeight, ed.reconnectBlockHeightLagThreshold)
335
+
returntrue
336
+
}
337
+
338
+
// The last block received may be lagging the actual block height of the peer
339
+
iflastBlockReceived+1<connectedPeerBlockHeight {
340
+
// We can still get more blocks from the connected peer. Don't disconnect
341
+
logger.Debugf("Block height on channel [%s] of connected peer [%s] from Discovery is %d which is greater than last block received+1: %d. Won't disconnect from this peer since more blocks can still be retrieved from the peer", ed.chConfig.ID(), connectedPeer.URL(), connectedPeerBlockHeight, lastBlockReceived+1)
logger.Debugf("Block height from blocks received is %d which is greater than or equal to the cutoff %d", connectedPeerBlockHeight, cutoffHeight)
312
-
} else {
313
-
logger.Infof("Block height from blocks received is %d which is less than the cutoff %d. Disconnecting from the peer...", connectedPeerBlockHeight, cutoffHeight)
logger.Debugf("Block height on channel [%s] from connected peer [%s] is %d which is greater than or equal to the cutoff %d so event client will not be disconnected from peer", ed.chConfig.ID(), connectedPeer.URL(), peerBlockHeight, cutoffHeight)
350
+
returntrue
319
351
}
352
+
353
+
logger.Infof("Block height on channel [%s] from connected peer is %d which is less than the cutoff %d. Disconnecting from the peer...", ed.chConfig.ID(), peerBlockHeight, cutoffHeight)
354
+
iferr:=ed.disconnect(); err!=nil {
355
+
logger.Warnf("Error disconnecting event client from channel [%s]: %s", ed.chConfig.ID(), err)
356
+
returntrue
357
+
}
358
+
359
+
logger.Info("Successfully disconnected event client from channel [%s]", ed.chConfig.ID())
0 commit comments