Skip to content

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
@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