Skip to content

Commit

Permalink
[5/n][vm-rewrite][sui][roughcut] Update sui deps on Move and add new …
Browse files Browse the repository at this point in the history
…trait implementations.

Things are still a bit rough around the edges in terms of getting the
execution versioning story right around deps into the VM-runtime (e.g.,
for `Serializable` value, cost tables etc). But that will be done in a
later PR.

In particular, here the direct dependency on
`move-execution/crates/shared` in sui-types will be removed once we pull
the shared legacy code crate out of `move-execution` and into something
like `legacy_vm_types` or similar under `move/crates`.

NB: The code in the PR may not be working as future PRs will build on top of
this.
  • Loading branch information
tzakian committed Feb 4, 2025
1 parent 486cb40 commit 49f2c90
Show file tree
Hide file tree
Showing 12 changed files with 3,328 additions and 2,529 deletions.
5,139 changes: 2,682 additions & 2,457 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,14 @@ exclude = [
"external-crates/move/crates/move-prover-test-utils",
"external-crates/move/crates/move-stackless-bytecode",
"external-crates/move/crates/move-stdlib",
"external-crates/move/crates/move-stdlib-natives",
"external-crates/move/crates/move-symbol-pool",
"external-crates/move/crates/move-transactional-test-runner",
"external-crates/move/crates/move-unit-test",
"external-crates/move/crates/move-vm-config",
"external-crates/move/crates/move-vm-integration-tests",
"external-crates/move/crates/move-vm-profiler",
"external-crates/move/crates/move-vm-runtime",
"external-crates/move/crates/move-vm-test-utils",
"external-crates/move/crates/move-vm-transactional-tests",
"external-crates/move/crates/move-vm-types",
"external-crates/move/crates/serializer-tests",
"external-crates/move/crates/test-generation",
"external-crates/move/move-execution/v0/crates/move-bytecode-verifier",
Expand Down Expand Up @@ -570,10 +567,10 @@ move-disassembler = { path = "external-crates/move/crates/move-disassembler" }
move-package = { path = "external-crates/move/crates/move-package" }
move-unit-test = { path = "external-crates/move/crates/move-unit-test" }
move-vm-config = { path = "external-crates/move/crates/move-vm-config" }
move-vm-test-utils = { path = "external-crates/move/crates/move-vm-test-utils/", features = [
## TODO(vm-rewrite): we need to have a better execution versioning story here as just relying on the vm-runtime directly is not kosher...
move-vm-runtime = { path = "external-crates/move/crates/move-vm-runtime/", features = [
"tiered-gas",
] }
move-vm-types = { path = "external-crates/move/crates/move-vm-types" }
move-vm-profiler = { path = "external-crates/move/crates/move-vm-profiler" }
move-command-line-common = { path = "external-crates/move/crates/move-command-line-common" }
move-transactional-test-runner = { path = "external-crates/move/crates/move-transactional-test-runner" }
Expand Down
26 changes: 26 additions & 0 deletions crates/simulacrum/src/store/in_mem_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

use move_binary_format::CompiledModule;
use move_bytecode_utils::module_cache::GetModule;
use move_core_types::account_address::AccountAddress;
use move_core_types::resolver::SerializedPackage;
use move_core_types::{language_storage::ModuleId, resolver::ModuleResolver};
use std::collections::{BTreeMap, HashMap};
use sui_config::genesis;
Expand Down Expand Up @@ -303,6 +305,30 @@ impl ModuleResolver for InMemoryStore {
fn get_module(&self, module_id: &ModuleId) -> Result<Option<Vec<u8>>, Self::Error> {
get_module(self, module_id)
}

fn get_packages_static<const N: usize>(
&self,
ids: [AccountAddress; N],
) -> Result<[Option<SerializedPackage>; N], Self::Error> {
let mut packages = [const { None }; N];
for (i, id) in ids.iter().enumerate() {
packages[i] = load_package_object_from_object_store(self, &ObjectID::from(*id))?
.map(|pkg| pkg.move_package().into_serialized_move_package())
}
Ok(packages)
}

fn get_packages(
&self,
ids: &[AccountAddress],
) -> Result<Vec<Option<SerializedPackage>>, Self::Error> {
ids.iter()
.map(|id| {
load_package_object_from_object_store(self, &ObjectID::from(*id))
.map(|pkg| pkg.map(|pkg| pkg.move_package().into_serialized_move_package()))
})
.collect()
}
}

impl ObjectStore for InMemoryStore {
Expand Down
26 changes: 24 additions & 2 deletions crates/sui-core/src/authority/authority_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use either::Either;
use fastcrypto::hash::{HashFunction, MultisetHash, Sha3_256};
use futures::stream::FuturesUnordered;
use itertools::izip;
use move_core_types::resolver::ModuleResolver;
use move_core_types::account_address::AccountAddress;
use move_core_types::resolver::{ModuleResolver, SerializedPackage};
use serde::{Deserialize, Serialize};
use sui_config::node::AuthorityStorePruningConfig;
use sui_macros::fail_point_arg;
Expand All @@ -31,7 +32,8 @@ use sui_types::error::UserInputError;
use sui_types::execution::TypeLayoutStore;
use sui_types::message_envelope::Message;
use sui_types::storage::{
get_module, BackingPackageStore, MarkerValue, ObjectKey, ObjectOrTombstone, ObjectStore,
get_module, get_package, BackingPackageStore, MarkerValue, ObjectKey, ObjectOrTombstone,
ObjectStore,
};
use sui_types::sui_system_state::get_sui_system_state;
use sui_types::{base_types::SequenceNumber, fp_bail, fp_ensure};
Expand Down Expand Up @@ -1957,6 +1959,26 @@ impl ModuleResolver for ResolverWrapper {
self.inc_cache_size_gauge();
get_module(&*self.resolver, module_id)
}

fn get_packages_static<const N: usize>(
&self,
ids: [AccountAddress; N],
) -> Result<[Option<SerializedPackage>; N], Self::Error> {
let mut packages = [const { None }; N];
for (i, id) in ids.iter().enumerate() {
packages[i] = get_package(&*self.resolver, &ObjectID::from(*id))?;
}
Ok(packages)
}

fn get_packages(
&self,
ids: &[AccountAddress],
) -> Result<Vec<Option<SerializedPackage>>, Self::Error> {
ids.iter()
.map(|id| get_package(&*self.resolver, &ObjectID::from(*id)))
.collect()
}
}

pub enum UpdateType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use std::{collections::BTreeMap, path::PathBuf, sync::Arc, time::Duration};

use move_binary_format::CompiledModule;
use move_bytecode_utils::module_cache::GetModule;
use move_core_types::account_address::AccountAddress;
use move_core_types::resolver::SerializedPackage;
use move_core_types::{language_storage::ModuleId, resolver::ModuleResolver};
use simulacrum::Simulacrum;
use std::num::NonZeroUsize;
Expand Down Expand Up @@ -498,6 +500,31 @@ impl ModuleResolver for PersistedStore {
.cloned()
}))
}

