Skip to content

Commit 471b522

Browse files
committed
use the condition: active size >= min active size in isolate2
1 parent 14a0750 commit 471b522

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

framework/src/main/java/org/tron/core/net/service/effective/ResilienceService.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,12 @@ private void disconnectIsolated2() {
111111
return;
112112
}
113113
logger.warn("Node is isolated, try to disconnect from peers");
114-
int peerSize = tronNetDelegate.getActivePeer().size();
115114

116115
//disconnect from the node whose lastActiveTime is smallest
117-
if (peerSize >= CommonParameter.getInstance().getMinActiveConnections()) {
116+
int activePeerSize = (int) tronNetDelegate.getActivePeer().stream()
117+
.filter(peer -> peer.getChannel().isActive())
118+
.count();
119+
if (activePeerSize >= CommonParameter.getInstance().getMinActiveConnections()) {
118120
List<PeerConnection> peers = tronNetDelegate.getActivePeer().stream()
119121
.filter(peer -> !peer.getChannel().isTrustPeer())
120122
.filter(peer -> peer.getChannel().isActive())
@@ -127,7 +129,7 @@ private void disconnectIsolated2() {
127129

128130
//disconnect from some passive nodes, make sure retention nodes' num <= 0.8 * maxConnection,
129131
//so new peers can come in
130-
peerSize = tronNetDelegate.getActivePeer().size();
132+
int peerSize = tronNetDelegate.getActivePeer().size();
131133
int threshold = (int) (CommonParameter.getInstance().getMaxConnections() * retentionPercent);
132134
if (peerSize > threshold) {
133135
int disconnectSize = peerSize - threshold;

0 commit comments

Comments
 (0)