Skip to content
Merged
Changes from 1 commit
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 @@ -50,7 +50,7 @@ public class SyncService {
private Map<BlockMessage, PeerConnection> blockJustReceived = new ConcurrentHashMap<>();

private long blockCacheTimeout = Args.getInstance().getBlockCacheTimeout();
private Cache<BlockId, Long> 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 @@ -138,13 +138,16 @@ public void processBlock(PeerConnection peer, BlockMessage blockMessage) {

public void onDisconnect(PeerConnection peer) {
if (!peer.getSyncBlockRequested().isEmpty()) {
peer.getSyncBlockRequested().keySet().forEach(blockId -> invalid(blockId));
peer.getSyncBlockRequested().keySet().forEach(blockId -> invalid(blockId, peer));
}
}

private void invalid(BlockId blockId) {
requestBlockIds.invalidate(blockId);
fetchFlag = true;
private void invalid(BlockId blockId, PeerConnection peerConnection) {
PeerConnection p = requestBlockIds.getIfPresent(blockId);
if (peerConnection.equals(p)) {
requestBlockIds.invalidate(blockId);
fetchFlag = true;
}
}

private LinkedList<BlockId> getBlockChainSummary(PeerConnection peer) throws P2pException {
Expand Down Expand Up @@ -209,7 +212,7 @@ private void startFetchSyncBlock() {
}
for (BlockId blockId : peer.getSyncBlockToFetch()) {
if (requestBlockIds.getIfPresent(blockId) == null) {
requestBlockIds.put(blockId, System.currentTimeMillis());
requestBlockIds.put(blockId, peer);
peer.getSyncBlockRequested().put(blockId, System.currentTimeMillis());
send.get(peer).add(blockId);
if (send.get(peer).size() >= MAX_BLOCK_FETCH_PER_PEER) {
Expand Down Expand Up @@ -243,7 +246,7 @@ private synchronized void handleSyncBlock() {
synchronized (tronNetDelegate.getBlockLock()) {
if (peerConnection.isDisconnect()) {
blockWaitToProcess.remove(msg);
invalid(msg.getBlockId());
invalid(msg.getBlockId(), peerConnection);
return;
}
final boolean[] isFound = {false};
Expand Down