Skip to content

Commit fa9eab2

Browse files
manolislioliosdamirkaamnn
authored
[framework] Display Registry (#23710)
## Description Introduces new Display using a registry (similar to coin): 1. Display no longer is restricted to `T: key`. We can have display for non top-level objects. 2. Enable migration paths from `Display<T>` and `Publisher`, as well as legacy deletion after migration. 3. Enable "system" migration path using a singleton Cap, that will be destroyed after moving V1s to the registry. **Why we are doing this?** 1. Display indexing currently relies on events, making it extremely hard to maintain proper indexing. This takes away this problem, by having a fixed point of lookup and rely on the live object set. 2. We wanna enable display for non-`key` objects too 3. Future-proof our way into an even better creation (e.g when args on init are landed) **TODOS:** - [x] Create the core framework code - [x] Add move tests for all cases - [x] Style / naming nits - [x] Create new system object `0xd`(?) - [ ] Leverage GQL's indexer's db to get a snapshot of V1 display objects and create the PTBs to migrate them - [x] Come up with a secure key policy to store the migration cap (if we agree on doing it that way) - [ ] Deprecate V1 package (`display.move`) [in a follow-up PR] ## Test plan How did you test the new or updated feature? --- ## 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: Enables Display V2 (`0xd` system object is created) - [ ] Nodes (Validators and Full nodes): - [ ] gRPC: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK: --------- Co-authored-by: Damir Shamanaev <damirka.ru@gmail.com> Co-authored-by: Ashok Menon <ashok@mystenlabs.com>
1 parent 7fd871b commit fa9eab2

File tree

27 files changed

+3431
-20
lines changed

27 files changed

+3431
-20
lines changed

crates/sui-adapter-transactional-tests/tests/deny_list_v2/coin_deny_and_undeny_address_balance_receiver.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ gas summary: computation_cost: 1000000, storage_cost: 2462400, storage_rebate:
2525

2626
task 3, lines 51-53:
2727
//# run sui::coin::deny_list_v2_add --args object(0x403) object(1,3) @B --type-args test::regulated_coin::REGULATED_COIN --sender A
28-
events: Event { package_id: sui, transaction_module: Identifier("coin"), sender: A, type_: StructTag { address: sui, module: Identifier("deny_list"), name: Identifier("PerTypeConfigCreated"), type_params: [] }, contents: [0, 0, 0, 0, 0, 0, 0, 0, 96, 53, 56, 53, 52, 48, 102, 51, 101, 100, 98, 52, 55, 98, 101, 50, 100, 49, 102, 97, 49, 54, 98, 52, 100, 51, 100, 56, 50, 49, 49, 97, 97, 55, 98, 51, 51, 52, 97, 101, 102, 100, 102, 98, 100, 56, 101, 53, 57, 49, 100, 48, 101, 49, 98, 98, 102, 51, 101, 100, 101, 100, 100, 98, 57, 58, 58, 114, 101, 103, 117, 108, 97, 116, 101, 100, 95, 99, 111, 105, 110, 58, 58, 82, 69, 71, 85, 76, 65, 84, 69, 68, 95, 67, 79, 73, 78, 61, 199, 45, 186, 21, 90, 110, 90, 45, 79, 121, 139, 89, 41, 35, 50, 97, 221, 198, 45, 196, 118, 7, 0, 209, 225, 159, 65, 59, 51, 14, 83] }
28+
events: Event { package_id: sui, transaction_module: Identifier("coin"), sender: A, type_: StructTag { address: sui, module: Identifier("deny_list"), name: Identifier("PerTypeConfigCreated"), type_params: [] }, contents: [0, 0, 0, 0, 0, 0, 0, 0, 96, 97, 98, 49, 50, 98, 55, 53, 98, 55, 54, 53, 52, 55, 101, 98, 56, 49, 55, 56, 102, 50, 50, 56, 54, 100, 49, 55, 56, 50, 57, 54, 55, 53, 54, 53, 51, 52, 48, 57, 50, 49, 51, 98, 102, 99, 50, 98, 98, 101, 55, 99, 49, 102, 56, 48, 55, 54, 54, 54, 48, 53, 54, 55, 100, 58, 58, 114, 101, 103, 117, 108, 97, 116, 101, 100, 95, 99, 111, 105, 110, 58, 58, 82, 69, 71, 85, 76, 65, 84, 69, 68, 95, 67, 79, 73, 78, 187, 185, 8, 111, 183, 37, 243, 247, 76, 179, 11, 187, 190, 163, 180, 166, 144, 42, 199, 57, 211, 35, 34, 225, 81, 92, 79, 186, 84, 130, 149, 55] }
2929
created: object(3,0), object(3,1), object(3,2)
3030
mutated: 0x0000000000000000000000000000000000000000000000000000000000000403, object(0,0), object(1,3)
3131
gas summary: computation_cost: 1000000, storage_cost: 12190400, storage_rebate: 2746260, non_refundable_storage_fee: 27740
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
---
2+
source: crates/sui-core/src/authority/execution_time_estimator.rs
3+
expression: snapshot_data
4+
---
5+
protocol_version: 116
6+
consensus_observations:
7+
- - MakeMoveVec
8+
- observations:
9+
- - 9
10+
- secs: 0
11+
nanos: 15000000
12+
- - 4
13+
- secs: 0
14+
nanos: 28000000
15+
- - 5
16+
- secs: 0
17+
nanos: 19000000
18+
- - 7
19+
- secs: 0
20+
nanos: 15000000
21+
stake_weighted_median:
22+
secs: 0
23+
nanos: 19000000
24+
- - MergeCoins
25+
- observations:
26+
- - 6
27+
- secs: 0
28+
nanos: 63000000
29+
- - 3
30+
- secs: 0
31+
nanos: 70000000
32+
- - 2
33+
- secs: 0
34+
nanos: 32000000
35+
- - 7
36+
- secs: 0
37+
nanos: 0
38+
stake_weighted_median:
39+
secs: 0
40+
nanos: 63000000
41+
- - SplitCoins
42+
- observations:
43+
- - 0
44+
- ~
45+
- - 0
46+
- ~
47+
- - 5
48+
- secs: 0
49+
nanos: 54000000
50+
- - 3
51+
- secs: 0
52+
nanos: 61000000
53+
stake_weighted_median:
54+
secs: 0
55+
nanos: 61000000
56+
- - TransferObjects
57+
- observations:
58+
- - 9
59+
- secs: 0
60+
nanos: 35000000
61+
- - 0
62+
- ~
63+
- - 7
64+
- secs: 0
65+
nanos: 28000000
66+
- - 5
67+
- secs: 0
68+
nanos: 91000000
69+
stake_weighted_median:
70+
secs: 0
71+
nanos: 35000000
72+
- - Upgrade
73+
- observations:
74+
- - 1
75+
- secs: 0
76+
nanos: 677000000
77+
- - 10
78+
- secs: 0
79+
nanos: 530000000
80+
- - 6
81+
- secs: 0
82+
nanos: 981000000
83+
- - 8
84+
- secs: 0
85+
nanos: 802000000
86+
stake_weighted_median:
87+
secs: 0
88+
nanos: 802000000
89+
- - MoveEntryPoint:
90+
package: "0x0000000000000000000000000000000000000000000000000000000000000001"
91+
module: coin
92+
function: transfer
93+
type_arguments: []
94+
- observations:
95+
- - 7
96+
- secs: 0
97+
nanos: 404000000
98+
- - 8
99+
- secs: 0
100+
nanos: 322000000
101+
- - 9
102+
- secs: 0
103+
nanos: 268000000
104+
- - 0
105+
- ~
106+
stake_weighted_median:
107+
secs: 0
108+
nanos: 322000000
109+
- - MoveEntryPoint:
110+
package: "0x0000000000000000000000000000000000000000000000000000000000000002"
111+
module: nft
112+
function: mint
113+
type_arguments: []
114+
- observations:
115+
- - 2
116+
- secs: 0
117+
nanos: 290000000
118+
- - 0
119+
- ~
120+
- - 5
121+
- secs: 0
122+
nanos: 307000000
123+
- - 10
124+
- secs: 0
125+
nanos: 0
126+
stake_weighted_median:
127+
secs: 0
128+
nanos: 290000000
129+
transaction_estimates:
130+
- - coin_transfer_call
131+
- secs: 0
132+
nanos: 322000000
133+
- - mixed_move_calls
134+
- secs: 0
135+
nanos: 612000000
136+
- - native_commands_with_observations
137+
- secs: 0
138+
nanos: 356000000
139+
- - transfer_objects_3_items
140+
- secs: 0
141+
nanos: 140000000
142+
- - split_coins_4_amounts
143+
- secs: 0
144+
nanos: 305000000
145+
- - merge_coins_2_sources
146+
- secs: 0
147+
nanos: 189000000
148+
- - make_move_vec_5_elements
149+
- secs: 0
150+
nanos: 114000000
151+
- - mixed_commands
152+
- secs: 0
153+
nanos: 228000000
154+
- - upgrade_package
155+
- secs: 0
156+
nanos: 802000000
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Copyright (c) Mysten Labs, Inc.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
use sui_types::supported_protocol_versions::SupportedProtocolVersions;
5+
use sui_types::{SUI_DISPLAY_REGISTRY_OBJECT_ID, SUI_FRAMEWORK_PACKAGE_ID};
6+
use test_cluster::TestClusterBuilder;
7+
8+
use sui_macros::sim_test;
9+
10+
#[sim_test]
11+
async fn test_create_display_registry_object() {
12+
let _guard =
13+
sui_protocol_config::ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
14+
// The new consensus handler requires these flags, and they are irrelevant to the test
15+
config.set_ignore_execution_time_observations_after_certs_closed_for_testing(true);
16+
config.set_record_time_estimate_processed_for_testing(true);
17+
config.set_prepend_prologue_tx_in_consensus_commit_in_checkpoints_for_testing(true);
18+
config.set_consensus_checkpoint_signature_key_includes_digest_for_testing(true);
19+
config.set_cancel_for_failed_dkg_early_for_testing(true);
20+
config.set_use_mfp_txns_in_load_initial_object_debts_for_testing(true);
21+
config.set_authority_capabilities_v2_for_testing(true);
22+
config
23+
});
24+
25+
let framework = sui_framework_snapshot::load_bytecode_snapshot(115)
26+
.unwrap()
27+
.into_iter()
28+
.map(|p| p.genesis_object())
29+
.collect::<Vec<_>>();
30+
31+
let package = framework
32+
.iter()
33+
.find(|f| f.id() == SUI_FRAMEWORK_PACKAGE_ID)
34+
.unwrap()
35+
.data
36+
.try_as_package()
37+
.unwrap();
38+
39+
// Make sure that `display_registry` does not exist on previous protocol version.
40+
assert!(
41+
!package
42+
.serialized_module_map()
43+
.contains_key("display_registry")
44+
);
45+
46+
let test_cluster = TestClusterBuilder::new()
47+
.with_protocol_version(115.into())
48+
.with_epoch_duration_ms(10000)
49+
.with_objects(framework)
50+
.with_supported_protocol_versions(SupportedProtocolVersions::new_for_testing(115, 116))
51+
.build()
52+
.await;
53+
54+
let handles = test_cluster.all_node_handles();
55+
56+
// no node has the display registry object yet
57+
for h in &handles {
58+
h.with(|node| {
59+
assert!(
60+
node.state()
61+
.get_object_cache_reader()
62+
.get_latest_object_ref_or_tombstone(SUI_DISPLAY_REGISTRY_OBJECT_ID)
63+
.is_none()
64+
);
65+
});
66+
}
67+
68+
// wait until feature is enabled
69+
test_cluster.wait_for_protocol_version(96.into()).await;
70+
// wait until next epoch - display registry object is created at the end of the first epoch
71+
// in which it is supported.
72+
test_cluster.wait_for_epoch_all_nodes(2).await; // protocol upgrade completes in epoch 1
73+
74+
for h in &handles {
75+
h.with(|node| {
76+
node.state()
77+
.get_object_cache_reader()
78+
.get_latest_object_ref_or_tombstone(SUI_DISPLAY_REGISTRY_OBJECT_ID)
79+
.expect("display registry object should exist");
80+
});
81+
}
82+
}

