Skip to content

Commit 5a487dc

Browse files
authored
Merge pull request #6381 from zeusoo001/sync-problem
feat(net): optimize the log of synchronization failure
2 parents 23a3f42 + f85de4a commit 5a487dc

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

framework/src/main/java/org/tron/core/net/service/sync/SyncService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ public void syncNext(PeerConnection peer) {
124124
peer.setSyncChainRequested(new Pair<>(chainSummary, System.currentTimeMillis()));
125125
peer.sendMessage(new SyncBlockChainMessage(chainSummary));
126126
} catch (Exception e) {
127-
logger.error("Peer {} sync failed, reason: {}", peer.getInetAddress(), e);
127+
if (e instanceof P2pException) {
128+
logger.warn("Peer {} sync failed, reason: {}", peer.getInetAddress(), e.getMessage());
129+
} else {
130+
logger.error("Peer {} sync failed.", peer.getInetAddress(), e);
131+
}
128132
peer.disconnect(ReasonCode.SYNC_FAIL);
129133
}
130134
}

framework/src/test/java/org/tron/core/net/services/SyncServiceTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.springframework.context.ApplicationContext;
2020
import org.tron.common.application.TronApplicationContext;
2121
import org.tron.common.utils.ReflectUtils;
22+
import org.tron.common.utils.Sha256Hash;
2223
import org.tron.core.Constant;
2324
import org.tron.core.capsule.BlockCapsule;
2425
import org.tron.core.config.DefaultConfig;
@@ -91,6 +92,13 @@ public void testStartSync() {
9192

9293
ReflectUtils.setFieldValue(peer, "tronState", TronState.INIT);
9394

95+
try {
96+
peer.setBlockBothHave(new BlockCapsule.BlockId(Sha256Hash.ZERO_HASH, -1));
97+
service.syncNext(peer);
98+
} catch (Exception e) {
99+
// no need to deal with
100+
}
101+
94102
service.startSync(peer);
95103
} catch (Exception e) {
96104
// no need to deal with

0 commit comments

Comments
 (0)