Skip to main content

espresso_node/api/
fs.rs

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 light_client::state::LightClientOptions;
48    use tempfile::TempDir;
49
50    use super::*;
51    use crate::api::{self, data_source::testing::TestableSequencerDataSource, options::Query};
52
53    #[async_trait]
54    impl TestableSequencerDataSource for DataSource {
55        type Storage = TempDir;
56
57        async fn create_storage() -> Self::Storage {
58            TempDir::new().unwrap()
59        }
60
61        fn persistence_options(storage: &Self::Storage) -> Self::Options {
62            Options::new(storage.path().into())
63        }
64
65        fn options(storage: &Self::Storage, opt: api::Options) -> api::Options {
66            opt.query_fs(
67                Query {
68                    light_client: LightClientOptions {
69                        // Enable testnet features when running in tests.
70                        decaf: true,
71                        ..Default::default()
72                    },
73                    ..Default::default()
74                },
75                Options::new(storage.path().into()),
76            )
77        }
78    }
79}