Skip to content

Commit dcd2a23

Browse files
committed
fix deploy
1 parent f46bc9e commit dcd2a23

11 files changed

Lines changed: 447 additions & 144 deletions

File tree

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ sui-execution = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"
8686
shared-crypto = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
8787
sui-move-natives-latest = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
8888
sui-adapter-latest = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
89-
# sui-adapter-v2 = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
89+
9090

9191
sui-rpc = { git = "https://github.com/MystenLabs/sui-rust-sdk.git", rev = "fb62af78b30f5dc64eeaec0094ab95b5ce5b7ce2" }
9292
sui-sdk-types = { git = "https://github.com/MystenLabs/sui-rust-sdk.git", rev = "fb62af78b30f5dc64eeaec0094ab95b5ce5b7ce2" }
@@ -114,9 +114,9 @@ fastcrypto = { git = "https://github.com/MystenLabs/fastcrypto", rev = "09f86974
114114
# sui-snapshot = {path = "../sui/crates/sui-snapshot"}
115115
# sui-core = {path = "../sui/crates/sui-core"}
116116
# sui-execution = {path = "../sui/sui-execution", features = ["testing"]}
117-
# # sui-adapter-v2 = {path = "../sui/sui-execution/v2/sui-adapter/"}
118117
# shared-crypto = {path = "../sui/crates/shared-crypto"}
119-
118+
# sui-move-natives-latest = {path = "../sui/sui-execution/latest/sui-move-natives/"}
119+
# sui-adapter-latest = {path = "../sui/sui-execution/latest/sui-adapter/"}
120120

121121
# Aptos dependencies
122122

crates/movy-replay/src/env.rs

Lines changed: 61 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ use std::{
66

77
use color_eyre::eyre::eyre;
88
use itertools::Itertools;
9+
use move_core_types::account_address::AccountAddress;
910
use movy_sui::{
1011
compile::SuiCompiledPackage,
11-
database::cache::ObjectSuiStoreCommit,
12+
database::{cache::ObjectSuiStoreCommit, graphql::GraphQlDatabase},
1213
rpc::graphql::{GraphQlClient, OwnerKind},
1314
};
1415
use movy_types::{
@@ -135,23 +136,36 @@ impl<
135136
epoch: u64,
136137
epoch_ms: u64,
137138
gas: ObjectID,
139+
unpublished: bool,
140+
verify_deps: bool,
138141
trace_movy_init: bool,
142+
rpc: &GraphQlDatabase,
139143
) -> Result<(MoveAddress, MovePackageAbi, MovePackageAbi, Vec<String>), MovyError> {
140144
tracing::info!("Compiling {} with non-test mode...", path.display());
141-
let abi_result = SuiCompiledPackage::build_all_unpublished_from_folder(path, false)?;
145+
let abi_result = SuiCompiledPackage::build_checked(path, false, unpublished, verify_deps)?;
142146
let mut non_test_abi = abi_result.abi()?;
147+
tracing::info!("Compiled summary: {}", &abi_result);
143148
tracing::info!("Compiling {} with test mode...", path.display());
144-
let compiled_result = SuiCompiledPackage::build_all_unpublished_from_folder(path, true)?;
149+
let compiled_result =
150+
SuiCompiledPackage::build_checked(path, true, unpublished, verify_deps)?;
151+
tracing::info!("Compiled summary: {}", &compiled_result);
152+
145153
let package_names = compiled_result.package_names.clone();
146154
let compiled_result = compiled_result.movy_mock()?;
147-
tracing::debug!(
148-
"test modules are {}",
149-
compiled_result
150-
.test_modules()
151-
.iter()
152-
.map(|v| v.self_id().name().to_string())
153-
.join(", ")
154-
);
155+
156+
// Deploy onchain deps (execpt stds)
157+
for dep in abi_result.dependencies().iter() {
158+
let dep = AccountAddress::from(*dep);
159+
if self.db.get_object(&dep.into()).is_none() {
160+
tracing::info!(
161+
"Dependency {} not found in our db for {}, trying to fetch it from onchain",
162+
dep,
163+
path.display()
164+
);
165+
self.deploy_package_at_address(dep.into(), rpc).await?;
166+
}
167+
}
168+
155169
let mut executor = SuiExecutor::new(self.db.clone())?;
156170
let address =
157171
executor.deploy_contract(epoch, epoch_ms, deployer.into(), gas, compiled_result)?;
@@ -279,23 +293,47 @@ impl<
279293
Ok(())
280294
}
281295

282-
pub async fn deploy_address(&self, package_id: MoveAddress) -> Result<(), MovyError> {
283-
let Some(package_object) = self.db.get_object(&package_id.into()) else {
284-
return Err(eyre!("Package object not found: {}", package_id).into());
285-
};
286-
287-
// Analyze package dependencies
288-
let pkg = package_object
289-
.data
290-
.try_as_package()
291-
.ok_or_else(|| eyre!("Expected package data"))?;
292-
for upgrade_info in pkg.linkage_table().values() {
293-
self.db.load_object(upgrade_info.upgraded_id.into()).await?;
296+
pub async fn deploy_object_id(
297+
&self,
298+
package_id: MoveAddress,
299+
rpc: &GraphQlDatabase,
300+
) -> Result<(), MovyError> {
301+
if let Some(object) = rpc.get_object(package_id.into()).await? {
302+
self.db.commit_single_object(object)?;
303+
} else {
304+
return Err(eyre!("object {} not found", package_id).into());
294305
}
295306

296307
Ok(())
297308
}
298309

310+
pub async fn deploy_package_at_address(
311+
&self,
312+
package_id: MoveAddress,
313+
rpc: &GraphQlDatabase,
314+
) -> Result<(), MovyError> {
315+
tracing::info!("Fetching package {} from chain", package_id);
316+
if let Some(object) = rpc.get_object(package_id.into()).await? {
317+
let pkg = object
318+
.data
319+
.try_as_package()
320+
.ok_or_else(|| eyre!("Expected package data for {}", object.id()))?;
321+
322+
for upgrade_info in pkg.linkage_table().values() {
323+
tracing::info!(
324+
"Fetching ugprade cap {} from chain",
325+
upgrade_info.upgraded_id
326+
);
327+
self.deploy_object_id(upgrade_info.upgraded_id.into(), rpc)
328+
.await?;
329+
}
330+
self.db.commit_single_object(object)?;
331+
} else {
332+
return Err(eyre!("package {} not found", package_id).into());
333+
}
334+
Ok(())
335+
}
336+
299337
pub async fn all_tys(&self) -> Result<BTreeSet<MoveStructTag>, MovyError> {
300338
let mut tags = BTreeSet::new();
301339
for obj in self.db.list_objects().await? {

crates/movy-replay/src/exec.rs

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ pub fn testing_proto() -> ProtocolConfig {
4141
ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Mainnet)
4242
}
4343

44+
fn random_digest() -> TransactionDigest {
45+
TransactionDigest::from_str("8thja5nUwaEw7L5ji9tnhCurpkjHdMunRffxwx1H9HsT").unwrap()
46+
}
47+
4448
#[derive(Clone)]
4549
pub struct SuiExecutor<T> {
4650
pub db: T,
@@ -288,42 +292,12 @@ where
288292
})
289293
.join(",")
290294
);
291-
// rebase to zero address as sui publish requires
292-
// for it in modules.iter_mut() {
293-
// let self_handle = it.self_handle().clone();
294-
// if let Some(address_mut) = it
295-
// .address_identifiers
296-
// .get_mut(self_handle.address.0 as usize)
297-
// && *address_mut != AccountAddress::ZERO
298-
// {
299-
// *address_mut = AccountAddress::ZERO;
300-
// }
301-
302-
// // TODO: Maybe unnecessary?
303-
// if package_id != ObjectID::ZERO {
304-
// for ident in it.address_identifiers.iter_mut() {
305-
// if ObjectID::from(*ident) == package_id {
306-
// *ident = AccountAddress::ZERO;
307-
// }
308-
// }
309-
// }
310-
// }
311295

312296
if package_id == ObjectID::ZERO {
313297
// derive id
314-
let id = ObjectID::derive_id(TransactionDigest::genesis_marker(), self.deploy_ids);
298+
let id = ObjectID::derive_id(random_digest(), self.deploy_ids);
315299
self.deploy_ids += 1;
316300
substitute_package_id(&mut modules, id)?;
317-
} else {
318-
// ensure the modules has the expected id
319-
for it in modules.iter_mut() {
320-
let self_handle = it.self_handle().clone();
321-
let self_address_idx = self_handle.address;
322-
323-
let addrs = &mut it.address_identifiers;
324-
let address_mut = addrs.get_mut(self_address_idx.0 as usize).unwrap();
325-
*address_mut = package_id.into();
326-
}
327301
}
328302

329303
let mut modules_bytes = vec![];
@@ -367,7 +341,7 @@ where
367341
self.db.commit_store(store, &effects)?;
368342
Ok(new_object.0)
369343
} else {
370-
Err(eyre!("fail to deploy").into())
344+
Err(eyre!("fail to deploy with {:?}", effects.status()).into())
371345
}
372346
}
373347
}

0 commit comments

Comments
 (0)