Skip to content

Commit b4ea7a4

Browse files
tzakianTimothy Zakian
andauthored
[3/n][object runtime type tags] Add type tags to object runtime update adapter to handle them (#22092)
## Description This updates the object runtime to only hold `TypeTag`s (or `MoveObjecType`s where appropriate) instead of VM runtime `Type`s. It's generally a pretty straightforward change, however there are a couple places worth calling out specifically and I've done so in-line. ## Test plan CI + adding new tests to make sure type tags coming from the object runtime are correctly resolved in newly-published packages. --- ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [X] Protocol: add a new feature flag that switches the object runtime to using TypeTags instead of VM runtime types. - [ ] Nodes (Validators and Full nodes): - [ ] gRPC: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK: --------- Co-authored-by: Timothy Zakian <timothyzakian@mac.lan>
1 parent 68655bf commit b4ea7a4

File tree

20 files changed

+380
-157
lines changed

20 files changed

+380
-157
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) Mysten Labs, Inc.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
//# init --addresses Test=0x0
5+
6+
//# publish
7+
module Test::M1 {
8+
public struct X has key {
9+
id: UID,
10+
}
11+
12+
fun init(ctx: &mut TxContext) {
13+
sui::transfer::transfer(X { id: object::new(ctx) }, ctx.sender());
14+
}
15+
}
16+
17+
//# view-object 1,1
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
source: external-crates/move/crates/move-transactional-test-runner/src/framework.rs
3+
---
4+
processed 3 tasks
5+
6+
task 1, lines 6-15:
7+
//# publish
8+
created: object(1,0), object(1,1)
9+
mutated: object(0,0)
10+
gas summary: computation_cost: 1000000, storage_cost: 6216800, storage_rebate: 0, non_refundable_storage_fee: 0
11+
12+
task 2, line 17:
13+
//# view-object 1,1
14+
Owner: Account Address ( _ )
15+
Version: 2
16+
Contents: Test::M1::X {
17+
id: sui::object::UID {
18+
id: sui::object::ID {
19+
bytes: fake(1,1),
20+
},
21+
},
22+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) Mysten Labs, Inc.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
//# init --addresses Test=0x0
5+
6+
//# publish
7+
module Test::M1 {
8+
public struct Event has copy, drop, store {
9+
x: u64,
10+
}
11+
12+
fun init(_ctx: &mut TxContext) {
13+
sui::event::emit(Event { x: 1 });
14+
}
15+
}
16+
17+
//# view-object 1,0
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
source: external-crates/move/crates/move-transactional-test-runner/src/framework.rs
3+
---
4+
processed 3 tasks
5+
6+
task 1, lines 6-15:
7+
//# publish
8+
events: Event { package_id: Test, transaction_module: Identifier("M1"), sender: _, type_: StructTag { address: Test, module: Identifier("M1"), name: Identifier("Event"), type_params: [] }, contents: [1, 0, 0, 0, 0, 0, 0, 0] }
9+
created: object(1,0)
10+
mutated: object(0,0)
11+
gas summary: computation_cost: 1000000, storage_cost: 4689200, storage_rebate: 0, non_refundable_storage_fee: 0
12+
13+
task 2, line 17:
14+
//# view-object 1,0
15+
1,0::M1

crates/sui-open-rpc/spec/openrpc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,7 @@
13751375
"soft_bundle": false,
13761376
"throughput_aware_consensus_submission": false,
13771377
"txn_base_cost_as_multiplier": false,
1378+
"type_tags_in_object_runtime": false,
13781379
"uncompressed_g1_group_elements": false,
13791380
"upgraded_multisig_supported": false,
13801381
"validate_identifier_inputs": false,

crates/sui-protocol-config/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,10 @@ struct FeatureFlags {
694694
// Enable native function for party transfer
695695
#[serde(skip_serializing_if = "is_false")]
696696
enable_party_transfer: bool,
697+
698+
// Signifies the cut-over of using type tags instead of `Type`s in the object runtime.
699+
#[serde(skip_serializing_if = "is_false")]
700+
type_tags_in_object_runtime: bool,
697701
}
698702

