Skip to content

revive: Include immutable storage deposit into the contracts storage_base_deposit#7230

Merged
athei merged 54 commits intomasterfrom
at/deposit
Feb 4, 2025
Merged

revive: Include immutable storage deposit into the contracts storage_base_deposit#7230
athei merged 54 commits intomasterfrom
at/deposit

Conversation

@athei
Copy link
Copy Markdown
Member

@athei athei commented Jan 18, 2025

This PR is centered around a main fix regarding the base deposit and a bunch of drive by or related fixtures that make sense to resolve in one go. It could be broken down more but I am constantly rebasing this PR and would appreciate getting those fixes in as-one.

This adds a multi block migration to Westend AssetHub that wipes the pallet state clean. This is necessary because of the changes to the ContractInfo storage item. It will not delete the child storage though. This will leave a tiny bit of garbage behind but won't cause any problems. They will just be orphaned.

Record the deposit for immutable data into the storage_base_deposit

The storage_base_deposit are all the deposit a contract has to pay for existing. It included the deposit for its own metadata and a deposit proportional (< 1.0x) to the size of its code. However, the immutable code size was not recorded there. This would lead to the situation where on terminate this portion wouldn't be refunded staying locked into the contract. It would also make the calculation of the deposit changes on set_code_hash more complicated when it updates the immutable data (to be done in #6985). Reason is because it didn't know how much was payed before since the storage prices could have changed in the mean time.

In order for this solution to work I needed to delay the deposit calculation for a new contract for after the contract is done executing is constructor as only then we know the immutable data size. Before, we just charged this eagerly in charge_instantiate before we execute the constructor. Now, we merely send the ED as free balance before the constructor in order to create the account. After the constructor is done we calculate the contract base deposit and charge it. This will make set_code_hash much easier to implement.

As a side effect it is now legal to call set_immutable_data multiple times per constructor (even though I see no reason to do so). It simply overrides the immutable data with the new value. The deposit accounting will be done after the constructor returns (as mentioned above) instead of when setting the immutable data.

Don't pre-charge for reading immutable data

I noticed that we were pre-charging weight for the max allowable immutable data when reading those values and then refunding after read. This is not necessary as we know its length without reading the storage as we store it out of band in contract metadata. This makes reading it free. Less pre-charging less problems.

Remove delegate locking

Fixes #7092

This is also in the spirit of making #6985 easier to implement. The locking complicates set_code_hash as we might need to block settings the code hash when locks exist. Check #7092 for further rationale.

Enforce "no terminate in constructor" eagerly

We used to enforce this rule after the contract execution returned. Now we error out early in the host call. This makes it easier to be sure to argue that a contract info still exists (wasn't terminated) when a constructor successfully returns. All around this his just much simpler than dealing this check.

Moved refcount functions to CodeInfo

They never really made sense to exist on Stack. But now with the locking gone this makes even less sense. The refcount is stored inside CodeInfo to lets just move them there.

Set CodeHashLockupDepositPercent for test runtime

The test runtime was setting CodeHashLockupDepositPercent to zero. This was trivializing many code paths and excluded them from testing. I set it to 30% which is our default value and fixed up all the tests that broke. This should give us confidence that the lockup doeposit collections properly works.

Reworked the MockExecutable to have both a deploy and a call entry point

This type used for testing could only have either entry points but not both. In order to fix the immutable_data_set_overrides I needed to a new function add_both to MockExecutable that allows to have both entry points. Make sure to make use of it in the future :)

@athei athei added the T7-smart_contracts This PR/Issue is related to smart contracts. label Jan 18, 2025
@athei athei requested a review from a team as a code owner January 23, 2025 00:06
@github-actions github-actions bot deleted a comment from athei Jan 23, 2025
@github-actions github-actions bot deleted a comment from athei Jan 23, 2025
@github-actions github-actions bot deleted a comment from athei Jan 23, 2025
@github-actions github-actions bot deleted a comment from athei Jan 23, 2025
@github-actions github-actions bot deleted a comment from athei Jan 23, 2025
@github-actions github-actions bot deleted a comment from athei Jan 23, 2025
…tend --pallet pallet_migrations --fail-fast --clean'
@github-actions github-actions bot deleted a comment from athei Jan 23, 2025
Copy link
Copy Markdown
Contributor

