-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support freeze package upgrading #1808
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,18 +108,21 @@ module moveos_std::module_store { | |
|
||
/// Publish modules to the module object's storage | ||
/// Return true if the modules are upgraded | ||
public(friend) fun publish_modules_internal(module_object: &mut Object<ModuleStore>, package_id: address, modules: vector<MoveModule>) : bool { | ||
public(friend) fun publish_modules_internal( | ||
module_object: &mut Object<ModuleStore>, package_id: address, modules: vector<MoveModule> | ||
) : bool { | ||
let i = 0; | ||
let len = vector::length(&modules); | ||
let (module_names, module_names_with_init_fn, indices) = move_module::sort_and_verify_modules(&modules, package_id); | ||
|
||
let is_upgrade = true; | ||
if (!exists_package(module_object, package_id)) { | ||
let package = object::add_object_field_with_id(module_object, package_id, Package {}); | ||
object::transfer_extend(package, tx_context::sender()); | ||
// TODO: should we transfer the Package object to tx sender or package id address? | ||
create_package(module_object, package_id, tx_context::sender()); | ||
is_upgrade = false; | ||
}; | ||
let package = borrow_mut_package(module_object, package_id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check if the |
||
|
||
let upgrade_flag = false; | ||
while (i < len) { | ||
let module_name = vector::pop_back(&mut module_names); | ||
let index = vector::pop_back(&mut indices); | ||
|
@@ -129,7 +132,6 @@ module moveos_std::module_store { | |
if (object::contains_field(package, module_name)) { | ||
let old_m = remove_module(package, module_name); | ||
move_module::check_comatibility(m, &old_m); | ||
upgrade_flag = true; | ||
} else { | ||
// request init function invoking | ||
if (vector::contains(&module_names_with_init_fn, &module_name)) { | ||
|
@@ -140,7 +142,12 @@ module moveos_std::module_store { | |
add_module(package, module_name, *m); | ||
i = i + 1; | ||
}; | ||
upgrade_flag | ||
is_upgrade | ||
} | ||
|
||
fun create_package(module_object: &mut Object<ModuleStore>, package_id: address, owner: address) { | ||
let package = object::add_object_field_with_id(module_object, package_id, Package {}); | ||
object::transfer_extend(package, owner); | ||
} | ||
|
||
fun borrow_package(module_store: &Object<ModuleStore>, package_id: address): &Object<Package> { | ||
|
@@ -173,6 +180,12 @@ module moveos_std::module_store { | |
object::borrow_mut<Allowlist>(allowlist_obj) | ||
} | ||
|
||
public fun freeze_package(package: Object<Package>) { | ||
object::to_frozen(package); | ||
} | ||
|
||
/************************ allowlist functions *************************/ | ||
|
||
/// Add an account to the allowlist. Only account in allowlist can publish modules. | ||
/// This is only valid when module_publishing_allowlist_enabled feature is enabled. | ||
public fun add_to_allowlist(account: &signer, publisher: address) { | ||
|
@@ -213,7 +226,6 @@ module moveos_std::module_store { | |
#[test_only] | ||
const COUNTER_MV_BYTES: vector<u8> = x"a11ceb0b060000000b01000402040403082b04330605391c07557908ce0140068e02220ab002050cb502640d9903020000010100020c000003000000000400000000050100000006010000000700020001080506010c01090700010c010a0508010c0504060407040001060c01030107080001080001050107090002060c09000106090007636f756e746572076163636f756e7407436f756e74657208696e63726561736509696e6372656173655f04696e69740d696e69745f666f725f746573740576616c756513626f72726f775f6d75745f7265736f75726365106d6f76655f7265736f757263655f746f0f626f72726f775f7265736f757263650000000000000000000000000000000000000000000000000000000000000042000000000000000000000000000000000000000000000000000000000000000205200000000000000000000000000000000000000000000000000000000000000042000201070300010400000211010201010000030c070038000c000a00100014060100000000000000160b000f0015020200000000050b0006000000000000000012003801020301000000050b0006000000000000000012003801020401000000050700380210001402000000"; | ||
|
||
|
||
#[test_only] | ||
fun drop_module_store(self: Object<ModuleStore>) { | ||
let ModuleStore {} = object::drop_unchecked(self); | ||
|
@@ -275,5 +287,24 @@ module moveos_std::module_store { | |
remove_from_allowlist(&system_account, @0x42); | ||
assert!(!is_in_allowlist(@0x42), 3); | ||
} | ||
|
||
#[test(account=@0x42)] | ||
#[expected_failure(abort_code = 9, location = object)] | ||
fun test_frozen_package(account: &signer) { | ||
init_module_store(); | ||
features::init_feature_store_for_test(); | ||
|
||
let module_object = borrow_mut_module_store(); | ||
let module_bytes = COUNTER_MV_BYTES; | ||
let m: MoveModule = move_module::new(module_bytes); | ||
|
||
publish_modules(module_object, account, vector::singleton(m)); | ||
publish_modules(module_object, account, vector::singleton(m)); | ||
|
||
let package_obj_id = object::custom_child_object_id<address, Package>(object::id(module_object), signer::address_of(account)); | ||
let (_, package) = object::take_object_extend< Package>(package_obj_id); | ||
freeze_package(package); | ||
publish_modules(module_object, account, vector::singleton(m)); | ||
} | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The package id address must equal the tx sender?
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.
This is not always the same. For example, sequencer publish the framework modules, the tx_sender should be sequencer?
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.
The sequencer can only upgrade the framework modules and can not publish a new package with the framework address.