-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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): fix failure to process FETCH_INV_DATA message #5460
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,11 +41,11 @@ | |
@Slf4j(topic = "net") | ||
@Component | ||
public class AdvService { | ||
|
||
private final int MAX_INV_TO_FETCH_CACHE_SIZE = 100_000; | ||
private final int MAX_TRX_CACHE_SIZE = 50_000; | ||
private final int MAX_BLOCK_CACHE_SIZE = 10; | ||
private final int MAX_SPREAD_SIZE = 1_000; | ||
private final long TIMEOUT = MSG_CACHE_DURATION_IN_BLOCKS * BLOCK_PRODUCED_INTERVAL; | ||
|
||
@Autowired | ||
private TronNetDelegate tronNetDelegate; | ||
|
@@ -264,13 +264,12 @@ private void consumerInvToFetch() { | |
Collection<PeerConnection> peers = tronNetDelegate.getActivePeer().stream() | ||
.filter(peer -> peer.isIdle()) | ||
.collect(Collectors.toList()); | ||
|
||
InvSender invSender = new InvSender(); | ||
long now = System.currentTimeMillis(); | ||
synchronized (this) { | ||
if (invToFetch.isEmpty() || peers.isEmpty()) { | ||
return; | ||
} | ||
long now = System.currentTimeMillis(); | ||
invToFetch.forEach((item, time) -> { | ||
if (time < now - MSG_CACHE_DURATION_IN_BLOCKS * BLOCK_PRODUCED_INTERVAL) { | ||
logger.info("This obj is too late to fetch, type: {} hash: {}", item.getType(), | ||
|
@@ -279,15 +278,16 @@ private void consumerInvToFetch() { | |
invToFetchCache.invalidate(item); | ||
return; | ||
} | ||
peers.stream().filter(peer -> peer.getAdvInvReceive().getIfPresent(item) != null | ||
&& invSender.getSize(peer) < MAX_TRX_FETCH_PER_PEER) | ||
.sorted(Comparator.comparingInt(peer -> invSender.getSize(peer))) | ||
.findFirst().ifPresent(peer -> { | ||
if (peer.checkAndPutAdvInvRequest(item, now)) { | ||
invSender.add(item, peer); | ||
} | ||
invToFetch.remove(item); | ||
}); | ||
peers.stream().filter(peer -> { | ||
Long t = peer.getAdvInvReceive().getIfPresent(item); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not the same, times from different caches There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you're right. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
if time >= now - TIMEOUT, |
||
return t != null && now - t < TIMEOUT && invSender.getSize(peer) < MAX_TRX_FETCH_PER_PEER; | ||
}).sorted(Comparator.comparingInt(peer -> invSender.getSize(peer))) | ||
.findFirst().ifPresent(peer -> { | ||
if (peer.checkAndPutAdvInvRequest(item, now)) { | ||
invSender.add(item, peer); | ||
} | ||
invToFetch.remove(item); | ||
}); | ||
}); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't
MSG_CACHE_DURATION_IN_BLOCKS * BLOCK_PRODUCED_INTERVAL
be replaced withTIMEOUT
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1