Skip to content

Commit

Permalink
Remove get_block_interval_without_block_range_root
Browse files Browse the repository at this point in the history
As it's supersed by `get_highest_block_range`, this means that we can
also remove the whole query behind it.
  • Loading branch information
Alenar committed Jul 15, 2024
1 parent dfb7854 commit 0056172
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 248 deletions.

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::*;
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ use mithril_common::StdResult;

use crate::database::query::{
DeleteBlockRangeRootQuery, DeleteCardanoTransactionQuery, GetBlockRangeRootQuery,
GetCardanoTransactionQuery, GetIntervalWithoutBlockRangeRootQuery, InsertBlockRangeRootQuery,
InsertCardanoTransactionQuery,
GetCardanoTransactionQuery, InsertBlockRangeRootQuery, InsertCardanoTransactionQuery,
};
use crate::database::record::{BlockRangeRootRecord, CardanoTransactionRecord};
use crate::sqlite::{ConnectionExtensions, SqliteConnection, SqliteConnectionPool};
Expand Down Expand Up @@ -235,22 +234,6 @@ impl CardanoTransactionRepository {
Ok(())
}

/// Get the block interval without block range root if any.
pub async fn get_block_interval_without_block_range_root(
&self,
) -> StdResult<Option<Range<BlockNumber>>> {
let interval = self
.connection_pool
.connection()?
.fetch_first(GetIntervalWithoutBlockRangeRootQuery::new())?
// Should be impossible - the request as written in the query always returns a single row
.unwrap_or_else(|| {
panic!("GetIntervalWithoutBlockRangeRootQuery should always return a single row")
});

interval.to_range()
}

/// Get the block number for a given slot number
pub async fn get_block_number_by_slot_number(
&self,
Expand Down Expand Up @@ -761,41 +744,6 @@ mod tests {
}
}

#[tokio::test]
async fn repository_get_block_interval_without_block_range_root() {
let connection = cardano_tx_db_connection().unwrap();
let repository = CardanoTransactionRepository::new(Arc::new(
SqliteConnectionPool::build_from_connection(connection),
));

// The last block range give the lower bound
let last_block_range = BlockRange::from_block_number(0);
repository
.create_block_range_roots(vec![(
last_block_range.clone(),
MKTreeNode::from_hex("AAAA").unwrap(),
)])
.await
.unwrap();

// The last transaction block number give the upper bound
let last_transaction_block_number = BlockRange::LENGTH * 4;
repository
.create_transaction("tx-1", last_transaction_block_number, 50, "block-1", 99)
.await
.unwrap();

let interval = repository
.get_block_interval_without_block_range_root()
.await
.unwrap();

assert_eq!(
Some(last_block_range.end..(last_transaction_block_number + 1)),
interval
);
}

#[tokio::test]
async fn repository_get_transactions_by_block_ranges() {
let connection = cardano_tx_db_connection().unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ impl TransactionStore for CardanoTransactionRepository {
self.store_transactions(transactions).await
}

async fn get_block_interval_without_block_range_root(
&self,
) -> StdResult<Option<Range<BlockNumber>>> {
self.get_block_interval_without_block_range_root().await
}

async fn get_transactions_in_range(
&self,
range: Range<BlockNumber>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ pub trait TransactionStore: Send + Sync {
/// Store list of transactions
async fn store_transactions(&self, transactions: Vec<CardanoTransaction>) -> StdResult<()>;

/// Get the interval of blocks whose merkle root has yet to be computed
async fn get_block_interval_without_block_range_root(
&self,
) -> StdResult<Option<Range<BlockNumber>>>;

/// Get transactions in an interval of blocks
async fn get_transactions_in_range(
&self,
Expand Down

0 comments on commit 0056172

Please sign in to comment.