-
Notifications
You must be signed in to change notification settings - Fork 9
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
Contract supporting migration staging path #14
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #14 +/- ##
==========================================
+ Coverage 74.30% 82.22% +7.91%
==========================================
Files 1 2 +1
Lines 144 225 +81
==========================================
+ Hits 107 185 +78
- Misses 37 40 +3 ☔ View full report in Codecov by Sentry. |
b1024b3
to
4be1303
Compare
/// Event emitted when a contract's code is staged | ||
/// status == true - insert | staged == false - replace | staged == nil - remove | ||
/// NOTE: Does not guarantee that the contract code is valid Cadence | ||
access(all) event StagingStatusUpdated( |
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.
🧡
/// Stages the contract code for the given contract name at the host address. If the contract is already staged, | ||
/// the code will be replaced. | ||
/// | ||
access(all) fun stageContract(host: &Host, name: String, code: String) { |
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.
Should this guard against using a host that is not saved? Or is it not possible to get a ref to a host with it not beeing saved?
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.
Correct, the Host
must be saved as host.address()
panics if owner == nil
address: Address, | ||
codeHash: [UInt8], | ||
contract: String, | ||
status: Bool? |
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.
personally i think a string that just uses the words "insert", "replace", "remove" is better here then this.
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.
Good point! Updated to action
field with values `"stage", "replace", and "unstage"
…tusUpdated event & .stageContract()
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.
Nice!
Mostly reviewed it from a Cadence code perspective, only reviewed the logic a little bit
} | ||
|
||
execute { | ||
self.admin.setStagingCutoff(atHeight: cutoff) |
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.
See above
self.admin.setStagingCutoff(atHeight: cutoff) | |
self.admin.setStagingCutoff(at: cutoff) |
Co-authored-by: Bastian Müller <[email protected]>
Co-authored-by: Bastian Müller <[email protected]>
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.
Looks good!
Maybe just include the code as-is in the event, there isn't really a need to turn it into a byte array
Co-authored-by: Bastian Müller <[email protected]>
Closes: #13
The basic interface to stage a contract is the same as deploying a contract - name + code. See the
stage_contract
&unstage_contract
transactions.To stage a contract, the developer first saves a
Host
resource in their account which they pass as a reference along with the contract name and code they wish to stage. TheHost
reference simply serves as proof of authority that the caller has access to the contract-hosting account, which in the simplest case would be the signer of the staging transaction, though conceivably this could be delegated to some other account via Capability - possibly helpful for some multisig contract hosts.Within the
MigrationContractStaging
contract account, code is saved on a contract-basis as aContractUpdate
struct within aCapsule
resource and stored at a the derived path. TheCapsule
simply serves as a dedicated repository for staged contract code.Included in the contact are methods for querying staging status and retrieval of staged code. This enables platforms like Flowview, Flowdiver, ContractBrowser, etc. to display the staging status of contracts on any given account.
To support ongoing staging progress across the network, the single
StagingStatusUpdated
event is emitted any time a contract is staged (status == "stage"
), staged code is replaced (status == "replace"
), or a contract is unstaged (status == "unstage"
).