Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(net) : optimize the isIdle method #5921

Merged
merged 2 commits into from
Jul 23, 2024

Conversation

zeusoo001
Copy link
Contributor

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:

  1. After processing the chain inventory message, set fetchFlag to true.
  2. The scheduler will execute the startFetchSyncBlock method to fetch the block, and at this time, fetchFlag will 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);
  1. Since advInvRequest is not empty at this time, peer.isIdle() returns false, so after this scheduling, the block is not obtained, but fetchFlag is 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())
  1. 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

@lvs007 lvs007 linked an issue Jul 18, 2024 that may be closed by this pull request
@lvs007 lvs007 merged commit afc3979 into tronprotocol:release_v4.7.6 Jul 23, 2024
5 checks passed
@zeusoo001 zeusoo001 deleted the f-isidle-method-opt branch August 13, 2024 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Timeout occurred when synchronizing blocks
4 participants