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): fix failure to process FETCH_INV_DATA message #5460

Merged
merged 2 commits into from
Sep 8, 2023
Merged
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 @@ -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;
Expand Down Expand Up @@ -264,30 +264,30 @@ 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) {
if (time < now - TIMEOUT) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an assumption: no more than 2w transactions will be broadcast within 15s?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At present, it is basically impossible to reach 20,000 within 15 seconds. We only focus on time and not TPS.

logger.info("This obj is too late to fetch, type: {} hash: {}", item.getType(),
item.getHash());
invToFetch.remove(item);
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t(L282) and time(L274) isn't that close to the same?

image image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not the same, times from different caches

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

math.abs(t-time) is very close to 0. Am I getting this right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

math.abs(t-time) is very close to 0

if time >= now - TIMEOUT, now - t < TIMEOUT when is it false?

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);
});
});
}

Expand Down