Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mpm: provider compatibility check #3204

Merged
merged 2 commits into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions vm/move-package-manager/src/compatibility_check_cmd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
use crate::releasement::module;

use itertools::Itertools;

use move_binary_format::CompiledModule;
use move_cli::sandbox::utils::PackageContext;
use move_cli::Move;

use move_core_types::resolver::ModuleResolver;
use starcoin_config::BuiltinNetworkID;
use starcoin_move_compiler::check_compiled_module_compat;
use starcoin_transactional_test_harness::remote_state::RemoteStateView;
use structopt::StructOpt;

#[derive(StructOpt)]
pub struct CompatibilityCheckCommand {
#[structopt(name = "rpc", long)]
/// use remote starcoin rpc as initial state.
rpc: Option<String>,
#[structopt(long = "block-number", requires("rpc"))]
/// block number to read state from. default to latest block number.
block_number: Option<u64>,

#[structopt(long = "network", short, conflicts_with("rpc"))]
/// genesis with the network
network: Option<BuiltinNetworkID>,
}

pub fn handle_compatibility_check(
move_args: &Move,
cmd: CompatibilityCheckCommand,
) -> anyhow::Result<()> {
let pkg_ctx = PackageContext::new(&move_args.package_path, &move_args.build_config)?;
let pkg = pkg_ctx.package();

let rpc = cmd.rpc.unwrap_or_else(|| {
format!(
"http://{}:{}",
cmd.network.unwrap().boot_nodes_domain(),
9850
)
});

let remote_view = RemoteStateView::from_url(&rpc, cmd.block_number).unwrap();

let mut incompatible_module_ids = vec![];
for m in pkg.modules()? {
let m = module(&m.unit)?;
let old_module = remote_view
.get_module(&m.self_id())
.map_err(|e| e.into_vm_status())?;
if let Some(old) = old_module {
let old_module = CompiledModule::deserialize(&old)?;
if !check_compiled_module_compat(&old_module, m) {
incompatible_module_ids.push(m.self_id());
}
}
}

if !incompatible_module_ids.is_empty() {
eprintln!(
"Modules {} is incompatible with remote chain: {}!",
incompatible_module_ids
.into_iter()
.map(|module_id| module_id.to_string())
.join(","),
&rpc
);
}
Ok(())
}
1 change: 1 addition & 0 deletions vm/move-package-manager/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod compatibility_check_cmd;
pub mod releasement;
use anyhow::Result;
use move_cli::Move;
Expand Down
9 changes: 8 additions & 1 deletion vm/move-package-manager/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ use anyhow::Result;
use move_cli::package::cli::handle_package_commands;
use move_cli::{experimental, package, sandbox, Move, DEFAULT_STORAGE_DIR};
use move_core_types::errmap::ErrorMapping;
use move_package_manager::compatibility_check_cmd::{
handle_compatibility_check, CompatibilityCheckCommand,
};
use move_package_manager::releasement::{handle_release, Releasement};
use move_package_manager::{run_transactional_test, TransactionalTestCommand};
use starcoin_vm_runtime::natives::starcoin_natives;
Expand Down Expand Up @@ -53,9 +56,12 @@ pub enum Commands {
cmd: experimental::cli::ExperimentalCommand,
},

// extra commands available can be added below
/// Run transaction tests in spectests dir.
#[structopt(name = "spectest")]
TransactionalTest(TransactionalTestCommand),
/// Check compatibility of modules comparing with remote chain chate.
#[structopt(name = "check-compatibility")]
CompatibilityCheck(CompatibilityCheckCommand),
}

fn main() -> Result<()> {
Expand All @@ -77,5 +83,6 @@ fn main() -> Result<()> {
}
Commands::Experimental { storage_dir, cmd } => cmd.handle_command(move_args, &storage_dir),
Commands::Release(releasement) => handle_release(move_args, releasement),
Commands::CompatibilityCheck(cmd) => handle_compatibility_check(move_args, cmd),
}
}
2 changes: 1 addition & 1 deletion vm/move-package-manager/src/releasement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub fn handle_release(
Ok(())
}

fn module(unit: &CompiledUnit) -> anyhow::Result<&CompiledModule> {
pub fn module(unit: &CompiledUnit) -> anyhow::Result<&CompiledModule> {
match unit {
CompiledUnit::Module(NamedCompiledModule { module, .. }) => Ok(module),
_ => anyhow::bail!("Found script in modules -- this shouldn't happen"),
Expand Down