-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat(net): optimize fetch inventory message processing logic #5895
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
base: release_v4.8.1
Are you sure you want to change the base?
Conversation
return true; | ||
} | ||
for (Sha256Hash hash : msg.getHashList()) { | ||
if (peer.getAdvInvSpread().getIfPresent(new Item(hash, InventoryType.BLOCK)) == null) { |
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.
The second request will be treated as synchronous and the check will fail. Refer to the code in the check function.
if (!isAdv) {
if (!peer.isNeedSyncFromUs()) {
throw new P2pException(TypeEnum.BAD_MESSAGE, "no need sync");
}
for (Sha256Hash hash : fetchInvDataMsg.getHashList()) {
long blockNum = new BlockId(hash).getNum();
long minBlockNum =
peer.getLastSyncBlockId().getNum() - 2 * NetConstants.SYNC_FETCH_BATCH_NUM;
if (blockNum < minBlockNum) {
throw new P2pException(TypeEnum.BAD_MESSAGE,
"minBlockNum: " + minBlockNum + ", blockNum: " + blockNum);
}
if (peer.getSyncBlockIdCache().getIfPresent(hash) != null) {
throw new P2pException(TypeEnum.BAD_MESSAGE, new BlockId(hash).getString() + " is exist");
}
peer.getSyncBlockIdCache().put(hash, System.currentTimeMillis());
}
}
Hi! Is there a related issue that explains the background of this PR? Or is this PR still a work in progress? |
The |
What does this PR do?
Optimize fetch inventory message processing logic.
Why are these changes required?
This PR has been tested by:
Follow up
Extra details