Skip to content

Commit 4da3d3b

Browse files
Timothy Zakiantzakian
authored andcommitted
[3/n][object runtime type tags] Add type tags to object runtime update adapter to handle them.
1 parent e04baee commit 4da3d3b

File tree

20 files changed

+388
-157
lines changed

20 files changed

+388
-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
@@ -1373,6 +1373,7 @@
13731373
"soft_bundle": false,
13741374
"throughput_aware_consensus_submission": false,
13751375
"txn_base_cost_as_multiplier": false,
1376+
"type_tags_in_object_runtime": false,
13761377
"uncompressed_g1_group_elements": false,
13771378
"upgraded_multisig_supported": false,
13781379
"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
@@ -684,6 +684,10 @@ struct FeatureFlags {
684684
// If true, resolves all type input ids to be defining ID based in the adapter
685685
#[serde(skip_serializing_if = "is_false")]
686686
resolve_type_input_ids_to_defining_id: bool,
687+
688+
// Signifies the cut-over of using type tags instead of `Type`s in the object runtime.
689+
#[serde(skip_serializing_if = "is_false")]
690+
type_tags_in_object_runtime: bool,
687691
}
688692

689693
fn is_false(b: &bool) -> bool {
@@ -1958,6 +1962,10 @@ impl ProtocolConfig {
19581962
pub fn resolve_type_input_ids_to_defining_id(&self) -> bool {
19591963
self.feature_flags.resolve_type_input_ids_to_defining_id
19601964
}
1965+
1966+
pub fn type_tags_in_object_runtime(&self) -> bool {
1967+
self.feature_flags.type_tags_in_object_runtime
1968+
}
19611969
}
19621970

19631971
#[cfg(not(msim))]
@@ -3495,6 +3503,7 @@ impl ProtocolConfig {
34953503
}
34963504
83 => {
34973505
cfg.feature_flags.resolve_type_input_ids_to_defining_id = true;
3506+
cfg.feature_flags.type_tags_in_object_runtime = true;
34983507
}
34993508
// Use this template when making changes:
35003509
//

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
@@ -80,6 +80,7 @@ feature_flags:
8080
enforce_checkpoint_timestamp_monotonicity: true
8181
max_ptb_value_size_v2: true
8282
resolve_type_input_ids_to_defining_id: true
83+
type_tags_in_object_runtime: true
8384
max_tx_size_bytes: 131072
8485
max_input_objects: 2048
8586
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
@@ -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__version_83.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ feature_flags:
9595
enforce_checkpoint_timestamp_monotonicity: true
9696
max_ptb_value_size_v2: true
9797
resolve_type_input_ids_to_defining_id: true
98+
type_tags_in_object_runtime: true
9899
max_tx_size_bytes: 131072
99100
max_input_objects: 2048
100101
max_size_written_objects: 5000000

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

Lines changed: 42 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,46 @@ 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(
167+
&self,
168+
tag: &TypeTag,
169+
store: &impl DataStore,
170+
) -> PartialVMResult<Option<A::MoveTypeLayout>> {
171+
match self
172+
.resolver
173+
.loader()
174+
.get_fully_annotated_type_layout(tag, store)
175+
{
176+
Ok(ty_layout) => Ok(Some(ty_layout)),
177+
Err(e) if e.major_status().status_type() == StatusType::InvariantViolation => {
178+
Err(e.to_partial())
179+
}
180+
Err(_) => Ok(None),
181+
}
182+
}
183+
184+
// TODO: This is a bit hacky right now since we need to pass the store, however this is only
185+
// used in test scenarios so we have some special knowledge that makes this work. In the new VM
186+
// however this is _MUCH_ nicer as we don't need to pass the datastore as the VM's linkage
187+
// tables must have the type present.
188+
pub fn type_tag_to_layout(
189+
&self,
190+
tag: &TypeTag,
191+
store: &impl DataStore,
192+
) -> PartialVMResult<Option<R::MoveTypeLayout>> {
193+
match self.resolver.loader().get_type_layout(tag, store) {
194+
Ok(ty_layout) => Ok(Some(ty_layout)),
195+
Err(e) if e.major_status().status_type() == StatusType::InvariantViolation => {
196+
Err(e.to_partial())
197+
}
198+
Err(_) => Ok(None),
199+
}
200+
}
201+
161202
pub fn type_to_abilities(&self, ty: &Type) -> PartialVMResult<AbilitySet> {
162203
self.resolver.loader().abilities(ty)
163204
}

0 commit comments

Comments
 (0)