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

[DO NOT LAND] unify packages in ptb logic #20827

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
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 unified linkage is unable to be created for the transaction")]
InvalidUnifiedLinkage,
// NOTE: if you want to add a new enum,
// please add it at the end for Rust SDK backward compatibility.
}
Expand Down
44 changes: 30 additions & 14 deletions crates/sui-types/src/move_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub struct UpgradeInfo {
// serde_bytes::ByteBuf is an analog of Vec<u8> with built-in fast serialization.
#[serde_as]
#[derive(Eq, PartialEq, Debug, Clone, Deserialize, Serialize, Hash)]
#[serde(rename_all = "camelCase")]
pub struct MovePackage {
id: ObjectID,
/// Most move packages are uniquely identified by their ID (i.e. there is only one version per
Expand All @@ -111,7 +112,7 @@ pub struct MovePackage {
version: SequenceNumber,
// TODO use session cache
#[serde_as(as = "BTreeMap<_, Bytes>")]
module_map: BTreeMap<String, Vec<u8>>,
pub module_map: BTreeMap<String, Vec<u8>>,

/// Maps struct/module to a package version where it was first defined, stored as a vector for
/// simple serialization and deserialization.
Expand Down Expand Up @@ -509,14 +510,22 @@ impl MovePackage {
&self,
module: &Identifier,
binary_config: &BinaryConfig,
) -> SuiResult<CompiledModule> {
self.deserialize_module_by_name(module.as_str(), binary_config)
}

pub fn deserialize_module_by_name(
&self,
module: &str,
binary_config: &BinaryConfig,
) -> SuiResult<CompiledModule> {
// TODO use the session's cache
let bytes = self
.serialized_module_map()
.get(module.as_str())
.ok_or_else(|| SuiError::ModuleNotFound {
module_name: module.to_string(),
})?;
let bytes =
self.serialized_module_map()
.get(module)
.ok_or_else(|| SuiError::ModuleNotFound {
module_name: module.to_string(),
})?;
CompiledModule::deserialize_with_config(bytes, binary_config).map_err(|error| {
SuiError::ModuleDeserializationFailure {
error: error.to_string(),
Expand Down Expand Up @@ -606,18 +615,25 @@ where
{
let mut normalized_modules = BTreeMap::new();
for bytecode in modules {
let module =
CompiledModule::deserialize_with_config(bytecode, binary_config).map_err(|error| {
SuiError::ModuleDeserializationFailure {
error: error.to_string(),
}
})?;
let normalized_module = normalized::Module::new(&module);
let normalized_module = normalize_module(bytecode, binary_config)?;
normalized_modules.insert(normalized_module.name.to_string(), normalized_module);
}
Ok(normalized_modules)
}

pub fn normalize_module<'a>(
bytecode: &'a Vec<u8>,
binary_config: &BinaryConfig,
) -> SuiResult<normalized::Module> {
let module =
CompiledModule::deserialize_with_config(bytecode, binary_config).map_err(|error| {
SuiError::ModuleDeserializationFailure {
error: error.to_string(),
}
})?;
Ok(normalized::Module::new(&module))
}

pub fn normalize_deserialized_modules<'a, I>(modules: I) -> BTreeMap<String, normalized::Module>
where
I: Iterator<Item = &'a CompiledModule>,
Expand Down
1 change: 1 addition & 0 deletions sui-execution/latest/sui-adapter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod execution_engine;
pub mod execution_mode;
pub mod execution_value;
pub mod gas_charger;
pub mod package_unification;
pub mod programmable_transactions;
pub mod temporary_store;
pub mod type_layout_resolver;
Expand Down
Loading
Loading