-
Notifications
You must be signed in to change notification settings - Fork 891
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
Fix get logs patch 2 #1381
Fix get logs patch 2 #1381
Conversation
be61973
to
04739bb
Compare
Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
71bb9b6
to
50a21b3
Compare
Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
final Optional<Long> ancestorBlockNumber = | ||
commonAncestorBlockHeader.map(ProcessableBlockHeader::getNumber); | ||
if (ancestorBlockNumber.isPresent()) { | ||
// walk through the blocks from the common ancestor to the received block in order to | ||
// reload the cache in case of reorg | ||
for (long number = ancestorBlockNumber.get() + 1; | ||
number < blockHeader.getNumber(); | ||
number++) { | ||
Optional<BlockHeader> ancestorBlockHeader = blockchain.getBlockHeader(number); | ||
if (ancestorBlockHeader.isPresent()) { | ||
cacheSingleBlock(ancestorBlockHeader.get(), cacheFile); | ||
} | ||
} | ||
} |
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.
nit: Feels a bit weird to use .map
and then .isPresent
here. Would be worth considering using .ifPresent
:
final Optional<Long> ancestorBlockNumber = | |
commonAncestorBlockHeader.map(ProcessableBlockHeader::getNumber); | |
if (ancestorBlockNumber.isPresent()) { | |
// walk through the blocks from the common ancestor to the received block in order to | |
// reload the cache in case of reorg | |
for (long number = ancestorBlockNumber.get() + 1; | |
number < blockHeader.getNumber(); | |
number++) { | |
Optional<BlockHeader> ancestorBlockHeader = blockchain.getBlockHeader(number); | |
if (ancestorBlockHeader.isPresent()) { | |
cacheSingleBlock(ancestorBlockHeader.get(), cacheFile); | |
} | |
} | |
} | |
commonAncestorBlockHeader | |
.map(ProcessableBlockHeader::getNumber) | |
.ifPresent(ancestorBlockNumber -> { | |
// walk through the blocks from the common ancestor to the received block in order to | |
// reload the cache in case of reorg | |
for (long number = ancestorBlockNumber.get() + 1; | |
number < blockHeader.getNumber(); | |
number++) { | |
blockchain.getBlockHeader(number).ifPresent( | |
header -> cacheSingleBlock(ancestorBlockHeader.get(), cacheFile)); | |
} | |
}); |
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.
Also, this isn't removing logs from the cache correctly when a reorg makes the chain shorter. It needs to delete all cache entries between the new chain head number and the old one if the new head number is less.
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.
Actually, if this index is only used as the initial filter, you wouldn't need to remove the later blocks when a reorg makes the chain shorter - you'd potentially check the blocks in this range when you didn't need to but it would just be treated as a false positive and sorted out once you're pulling logs out of the actual blocks.
In that case I think this should work. Will deploy it and test it out.
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.
in fact in case of a shorter reorg the cache will be truncated the first time cacheSingleBlock is used. this is why I did not add anything else here.
Line 184 in be89cd9
final long validCacheSize = offset + BLOOM_BITS_LENGTH; |
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.
I always use ifpresent but in this case cacheSingleBlock can throw an exception and there is a catch here. if I use ifPresent I should put 2 catch with the same implementation. this is the main reason for using isPresent 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.
LGTM. I'd strongly recommend updating the cache version again though - those who skip release to release still only reindex once, but anyone who updated to the snapshot reindexes again to fix the log cache. So helps some people with no down side.
ok you convinced me I will update the version |
Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
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.
Looks good to me.
Signed-off-by: Karim TAAM karim.t2am@gmail.com
PR description
LogBloom could be invalid in the cache after a reorg. With this PR, there is an update of the cache every time a reorg takes place
Test performed
Changelog