Skip to content
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

KB Article: Contract migration to 2.0 #27

Closed
wants to merge 2 commits into from

Conversation

sczembor
Copy link
Contributor

@sczembor sczembor commented Jun 28, 2024

No description provided.

Copy link

@deuszex deuszex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link to original codes because they might be (or are already) subject to change.
runtime::get_call_stack behaves differently from 1.x versions.
You are using cep-18 as an example but in said code the source of most changes is how we handle the new data structuring of runtime::get_call_stack
ContractPackageHash was half removed in favour of the new PackageHash type which on .into() function call turns into Key::Package variant as opposed to the old ContractPackageHash which shared Key::Hash variant with ContractHash.
get_caller on the otherhand currently still returns account_hash which might cause confusion with the developers as it turns into Key::Account while there is a new Key::AddressableEntity(Account) variant to side with the new Key::AddressableEntity(SmartContract) variant.

- **Native Events and Message Topics:**
- Casper 2.0 prioritizes native event emission through message topics, offering flexibility and better integration.
- Utilize `runtime::emit_message` to send events on specific topics.
- **CES (Casper Event Standard):**
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case this is a doc for overall condor migration, CES should not be here. That is an implementation detail per contract and is not relevant for general condor readiness.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept it here as a major change for smart contract developers with a note While not mandatory, switching to native events is recommended due to their cost-efficiency. I removed the info about events from the Upgrade steps section

3. **Event Handling:**
- **Native Events and Message Topics:**
- Casper 2.0 prioritizes native event emission through message topics, offering flexibility and better integration.
- Utilize `runtime::emit_message` to send events on specific topics.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Messages are not held in global state, so they are not subject to the gas cost counted per stored byte, making them them cost 1/10 as much as storing the same data a dictionary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added info about it


## Essential Upgrade Steps

1. **Key Migration:**
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be done for existing contracts in case the contract developer/maintainer changes the way they handle keys. It is possible to write your codes in a manner that you don't need to do these migration steps.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this info


```rust
#[no_mangle]
pub fn migrate_user_balance_keys() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without further context/comments/documentation, this code might not mean much to most people. Link to original.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comments to the code example explaining what is happening in more details

@Adrian-Wrona Adrian-Wrona changed the title Article: Contract migration to 2.0 KB Article: Contract migration to 2.0 Jul 5, 2024
@sczembor
Copy link
Contributor Author

sczembor commented Jul 8, 2024

Link to original codes because they might be (or are already) subject to change. runtime::get_call_stack behaves differently from 1.x versions. You are using cep-18 as an example but in said code the source of most changes is how we handle the new data structuring of runtime::get_call_stack ContractPackageHash was half removed in favour of the new PackageHash type which on .into() function call turns into Key::Package variant as opposed to the old ContractPackageHash which shared Key::Hash variant with ContractHash. get_caller on the otherhand currently still returns account_hash which might cause confusion with the developers as it turns into Key::Account while there is a new Key::AddressableEntity(Account) variant to side with the new Key::AddressableEntity(SmartContract) variant.

Applied all the suggestions. There is a note at the beginning saying that it is a WIP and may be subject to change as well as adding important information about get_caller_stack and get_caller to the migration steps. Thanks for the review

@sczembor sczembor marked this pull request as ready for review July 9, 2024 08:01
@Adrian-Wrona Adrian-Wrona added this to the Active Support milestone Jul 9, 2024
@melpadden melpadden added the on-hold Work has begun, but must be paused due to some external dependency label Jul 16, 2024
@melpadden melpadden linked an issue Jul 16, 2024 that may be closed by this pull request
@melpadden melpadden closed this Jul 26, 2024
@melpadden melpadden deleted the contract_migration_guide branch July 26, 2024 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
on-hold Work has begun, but must be paused due to some external dependency
Projects
None yet
Development

Successfully merging this pull request may close these issues.

KB Article: Smart Contract Migration Guide
4 participants