699703
fn is_false(b: &bool) -> bool {
@@ -1978,6 +1982,10 @@ impl ProtocolConfig {
19781982
pub fn enable_party_transfer(&self) -> bool {
19791983
self.feature_flags.enable_party_transfer
19801984
}
1985+
1986+
pub fn type_tags_in_object_runtime(&self) -> bool {
1987+
self.feature_flags.type_tags_in_object_runtime
1988+
}
19811989
}
19821990

19831991
#[cfg(not(msim))]
@@ -3539,6 +3547,7 @@ impl ProtocolConfig {
35393547
// native function on mainnet.
35403548
cfg.feature_flags.enable_nitro_attestation_upgraded_parsing = true;
35413549
cfg.feature_flags.enable_nitro_attestation = true;
3550+
cfg.feature_flags.type_tags_in_object_runtime = true;
35423551
}
35433552
// Use this template when making changes:
35443553
//

crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Mainnet_version_83.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ feature_flags:
9090
enforce_checkpoint_timestamp_monotonicity: true
9191
max_ptb_value_size_v2: true
9292
resolve_type_input_ids_to_defining_id: true
93+
type_tags_in_object_runtime: true
9394
max_tx_size_bytes: 131072
9495
max_input_objects: 2048
9596
max_size_written_objects: 5000000

crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Testnet_version_83.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ feature_flags:
9292
enforce_checkpoint_timestamp_monotonicity: true
9393
max_ptb_value_size_v2: true
9494
resolve_type_input_ids_to_defining_id: true
95+
type_tags_in_object_runtime: true
9596
max_tx_size_bytes: 131072
9697
max_input_objects: 2048
9798
max_size_written_objects: 5000000

crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__version_83.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ feature_flags:
9797
enforce_checkpoint_timestamp_monotonicity: true
9898
max_ptb_value_size_v2: true
9999
resolve_type_input_ids_to_defining_id: true
100+
type_tags_in_object_runtime: true
100101
max_tx_size_bytes: 131072
101102
max_input_objects: 2048
102103
max_size_written_objects: 5000000

external-crates/move/crates/move-vm-runtime/src/native_functions.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ use move_core_types::{
2020
};
2121
use move_vm_config::runtime::VMRuntimeLimitsConfig;
2222
use move_vm_types::{
23-
loaded_data::runtime_types::Type, natives::function::NativeResult, values::Value,
23+
data_store::DataStore, loaded_data::runtime_types::Type, natives::function::NativeResult,
24+
values::Value,
2425
};
2526
use std::{
2627
cell::RefCell,
@@ -158,6 +159,36 @@ impl<'b> NativeContext<'_, 'b> {
158159
}
159160
}
160161

162+
// TODO: This is a bit hacky right now since we need to pass the store, however this is only
163+
// used in test scenarios so we have some special knowledge that makes this work. In the new VM
164+
// however this is _MUCH_ nicer as we don't need to pass the datastore as the VM's linkage
165+
// tables must have the type present.
166+
pub fn type_tag_to_fully_annotated_layout_for_test_scenario_only(
167+
&self,
168+
tag: &TypeTag,
169+
store: &impl DataStore,
170+
) -> PartialVMResult<A::MoveTypeLayout> {
171+
self.resolver
172+
.loader()
173+
.get_fully_annotated_type_layout(tag, store)
174+
.map_err(|e| e.to_partial())
175+
}
176+
177+
// TODO: This is a bit hacky right now since we need to pass the store, however this is only
178+
// used in test scenarios so we have some special knowledge that makes this work. In the new VM
179+
// however this is _MUCH_ nicer as we don't need to pass the datastore as the VM's linkage
180+
// tables must have the type present.
181+
pub fn type_tag_to_layout_for_test_scenario_only(
182+
&self,
183+
tag: &TypeTag,
184+
store: &impl DataStore,
185+
) -> PartialVMResult<R::MoveTypeLayout> {
186+
self.resolver
187+
.loader()
188+
.get_type_layout(tag, store)
189+
.map_err(|e| e.to_partial())
190+
}
191+
161192
pub fn type_to_abilities(&self, ty: &Type) -> PartialVMResult<AbilitySet> {
162193
self.resolver.loader().abilities(ty)
163194
}

0 commit comments

Comments
 (0)