1use std::path::Path;
2
3use async_trait::async_trait;
4use hotshot_query_service::data_source::FileSystemDataSource;
5
6use super::data_source::{Provider, PruningDataSource, SequencerDataSource};
7use crate::{SeqTypes, catchup::CatchupStorage, persistence::fs::Options};
8
9pub type DataSource = FileSystemDataSource<SeqTypes, Provider>;
10
11#[async_trait]
12impl SequencerDataSource for DataSource {
13 type Options = Options;
14
15 async fn create(opt: Self::Options, provider: Provider, reset: bool) -> anyhow::Result<Self> {
16 let path = Path::new(opt.path());
17 let data_source = {
18 if reset {
19 FileSystemDataSource::create(path, provider).await?
20 } else {
21 FileSystemDataSource::open(path, provider).await?
22 }
23 };
24
25 Ok(data_source)
26 }
27}
28
29impl CatchupStorage for DataSource {}
30
31impl PruningDataSource for DataSource {
32 async fn get_oldest_block(
33 &self,
34 ) -> anyhow::Result<Option<hotshot_query_service::availability::BlockQueryData<SeqTypes>>> {
35 Ok(None)
36 }
37
38 async fn get_oldest_leaf(
39 &self,
40 ) -> anyhow::Result<Option<hotshot_query_service::availability::LeafQueryData<SeqTypes>>> {
41 Ok(None)
42 }
43}
44
45#[cfg(test)]
46mod impl_testable_data_source {
47 use tempfile::TempDir;
48
49 use super::*;
50 use crate::api::{self, data_source::testing::TestableSequencerDataSource, options::Query};
51
52 #[async_trait]
53 impl TestableSequencerDataSource for DataSource {
54 type Storage = TempDir;
55
56 async fn create_storage() -> Self::Storage {
57 TempDir::new().unwrap()
58 }
59
60 fn persistence_options(storage: &Self::Storage) -> Self::Options {
61 Options::new(storage.path().into())
62 }
63
64 fn options(storage: &Self::Storage, opt: api::Options) -> api::Options {
65 opt.query_fs(Query::default(), Options::new(storage.path().into()))
66 }
67 }
68}