crates/sui-framework/docs/sui/display.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ More entry functions might be added in the future depending on the use cases.
2828
- [Function `is_authorized`](#sui_display_is_authorized)
2929
- [Function `version`](#sui_display_version)
3030
- [Function `fields`](#sui_display_fields)
31+
- [Function `destroy`](#sui_display_destroy)
3132
- [Function `create_internal`](#sui_display_create_internal)
3233
- [Function `add_internal`](#sui_display_add_internal)
3334

@@ -510,6 +511,32 @@ Read the <code><a href="../sui/display.md#sui_display_fields">fields</a></code>
510511

511512

512513

514+
</details>
515+
516+
<a name="sui_display_destroy"></a>
517+
518+
## Function `destroy`
519+
520+
Allow destroying legacy display objects.
521+
522+
523+
<pre><code><b>public</b>(<a href="../sui/package.md#sui_package">package</a>) <b>fun</b> <a href="../sui/display.md#sui_display_destroy">destroy</a>&lt;T: key&gt;(<a href="../sui/display.md#sui_display">display</a>: <a href="../sui/display.md#sui_display_Display">sui::display::Display</a>&lt;T&gt;)
524+
</code></pre>
525+
526+
527+
528+
<details>
529+
<summary>Implementation</summary>
530+
531+
532+
<pre><code><b>public</b>(<a href="../sui/package.md#sui_package">package</a>) <b>fun</b> <a href="../sui/display.md#sui_display_destroy">destroy</a>&lt;T: key&gt;(<a href="../sui/display.md#sui_display">display</a>: <a href="../sui/display.md#sui_display_Display">Display</a>&lt;T&gt;) {
533+
<b>let</b> <a href="../sui/display.md#sui_display_Display">Display</a> { id, .. } = <a href="../sui/display.md#sui_display">display</a>;
534+
id.delete();
535+
}
536+
</code></pre>
537+
538+
539+
513540
</details>
514541

515542
<a name="sui_display_create_internal"></a>

0 commit comments

Comments
 (0)