I'm lurking through code that tries to sync blocks with other peer. I mean thread started at line ~4463 (I call it "loading thread").
It requests "getMilestoneBlockIds". Peer process this request with code
int jumpLength = block.height * 4 / 1461 + 1;
while (block.height > 0) {
milestoneBlockIds.add(convert(block.getId()));
for (int i = 0; i < jumpLength && block.height > 0; i++) {
block = blocks.get(block.previousBlock);
}
}
If I not fail with elementary math, this code returns about four blockIds for one day. So day by day this request moves more and more bytes through network.
What for?
Note: list is in descending order, first block in list is last block in blockchain.
Take a look back to loading thread code.
for (int i = 0; i < milestoneBlockIds.size(); i++) {
long blockId = (new BigInteger((String)milestoneBlockIds.get(i))).longValue();
Block block = blocks.get(blockId);
if (block != null) {
commonBlockId = blockId;
break;
}
}
This code executes only if peer has higher cumulative difficulty, so it's last block never match with our's. So even if we're not in forked chain, common block will be about six hour ago. Or about 360 blocks ago.
So next request to peer will be "getNextBlockIds", which submissivelly returns about 360 blockIds. Many bytes! If we're not in forked chain, chances are very high that only one or two last ids are interesting for us.
But what if we're forked too deep? Take a look at this check:
if (Block.getLastBlock().height - blocks.get(commonBlockId).height < 720)
We're not interested in very low common block anyway!
If my assumptions are correct (and I no failed in elementary math), it's better to:
1. Limit "getMilestoneBlockIds" request with sending lower height of common block.
2. Send 1st, 2nd, 4th, 8th and so on blockIds from the top down to lower height, in response to this request. Or use some other principle, but assume that latest blocks are more wanted most times.
Am I miss something?