Skip to content

Commit 86feabc

Browse files
tzakianTimothy Zakian
andauthored
[1/n][object runtime type tags][cleanup-only] Pull SuiDataStore into a separate module (#22079)
## Description Pulls the `SuiDataStore` into a separate module, and cleans up formatting of `use`s. No semantic changes. ## Test plan CI Co-authored-by: Timothy Zakian <timothyzakian@mac.lan>
1 parent 8f7210b commit 86feabc

File tree

4 files changed

+143
-136
lines changed

4 files changed

+143
-136
lines changed

sui-execution/latest/sui-adapter/src/programmable_transactions/context.rs

Lines changed: 27 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -5,67 +5,63 @@ pub use checked::*;
55

66
#[sui_macros::with_checked_arithmetic]
77
mod checked {
8-
use std::{
9-
borrow::Borrow,
10-
cell::RefCell,
11-
collections::{BTreeMap, BTreeSet, HashMap},
12-
rc::Rc,
13-
sync::Arc,
8+
use crate::{
9+
adapter::new_native_extensions,
10+
error::convert_vm_error,
11+
execution_mode::ExecutionMode,
12+
execution_value::{
13+
CommandKind, ExecutionState, InputObjectMetadata, InputValue, ObjectContents,
14+
ObjectValue, RawValueType, ResultValue, SizeBound, TryFromValue, UsageKind, Value,
15+
},
16+
gas_charger::GasCharger,
17+
gas_meter::SuiGasMeter,
18+
programmable_transactions::{data_store::SuiDataStore, linkage_view::LinkageView},
19+
type_resolver::TypeTagResolver,
1420
};
15-
16-
use crate::error::convert_vm_error;
17-
use crate::execution_mode::ExecutionMode;
18-
use crate::execution_value::{CommandKind, ObjectContents, TryFromValue, Value};
19-
use crate::execution_value::{
20-
ExecutionState, InputObjectMetadata, InputValue, ObjectValue, RawValueType, ResultValue,
21-
UsageKind,
22-
};
23-
use crate::gas_charger::GasCharger;
24-
use crate::gas_meter::SuiGasMeter;
25-
use crate::programmable_transactions::linkage_view::LinkageView;
26-
use crate::type_resolver::TypeTagResolver;
27-
use crate::{adapter::new_native_extensions, execution_value::SizeBound};
2821
use move_binary_format::{
2922
CompiledModule,
30-
errors::{Location, PartialVMError, PartialVMResult, VMError, VMResult},
23+
errors::{Location, PartialVMError, VMError, VMResult},
3124
file_format::{AbilitySet, CodeOffset, FunctionDefinitionIndex, TypeParameterIndex},
3225
};
33-
use move_core_types::resolver::ModuleResolver;
34-
use move_core_types::vm_status::StatusCode;
3526
use move_core_types::{
3627
account_address::AccountAddress,
3728
identifier::IdentStr,
3829
language_storage::{ModuleId, StructTag, TypeTag},
30+
vm_status::StatusCode,
3931
};
4032
use move_trace_format::format::MoveTraceBuilder;
41-
use move_vm_runtime::native_extensions::NativeContextExtensions;
4233
use move_vm_runtime::{
4334
move_vm::MoveVM,
35+
native_extensions::NativeContextExtensions,
4436
session::{LoadedFunctionInstantiation, SerializedReturnValues},
4537
};
46-
use move_vm_types::data_store::DataStore;
4738
use move_vm_types::loaded_data::runtime_types::Type;
4839
use mysten_common::debug_fatal;
40+
use std::{
41+
borrow::Borrow,
42+
cell::RefCell,
43+
collections::{BTreeMap, BTreeSet, HashMap},
44+
rc::Rc,
45+
sync::Arc,
46+
};
4947
use sui_move_natives::object_runtime::{
5048
self, LoadedRuntimeObject, ObjectRuntime, RuntimeResults, get_all_uids, max_event_error,
5149
};
5250
use sui_protocol_config::ProtocolConfig;
53-
use sui_types::storage::{DenyListResult, PackageObject};
5451
use sui_types::{
5552
balance::Balance,
5653
base_types::{MoveObjectType, ObjectID, SuiAddress, TxContext},
5754
coin::Coin,
58-
error::{ExecutionError, ExecutionErrorKind},
55+
error::{ExecutionError, ExecutionErrorKind, command_argument_error},
5956
event::Event,
60-
execution::ExecutionResultsV2,
57+
execution::{ExecutionResults, ExecutionResultsV2},
58+
execution_status::CommandArgumentError,
6159
metrics::LimitsMetrics,
6260
move_package::MovePackage,
63-
object::{Data, MoveObject, Object, ObjectInner, Owner},
64-
storage::BackingPackageStore,
61+
object::{Authenticator, Data, MoveObject, Object, ObjectInner, Owner},
62+
storage::{BackingPackageStore, DenyListResult, PackageObject},
6563
transaction::{Argument, CallArg, ObjectArg},
6664
};
67-
use sui_types::{error::command_argument_error, execution_status::CommandArgumentError};
68-
use sui_types::{execution::ExecutionResults, object::Authenticator};
6965
use tracing::instrument;
7066

7167
/// Maintains all runtime state specific to programmable transactions
@@ -1711,94 +1707,6 @@ mod checked {
17111707
}
17121708
}
17131709

1714-
// Implementation of the `DataStore` trait for the Move VM.
1715-
// When used during execution it may have a list of new packages that have
1716-
// just been published in the current context. Those are used for module/type
1717-
// resolution when executing module init.
1718-
// It may be created with an empty slice of packages either when no publish/upgrade
1719-
// are performed or when a type is requested not during execution.
1720-
pub(crate) struct SuiDataStore<'state, 'a> {
1721-
linkage_view: &'a LinkageView<'state>,
1722-
new_packages: &'a [MovePackage],
1723-
}
1724-
1725-
impl<'state, 'a> SuiDataStore<'state, 'a> {
1726-
pub(crate) fn new(
1727-
linkage_view: &'a LinkageView<'state>,
1728-
new_packages: &'a [MovePackage],
1729-
) -> Self {
1730-
Self {
1731-
linkage_view,
1732-
new_packages,
1733-
}
1734-
}
1735-
1736-
fn get_module(&self, module_id: &ModuleId) -> Option<&Vec<u8>> {
1737-
for package in self.new_packages {
1738-
let module = package.get_module(module_id);
1739-
if module.is_some() {
1740-
return module;
1741-
}
1742-
}
1743-
None
1744-
}
1745-
}
1746-
1747-
// TODO: `DataStore` will be reworked and this is likely to disappear.
1748-
// Leaving this comment around until then as testament to better days to come...
1749-
impl DataStore for SuiDataStore<'_, '_> {
1750-
fn link_context(&self) -> AccountAddress {
1751-
self.linkage_view.link_context()
1752-
}
1753-
1754-
fn relocate(&self, module_id: &ModuleId) -> PartialVMResult<ModuleId> {
1755-
self.linkage_view.relocate(module_id).map_err(|err| {
1756-
PartialVMError::new(StatusCode::LINKER_ERROR)
1757-
.with_message(format!("Error relocating {module_id}: {err:?}"))
1758-
})
1759-
}
1760-
1761-
fn defining_module(
1762-
&self,
1763-
runtime_id: &ModuleId,
1764-
struct_: &IdentStr,
1765-
) -> PartialVMResult<ModuleId> {
1766-
self.linkage_view
1767-
.defining_module(runtime_id, struct_)
1768-
.map_err(|err| {
1769-
PartialVMError::new(StatusCode::LINKER_ERROR).with_message(format!(
1770-
"Error finding defining module for {runtime_id}::{struct_}: {err:?}"
1771-
))
1772-
})
1773-
}
1774-
1775-
fn load_module(&self, module_id: &ModuleId) -> VMResult<Vec<u8>> {
1776-
if let Some(bytes) = self.get_module(module_id) {
1777-
return Ok(bytes.clone());
1778-
}
1779-
match self.linkage_view.get_module(module_id) {
1780-
Ok(Some(bytes)) => Ok(bytes),
1781-
Ok(None) => Err(PartialVMError::new(StatusCode::LINKER_ERROR)
1782-
.with_message(format!("Cannot find {:?} in data cache", module_id))
1783-
.finish(Location::Undefined)),
1784-
Err(err) => {
1785-
let msg = format!("Unexpected storage error: {:?}", err);
1786-
Err(
1787-
PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR)
1788-
.with_message(msg)
1789-
.finish(Location::Undefined),
1790-
)
1791-
}
1792-
}
1793-
}
1794-
1795-
fn publish_module(&mut self, _module_id: &ModuleId, _blob: Vec<u8>) -> VMResult<()> {
1796-
// we cannot panic here because during execution and publishing this is
1797-
// currently called from the publish flow in the Move runtime
1798-
Ok(())
1799-
}
1800-
}
1801-
18021710
enum EitherError {
18031711
CommandArgument(CommandArgumentError),
18041712
Execution(ExecutionError),
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Copyright (c) Mysten Labs, Inc.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
use crate::programmable_transactions::linkage_view::LinkageView;
5+
use move_binary_format::errors::{Location, PartialVMError, PartialVMResult, VMResult};
6+
use move_core_types::{
7+
account_address::AccountAddress, identifier::IdentStr, language_storage::ModuleId,
8+
resolver::ModuleResolver, vm_status::StatusCode,
9+
};
10+
use move_vm_types::data_store::DataStore;
11+
use sui_types::move_package::MovePackage;
12+
13+
// Implementation of the `DataStore` trait for the Move VM.
14+
// When used during execution it may have a list of new packages that have
15+
// just been published in the current context. Those are used for module/type
16+
// resolution when executing module init.
17+
// It may be created with an empty slice of packages either when no publish/upgrade
18+
// are performed or when a type is requested not during execution.
19+
pub(crate) struct SuiDataStore<'state, 'a> {
20+
linkage_view: &'a LinkageView<'state>,
21+
new_packages: &'a [MovePackage],
22+
}
23+
24+
impl<'state, 'a> SuiDataStore<'state, 'a> {
25+
pub(crate) fn new(
26+
linkage_view: &'a LinkageView<'state>,
27+
new_packages: &'a [MovePackage],
28+
) -> Self {
29+
Self {
30+
linkage_view,
31+
new_packages,
32+
}
33+
}
34+
35+
fn get_module(&self, module_id: &ModuleId) -> Option<&Vec<u8>> {
36+
for package in self.new_packages {
37+
let module = package.get_module(module_id);
38+
if module.is_some() {
39+
return module;
40+
}
41+
}
42+
None
43+
}
44+
}
45+
46+
// TODO: `DataStore` will be reworked and this is likely to disappear.
47+
// Leaving this comment around until then as testament to better days to come...
48+
impl DataStore for SuiDataStore<'_, '_> {
49+
fn link_context(&self) -> AccountAddress {
50+
self.linkage_view.link_context()
51+
}
52+
53+
fn relocate(&self, module_id: &ModuleId) -> PartialVMResult<ModuleId> {
54+
self.linkage_view.relocate(module_id).map_err(|err| {
55+
PartialVMError::new(StatusCode::LINKER_ERROR)
56+
.with_message(format!("Error relocating {module_id}: {err:?}"))
57+
})
58+
}
59+
60+
fn defining_module(
61+
&self,
62+
runtime_id: &ModuleId,
63+
struct_: &IdentStr,
64+
) -> PartialVMResult<ModuleId> {
65+
self.linkage_view
66+
.defining_module(runtime_id, struct_)
67+
.map_err(|err| {
68+
PartialVMError::new(StatusCode::LINKER_ERROR).with_message(format!(
69+
"Error finding defining module for {runtime_id}::{struct_}: {err:?}"
70+
))
71+
})
72+
}
73+
74+
fn load_module(&self, module_id: &ModuleId) -> VMResult<Vec<u8>> {
75+
if let Some(bytes) = self.get_module(module_id) {
76+
return Ok(bytes.clone());
77+
}
78+
match self.linkage_view.get_module(module_id) {
79+
Ok(Some(bytes)) => Ok(bytes),
80+
Ok(None) => Err(PartialVMError::new(StatusCode::LINKER_ERROR)
81+
.with_message(format!("Cannot find {:?} in data cache", module_id))
82+
.finish(Location::Undefined)),
83+
Err(err) => {
84+
let msg = format!("Unexpected storage error: {:?}", err);
85+
Err(
86+
PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR)
87+
.with_message(msg)
88+
.finish(Location::Undefined),
89+
)
90+
}
91+
}
92+
}
93+
94+
fn publish_module(&mut self, _module_id: &ModuleId, _blob: Vec<u8>) -> VMResult<()> {
95+
// we cannot panic here because during execution and publishing this is
96+
// currently called from the publish flow in the Move runtime
97+
Ok(())
98+
}
99+
}

sui-execution/latest/sui-adapter/src/programmable_transactions/execution.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@ pub use checked::*;
55

66
#[sui_macros::with_checked_arithmetic]
77
mod checked {
8-
use crate::execution_mode::ExecutionMode;
9-
use crate::execution_value::{
10-
CommandKind, ExecutionState, ObjectContents, ObjectValue, RawValueType, Value,
11-
ensure_serialized_size,
8+
use crate::{
9+
adapter::substitute_package_id,
10+
execution_mode::ExecutionMode,
11+
execution_value::{
12+
CommandKind, ExecutionState, ObjectContents, ObjectValue, RawValueType, Value,
13+
ensure_serialized_size,
14+
},
15+
gas_charger::GasCharger,
16+
programmable_transactions::{context::*, data_store::SuiDataStore},
1217
};
13-
use crate::gas_charger::GasCharger;
14-
use move_binary_format::file_format::AbilitySet;
1518
use move_binary_format::{
1619
CompiledModule,
1720
compatibility::{Compatibility, InclusionCheck},
1821
errors::{Location, PartialVMResult, VMResult},
19-
file_format::{CodeOffset, FunctionDefinitionIndex, LocalIndex, Visibility},
22+
file_format::{AbilitySet, CodeOffset, FunctionDefinitionIndex, LocalIndex, Visibility},
2023
file_format_common::VERSION_6,
2124
normalized,
2225
};
@@ -33,9 +36,8 @@ mod checked {
3336
};
3437
use move_vm_types::loaded_data::runtime_types::{CachedDatatype, Type};
3538
use serde::{Deserialize, de::DeserializeSeed};
36-
use std::cell::OnceCell;
3739
use std::{
38-
cell::RefCell,
40+
cell::{OnceCell, RefCell},
3941
collections::{BTreeMap, BTreeSet},
4042
fmt,
4143
rc::Rc,
@@ -44,11 +46,6 @@ mod checked {
4446
};
4547
use sui_move_natives::object_runtime::ObjectRuntime;
4648
use sui_protocol_config::ProtocolConfig;
47-
use sui_types::execution::{ExecutionTiming, ResultWithTimings};
48-
use sui_types::execution_config_utils::to_binary_config;
49-
use sui_types::execution_status::{CommandArgumentError, PackageUpgradeError};
50-
use sui_types::storage::{PackageObject, get_package_objects};
51-
use sui_types::type_input::TypeInput;
5249
use sui_types::{
5350
SUI_FRAMEWORK_ADDRESS,
5451
base_types::{
@@ -58,24 +55,26 @@ mod checked {
5855
},
5956
coin::Coin,
6057
error::{ExecutionError, ExecutionErrorKind, command_argument_error},
58+
execution::{ExecutionTiming, ResultWithTimings},
59+
execution_config_utils::to_binary_config,
60+
execution_status::{CommandArgumentError, PackageUpgradeError},
6161
id::RESOLVED_SUI_ID,
6262
metrics::LimitsMetrics,
6363
move_package::{
6464
MovePackage, UpgradeCap, UpgradePolicy, UpgradeReceipt, UpgradeTicket,
6565
normalize_deserialized_modules,
6666
},
67+
storage::{PackageObject, get_package_objects},
6768
transaction::{Command, ProgrammableMoveCall, ProgrammableTransaction},
6869
transfer::RESOLVED_RECEIVING_STRUCT,
70+
type_input::TypeInput,
6971
};
7072
use sui_verifier::{
7173
INIT_FN_NAME,
7274
private_generics::{EVENT_MODULE, PRIVATE_TRANSFER_FUNCTIONS, TRANSFER_MODULE},
7375
};
7476
use tracing::instrument;
7577

76-
use crate::adapter::substitute_package_id;
77-
use crate::programmable_transactions::context::*;
78-
7978
pub fn execute<Mode: ExecutionMode>(
8079
protocol_config: &ProtocolConfig,
8180
metrics: Arc<LimitsMetrics>,

sui-execution/latest/sui-adapter/src/programmable_transactions/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
pub mod context;
5+
pub mod data_store;
56
pub mod execution;
67
pub mod linkage_view;

0 commit comments

Comments
 (0)