Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
23 changes: 21 additions & 2 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ members = [
"util/movement/*",
"util/movement-aptos/*",
"util/bcs-ext",
"util/types"
"util/types",
"util/util"

]

Expand Down Expand Up @@ -215,6 +216,7 @@ movement-aptos = { path = "util/movement-aptos/movement-aptos" }
movement-aptos-core = { path = "util/movement-aptos/core" }
movement-aptos-core-util = { path = "util/movement-aptos/core-util" }
mtma-types = { path = "util/types" }
mtma-util = { path = "util/util" }

## Environments
### util
Expand Down
2 changes: 1 addition & 1 deletion checks/migrator/checks/pre-l1-merge/src/pre_l1_merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub mod test {
// Create a Movement instance with the config
let movement = Movement::new(
movement_config.clone(),
movement_core::MovementWorkspace::try_temp()?,
movement_core::MovementWorkspace::try_temp()?.into(),
Overlays::default(),
true,
true,
Expand Down
2 changes: 2 additions & 0 deletions environments/core/box/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ clap = { workspace = true }
thiserror = { workspace = true }
mtma-migrator-types = { workspace = true }
mtma-environment-types = { workspace = true }
kestrel = { workspace = true }
tokio = { workspace = true }

[lints]
workspace = true
16 changes: 14 additions & 2 deletions environments/core/box/src/environment/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::BoxEnvironment;
use clap::Parser;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
use std::path::PathBuf;

/// Errors thrown when working with the [Config].
#[derive(Debug, thiserror::Error)]
Expand All @@ -16,13 +17,24 @@ pub enum EnvironmentConfigError {
/// This is the frontend for the core API.
#[derive(Parser, Debug, Serialize, Deserialize, Clone, Default)]
#[clap(help_expected = true)]
pub struct Config {}
pub struct Config {
/// The rest api url of the box environment.
pub rest_api_url: String,
/// The db dir of the box environment.
pub db_dir: PathBuf,
/// Whether to isolate the box environment by snapshotting the movement runner and where to store the snapshot.
pub snapshot_dir: Option<PathBuf>,
}

impl Config {
/// Builds the [BoxEnvironment] struct from the config.
///
/// Note: preserving faillibility here because we may add debug path configuration to the [BoxEnvironment] soon.
pub fn build(&self) -> Result<BoxEnvironment, EnvironmentConfigError> {
Ok(BoxEnvironment::new())
Ok(BoxEnvironment::new(
self.rest_api_url.clone(),
self.db_dir.clone(),
self.snapshot_dir.clone(),
))
}
}
54 changes: 49 additions & 5 deletions environments/core/box/src/environment/environment.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use anyhow::Context;
use mtma_environment_types::{EnvironmentError, Environmentish};
use mtma_migrator_types::migrator::MovementMigrator;
use mtma_migrator_types::migrator::{
movement_migrator::{LiveMigrator, Runner},
MovementMigrator,
};
use std::fmt::Debug;
use std::path::PathBuf;

/// Errors thrown when using the [BoxEnvironment].
#[derive(Debug, thiserror::Error)]
Expand All @@ -15,16 +20,55 @@ impl From<BoxEnvironmentError> for EnvironmentError {
}
}

pub struct BoxEnvironment {}
pub struct BoxEnvironment {
/// The rest api url of the box environment.
pub rest_api_url: String,
/// The db dir of the box environment.
pub db_dir: PathBuf,
/// Whether to isolate the box environment by snapshotting the movement runner and where to store the snapshot.
pub snapshot_dir: Option<PathBuf>,
}

impl BoxEnvironment {
pub fn new() -> Self {
Self {}
pub fn new(rest_api_url: String, db_dir: PathBuf, snapshot_dir: Option<PathBuf>) -> Self {
Self { rest_api_url, db_dir, snapshot_dir }
}
}

impl Environmentish for BoxEnvironment {
async fn build_movement_migrator(&self) -> Result<MovementMigrator, EnvironmentError> {
Err(BoxEnvironmentError::Internal(anyhow::anyhow!("not implemented").into()).into())
// construct the live migrator
let movement_migrator = MovementMigrator::new(Runner::Live(LiveMigrator::new(
self.rest_api_url.clone(),
self.db_dir.clone(),
)));

// make sure the live migrator is ready
let movement_migrator_for_task = movement_migrator.clone();
let migrator_task = kestrel::task(async move { movement_migrator_for_task.run().await });

// wait for the rest api to be ready
let _rest_api_url = movement_migrator
.wait_for_rest_api_url(tokio::time::Duration::from_secs(300))
.await
.context("failed to wait for the rest api to be ready")
.map_err(|e| BoxEnvironmentError::Internal(e.into()))?;

// end the migrator task
kestrel::end!(migrator_task)
.context("failed to end the migrator task")
.map_err(|e| BoxEnvironmentError::Internal(e.into()))?;

// if we're snapshotting the movement_migrator should be a snapshot of the live migrator
let movement_migrator = match &self.snapshot_dir {
Some(snapshot_dir) => movement_migrator
.snapshot(snapshot_dir.clone())
.await
.context("failed to snapshot the movement migrator")
.map_err(|e| BoxEnvironmentError::Internal(e.into()))?,
None => movement_migrator,
};

Ok(movement_migrator)
}
}
8 changes: 7 additions & 1 deletion migration/cli/migrate-node/docs/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,13 @@ Options:
**Selection (2/4):** `environment-box`
The config for the [BoxEnvironment]

Usage: --environment-box.*
Usage: --environment-box.* <REST_API_URL> <DB_DIR> [SNAPSHOT_DIR]

Arguments:
<REST_API_URL> The rest api url of the box environment
<DB_DIR> The db dir of the box environment
[SNAPSHOT_DIR] Whether to isolate the box environment by snapshotting the movement runner and where to store the
snapshot

Options:
-h, --help Print help (see more with '--help')
Expand Down
54 changes: 47 additions & 7 deletions migration/cli/migrate-node/src/cli/migrate/select.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use anyhow::Context;
use clap::Parser;
use mtma_box_environment::Config as BoxEnvironmentConfig;
use mtma_environment_types::Environmentish;
use mtma_migrator_types::migration::Migrationish;
use mtma_migrator_types::migrator::MovementMigrator;
use mtma_node_null_core::Config as NullConfig;
use mtma_provisioner_environment::Config as ProvisionerEnvironmentConfig;
use mtma_testing_environment::Config as TestingEnvironmentConfig;
Expand All @@ -19,12 +19,12 @@ pub struct Select {
}

impl select::Select {
pub async fn execute(&self) -> Result<(), anyhow::Error> {
pub async fn get_movement_migrator(&self) -> Result<MovementMigrator, anyhow::Error> {
let (
maybe_environment_testing,
maybe_environment_box,
maybe_environment_provisioner,
maybe_null,
_maybe_null,
) = self.select().map_err(|e| anyhow::anyhow!("{}", e))?;

// if more than one environment is provided, we need to error
Expand All @@ -38,11 +38,51 @@ impl select::Select {
));
}

let environment_config = maybe_environment_testing.context(
"--environment-testing is the only supported environment; it must be provided",
)?;
match maybe_environment_testing {
Some(environment_testing) => {
let environment_config = environment_testing.build()?;
return environment_config
.build_movement_migrator()
.await
.map_err(|e| anyhow::anyhow!("{}", e));
}
None => {}
}

match maybe_environment_box {
Some(environment_box) => {
let environment_config = environment_box.build()?;
return environment_config
.build_movement_migrator()
.await
.map_err(|e| anyhow::anyhow!("{}", e));
}
None => {}
}

match maybe_environment_provisioner {
Some(environment_provisioner) => {
let environment_config = environment_provisioner.build()?;
return environment_config
.build_movement_migrator()
.await
.map_err(|e| anyhow::anyhow!("{}", e));
}
None => {}
}

return Err(anyhow::anyhow!("no environment provided"));
}

pub async fn execute(&self) -> Result<(), anyhow::Error> {
let (
_maybe_environment_testing,
_maybe_environment_box,
_maybe_environment_provisioner,
maybe_null,
) = self.select().map_err(|e| anyhow::anyhow!("{}", e))?;

let movement_migrator = environment_config.build()?.build_movement_migrator().await?;
let movement_migrator = self.get_movement_migrator().await?;

if let Some(null) = maybe_null {
let null_migration = null.build()?;
Expand Down
2 changes: 1 addition & 1 deletion migration/core/migrator/mtma-null/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ anyhow = { workspace = true }
thiserror = { workspace = true }
mtma-node-types = { workspace = true }
chrono = { workspace = true }
walkdir = { workspace = true }
uuid = { workspace = true }
tracing = { workspace = true }
mtma-types = { workspace = true }
mtma-util = { workspace = true }

[lints]
workspace = true
21 changes: 1 addition & 20 deletions migration/core/migrator/mtma-null/src/migrate/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,9 @@ use mtma_types::movement_aptos::aptos_db::AptosDB;
use mtma_types::movement_aptos::aptos_storage_interface::DbReaderWriter;

use anyhow::Context;
use std::fs;
use mtma_util::file::copy_dir_recursive;
use std::path::Path;
use tracing::info;
use walkdir::WalkDir;

/// Copies a directory recursively.
///
/// todo: move this out of the migration module
fn copy_dir_recursive(src: &Path, dst: &Path) -> std::io::Result<()> {
for entry in WalkDir::new(src) {
let entry = entry?;
let rel_path = entry.path().strip_prefix(src).unwrap();
let dest_path = dst.join(rel_path);

if entry.file_type().is_dir() {
fs::create_dir_all(&dest_path)?;
} else {
fs::copy(entry.path(), &dest_path)?;
}
}
Ok(())
}

/// Errors thrown during the migration.
#[derive(Debug, thiserror::Error)]
Expand Down
2 changes: 1 addition & 1 deletion migration/core/node/mtma-null/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ anyhow = { workspace = true }
thiserror = { workspace = true }
mtma-node-types = { workspace = true }
chrono = { workspace = true }
walkdir = { workspace = true }
uuid = { workspace = true }
tracing = { workspace = true }
mtma-types = { workspace = true }
mtma-util = { workspace = true }

[lints]
workspace = true
Loading
Loading