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

[WIP] Missing Blocks #25

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion crates/db/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum BlockFilter {

impl Client {
/// Returns the slot number of blocks which we have indexed
pub fn indexed_blocks(
pub fn indexed_slots(
self,
conn: &mut PgConnection,
block_table_choice: BlockTableChoice,
Expand All @@ -47,6 +47,31 @@ impl Client {

Ok(numbers)
}
/// Returns the slot number of blocks which we have indexed
pub fn indexed_blocks(
self,
conn: &mut PgConnection,
block_table_choice: BlockTableChoice,
) -> anyhow::Result<Vec<i64>> {
let numbers: Vec<i64> = match block_table_choice {
BlockTableChoice::Blocks => {
use super::schema::blocks::dsl::{self, blocks};
blocks
.select(dsl::number)
.get_results(conn)
.with_context(|| "failed to select block numbers")?
}
BlockTableChoice::Blocks2 => {
use super::schema::blocks_2::dsl::{self, blocks_2};
blocks_2
.select(dsl::number)
.get_results(conn)
.with_context(|| "failed to select block numbers")?
}
};

Ok(numbers)
}
/// Returns up to `limit` blocks which do not have the slot column set
pub fn slot_is_null(
self,
Expand Down
24 changes: 12 additions & 12 deletions crates/db/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,22 @@ fn test_blocks() {
assert_eq!(res.len(), 1);
}
// check that setting slot by default worked
let indexed_blocks: HashSet<i64> = client
.indexed_blocks(&mut db_conn, BlockTableChoice::Blocks)
let indexed_slots: HashSet<i64> = client
.indexed_slots(&mut db_conn, BlockTableChoice::Blocks)
.unwrap()
.into_iter()
.filter_map(|block| Some(block?))
.collect();
let mut expected_set = (2..101).into_iter().collect::<HashSet<i64>>();
assert_eq!(expected_set, indexed_blocks);
assert_eq!(expected_set, indexed_slots);
// check that setting slot by default worked
let indexed_blocks: HashSet<i64> = client
.indexed_blocks(&mut db_conn, BlockTableChoice::Blocks2)
let indexed_slots: HashSet<i64> = client
.indexed_slots(&mut db_conn, BlockTableChoice::Blocks2)
.unwrap()
.into_iter()
.filter_map(|block| Some(block?))
.collect();
assert_eq!(expected_set, indexed_blocks);
assert_eq!(expected_set, indexed_slots);

// update slot number for blocks which are missing it
for i in 200..300 {
Expand Down Expand Up @@ -148,21 +148,21 @@ fn test_blocks() {
assert_ne!(block2[0].slot, block[0].slot);
assert_eq!(block2[0].data, block[0].data);
}
let indexed_blocks: HashSet<i64> = client
.indexed_blocks(&mut db_conn, BlockTableChoice::Blocks)
let indexed_slots: HashSet<i64> = client
.indexed_slots(&mut db_conn, BlockTableChoice::Blocks)
.unwrap()
.into_iter()
.filter_map(|block| Some(block?))
.collect();
expected_set.extend((201..301).into_iter().collect::<HashSet<i64>>());
assert_eq!(expected_set, indexed_blocks);
let indexed_blocks: HashSet<i64> = client
.indexed_blocks(&mut db_conn, BlockTableChoice::Blocks2)
assert_eq!(expected_set, indexed_slots);
let indexed_slots: HashSet<i64> = client
.indexed_slots(&mut db_conn, BlockTableChoice::Blocks2)
.unwrap()
.into_iter()
.filter_map(|block| Some(block?))
.collect();
assert_eq!(expected_set, indexed_blocks);
assert_eq!(expected_set, indexed_slots);

// now test the edge case where block_number == slot number and slot number is not null
for i in 1000..1500 {
Expand Down
Loading