From 7fa1757226271b6d49b5ea4e25b33dc9e8e4d1d5 Mon Sep 17 00:00:00 2001 From: Marcelo Diop-Gonzalez Date: Fri, 28 Apr 2023 11:22:33 -0400 Subject: [PATCH] fix(mirror): migrate the source storage before opening it (#8982) 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 --- nearcore/src/lib.rs | 2 +- tools/mirror/src/offline.rs | 16 ++++------------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/nearcore/src/lib.rs b/nearcore/src/lib.rs index ab1db431b46..576d3556bb5 100644 --- a/nearcore/src/lib.rs +++ b/nearcore/src/lib.rs @@ -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 { +pub fn open_storage(home_dir: &Path, near_config: &mut NearConfig) -> anyhow::Result { let migrator = migrations::Migrator::new(near_config); let opener = NodeStorage::opener( home_dir, diff --git a/tools/mirror/src/offline.rs b/tools/mirror/src/offline.rs index 6fa36902e72..11d1f37158d 100644 --- a/tools/mirror/src/offline.rs +++ b/tools/mirror/src/offline.rs @@ -34,20 +34,12 @@ pub(crate) struct ChainAccess { impl ChainAccess { pub(crate) fn new>(home: P) -> anyhow::Result { - 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,