@pgherveou pgherveou left a comment

Choose a reason for hiding this comment

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

Looks good, apart from the migration that probably need proper weight instead of just using RuntimeDbWeight

@github-actions github-actions bot deleted a comment from athei Feb 4, 2025
@github-actions github-actions bot deleted a comment from athei Feb 4, 2025
@github-actions github-actions bot deleted a comment from athei Feb 4, 2025
@github-actions github-actions bot deleted a comment from athei Feb 4, 2025
@athei
Copy link
Copy Markdown
Member Author

athei commented Feb 4, 2025

/cmd bench --runtime dev --pallet pallet_revive --clean

@github-actions github-actions bot deleted a comment from athei Feb 4, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 4, 2025

Command "bench --runtime dev --pallet pallet_revive --clean" has started 🚀 See logs here

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 4, 2025

Command "bench --runtime dev --pallet pallet_revive --clean" has finished ✅ See logs here

Details

Subweight results:
File Extrinsic Old New Change [%]
substrate/frame/revive/src/weights.rs seal_get_storage - - ERROR
cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_preimage.rs ensure_updated - - ERROR
cumulus/parachains/runtimes/people/people-rococo/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/pallets/collator-selection/src/weights.rs leave_intent - - ERROR
cumulus/pallets/collator-selection/src/weights.rs new_session - - ERROR
cumulus/pallets/collator-selection/src/weights.rs register_as_candidate - - ERROR
cumulus/pallets/collator-selection/src/weights.rs set_invulnerables - - ERROR
cumulus/pallets/collator-selection/src/weights.rs take_candidate_slot - - ERROR
cumulus/pallets/collator-selection/src/weights.rs update_bond - - ERROR
cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_collator_selection.rs update_bond - - ERROR
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_collator_selection.rs update_bond - - ERROR
cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/pallet_collator_selection.rs update_bond - - ERROR
cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/pallet_collator_selection.rs update_bond - - ERROR
cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_collator_selection.rs update_bond - - ERROR
cumulus/parachains/runtimes/people/people-rococo/src/weights/pallet_collator_selection.rs update_bond - - ERROR
cumulus/parachains/runtimes/people/people-westend/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/parachains/runtimes/people/people-westend/src/weights/pallet_collator_selection.rs update_bond - - ERROR
polkadot/runtime/westend/src/weights/pallet_preimage.rs ensure_updated - - ERROR
substrate/frame/election-provider-support/src/weights.rs phragmen - - ERROR
substrate/frame/election-provider-support/src/weights.rs phragmms - - ERROR
substrate/frame/revive/src/weights.rs seal_clear_storage - - ERROR
substrate/frame/revive/src/weights.rs seal_clear_transient_storage - - ERROR
substrate/frame/revive/src/weights.rs seal_contains_storage - - ERROR
substrate/frame/revive/src/weights.rs seal_contains_transient_storage - - ERROR
substrate/frame/revive/src/weights.rs seal_deposit_event - - ERROR
substrate/frame/revive/src/weights.rs seal_get_transient_storage - - ERROR
substrate/frame/revive/src/weights.rs seal_set_storage - - ERROR
substrate/frame/revive/src/weights.rs seal_set_transient_storage - - ERROR
substrate/frame/revive/src/weights.rs seal_take_storage - - ERROR
substrate/frame/revive/src/weights.rs seal_take_transient_storage - - ERROR
polkadot/runtime/rococo/src/weights/pallet_migrations.rs on_init_loop 193.00ns 232.00ns +20.21
polkadot/runtime/westend/src/weights/pallet_migrations.rs exec_migration_skipped_historic 60.96us 66.02us +8.30
polkadot/runtime/westend/src/weights/pallet_migrations.rs on_init_loop 193.00ns 207.00ns +7.25
substrate/frame/revive/src/weights.rs seal_caller 278.00ns 296.00ns +6.47
substrate/frame/revive/src/weights.rs get_transient_storage_empty 1.43us 1.50us +5.40
cumulus/parachains/runtimes/people/people-westend/src/weights/pallet_migrations.rs exec_migration_advance 60.40us 57.32us -5.09
cumulus/parachains/runtimes/people/people-rococo/src/weights/pallet_migrations.rs on_init_loop 193.00ns 183.00ns -5.18
cumulus/parachains/runtimes/people/people-rococo/src/weights/pallet_migrations.rs exec_migration_skipped_historic 60.96us 57.66us -5.41
cumulus/parachains/runtimes/people/people-rococo/src/weights/pallet_migrations.rs exec_migration_advance 60.40us 57.11us -5.44
cumulus/parachains/runtimes/people/people-westend/src/weights/pallet_migrations.rs force_onboard_mbms 56.32us 53.23us -5.48
cumulus/parachains/runtimes/people/people-rococo/src/weights/pallet_migrations.rs force_onboard_mbms 56.32us 53.17us -5.59
substrate/frame/revive/src/weights.rs seal_base_fee 266.00ns 250.00ns -6.02
substrate/frame/revive/src/weights.rs seal_value_transferred 292.00ns 273.00ns -6.51
substrate/frame/revive/src/weights.rs seal_ref_time_left 263.00ns 244.00ns -7.22
substrate/frame/revive/src/weights.rs seal_gas_limit 290.00ns 268.00ns -7.59
substrate/frame/migrations/src/weights.rs progress_mbms_none 28.09us 25.75us -8.32
substrate/frame/migrations/src/weights.rs force_onboard_mbms 58.00us 53.11us -8.44
substrate/frame/revive/src/weights.rs seal_minimum_balance 284.00ns 260.00ns -8.45
substrate/frame/revive/src/weights.rs seal_address 274.00ns 249.00ns -9.12
substrate/frame/migrations/src/weights.rs exec_migration_advance 62.80us 56.89us -9.40
substrate/frame/migrations/src/weights.rs on_init_loop 197.00ns 174.00ns -11.68
cumulus/parachains/runtimes/people/people-westend/src/weights/pallet_migrations.rs on_init_loop 193.00ns 168.00ns -12.95
substrate/frame/migrations/src/weights.rs exec_migration_skipped_historic 67.08us 57.63us -14.09
substrate/frame/revive/src/weights.rs seal_terminate 4.62ms 489.53us -89.41
substrate/frame/migrations/src/weights.rs reset_pallet_migration 257.88ms Added
polkadot/runtime/westend/src/weights/pallet_migrations.rs reset_pallet_migration 257.89ms Added
polkadot/runtime/rococo/src/weights/pallet_migrations.rs reset_pallet_migration 257.84ms Added
cumulus/parachains/runtimes/people/people-westend/src/weights/pallet_migrations.rs reset_pallet_migration 257.95ms Added
cumulus/parachains/runtimes/people/people-rococo/src/weights/pallet_migrations.rs reset_pallet_migration 257.92ms Added
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_migrations.rs reset_pallet_migration 257.92ms Added
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_migrations.rs progress_mbms_none 27.81us Added
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_migrations.rs onboard_new_mbms 159.00us Added
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_migrations.rs on_init_loop 188.00ns Added
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_migrations.rs force_set_cursor 102.92us Added
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_migrations.rs force_set_active_cursor 103.32us Added
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_migrations.rs force_onboard_mbms 56.76us Added
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_migrations.rs exec_migration_skipped_historic 62.54us Added
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_migrations.rs exec_migration_fail 164.12us Added
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_migrations.rs exec_migration_completed 131.46us Added
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_migrations.rs exec_migration_complete 163.27us Added
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_migrations.rs exec_migration_advance 61.58us Added
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_migrations.rs clear_historic 32.44ms Added
Command output:

✅ Successful benchmarks of runtimes/pallets:
-- dev: ['pallet_revive']

@athei athei enabled auto-merge February 4, 2025 21:08
@athei athei added this pull request to the merge queue Feb 4, 2025
Merged via the queue into master with commit 4c28354 Feb 4, 2025
140 of 143 checks passed
@athei athei deleted the at/deposit branch February 4, 2025 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T7-smart_contracts This PR/Issue is related to smart contracts.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

revive: Remove delegate locking mechanism

7 participants