feat(net) : optimize the isIdle method by zeusoo001 · Pull Request #5921 · tronprotocol/java-tron
What does this PR do?
Optimize the isIdle method. refer to issue #5913
Why are these changes required?
During the block synchronization process, if the broadcast list has not been received, the synchronization may fail. The detailed process is as follows:
- After processing the
chain inventorymessage, setfetchFlagto true. - The scheduler will execute the
startFetchSyncBlockmethod to fetch the block, and at this time,fetchFlagwill be set to false.
etchExecutor.scheduleWithFixedDelay(() -> {
try {
if (fetchFlag) {
fetchFlag = false;
startFetchSyncBlock();
}
} catch (Exception e) {
logger.error("Fetch sync block error", e);
}
}, 10, 1, TimeUnit.SECONDS);
- Since
advInvRequestis not empty at this time,peer.isIdle()returns false, so after this scheduling, the block is not obtained, butfetchFlagis set to false and cannot be set back, so the block cannot be obtained later.
private void startFetchSyncBlock() {
HashMap<PeerConnection, List<BlockId>> send = new HashMap<>();
tronNetDelegate.getActivePeer().stream()
.filter(peer -> peer.isNeedSyncFromPeer() && peer.isIdle())
.filter(peer -> peer.isFetchAble())
- Since the block is not obtained, the peer status cannot be updated, the status check will fail, and the connection will be disconnected.
This PR has been tested by:
- Unit Tests
- Manual Testing
Follow up
Extra details