Skip to content

Commit

Permalink
fix(mirror): migrate the source storage before opening it (#8982)
Browse files Browse the repository at this point in the history
Just using near_store::NodeStorage::opener() without a migrator doesn't work if the DB version of the binary is newer than the database with the source chain transactions, which is pretty likely in practice. To fix it, we can mark nearcore::open_storage() as pub and just call that
  • Loading branch information
marcelo-gonzalez committed Apr 28, 2023
1 parent 4429ca6 commit 7fa1757
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
2 changes: 1 addition & 1 deletion nearcore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub fn get_default_home() -> PathBuf {
/// The end goal is to get rid of `archive` option in `config.json` file and
/// have the type of the node be determined purely based on kind of database
/// being opened.
fn open_storage(home_dir: &Path, near_config: &mut NearConfig) -> anyhow::Result<NodeStorage> {
pub fn open_storage(home_dir: &Path, near_config: &mut NearConfig) -> anyhow::Result<NodeStorage> {
let migrator = migrations::Migrator::new(near_config);
let opener = NodeStorage::opener(
home_dir,
Expand Down
16 changes: 4 additions & 12 deletions tools/mirror/src/offline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,12 @@ pub(crate) struct ChainAccess {

impl ChainAccess {
pub(crate) fn new<P: AsRef<Path>>(home: P) -> anyhow::Result<Self> {
let config =
let mut config =
nearcore::config::load_config(home.as_ref(), GenesisValidationMode::UnsafeFast)
.with_context(|| format!("Error loading config from {:?}", home.as_ref()))?;
// leave it ReadWrite since otherwise there are problems with the compiled contract cache
let store_opener = near_store::NodeStorage::opener(
home.as_ref(),
config.config.archive,
&config.config.store,
None,
);
let store = store_opener
.open()
.with_context(|| format!("Error opening store in {:?}", home.as_ref()))?
.get_hot_store();
let node_storage =
nearcore::open_storage(home.as_ref(), &mut config).context("failed opening storage")?;
let store = node_storage.get_hot_store();
let chain = ChainStore::new(
store.clone(),
config.genesis.config.genesis_height,
Expand Down

0 comments on commit 7fa1757

Please sign in to comment.