Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sui-framework/package]
Publisher
checks recognise upgrades (#12026)
## Description Change the behaviour of functions like: ``` sui::package::from_package<T>(self: &Publisher): bool sui::package::from_module<T>(self: &Publisher): bool ``` to return `true` when `T` is from an upgraded version of the package associated with `Publisher`. Previously it was impossible to check the package ownership of a type introduced in an upgraded package (the upgraded type's type name didn't match the original package's `Publisher` and it was impossible to create a `Publisher` for the upgraded package, because it requires an OTW which we can't create for upgraded packages). This support was added by introducing a new stdlib function: `std::typename::get_original`, as of protocol version 11, which produces a runtime representation of the type that uses original (aka runtime) package IDs instead of defining package IDs (the default behaviour for `std::typename::get` and any other case where a runtime representation of the type is converted into an on-chain or storage representation of a type). ## Test Plan New transactional test cases for `std::type_name::get_original` and `sui::package::from_package`: ``` $ cargo nextest run -- upgrade/type_names.move $ cargo nextest run -- upgrade/publisher.move ``` --- If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process. ### Type of Change (Check all that apply) - [x] user-visible impact - [ ] breaking change for a client SDKs - [x] breaking change for FNs (FN binary must upgrade) - [x] breaking change for validators or node operators (must upgrade binaries) - [ ] breaking change for on-chain data layout - [ ] necessitate either a data wipe or data migration ### Release notes As of protocol version 11: - `sui::package::from_package<T>(self: &Publisher)` and `sui::package::from_module<T>(self: &Publisher)` return `true` when `T` is a type introduced at any upgraded version of the package associated with `self: &Publisher` (rather than just the types originally present when that package was published). - `std::type_name::get_original` is introduced as a new stdlib function to return a representation of the type where package IDs have all been normalized to "original" IDs (the ID of the first version of a package) in contrast to the default behaviour of `std::type_name::get` which distinguishes types introduced at different versions of a package by assigning them the ID of the package that introduced them.
- Loading branch information
Showing
17 changed files
with
569 additions
and
63 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
crates/sui-adapter-transactional-tests/tests/upgrade/publisher.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
processed 5 tasks | ||
|
||
init: | ||
A: object(0,0) | ||
|
||
task 1 'publish'. lines 6-17: | ||
created: object(1,0), object(1,1), object(1,2) | ||
mutated: object(0,0) | ||
gas summary: computation_cost: 1000000, storage_cost: 8557600, storage_rebate: 0, non_refundable_storage_fee: 0 | ||
|
||
task 2 'upgrade'. lines 19-35: | ||
created: object(2,0) | ||
mutated: object(0,0), object(1,2) | ||
gas summary: computation_cost: 1000000, storage_cost: 7691200, storage_rebate: 2595780, non_refundable_storage_fee: 26220 | ||
|
||
task 3 'run'. lines 37-37: | ||
mutated: object(0,0), object(1,1) | ||
gas summary: computation_cost: 1000000, storage_cost: 2812000, storage_rebate: 2783880, non_refundable_storage_fee: 28120 | ||
|
||
task 4 'run'. lines 39-39: | ||
mutated: object(0,0), object(1,1) | ||
gas summary: computation_cost: 1000000, storage_cost: 2812000, storage_rebate: 2783880, non_refundable_storage_fee: 28120 |
39 changes: 39 additions & 0 deletions
39
crates/sui-adapter-transactional-tests/tests/upgrade/publisher.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//# init --addresses A0=0x0 A1=0x0 --accounts A | ||
|
||
//# publish --upgradeable --sender A | ||
module A0::m { | ||
use sui::package; | ||
use sui::tx_context::TxContext; | ||
|
||
struct A {} | ||
struct M has drop {} | ||
|
||
fun init(m: M, ctx: &mut TxContext) { | ||
package::claim_and_keep(m, ctx); | ||
} | ||
} | ||
|
||
//# upgrade --package A0 --upgrade-capability 1,2 --sender A | ||
module A1::m { | ||
use sui::package::{Self, Publisher}; | ||
use sui::tx_context::TxContext; | ||
|
||
struct A {} | ||
struct B {} | ||
struct M has drop {} | ||
|
||
fun init(m: M, ctx: &mut TxContext) { | ||
package::claim_and_keep(m, ctx); | ||
} | ||
|
||
entry fun test<T>(p: &Publisher) { | ||
assert!(package::from_package<T>(p), 0) | ||
} | ||
} | ||
|
||
//# run A1::m::test --type-args A0::m::A --args object(1,1) --sender A | ||
|
||
//# run A1::m::test --type-args A1::m::B --args object(1,1) --sender A |
59 changes: 59 additions & 0 deletions
59
crates/sui-adapter-transactional-tests/tests/upgrade/type_names.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
processed 12 tasks | ||
|
||
init: | ||
A: object(0,0) | ||
|
||
task 1 'publish'. lines 6-17: | ||
created: object(1,0), object(1,1) | ||
mutated: object(0,0) | ||
gas summary: computation_cost: 1000000, storage_cost: 6171200, storage_rebate: 0, non_refundable_storage_fee: 0 | ||
|
||
task 2 'upgrade'. lines 19-30: | ||
created: object(2,0) | ||
mutated: object(0,0), object(1,1) | ||
gas summary: computation_cost: 1000000, storage_cost: 6520800, storage_rebate: 2595780, non_refundable_storage_fee: 26220 | ||
|
||
task 3 'upgrade'. lines 32-62: | ||
created: object(3,0) | ||
mutated: object(0,0), object(1,1) | ||
gas summary: computation_cost: 1000000, storage_cost: 9066800, storage_rebate: 2595780, non_refundable_storage_fee: 26220 | ||
|
||
task 4 'run'. lines 64-64: | ||
created: object(4,0) | ||
mutated: object(0,0) | ||
gas summary: computation_cost: 1000000, storage_cost: 2728400, storage_rebate: 978120, non_refundable_storage_fee: 9880 | ||
|
||
task 5 'run'. lines 66-66: | ||
created: object(5,0) | ||
mutated: object(0,0) | ||
gas summary: computation_cost: 1000000, storage_cost: 2728400, storage_rebate: 978120, non_refundable_storage_fee: 9880 | ||
|
||
task 6 'run'. lines 68-68: | ||
created: object(6,0) | ||
mutated: object(0,0) | ||
gas summary: computation_cost: 1000000, storage_cost: 2728400, storage_rebate: 978120, non_refundable_storage_fee: 9880 | ||
|
||
task 7 'run'. lines 70-70: | ||
created: object(7,0) | ||
mutated: object(0,0) | ||
gas summary: computation_cost: 1000000, storage_cost: 2728400, storage_rebate: 978120, non_refundable_storage_fee: 9880 | ||
|
||
task 8 'view-object'. lines 72-72: | ||
Owner: Account Address ( A ) | ||
Version: 5 | ||
Contents: A0::m::Canary {id: sui::object::UID {id: sui::object::ID {bytes: fake(4,0)}}, addr: vector[57u8, 98u8, 48u8, 52u8, 101u8, 52u8, 50u8, 57u8, 50u8, 54u8, 101u8, 55u8, 48u8, 54u8, 54u8, 56u8, 99u8, 101u8, 56u8, 50u8, 97u8, 52u8, 99u8, 50u8, 51u8, 56u8, 56u8, 98u8, 101u8, 52u8, 101u8, 50u8, 100u8, 52u8, 99u8, 53u8, 98u8, 54u8, 54u8, 49u8, 98u8, 101u8, 48u8, 50u8, 52u8, 98u8, 53u8, 56u8, 101u8, 49u8, 53u8, 49u8, 56u8, 101u8, 55u8, 49u8, 99u8, 55u8, 54u8, 56u8, 57u8, 50u8, 51u8, 54u8]} | ||
|
||
task 9 'view-object'. lines 74-74: | ||
Owner: Account Address ( A ) | ||
Version: 6 | ||
Contents: A0::m::Canary {id: sui::object::UID {id: sui::object::ID {bytes: fake(5,0)}}, addr: vector[57u8, 98u8, 48u8, 52u8, 101u8, 52u8, 50u8, 57u8, 50u8, 54u8, 101u8, 55u8, 48u8, 54u8, 54u8, 56u8, 99u8, 101u8, 56u8, 50u8, 97u8, 52u8, 99u8, 50u8, 51u8, 56u8, 56u8, 98u8, 101u8, 52u8, 101u8, 50u8, 100u8, 52u8, 99u8, 53u8, 98u8, 54u8, 54u8, 49u8, 98u8, 101u8, 48u8, 50u8, 52u8, 98u8, 53u8, 56u8, 101u8, 49u8, 53u8, 49u8, 56u8, 101u8, 55u8, 49u8, 99u8, 55u8, 54u8, 56u8, 57u8, 50u8, 51u8, 54u8]} | ||
|
||
task 10 'view-object'. lines 76-76: | ||
Owner: Account Address ( A ) | ||
Version: 7 | ||
Contents: A0::m::Canary {id: sui::object::UID {id: sui::object::ID {bytes: fake(6,0)}}, addr: vector[57u8, 98u8, 48u8, 52u8, 101u8, 52u8, 50u8, 57u8, 50u8, 54u8, 101u8, 55u8, 48u8, 54u8, 54u8, 56u8, 99u8, 101u8, 56u8, 50u8, 97u8, 52u8, 99u8, 50u8, 51u8, 56u8, 56u8, 98u8, 101u8, 52u8, 101u8, 50u8, 100u8, 52u8, 99u8, 53u8, 98u8, 54u8, 54u8, 49u8, 98u8, 101u8, 48u8, 50u8, 52u8, 98u8, 53u8, 56u8, 101u8, 49u8, 53u8, 49u8, 56u8, 101u8, 55u8, 49u8, 99u8, 55u8, 54u8, 56u8, 57u8, 50u8, 51u8, 54u8]} | ||
|
||
task 11 'view-object'. lines 78-78: | ||
Owner: Account Address ( A ) | ||
Version: 8 | ||
Contents: A0::m::Canary {id: sui::object::UID {id: sui::object::ID {bytes: fake(7,0)}}, addr: vector[98u8, 55u8, 50u8, 55u8, 55u8, 53u8, 48u8, 100u8, 98u8, 50u8, 54u8, 48u8, 49u8, 52u8, 101u8, 53u8, 54u8, 101u8, 99u8, 102u8, 57u8, 50u8, 99u8, 100u8, 51u8, 50u8, 101u8, 52u8, 100u8, 48u8, 54u8, 56u8, 50u8, 51u8, 56u8, 56u8, 50u8, 49u8, 54u8, 50u8, 51u8, 99u8, 48u8, 52u8, 54u8, 57u8, 56u8, 100u8, 57u8, 54u8, 50u8, 57u8, 48u8, 56u8, 100u8, 49u8, 50u8, 48u8, 97u8, 53u8, 49u8, 54u8, 100u8, 48u8]} |
78 changes: 78 additions & 0 deletions
78
crates/sui-adapter-transactional-tests/tests/upgrade/type_names.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//# init --addresses A0=0x0 A1=0x0 A2=0x0 --accounts A | ||
|
||
//# publish --upgradeable --sender A | ||
module A0::m { | ||
use sui::object::UID; | ||
|
||
struct Canary has key { | ||
id: UID, | ||
addr: vector<u8>, | ||
} | ||
|
||
struct A {} | ||
|
||
} | ||
|
||
//# upgrade --package A0 --upgrade-capability 1,1 --sender A | ||
module A1::m { | ||
use sui::object::UID; | ||
|
||
struct Canary has key { | ||
id: UID, | ||
addr: vector<u8>, | ||
} | ||
|
||
struct A {} | ||
struct B {} | ||
} | ||
|
||
//# upgrade --package A1 --upgrade-capability 1,1 --sender A | ||
module A2::m { | ||
use std::ascii; | ||
use std::type_name; | ||
use sui::object::{Self, UID}; | ||
use sui::transfer; | ||
use sui::tx_context::{Self, TxContext}; | ||
|
||
struct Canary has key { | ||
id: UID, | ||
addr: vector<u8>, | ||
} | ||
|
||
struct A {} | ||
struct B {} | ||
|
||
entry fun canary<T>(use_original: bool, ctx: &mut TxContext) { | ||
let type = if (use_original) { | ||
type_name::get_original<T>() | ||
} else { | ||
type_name::get<T>() | ||
}; | ||
|
||
let addr = ascii::into_bytes(type_name::get_address(&type)); | ||
|
||
transfer::transfer( | ||
Canary { id: object::new(ctx), addr }, | ||
tx_context::sender(ctx), | ||
) | ||
} | ||
} | ||
|
||
//# run A2::m::canary --type-args A0::m::A --args true --sender A | ||
|
||
//# run A2::m::canary --type-args A1::m::B --args true --sender A | ||
|
||
//# run A2::m::canary --type-args A0::m::A --args false --sender A | ||
|
||
//# run A2::m::canary --type-args A1::m::B --args false --sender A | ||
|
||
//# view-object 4,0 | ||
|
||
//# view-object 5,0 | ||
|
||
//# view-object 6,0 | ||
|
||
//# view-object 7,0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
731ed97
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
offline-signer-helper – ./dapps/offline-signer-helper
offline-signer-helper-mysten-labs.vercel.app
offline-signer-helper.vercel.app
offline-signer-helper-git-main-mysten-labs.vercel.app
731ed97
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 Validators 500/s Owned Transactions Benchmark Results
4 Validators 500/s Shared Transactions Benchmark Results
20 Validators 50/s Owned Transactions Benchmark Results
20 Validators 50/s Shared Transactions Benchmark Results
Narwhal Benchmark Results