-
Notifications
You must be signed in to change notification settings - Fork 1
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: support non consecutive blocks ryhope #425
Open
nicholas-mainardi
wants to merge
26
commits into
generic-extraction-integration-test-mapping-of-mappings
Choose a base branch
from
feat/support_non_consecutive_blocks_ryhope
base: generic-extraction-integration-test-mapping-of-mappings
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
7f610bc
Support non-contiguous block numbers
nicholas-mainardi c59a1e1
fmt + clippy
nicholas-mainardi cc7fd0b
Make current_epoch in EpochStorage trait return error
nicholas-mainardi 72c45e9
fmt
nicholas-mainardi 2bf0658
Fix table name provided to core_index_keys
nicholas-mainardi cf1c60f
Avoid expenmsive JOIN in some queries
nicholas-mainardi cfc65ad
Optimize row cache SQL queries
nicholas-mainardi 652e732
Optimize JOIN wide lineage rows tree + fix eth test
nicholas-mainardi 64a30c9
Address comments
nicholas-mainardi 2d99d5e
Optimize InMemoryEpochMapper + imporve handling of incremental user e…
nicholas-mainardi f5f7db2
Add untracked file
nicholas-mainardi 91191ae
Add maximum size to epoch mapper cache
nicholas-mainardi 869a968
fmt
nicholas-mainardi e548c1e
Improve fetch_many_at
nicholas-mainardi 8b591ab
Address comments
nicholas-mainardi 57c5c10
Add indexes + optimizes bracketer secondary index
nicholas-mainardi 33077f4
fmt
nicholas-mainardi 7ffb465
Fix pidgy_pinguit test
nicholas-mainardi 8eab5b5
Split bracketer queries for performance
nicholas-mainardi ea59525
fmt
nicholas-mainardi 737079d
Improve comments to bracketer secondary index
nicholas-mainardi 1298394
Fix after rebase
nicholas-mainardi 73540da
fmt
nicholas-mainardi cc8326c
Change indexing integration test to support non-consecutive blocks
nicholas-mainardi 2f13f53
Query in integration test compatible with non-conseuctive blocks
nicholas-mainardi 54a23a2
Fix typo in bracketer_primary_index query
nicholas-mainardi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,60 @@ | ||
//! Module to handle the block number as a primary index | ||
use ryhope::tree::{sbbst, TreeTopology}; | ||
|
||
/// The index tree when the primary index is the block number of a blockchain is a sbbst since it | ||
/// is a highly optimized tree for monotonically increasing index. It produces very little | ||
/// tree-manipulating operations on update, and therefore, requires the least amount of reproving | ||
/// when adding a new index. | ||
/// NOTE: when dealing with another type of index, i.e. a general index such as what can happen on | ||
/// a result table, then this tree does not work anymore. | ||
pub type BlockTree = sbbst::Tree; | ||
use anyhow::anyhow; | ||
use ryhope::{ | ||
storage::{pgsql::PgsqlStorage, RoEpochKvStorage}, | ||
tree::{sbbst, TreeTopology}, | ||
MerkleTreeKvDb, | ||
}; | ||
|
||
use crate::query::planner::TreeFetcher; | ||
|
||
use super::index::IndexNode; | ||
|
||
/// The index tree when the primary index is an epoch in a time-series DB, like the block number for a blockchain. | ||
/// It is a sbbst since it is a highly optimized tree for monotonically increasing index. | ||
/// It produces very little tree-manipulating operations on update, and therefore, requires the least amount | ||
/// of reproving when adding a new index. | ||
/// NOTE: it is still required that monotonically increasing indexes are inserted in the tree, | ||
/// i.e. a general index such as what can happen on a result table wouldn't work with this tree. | ||
pub type BlockTree = sbbst::EpochTree; | ||
/// The key used to refer to a table where the block number is the primary index. | ||
pub type BlockTreeKey = <BlockTree as TreeTopology>::Key; | ||
/// Just an alias that give more meaning depending on the context | ||
pub type BlockPrimaryIndex = BlockTreeKey; | ||
|
||
pub type IndexStorage = PgsqlStorage<BlockTree, IndexNode<BlockPrimaryIndex>, false>; | ||
pub type MerkleIndexTree = MerkleTreeKvDb<BlockTree, IndexNode<BlockPrimaryIndex>, IndexStorage>; | ||
|
||
/// Get the previous epoch of `epoch` in `tree` | ||
pub async fn get_previous_epoch( | ||
tree: &MerkleIndexTree, | ||
epoch: BlockPrimaryIndex, | ||
) -> anyhow::Result<Option<BlockPrimaryIndex>> { | ||
let current_epoch = tree.current_epoch().await?; | ||
let epoch_ctx = tree | ||
.node_context(&epoch) | ||
.await? | ||
.ok_or(anyhow!("epoch {epoch} not found in the tree"))?; | ||
|
||
Ok(tree | ||
.get_predecessor(&epoch_ctx, current_epoch) | ||
.await | ||
.map(|(ctx, _)| ctx.node_id)) | ||
} | ||
|
||
/// Get the next epoch of `epoch` in `tree` | ||
pub async fn get_next_epoch( | ||
tree: &MerkleIndexTree, | ||
epoch: BlockPrimaryIndex, | ||
) -> anyhow::Result<Option<BlockPrimaryIndex>> { | ||
let current_epoch = tree.current_epoch().await?; | ||
let epoch_ctx = tree | ||
.node_context(&epoch) | ||
.await? | ||
.ok_or(anyhow!("epoch {epoch} not found in the tree"))?; | ||
|
||
Ok(tree | ||
.get_successor(&epoch_ctx, current_epoch) | ||
.await | ||
.map(|(ctx, _)| ctx.node_id)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Change comments above which is still very much linked to sequential usecase
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.
Done in commit 23affb5