Skip to content

Commit 1fc8110

Browse files
committed
several improvements
1 parent a7a5997 commit 1fc8110

4 files changed

Lines changed: 77 additions & 15 deletions

File tree

crates/movy-replay/src/env.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use sui_types::{
3030
use crate::{
3131
db::{ObjectStoreCachedStore, ObjectStoreInfo},
3232
exec::SuiExecutor,
33-
tracer::NopTracer,
33+
tracer::{NopTracer, tree::TreeTracer},
3434
};
3535

3636
pub struct SuiTestingEnv<T> {
@@ -135,6 +135,7 @@ impl<
135135
epoch: u64,
136136
epoch_ms: u64,
137137
gas: ObjectID,
138+
trace_movy_init: bool,
138139
) -> Result<(MoveAddress, MovePackageAbi, MovePackageAbi, Vec<String>), MovyError> {
139140
tracing::info!("Compiling {} with non-test mode...", path.display());
140141
let abi_result = SuiCompiledPackage::build_all_unpublished_from_folder(path, false)?;
@@ -174,17 +175,34 @@ impl<
174175
);
175176
let ptb = builder.finish();
176177
tracing::info!("Detected a {} at: {}", MOVY_INIT, md.module_id);
177-
let results = executor.run_ptb_with_gas::<NopTracer>(
178+
let tracer = if trace_movy_init {
179+
Some(TreeTracer::new())
180+
} else {
181+
None
182+
};
183+
let mut results = executor.run_ptb_with_gas(
178184
ptb,
179185
epoch,
180186
epoch_ms,
181187
deployer.into(),
182188
gas,
183-
None,
189+
tracer,
184190
)?;
191+
let trace = if let Some(tracer) = std::mem::take(&mut results.tracer) {
192+
Some(tracer.take_inner().pprint())
193+
} else {
194+
None
195+
};
185196
if !results.effects.status().is_ok() {
197+
if let Some(trace) = trace {
198+
tracing::error!("movy_init reverts with:\n{}", trace);
199+
}
186200
return Err(eyre!("movy_init reverts!").into());
187201
}
202+
tracing::trace!(
203+
"movy_init trace:\n{}",
204+
trace.unwrap_or_else(|| "-".to_string())
205+
);
188206
tracing::info!("Commiting movy_init effects...");
189207
tracing::debug!(
190208
"Status: {:?} Changed Objects: {}, Removed Objects: {}",
@@ -238,8 +256,8 @@ impl<
238256
let objects = rpc
239257
.filter_objects(ckpt, Some(OwnerKind::Shared), None, Some(tag))
240258
.await?;
241-
for object in objects.iter() {
242-
self.db.load_object(object.id().into()).await?;
259+
for object in objects.into_iter() {
260+
self.db.commit_single_object(object)?;
243261
}
244262
}
245263
}

crates/movy-replay/src/exec.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,22 @@ use sui_adapter_latest::{
1313
};
1414
use sui_move_natives_latest::all_natives;
1515
use sui_types::{
16-
TypeTag, base_types::{ObjectID, SuiAddress}, committee::ProtocolVersion, digests::TransactionDigest, effects::{TransactionEffects, TransactionEffectsAPI}, gas::SuiGasStatus, inner_temporary_store::InnerTemporaryStore, metrics::LimitsMetrics, object::Owner, storage::{BackingStore, ObjectStore, WriteKind}, supported_protocol_versions::{Chain, ProtocolConfig}, transaction::{
16+
TypeTag,
17+
base_types::{ObjectID, SuiAddress},
18+
committee::ProtocolVersion,
19+
digests::TransactionDigest,
20+
effects::{TransactionEffects, TransactionEffectsAPI},
21+
gas::SuiGasStatus,
22+
inner_temporary_store::InnerTemporaryStore,
23+
metrics::LimitsMetrics,
24+
object::Owner,
25+
storage::{BackingStore, ObjectStore, WriteKind},
26+
supported_protocol_versions::{Chain, ProtocolConfig},
27+
transaction::{
1728
Argument, CallArg, CheckedInputObjects, Command, InputObjectKind, ObjectReadResult,
1829
ObjectReadResultKind, ProgrammableTransaction, TransactionData, TransactionDataAPI,
1930
TransactionKind,
20-
}
31+
},
2132
};
2233
use tracing::{debug, trace, warn};
2334

@@ -78,7 +89,7 @@ where
7889
metrics,
7990
registry,
8091
movevm,
81-
deploy_ids: 0
92+
deploy_ids: 0,
8293
})
8394
}
8495
pub fn new(db: T) -> Result<Self, MovyError> {

crates/movy/src/sui/env.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ pub struct SuiTargetArgs {
3838
pub objects: Option<Vec<MoveAddress>>,
3939
#[arg(short, long, help = "Local packages to build.")]
4040
pub locals: Option<Vec<PathBuf>>,
41+
#[arg(long, help = "Trace movy_init")]
42+
pub trace_movy_init: bool,
4143
}
4244

4345
impl SuiTargetArgs {
@@ -99,7 +101,15 @@ impl SuiTargetArgs {
99101
for local in self.locals.iter().flatten() {
100102
tracing::info!("Deploying the local package at {}", local.display());
101103
let (target_package, testing_abi, abi, package_names) = env
102-
.load_local(local, deployer, attacker, epoch, epoch_ms, gas.into())
104+
.load_local(
105+
local,
106+
deployer,
107+
attacker,
108+
epoch,
109+
epoch_ms,
110+
gas.into(),
111+
self.trace_movy_init,
112+
)
103113
.await?;
104114
for name in package_names.iter() {
105115
local_name_map.insert(name.clone(), target_package);

crates/movy/src/sui/fuzz.rs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ use movy_replay::{
1212
env::SuiTestingEnv,
1313
};
1414
use movy_sui::{
15-
database::{cache::CachedStore, graphql::GraphQlDatabase},
15+
database::{cache::CachedStore, empty::EmptyStore, graphql::GraphQlDatabase},
1616
rpc::{graphql::GraphQlClient, grpc::SuiGrpcArg},
17+
utils::TrivialBackStore,
1718
};
1819
use movy_types::{
1920
abi::MoveModuleId,
@@ -137,6 +138,11 @@ pub struct SuiFuzzArgs {
137138
)]
138139
pub force_removal: bool,
139140

141+
#[arg(short, long, help = "Enable GraphQL fallback")]
142+
pub graphql: bool,
143+
#[arg(long, help = "Enable GraphQL during deployment")]
144+
pub graphql_deployment: bool,
145+
140146
#[clap(flatten)]
141147
pub onchain: SuiOnchainArguments,
142148
#[clap(flatten)]
@@ -189,10 +195,16 @@ impl SuiFuzzArgs {
189195
.onchain
190196
.resolve_onchain_primitives(Some(&graphql))
191197
.await?;
192-
let env = CachedStore::new(GraphQlDatabase::new_client(
193-
graphql.clone(),
194-
primitives.checkpoint,
195-
));
198+
199+
let inner = if self.graphql_deployment {
200+
TrivialBackStore::T1(GraphQlDatabase::new_client(
201+
graphql.clone(),
202+
primitives.checkpoint,
203+
))
204+
} else {
205+
TrivialBackStore::T2(EmptyStore::default())
206+
};
207+
let env = CachedStore::new(inner);
196208
let gas_id = ObjectID::random_from_rng(&mut rand);
197209
env.mint_coin_id(
198210
MoveTypeTag::from_str("0x2::sui::SUI").unwrap(),
@@ -283,8 +295,19 @@ impl SuiFuzzArgs {
283295
// Arc<T> is send only if T is Sync while RefCell is not.
284296
let inner = testing_env.into_inner();
285297
let inner = Arc::try_unwrap(inner).unwrap();
298+
let dump = inner.inner.take();
299+
let inner = if self.graphql {
300+
TrivialBackStore::T1(GraphQlDatabase::new_client(
301+
graphql.clone(),
302+
primitives.checkpoint,
303+
))
304+
} else {
305+
TrivialBackStore::T2(EmptyStore::default())
306+
};
307+
let store = CachedStore::new(inner);
308+
store.restore_snapshot(dump);
286309
tokio::task::spawn_blocking(move || {
287-
let env = SuiTestingEnv::new(inner.wrapped());
310+
let env = SuiTestingEnv::new(store.wrapped());
288311
sui_fuzz::fuzz(
289312
meta,
290313
env,

0 commit comments

Comments
 (0)