Skip to content

Commit bdf7519

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 6542c29 commit bdf7519

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
@@ -1374,6 +1374,7 @@
13741374
"soft_bundle": false,
13751375
"throughput_aware_consensus_submission": false,
13761376
"txn_base_cost_as_multiplier": false,
1377+
"type_tags_in_object_runtime": false,
13771378
"uncompressed_g1_group_elements": false,
13781379
"upgraded_multisig_supported": false,
13791380
"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
@@ -689,6 +689,10 @@ struct FeatureFlags {
689689
// Enable native function for party transfer
690690
#[serde(skip_serializing_if = "is_false")]
691691
enable_party_transfer: bool,
692+
693+
// Signifies the cut-over of using type tags instead of `Type`s in the object runtime.
694+
#[serde(skip_serializing_if = "is_false")]
695+
type_tags_in_object_runtime: bool,
692696
}
693697

694698
fn is_false(b: &bool) -> bool {
@@ -1969,6 +1973,10 @@ impl ProtocolConfig {
19691973
pub fn enable_party_transfer(&self) -> bool {
19701974
self.feature_flags.enable_party_transfer
19711975
}
1976+
1977+
pub fn type_tags_in_object_runtime(&self) -> bool {
1978+
self.feature_flags.type_tags_in_object_runtime
1979+
}
19721980
}
19731981

19741982
#[cfg(not(msim))]
@@ -3525,6 +3533,7 @@ impl ProtocolConfig {
35253533

35263534
// Enable the new depth-first block sync logic.
35273535
cfg.feature_flags.consensus_batched_block_sync = true;
3536+
cfg.feature_flags.type_tags_in_object_runtime = true;
35283537
}
35293538
// Use this template when making changes:
35303539
//

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
@@ -87,6 +87,7 @@ feature_flags:
8787
enforce_checkpoint_timestamp_monotonicity: true
8888
max_ptb_value_size_v2: true
8989
resolve_type_input_ids_to_defining_id: true
90+
type_tags_in_object_runtime: true
9091
max_tx_size_bytes: 131072
9192
max_input_objects: 2048
9293
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)