Add support for the delayed upgrade#44
Conversation
|
|
||
| #[#cratename::only(owner)] | ||
| fn up_stage_code(&mut self, #[serializer(borsh)] code: Vec<u8>) { | ||
| fn up_stage_code(&mut self, #[serializer(borsh)] code: Vec<u8>, #[serializer(borsh)] delay_timestamp: u64) { |
There was a problem hiding this comment.
Orthogonal to this PR. I wonder if we should avoid borsh here and use json, passing the code in base64. It will be more inefficient, but better for readability.
There was a problem hiding this comment.
@mfornet @sept-en
I've implemented it as base64 here 5c23697, but I worry that the gas limit could be reached faster by deploying a big contract.
The difference is 12TG for the example contract
https://explorer.testnet.near.org/transactions/HhRhMqRxLg2fSSEZ1ND3mBNL7m7wmw4oqqZmzVCPq6M4
https://explorer.testnet.near.org/transactions/7jn1RE5y9VwzvAQ1Q9Mpd5JqnB7KXZfou1NXKe6uWdRd
mooori
left a comment
There was a problem hiding this comment.
How about introducing helper functions for storage writes too? It’s a nit, but I think it would improve readability.
#[inline]
fn up_set_duration(key: __UpgradableStorageKey, duration: &near_sdk::Duration) {
near_sdk::env::storage_write(self.up_storage_key(key).as_ref(), duration.to_be_bytes());
}
// Same for `fn up_set_timestamp`.These functions would be the counterparts of up_get_{duration, timestamp}.
Please remember to update the Upgradable section in the root README.
* Remove `UpdateStagingDurationTimestamp` * Add helper functions * Improve naming
|
mooori
left a comment
There was a problem hiding this comment.
How about using the term delay instead of staging duration in the code? I think that could make things clearer, for instance:
fn up_stage_new_delay(&self, delay: Option<near_sdk::Duration>);
// instead of
fn up_stage_update_staging_duration(&self, staging_duration: Option<near_sdk::Duration>);There are events for StageCode and DeployCode.
I think it would make sense to also have events like StageDelay and SetDelay
The term |
mooori
left a comment
There was a problem hiding this comment.
LGTM in general. Left some minor comments that I think should be addressed before merging.
Implement #20
Added apis:
Added storage keys: