Skip to content

Commit

Permalink
Merge pull request #1820 from input-output-hk/djo/1785/last_tx_not_pr…
Browse files Browse the repository at this point in the history
…oved

Bugfix: Block range computation ignored last block range & last block range if it finished with empty blocks
  • Loading branch information
Alenar committed Jul 16, 2024
2 parents 702e519 + 73f7be8 commit ae12eb6
Show file tree
Hide file tree
Showing 17 changed files with 356 additions and 380 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/mithril-persistence/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-persistence"
version = "0.2.16"
version = "0.2.17"
description = "Common types, interfaces, and utilities to persist data for Mithril nodes."
authors = { workspace = true }
edition = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ impl GetBlockRangeRootQuery {
condition: WhereCondition::new("start < ?*", vec![Value::Integer(block_number as i64)]),
}
}

pub fn highest() -> Self {
Self {
condition: WhereCondition::new("end = (select max(end) from block_range_root)", vec![]),
}
}
}

impl Query for GetBlockRangeRootQuery {
Expand Down Expand Up @@ -134,4 +140,26 @@ mod tests {

assert_eq!(dataset, cursor);
}

#[test]
fn test_get_highest_with_empty_db() {
let connection = cardano_tx_db_connection().unwrap();

let cursor: Option<BlockRangeRootRecord> = connection
.fetch_first(GetBlockRangeRootQuery::highest())
.unwrap();
assert_eq!(None, cursor);
}

#[test]
fn test_get_highest() {
let connection = cardano_tx_db_connection().unwrap();
let dataset = block_range_root_dataset();
insert_block_range_roots(&connection, dataset.clone());

let cursor: Option<BlockRangeRootRecord> = connection
.fetch_first(GetBlockRangeRootQuery::highest())
.unwrap();
assert_eq!(dataset.last().cloned(), cursor);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
mod delete_block_range_root;
mod get_block_range_root;
mod get_interval_without_block_range;
mod insert_block_range;

pub use delete_block_range_root::*;
pub use get_block_range_root::*;
pub use get_interval_without_block_range::*;
pub use insert_block_range::*;

#[cfg(test)]
Expand Down

This file was deleted.

2 changes: 0 additions & 2 deletions internal/mithril-persistence/src/database/record/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

mod block_range_root;
mod cardano_transaction;
mod interval_without_block_range_root;

pub use block_range_root::*;
pub use cardano_transaction::*;
pub use interval_without_block_range_root::*;
Loading

0 comments on commit ae12eb6

Please sign in to comment.