diff --git a/src/data_source/extension.rs b/src/data_source/extension.rs index 6831930c6..7477f0ede 100644 --- a/src/data_source/extension.rs +++ b/src/data_source/extension.rs @@ -119,11 +119,13 @@ where D: VersionedDataSource + Send, U: Send + Sync, { - type Transaction<'a> = D::Transaction<'a> + type Transaction<'a> + = D::Transaction<'a> where Self: 'a; - type ReadOnly<'a> = D::ReadOnly<'a> + type ReadOnly<'a> + = D::ReadOnly<'a> where Self: 'a; @@ -144,22 +146,28 @@ where Types: NodeType, Payload: QueryablePayload, { - type LeafRange = D::LeafRange + type LeafRange + = D::LeafRange where R: RangeBounds + Send; - type BlockRange = D::BlockRange + type BlockRange + = D::BlockRange where R: RangeBounds + Send; - type PayloadRange = D::PayloadRange + type PayloadRange + = D::PayloadRange where R: RangeBounds + Send; - type PayloadMetadataRange = D::PayloadMetadataRange + type PayloadMetadataRange + = D::PayloadMetadataRange where R: RangeBounds + Send; - type VidCommonRange = D::VidCommonRange + type VidCommonRange + = D::VidCommonRange where R: RangeBounds + Send; - type VidCommonMetadataRange = D::VidCommonMetadataRange + type VidCommonMetadataRange + = D::VidCommonMetadataRange where R: RangeBounds + Send; diff --git a/src/data_source/fetching.rs b/src/data_source/fetching.rs index bac7ee287..274110a11 100644 --- a/src/data_source/fetching.rs +++ b/src/data_source/fetching.rs @@ -560,22 +560,28 @@ where for<'a> S::ReadOnly<'a>: AvailabilityStorage + NodeStorage + PrunedHeightStorage, P: AvailabilityProvider, { - type LeafRange = BoxStream<'static, Fetch>> + type LeafRange + = BoxStream<'static, Fetch>> where R: RangeBounds + Send; - type BlockRange = BoxStream<'static, Fetch>> + type BlockRange + = BoxStream<'static, Fetch>> where R: RangeBounds + Send; - type PayloadRange = BoxStream<'static, Fetch>> + type PayloadRange + = BoxStream<'static, Fetch>> where R: RangeBounds + Send; - type PayloadMetadataRange = BoxStream<'static, Fetch>> + type PayloadMetadataRange + = BoxStream<'static, Fetch>> where R: RangeBounds + Send; - type VidCommonRange = BoxStream<'static, Fetch>> + type VidCommonRange + = BoxStream<'static, Fetch>> where R: RangeBounds + Send; - type VidCommonMetadataRange = BoxStream<'static, Fetch>> + type VidCommonMetadataRange + = BoxStream<'static, Fetch>> where R: RangeBounds + Send; @@ -715,10 +721,12 @@ where S: VersionedDataSource + Send + Sync, P: Send + Sync, { - type Transaction<'a> = S::Transaction<'a> + type Transaction<'a> + = S::Transaction<'a> where Self: 'a; - type ReadOnly<'a> = S::ReadOnly<'a> + type ReadOnly<'a> + = S::ReadOnly<'a> where Self: 'a; @@ -761,10 +769,12 @@ where S: VersionedDataSource + Send + Sync, P: Send + Sync, { - type Transaction<'a> = S::Transaction<'a> + type Transaction<'a> + = S::Transaction<'a> where Self: 'a; - type ReadOnly<'a> = S::ReadOnly<'a> + type ReadOnly<'a> + = S::ReadOnly<'a> where Self: 'a; diff --git a/src/data_source/storage/fail_storage.rs b/src/data_source/storage/fail_storage.rs index 7677927ee..d9f58c5f5 100644 --- a/src/data_source/storage/fail_storage.rs +++ b/src/data_source/storage/fail_storage.rs @@ -205,10 +205,12 @@ impl VersionedDataSource for FailStorage where S: VersionedDataSource, { - type Transaction<'a> = Transaction> + type Transaction<'a> + = Transaction> where Self: 'a; - type ReadOnly<'a> = Transaction> + type ReadOnly<'a> + = Transaction> where Self: 'a; diff --git a/src/data_source/storage/fs.rs b/src/data_source/storage/fs.rs index 9dc1d23b5..cd90be83a 100644 --- a/src/data_source/storage/fs.rs +++ b/src/data_source/storage/fs.rs @@ -281,7 +281,7 @@ pub trait Revert { fn revert(&mut self); } -impl<'a, Types> Revert for RwLockWriteGuard<'a, FileSystemStorageInner> +impl Revert for RwLockWriteGuard<'_, FileSystemStorageInner> where Types: NodeType, Payload: QueryablePayload, @@ -293,7 +293,7 @@ where } } -impl<'a, Types> Revert for RwLockReadGuard<'a, FileSystemStorageInner> +impl Revert for RwLockReadGuard<'_, FileSystemStorageInner> where Types: NodeType, Payload: QueryablePayload, @@ -357,10 +357,12 @@ impl VersionedDataSource for FileSystemStorage where Payload: QueryablePayload, { - type Transaction<'a> = Transaction>> + type Transaction<'a> + = Transaction>> where Self: 'a; - type ReadOnly<'a> = Transaction>> + type ReadOnly<'a> + = Transaction>> where Self: 'a; diff --git a/src/data_source/storage/ledger_log.rs b/src/data_source/storage/ledger_log.rs index bbacaf368..0d171f732 100644 --- a/src/data_source/storage/ledger_log.rs +++ b/src/data_source/storage/ledger_log.rs @@ -71,13 +71,7 @@ impl LedgerLog { let len = store.iter().len(); tracing::info!("loading LedgerLog {}, len={}", file_pattern, len); - let cache_start = if len > cache_size { - len - cache_size - } else { - // If the cache is large enough to contain every object in storage, we start it at index - // 0 so that it does. - 0 - }; + let cache_start = len.saturating_sub(cache_size); let mut missing = 0; let mut cache = store .iter() @@ -220,7 +214,7 @@ pub struct Iter<'a, T: Serialize + DeserializeOwned> { store: append_log::Iter<'a, BincodeLoadStore>>, } -impl<'a, T: Serialize + DeserializeOwned + Clone> Iterator for Iter<'a, T> { +impl Iterator for Iter<'_, T> { type Item = Option; fn next(&mut self) -> Option { @@ -264,7 +258,7 @@ impl<'a, T: Serialize + DeserializeOwned + Clone> Iterator for Iter<'a, T> { } } -impl<'a, T: Serialize + DeserializeOwned + Clone> ExactSizeIterator for Iter<'a, T> {} +impl ExactSizeIterator for Iter<'_, T> {} #[cfg(test)] mod test { diff --git a/src/data_source/storage/no_storage.rs b/src/data_source/storage/no_storage.rs index 49c1064aa..6c4c42f8e 100644 --- a/src/data_source/storage/no_storage.rs +++ b/src/data_source/storage/no_storage.rs @@ -56,10 +56,12 @@ pub struct Transaction<'a> { } impl VersionedDataSource for NoStorage { - type Transaction<'a> = Transaction<'a> + type Transaction<'a> + = Transaction<'a> where Self: 'a; - type ReadOnly<'a> = Transaction<'a> + type ReadOnly<'a> + = Transaction<'a> where Self: 'a; @@ -97,7 +99,7 @@ impl PrunerConfig for NoStorage {} impl PruneStorage for NoStorage { type Pruner = (); } -impl<'a> PrunedHeightStorage for Transaction<'a> {} +impl PrunedHeightStorage for Transaction<'_> {} impl HasMetrics for NoStorage { fn metrics(&self) -> &PrometheusMetrics { @@ -106,7 +108,7 @@ impl HasMetrics for NoStorage { } #[async_trait] -impl<'a, Types: NodeType> AvailabilityStorage for Transaction<'a> +impl AvailabilityStorage for Transaction<'_> where Payload: QueryablePayload, { @@ -240,7 +242,7 @@ where } #[async_trait] -impl<'a, Types: NodeType> NodeStorage for Transaction<'a> +impl NodeStorage for Transaction<'_> where Payload: QueryablePayload, { @@ -462,10 +464,12 @@ pub mod testing { // Now a lot of boilerplate to implement all teh traits for [`DataSource`], by dispatching each // method to either variant. impl VersionedDataSource for DataSource { - type Transaction<'a> = Transaction<'a, ::Transaction<'a>> + type Transaction<'a> + = Transaction<'a, ::Transaction<'a>> where Self: 'a; - type ReadOnly<'a> = Transaction<'a, ::ReadOnly<'a>> + type ReadOnly<'a> + = Transaction<'a, ::ReadOnly<'a>> where Self: 'a; @@ -554,22 +558,28 @@ pub mod testing { #[async_trait] impl AvailabilityDataSource for DataSource { - type LeafRange = BoxStream<'static, Fetch>> + type LeafRange + = BoxStream<'static, Fetch>> where R: RangeBounds + Send; - type BlockRange = BoxStream<'static, Fetch>> + type BlockRange + = BoxStream<'static, Fetch>> where R: RangeBounds + Send; - type PayloadRange = BoxStream<'static, Fetch>> + type PayloadRange + = BoxStream<'static, Fetch>> where R: RangeBounds + Send; - type PayloadMetadataRange = BoxStream<'static, Fetch>> + type PayloadMetadataRange + = BoxStream<'static, Fetch>> where R: RangeBounds + Send; - type VidCommonRange = BoxStream<'static, Fetch>> + type VidCommonRange + = BoxStream<'static, Fetch>> where R: RangeBounds + Send; - type VidCommonMetadataRange = BoxStream<'static, Fetch>> + type VidCommonMetadataRange + = BoxStream<'static, Fetch>> where R: RangeBounds + Send; @@ -720,7 +730,7 @@ pub mod testing { } #[async_trait] - impl<'a, T> NodeStorage for Transaction<'a, T> + impl NodeStorage for Transaction<'_, T> where T: NodeStorage + Send, { diff --git a/src/data_source/storage/sql.rs b/src/data_source/storage/sql.rs index d1723709d..0a0e025aa 100644 --- a/src/data_source/storage/sql.rs +++ b/src/data_source/storage/sql.rs @@ -777,10 +777,12 @@ impl PruneStorage for SqlStorage { } impl VersionedDataSource for SqlStorage { - type Transaction<'a> = Transaction + type Transaction<'a> + = Transaction where Self: 'a; - type ReadOnly<'a> = Transaction + type ReadOnly<'a> + = Transaction where Self: 'a; diff --git a/src/data_source/storage/sql/db.rs b/src/data_source/storage/sql/db.rs index 5b3c86aa7..e4804e8b9 100644 --- a/src/data_source/storage/sql/db.rs +++ b/src/data_source/storage/sql/db.rs @@ -37,7 +37,6 @@ /// for<'a> i64: Type + Encode<'a, DB>, /// {} /// ``` - #[cfg(feature = "embedded-db")] pub type Db = sqlx::Sqlite; #[cfg(not(feature = "embedded-db"))] diff --git a/src/data_source/storage/sql/migrate.rs b/src/data_source/storage/sql/migrate.rs index 694a68608..c86c0fb34 100644 --- a/src/data_source/storage/sql/migrate.rs +++ b/src/data_source/storage/sql/migrate.rs @@ -22,7 +22,7 @@ pub(super) struct Migrator<'a> { } #[async_trait] -impl<'a> AsyncTransaction for Migrator<'a> { +impl AsyncTransaction for Migrator<'_> { type Error = sqlx::Error; async fn execute(&mut self, queries: &[&str]) -> sqlx::Result { @@ -38,7 +38,7 @@ impl<'a> AsyncTransaction for Migrator<'a> { } #[async_trait] -impl<'a> AsyncQuery> for Migrator<'a> { +impl AsyncQuery> for Migrator<'_> { async fn query(&mut self, query: &str) -> sqlx::Result> { let mut tx = self.conn.begin().await?; @@ -68,4 +68,4 @@ impl<'a> AsyncQuery> for Migrator<'a> { } } -impl<'a> AsyncMigrate for Migrator<'a> {} +impl AsyncMigrate for Migrator<'_> {} diff --git a/src/data_source/storage/sql/queries.rs b/src/data_source/storage/sql/queries.rs index d2a94063c..7b8510323 100644 --- a/src/data_source/storage/sql/queries.rs +++ b/src/data_source/storage/sql/queries.rs @@ -1,3 +1,4 @@ +#![allow(clippy::needless_lifetimes)] // Copyright (c) 2022 Espresso Systems (espressosys.com) // This file is part of the HotShot Query Service library. // @@ -81,9 +82,9 @@ pub(super) mod state; /// ``` #[derive(Derivative, Default)] #[derivative(Debug)] -pub struct QueryBuilder<'q> { +pub struct QueryBuilder<'a> { #[derivative(Debug = "ignore")] - arguments: ::Arguments<'q>, + arguments: ::Arguments<'a>, } impl<'q> QueryBuilder<'q> { @@ -113,7 +114,7 @@ impl<'q> QueryBuilder<'q> { } } -impl<'q> QueryBuilder<'q> { +impl QueryBuilder<'_> { /// Construct a SQL `WHERE` clause which filters for a header exactly matching `id`. pub fn header_where_clause( &mut self, diff --git a/src/explorer/monetary_value.rs b/src/explorer/monetary_value.rs index 2e077a274..399e18e02 100644 --- a/src/explorer/monetary_value.rs +++ b/src/explorer/monetary_value.rs @@ -293,7 +293,7 @@ where } } -impl<'de> serde::de::Visitor<'de> for MonetaryValueVisitor { +impl serde::de::Visitor<'_> for MonetaryValueVisitor { type Value = MonetaryValue; fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { diff --git a/src/lib.rs b/src/lib.rs index 7bf465fcd..e77ab5a9f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -627,40 +627,28 @@ mod test { #[async_trait] impl AvailabilityDataSource for CompositeState { - type LeafRange = - >::LeafRange + type LeafRange + = >::LeafRange where R: RangeBounds + Send; - type BlockRange = - >::BlockRange + type BlockRange + = >::BlockRange where R: RangeBounds + Send; - type PayloadRange = - >::PayloadRange + type PayloadRange + = >::PayloadRange where R: RangeBounds + Send; - type PayloadMetadataRange = - >::PayloadMetadataRange + type PayloadMetadataRange + = >::PayloadMetadataRange where R: RangeBounds + Send; - type VidCommonRange = - >::VidCommonRange + type VidCommonRange + = >::VidCommonRange where R: RangeBounds + Send; - type VidCommonMetadataRange = - >::VidCommonMetadataRange + type VidCommonMetadataRange + = >::VidCommonMetadataRange where R: RangeBounds + Send;