Skip to content

Commit

Permalink
fix: put migration version
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangsoledad committed Jun 24, 2021
1 parent df28490 commit 1f417c0
Show file tree
Hide file tree
Showing 40 changed files with 524 additions and 415 deletions.
14 changes: 12 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ckb-verification-traits = { path = "../verification/traits", version = "= 0.44.0
ckb-app-config = { path = "../util/app-config", version = "= 0.44.0-pre" }
ckb-resource = { path = "../resource", version = "= 0.44.0-pre" }
ckb-network = { path = "../network", version = "= 0.44.0-pre" }
ckb-launcher = { path = "../util/launcher", version = "= 0.44.0-pre" }
tempfile = "3.0"

[[bench]]
Expand Down
3 changes: 2 additions & 1 deletion benches/benches/benchmarks/overall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use ckb_chain::chain::{ChainController, ChainService};
use ckb_chain_spec::consensus::{ConsensusBuilder, ProposalWindow};
use ckb_dao_utils::genesis_dao_data;
use ckb_jsonrpc_types::JsonBytes;
use ckb_launcher::SharedBuilder;
use ckb_network::{DefaultExitHandler, NetworkController, NetworkService, NetworkState};
use ckb_shared::{Shared, SharedBuilder, Snapshot};
use ckb_shared::{Shared, Snapshot};
use ckb_store::ChainStore;
use ckb_types::{
bytes::Bytes,
Expand Down
3 changes: 2 additions & 1 deletion benches/benches/benchmarks/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use ckb_app_config::{BlockAssemblerConfig, TxPoolConfig};
use ckb_chain::chain::{ChainController, ChainService};
use ckb_chain_spec::{ChainSpec, IssuedCell};
use ckb_jsonrpc_types::JsonBytes;
use ckb_launcher::SharedBuilder;
use ckb_resource::Resource;
use ckb_shared::{Shared, SharedBuilder, Snapshot};
use ckb_shared::{Shared, Snapshot};
use ckb_store::ChainStore;
use ckb_types::{
bytes::Bytes,
Expand Down
3 changes: 2 additions & 1 deletion benches/benches/benchmarks/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use ckb_chain_spec::consensus::{ConsensusBuilder, ProposalWindow};
use ckb_crypto::secp::Privkey;
use ckb_dao::DaoCalculator;
use ckb_dao_utils::genesis_dao_data;
use ckb_shared::{Shared, SharedBuilder, Snapshot};
use ckb_launcher::SharedBuilder;
use ckb_shared::{Shared, Snapshot};
use ckb_store::ChainStore;
use ckb_system_scripts::BUNDLED_CELL;
use ckb_test_chain_utils::always_success_cell;
Expand Down
1 change: 1 addition & 0 deletions chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ ckb-dao-utils = { path = "../util/dao/utils", version = "= 0.44.0-pre" }
ckb-tx-pool = { path = "../tx-pool", version = "= 0.44.0-pre" }
ckb-jsonrpc-types = { path = "../util/jsonrpc-types", version = "= 0.44.0-pre" }
ckb-network = { path = "../network", version = "= 0.44.0-pre" }
ckb-launcher = { path = "../util/launcher", version = "= 0.44.0-pre" }
lazy_static = "1.4"
tempfile = "3.0"

Expand Down
3 changes: 2 additions & 1 deletion chain/src/tests/block_assembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use ckb_chain_spec::consensus::Consensus;
use ckb_dao_utils::genesis_dao_data;
use ckb_jsonrpc_types::BlockTemplate;
use ckb_jsonrpc_types::ScriptHashType;
use ckb_launcher::SharedBuilder;
use ckb_shared::Shared;
use ckb_shared::Snapshot;
use ckb_shared::{Shared, SharedBuilder};
use ckb_store::ChainStore;
use ckb_tx_pool::{PlugTarget, TxEntry};
use ckb_types::{
Expand Down
2 changes: 1 addition & 1 deletion chain/src/tests/find_fork.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::chain::{ChainService, ForkChanges};
use crate::tests::util::{MockChain, MockStore};
use ckb_chain_spec::consensus::{Consensus, ProposalWindow};
use ckb_shared::SharedBuilder;
use ckb_launcher::SharedBuilder;
use ckb_store::ChainStore;
use ckb_types::{
core::{BlockBuilder, BlockExt, BlockView},
Expand Down
2 changes: 1 addition & 1 deletion chain/src/tests/truncate.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::chain::ChainService;
use crate::tests::util::{MockChain, MockStore};
use ckb_chain_spec::consensus::Consensus;
use ckb_shared::SharedBuilder;
use ckb_launcher::SharedBuilder;
use ckb_store::ChainStore;
use ckb_verification_traits::Switch;
use std::sync::Arc;
Expand Down
2 changes: 1 addition & 1 deletion chain/src/tests/uncle.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::chain::ChainService;
use crate::tests::util::{MockChain, MockStore};
use ckb_chain_spec::consensus::Consensus;
use ckb_shared::SharedBuilder;
use ckb_launcher::SharedBuilder;
use ckb_store::ChainStore;
use ckb_verification_traits::Switch;
use std::sync::Arc;
Expand Down
2 changes: 1 addition & 1 deletion chain/src/tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use ckb_chain_spec::consensus::{Consensus, ConsensusBuilder};
use ckb_dao::DaoCalculator;
use ckb_dao_utils::genesis_dao_data;
use ckb_jsonrpc_types::ScriptHashType;
use ckb_launcher::SharedBuilder;
use ckb_network::{DefaultExitHandler, NetworkController, NetworkService, NetworkState};
use ckb_shared::shared::Shared;
use ckb_shared::SharedBuilder;
use ckb_store::ChainStore;
pub use ckb_test_chain_utils::MockStore;
use ckb_test_chain_utils::{
Expand Down
11 changes: 3 additions & 8 deletions ckb-bin/src/subcommand/export.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
use ckb_app_config::{ExitCode, ExportArgs};
use ckb_async_runtime::Handle;
use ckb_instrument::Export;
use ckb_shared::SharedBuilder;
use ckb_launcher::SharedBuilder;

pub fn export(args: ExportArgs, async_handle: Handle) -> Result<(), ExitCode> {
let (shared, _) = SharedBuilder::new(&args.config.db, None, async_handle)
.consensus(args.consensus)
.build()
.map_err(|err| {
eprintln!("Export error: {:?}", err);
ExitCode::Failure
})?;
let builder = SharedBuilder::new(&args.config.db, None, async_handle)?;
let (shared, _) = builder.consensus(args.consensus).build()?;
Export::new(shared, args.target).execute().map_err(|err| {
eprintln!("Export error: {:?}", err);
ExitCode::Failure
Expand Down
11 changes: 3 additions & 8 deletions ckb-bin/src/subcommand/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@ use ckb_app_config::{ExitCode, ImportArgs};
use ckb_async_runtime::Handle;
use ckb_chain::chain::ChainService;
use ckb_instrument::Import;
use ckb_shared::SharedBuilder;
use ckb_launcher::SharedBuilder;

pub fn import(args: ImportArgs, async_handle: Handle) -> Result<(), ExitCode> {
let (shared, mut pack) = SharedBuilder::new(&args.config.db, None, async_handle)
.consensus(args.consensus)
.build()
.map_err(|err| {
eprintln!("Import error: {:?}", err);
ExitCode::Failure
})?;
let builder = SharedBuilder::new(&args.config.db, None, async_handle)?;
let (shared, mut pack) = builder.consensus(args.consensus).build()?;

let chain_service = ChainService::new(shared, pack.take_proposal_table());
let chain_controller = chain_service.start::<&str>(Some("ImportChainService"));
Expand Down
79 changes: 47 additions & 32 deletions ckb-bin/src/subcommand/migrate.rs
Original file line number Diff line number Diff line change
@@ -1,49 +1,64 @@
use ckb_app_config::{ExitCode, MigrateArgs};
use ckb_launcher::DatabaseMigration;
use ckb_launcher::migrate::Migrate;

use crate::helper::prompt;

pub fn migrate(args: MigrateArgs) -> Result<(), ExitCode> {
let migration = DatabaseMigration::new(&args.config.db.path);
let migrate = Migrate::new(&args.config.db.path);

if args.check {
if migration.migration_check() {
return Ok(());
} else {
return Err(ExitCode::Cli);
}
}
{
let read_only_db = migrate.open_read_only_db().map_err(|e| {
eprintln!("migrate error {}", e);
ExitCode::Failure
})?;

if !migration.migration_check() {
return Ok(());
}
if let Some(db) = read_only_db {
if args.check {
if migrate.check(&db) {
return Ok(());
} else {
return Err(ExitCode::Cli);
}
}

if migration.require_expensive_migrations() && !args.force {
if atty::is(atty::Stream::Stdin) && atty::is(atty::Stream::Stdout) {
let input = prompt("\
\n\
Doing migration will take quite a long time before CKB could work again.\n\
Another choice is to delete all data, then synchronize them again.\n\
\n\
Once the migration started, the data will be no longer compatible with all older versions CKB,\n\
so we strongly recommended you to backup the old data before migrating.\n\
\nIf you want to migrate the data, please input YES, otherwise, the current process will exit.\n\
> ",
);
if input.trim().to_lowercase() != "yes" {
eprintln!("The migration was declined since the user didn't confirm.");
return Err(ExitCode::Failure);
if !migrate.check(&db) {
return Ok(());
}

if migrate.require_expensive(&db) && !args.force {
if atty::is(atty::Stream::Stdin) && atty::is(atty::Stream::Stdout) {
let input = prompt("\
\n\
Doing migration will take quite a long time before CKB could work again.\n\
Another choice is to delete all data, then synchronize them again.\n\
\n\
Once the migration started, the data will be no longer compatible with all older versions CKB,\n\
so we strongly recommended you to backup the old data before migrating.\n\
\nIf you want to migrate the data, please input YES, otherwise, the current process will exit.\n\
> ",
);
if input.trim().to_lowercase() != "yes" {
eprintln!("The migration was declined since the user didn't confirm.");
return Err(ExitCode::Failure);
}
} else {
eprintln!("Run error: use --force to migrate without interactive prompt");
return Err(ExitCode::Failure);
}
}
} else {
eprintln!("Run error: use --force to migrate without interactive prompt");
return Err(ExitCode::Failure);
}
}

migration.migrate().map_err(|err| {
eprintln!("Run error: {:?}", err);
let bulk_load_db_db = migrate.open_bulk_load_db().map_err(|e| {
eprintln!("migrate error {}", e);
ExitCode::Failure
})?;

if let Some(db) = bulk_load_db_db {
migrate.migrate(db).map_err(|err| {
eprintln!("Run error: {:?}", err);
ExitCode::Failure
})?;
}
Ok(())
}
21 changes: 8 additions & 13 deletions ckb-bin/src/subcommand/replay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@ use ckb_async_runtime::Handle;
use ckb_chain::chain::ChainService;
use ckb_chain_iter::ChainIterator;
use ckb_instrument::{ProgressBar, ProgressStyle};
use ckb_shared::{Shared, SharedBuilder};
use ckb_launcher::SharedBuilder;
use ckb_shared::Shared;
use ckb_store::ChainStore;
use ckb_verification_traits::Switch;
use std::sync::Arc;

pub fn replay(args: ReplayArgs, async_handle: Handle) -> Result<(), ExitCode> {
let (shared, _) = SharedBuilder::new(&args.config.db, None, async_handle.clone())
let shared_builder = SharedBuilder::new(&args.config.db, None, async_handle.clone())?;
let (shared, _) = shared_builder
.consensus(args.consensus.clone())
.tx_pool_config(args.config.tx_pool)
.build()
.map_err(|err| {
eprintln!("replay error: {:?}", err);
ExitCode::Failure
})?;
.build()?;

if !args.tmp_target.is_dir() {
eprintln!(
Expand All @@ -33,14 +31,11 @@ pub fn replay(args: ReplayArgs, async_handle: Handle) -> Result<(), ExitCode> {
let mut tmp_db_config = args.config.db.clone();
tmp_db_config.path = tmp_db_dir.path().to_path_buf();

let (tmp_shared, mut pack) = SharedBuilder::new(&tmp_db_config, None, async_handle)
let shared_builder = SharedBuilder::new(&tmp_db_config, None, async_handle)?;
let (tmp_shared, mut pack) = shared_builder
.consensus(args.consensus)
.tx_pool_config(args.config.tx_pool)
.build()
.map_err(|err| {
eprintln!("replay error: {:?}", err);
ExitCode::Failure
})?;
.build()?;
let chain = ChainService::new(tmp_shared, pack.take_proposal_table());

if let Some((from, to)) = args.profile {
Expand Down
1 change: 0 additions & 1 deletion ckb-bin/src/subcommand/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub fn run(args: RunArgs, version: Version, async_handle: Handle) -> Result<(),
let miner_enable = block_assembler_config.is_some();
let exit_handler = DefaultExitHandler::default();

launcher.migrate_guard()?;
let (shared, mut pack) = launcher.build_shared(block_assembler_config)?;

// spawn freezer background process
Expand Down
Loading

0 comments on commit 1f417c0

Please sign in to comment.