mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
fix: copy and prune data from database with move_to_static_files, before a pipeline run/unwind (#8127)
This commit is contained in:
@ -34,10 +34,10 @@ use reth_db::mdbx::DatabaseArguments;
|
||||
/// A common provider that fetches data from a database or static file.
|
||||
///
|
||||
/// This provider implements most provider or provider factory traits.
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug)]
|
||||
pub struct ProviderFactory<DB> {
|
||||
/// Database
|
||||
db: DB,
|
||||
db: Arc<DB>,
|
||||
/// Chain spec
|
||||
chain_spec: Arc<ChainSpec>,
|
||||
/// Static File Provider
|
||||
@ -52,7 +52,7 @@ impl<DB> ProviderFactory<DB> {
|
||||
static_files_path: PathBuf,
|
||||
) -> RethResult<ProviderFactory<DB>> {
|
||||
Ok(Self {
|
||||
db,
|
||||
db: Arc::new(db),
|
||||
chain_spec,
|
||||
static_file_provider: StaticFileProvider::new(static_files_path)?,
|
||||
})
|
||||
@ -71,7 +71,7 @@ impl<DB> ProviderFactory<DB> {
|
||||
|
||||
#[cfg(any(test, feature = "test-utils"))]
|
||||
/// Consumes Self and returns DB
|
||||
pub fn into_db(self) -> DB {
|
||||
pub fn into_db(self) -> Arc<DB> {
|
||||
self.db
|
||||
}
|
||||
}
|
||||
@ -86,7 +86,7 @@ impl ProviderFactory<DatabaseEnv> {
|
||||
static_files_path: PathBuf,
|
||||
) -> RethResult<Self> {
|
||||
Ok(ProviderFactory::<DatabaseEnv> {
|
||||
db: init_db(path, args).map_err(|e| RethError::Custom(e.to_string()))?,
|
||||
db: Arc::new(init_db(path, args).map_err(|e| RethError::Custom(e.to_string()))?),
|
||||
chain_spec,
|
||||
static_file_provider: StaticFileProvider::new(static_files_path)?,
|
||||
})
|
||||
@ -558,6 +558,15 @@ impl<DB: Database> PruneCheckpointReader for ProviderFactory<DB> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<DB> Clone for ProviderFactory<DB> {
|
||||
fn clone(&self) -> Self {
|
||||
ProviderFactory {
|
||||
db: Arc::clone(&self.db),
|
||||
chain_spec: self.chain_spec.clone(),
|
||||
static_file_provider: self.static_file_provider.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::ProviderFactory;
|
||||
|
||||
Reference in New Issue
Block a user