fn get_packages_static<const N: usize>(
&self,
ids: [AccountAddress; N],
) -> Result<[Option<SerializedPackage>; N], Self::Error> {
let mut packages = [const { None }; N];
for (i, id) in ids.iter().enumerate() {
packages[i] = self
.get_package_object(&ObjectID::from(*id))?
.map(|pkg| pkg.move_package().into_serialized_move_package());
}
Ok(packages)
}

fn get_packages(
&self,
ids: &[AccountAddress],
) -> Result<Vec<Option<SerializedPackage>>, Self::Error> {
ids.iter()
.map(|id| {
self.get_package_object(&ObjectID::from(*id))
.map(|x| x.map(|pkg| pkg.move_package().into_serialized_move_package()))
})
.collect()
}
}

impl ObjectStore for PersistedStore {
Expand Down
27 changes: 23 additions & 4 deletions crates/sui-transactional-test-runner/src/test_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use move_core_types::ident_str;
use move_core_types::parsing::address::ParsedAddress;
use move_core_types::{
account_address::AccountAddress,
identifier::IdentStr,
identifier::{IdentStr, Identifier},
language_storage::{ModuleId, TypeTag},
};
use move_symbol_pool::Symbol;
Expand All @@ -35,7 +35,7 @@ use move_transactional_test_runner::{
framework::{compile_any, store_modules, CompiledState, MoveTestAdapter},
tasks::{InitCommand, RunCommand, SyntaxChoice, TaskInput},
};
use move_vm_runtime::session::SerializedReturnValues;
use move_vm_runtime::shared::serialization::SerializedReturnValues;
use once_cell::sync::Lazy;
use rand::{rngs::StdRng, Rng, SeedableRng};
use std::fmt::{self, Write};
Expand Down Expand Up @@ -199,6 +199,7 @@ impl<'a> MoveTestAdapter<'a> for SuiTestAdapter {
| TaskCommand::PrintBytecode(_)
| TaskCommand::Publish(_, _)
| TaskCommand::Run(_, _)
| TaskCommand::PublishAndCall(_, _)
| TaskCommand::Subcommand(..) => None,
}
}
Expand Down Expand Up @@ -931,7 +932,7 @@ impl<'a> MoveTestAdapter<'a> for SuiTestAdapter {
.named_address_mapping
.insert(package, before_upgrade);
}
let (warnings_opt, output, data, modules) = result?;
let (warnings_opt, data, (output, modules)) = result?;
store_modules(self, syntax, data, modules);
Ok(merge_output(warnings_opt, output))
}
Expand All @@ -940,7 +941,7 @@ impl<'a> MoveTestAdapter<'a> for SuiTestAdapter {
dependencies,
}) => {
let syntax = syntax.unwrap_or_else(|| self.default_syntax());
let (warnings_opt, output, data, modules) = compile_any(
let (warnings_opt, data, (output, modules)) = compile_any(
self,
"upgrade",
syntax,
Expand Down Expand Up @@ -1149,6 +1150,24 @@ impl<'a> MoveTestAdapter<'a> for SuiTestAdapter {
}
anyhow!(err)
}

/// Sui implements module publishes with calls via normal publish with `init` functions.
/// When we add init functions with arguments, we will need to implement this. For now we leave
/// this unimplemented.
async fn publish_modules_with_calls(
&mut self,
_modules: Vec<MaybeNamedCompiledModule>,
_calls: Vec<(ModuleId, Identifier, Vec<SuiValue>)>,
_signers: Vec<ParsedAddress>,
_gas_budget: Option<u64>,
_extra_args: Self::ExtraPublishArgs,
) -> anyhow::Result<(
Option<String>,
Vec<MaybeNamedCompiledModule>,
Vec<SerializedReturnValues>,
)> {
unimplemented!()
}
}

fn merge_output(left: Option<String>, right: Option<String>) -> Option<String> {
Expand Down
8 changes: 5 additions & 3 deletions crates/sui-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ move-command-line-common.workspace = true
move-core-types.workspace = true
move-disassembler.workspace = true
move-ir-types.workspace = true
move-vm-test-utils.workspace = true
move-vm-types.workspace = true
move-vm-runtime.workspace = true
move-vm-profiler.workspace = true
num-traits = "0.2.18"
num-bigint = { version = "0.4", default-features = false, features = ["rand"] }
Expand All @@ -77,6 +76,9 @@ lru.workspace = true

sui-sdk-types.workspace = true

## TODO(vm-rewrite): Determine where to place the historical trait implementation of the `GasMeter` trait, and this will determine whether we remove this, or if we want to add it to the workspace officially.
move-vm-types-old = { path = "../../external-crates/move/move-execution/shared/crates/move-vm-types", package = "move-vm-types" }

[dev-dependencies]
bincode.workspace = true
criterion.workspace = true
Expand All @@ -101,6 +103,6 @@ harness = false
default = []
tracing = [
"move-vm-profiler/tracing",
"move-vm-test-utils/tracing",
"move-vm-runtime/tracing",
]
fuzzing = ["move-core-types/fuzzing"]
3 changes: 3 additions & 0 deletions crates/sui-types/src/execution_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ pub enum ExecutionFailureStatus {

#[error("Certificate is cancelled because randomness could not be generated this epoch")]
ExecutionCancelledDueToRandomnessUnavailable,

#[error("A valid linkage was unable to be determined for the transaction")]
InvalidLinkage,
// NOTE: if you want to add a new enum,
// please add it at the end for Rust SDK backward compatibility.
}
Expand Down
Loading

0 comments on commit 49f2c90

Please sign in to comment.