Skip to content

Commit

Permalink
test?: make unsafe initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
rymnc committed Oct 9, 2024
1 parent 3c49e96 commit 8d0464e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
10 changes: 10 additions & 0 deletions crates/fuel-core/src/combined_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,16 @@ impl CombinedDatabase {
}
}

/// Converts the combined database into a genesis combined database without
/// checking the height of the databases.
pub fn unsafe_into_genesis(self) -> CombinedGenesisDatabase {
CombinedGenesisDatabase {
on_chain: self.on_chain.unsafe_into_genesis(),
off_chain: self.off_chain.unsafe_into_genesis(),
relayer: self.relayer.unsafe_into_genesis(),
}
}

/// Rollbacks the state of the blockchain to a specific block height.
pub fn rollback_to<S>(
&self,
Expand Down
7 changes: 7 additions & 0 deletions crates/fuel-core/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ where
);
GenesisDatabase::new(self.into_inner().data)
}

/// !!!! WARNING !!!!
/// This method is unsafe because it doesn't check if the height is already set.
/// This allows overriding the genesis state with a new one.
pub fn unsafe_into_genesis(self) -> GenesisDatabase<Description> {
GenesisDatabase::new(self.into_inner().data)
}
}

impl<Description, Stage> Database<Description, Stage>
Expand Down
16 changes: 8 additions & 8 deletions crates/fuel-core/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,17 +330,17 @@ impl FuelService {
.await?;

self.shared.block_importer.commit_result(result).await?;
} else {
// repopulate missing tables
genesis::recover_missing_tables_from_genesis_state_config(
watcher.clone(),
&self.shared.config,
&self.shared.database,
)
.await?;
}
}

// repopulate missing tables
genesis::recover_missing_tables_from_genesis_state_config(
watcher.clone(),
&self.shared.config,
&self.shared.database,
)
.await?;

self.override_chain_config_if_needed()
}
}
Expand Down
5 changes: 2 additions & 3 deletions crates/fuel-core/src/service/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,10 @@ mod importer;
mod progress;
mod task_manager;

use self::importer::SnapshotImporter;
pub use exporter::Exporter;
pub use task_manager::NotifyCancel;

use self::importer::SnapshotImporter;

/// Performs the importing of the genesis block from the snapshot.
pub async fn execute_genesis_block(
watcher: StateWatcher,
Expand Down Expand Up @@ -156,7 +155,7 @@ pub async fn recover_missing_tables_from_genesis_state_config(
db: &CombinedDatabase,
) -> anyhow::Result<()> {
let genesis_block = create_genesis_block(config);
let db = db.clone().into_genesis();
let db = db.clone().unsafe_into_genesis();

SnapshotImporter::repopulate_maybe_missing_tables(
db.clone(),
Expand Down

0 comments on commit 8d0464e

Please sign in to comment.