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): optimize fetch inventory message processing logic #5895

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

zeusoo001
Copy link
Contributor

@zeusoo001 zeusoo001 commented Jul 1, 2024

What does this PR do?
Optimize fetch inventory message processing logic.

Why are these changes required?

This PR has been tested by:

  • Unit Tests
  • Manual Testing

Follow up

Extra details

@zeusoo001 zeusoo001 changed the title feat(net): optimize fetch inventory message broadcast processing logic feat(net): optimize fetch inventory message processing logic Jul 1, 2024
return true;
}
for (Sha256Hash hash : msg.getHashList()) {
if (peer.getAdvInvSpread().getIfPresent(new Item(hash, InventoryType.BLOCK)) == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

多次请求 BLOCK 仅是 isAdvInv 方法返回 false,并不会导致 check 方法失败吧?

Copy link
Contributor

@xxo1shine xxo1shine Jul 10, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants