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: Implement Block Height Stream #776

Merged
merged 20 commits into from
Jun 14, 2024
Merged

Conversation

darunrs
Copy link
Collaborator

@darunrs darunrs commented Jun 6, 2024

I've implemented a struct which is capable of returning an async stream which yields block heights matching a particular contract filter starting from a specified block height. This should serve as a replacement for the existing method of getting block heights by querying Delta Lake through the Delta Lake Client.

Some differences between Delta Lake and this new stream is that it yields a SINGLE block height rather than all block heights. In addition, we now query the bitmap indexer's tables for block heights for one day, instead of for all days. This should improve time to get a block as well as reduce the memory footprint.

@darunrs darunrs linked an issue Jun 10, 2024 that may be closed by this pull request
@darunrs darunrs force-pushed the block-streamer-blockheight-stream branch from eed39fc to 71d6c59 Compare June 11, 2024 17:19
@darunrs darunrs marked this pull request as ready for review June 11, 2024 17:23
@darunrs darunrs requested a review from a team as a code owner June 11, 2024 17:23
block-streamer/src/bitmap.rs Outdated Show resolved Hide resolved
block-streamer/src/block_height_stream.rs Outdated Show resolved Hide resolved
block-streamer/src/block_height_stream.rs Outdated Show resolved Hide resolved
block-streamer/src/block_height_stream.rs Outdated Show resolved Hide resolved
block-streamer/src/block_height_stream.rs Outdated Show resolved Hide resolved
block-streamer/src/graphql/client.rs Show resolved Hide resolved
block-streamer/src/block_height_stream.rs Outdated Show resolved Hide resolved
block-streamer/src/block_height_stream.rs Outdated Show resolved Hide resolved
@darunrs darunrs requested a review from morgsmccauley June 13, 2024 23:34
Copy link
Collaborator

@morgsmccauley morgsmccauley left a comment

Choose a reason for hiding this comment

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

Good work man :) Looks good overall, just a couple comments

if self.data.get_bit(self.bit_index) {
self.bit_index += 1;
return Some(
self.data.start_block_height + u64::try_from(self.bit_index - 1).ok()?,
Copy link
Collaborator

Choose a reason for hiding this comment

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

In what scenario would we not be able to parse this? Is returning None really the right thing to do here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not just make bit_index u64?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So bit_index needs to be usize to index into the vector. I could still make it u64 but then I need to convert it to usize eventually when doing vector[index]. Converting from usize to u64 shouldn't ever fail anyway as the largest value a bit_index should ever be is 86400 anyway. Even if we change bitmap to index by year, it would be roughly 32 million, which easily fits inside a 32bit uint.

I also agree that returning None is strange. Converting a u64 to usize is "trickier" since usize could be a u32 depending on the architecture. But converting a usize to u64 should never fail and truncate data since most architectures are 64bit anyway. I'll just use the "as" keyword in this instance.

block-streamer/src/bitmap.rs Outdated Show resolved Hide resolved
@@ -1,65 +1,101 @@
use anyhow::anyhow;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great work on this, the separated structs makes this a lot easier to understand :)

block-streamer/src/bitmap.rs Outdated Show resolved Hide resolved
block-streamer/src/bitmap_processor.rs Show resolved Hide resolved
block-streamer/src/bitmap_processor.rs Outdated Show resolved Hide resolved
@darunrs darunrs merged commit 609b7df into main Jun 14, 2024
8 checks passed
@darunrs darunrs deleted the block-streamer-blockheight-stream branch June 14, 2024 15:17
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.

Implement stream which yields block heights given bitmap
2 participants