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

fix(net): solve 'no need sync' issue reported by nodes #4996

Merged
merged 2 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public void processMessage(PeerConnection peer, TronMessage msg) throws P2pExcep

check(peer, chainInventoryMessage);

peer.setFetchAble(false);

peer.setNeedSyncFromPeer(true);

peer.setSyncChainRequested(null);
Expand Down Expand Up @@ -78,10 +80,12 @@ public void processMessage(PeerConnection peer, TronMessage msg) throws P2pExcep
} catch (NoSuchElementException e) {
logger.warn("Process ChainInventoryMessage failed, peer {}, isDisconnect:{}",
peer.getInetAddress(), peer.isDisconnect());
peer.setFetchAble(true);
return;
}
}

peer.setFetchAble(true);
if ((chainInventoryMessage.getRemainNum() == 0 && !peer.getSyncBlockToFetch().isEmpty())
|| (chainInventoryMessage.getRemainNum() != 0
&& peer.getSyncBlockToFetch().size() > NetConstants.SYNC_FETCH_BATCH_NUM)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public class PeerConnection {
@Setter
private volatile boolean isRelayPeer;

@Setter
@Getter
private volatile boolean fetchAble;

@Getter
@Setter
private ByteString address;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public class SyncService {
private Map<BlockMessage, PeerConnection> blockJustReceived = new ConcurrentHashMap<>();

private long blockCacheTimeout = Args.getInstance().getBlockCacheTimeout();
private Cache<BlockId, PeerConnection> requestBlockIds = CacheBuilder.newBuilder().maximumSize(10_000)
private Cache<BlockId, PeerConnection> requestBlockIds = CacheBuilder.newBuilder()
.maximumSize(10_000)
.expireAfterWrite(blockCacheTimeout, TimeUnit.MINUTES).initialCapacity(10_000)
.recordStats().build();

Expand Down Expand Up @@ -206,6 +207,7 @@ private void startFetchSyncBlock() {
HashMap<PeerConnection, List<BlockId>> send = new HashMap<>();
tronNetDelegate.getActivePeer().stream()
.filter(peer -> peer.isNeedSyncFromPeer() && peer.isIdle())
.filter(peer -> peer.isFetchAble())
.forEach(peer -> {
if (!send.containsKey(peer)) {
send.put(peer, new LinkedList<>());
Expand Down