Skip to content

Commit

Permalink
move init conversion earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
antiochp committed Aug 21, 2020
1 parent 0167a8d commit d81c22c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::types::{
BlockStatus, ChainAdapter, CommitPos, NoStatus, Options, Tip, TxHashsetWriteStatus,
};
use crate::util::secp::pedersen::{Commitment, RangeProof};
use crate::util::RwLock;
use crate::{util::RwLock, ChainStore};
use grin_store::Error::NotFoundErr;
use std::collections::HashMap;
use std::fs::{self, File};
Expand Down Expand Up @@ -171,6 +171,10 @@ impl Chain {
) -> Result<Chain, Error> {
let store = Arc::new(store::ChainStore::new(&db_root)?);

// DB migrations to be run prior to the chain being used.
// Migrate full blocks to protocol version v3.
Chain::migrate_db_v2_v3(&store)?;

// open the txhashset, creating a new one if necessary
let mut txhashset = txhashset::TxHashSet::open(db_root.clone(), store.clone(), None)?;

Expand Down Expand Up @@ -218,10 +222,6 @@ impl Chain {
genesis: genesis.header,
};

// DB migrations to be run prior to the chain being used.
// Migrate full blocks to protocol version v3.
chain.migrate_db_v2_v3()?;

chain.log_heads()?;

Ok(chain)
Expand Down Expand Up @@ -1410,8 +1410,8 @@ impl Chain {

/// Migrate our local db from v2 to v3.
/// "commit only" inputs.
fn migrate_db_v2_v3(&self) -> Result<(), Error> {
let store_v2 = self.store.with_version(ProtocolVersion(2));
fn migrate_db_v2_v3(store: &ChainStore) -> Result<(), Error> {
let store_v2 = store.with_version(ProtocolVersion(2));
let batch = store_v2.batch()?;
for (_, block) in batch.blocks_iter()? {
batch.migrate_block(&block, ProtocolVersion(3))?;
Expand Down

0 comments on commit d81c22c

Please sign in to comment.