This repository was archived by the owner on Nov 15, 2023. It is now read-only.
  
  
  - 
                Notifications
    You must be signed in to change notification settings 
- Fork 2.7k
Make automatic storage deposits resistant against changing deposit prices #12083
          
     Merged
      
      
    Conversation
  
    
      This file contains hidden or 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
    
  
  
    
    
              
                    cmichi
  
              
              approved these changes
              
                  
                    Sep 19, 2022 
                  
              
              
            
            
| Should also update  | 
              
                    HCastano
  
              
              approved these changes
              
                  
                    Sep 20, 2022 
                  
              
              
            
            
              
                    agryaznov
  
              
              reviewed
              
                  
                    Sep 20, 2022 
                  
              
              
            
            
Co-authored-by: Sasha Gryaznov <[email protected]>
Co-authored-by: Sasha Gryaznov <[email protected]>
| bot merge | 
| Waiting for commit status. | 
    
  ordian 
      pushed a commit
      that referenced
      this pull request
    
      Sep 23, 2022 
    
    
      
  
    
      
    
  
* master: [Fix] parameter_types! dead code errors (#12340) [Feature] Sequential migration execution for try-runtime (#12319) bench: Use `_` instead of `::` in auto-generated file names (#12332) Fast Unstake Pallet (#12129) Rename anonymous to pure proxy (#12283) Migrate remaining old decl_* macros to the new pallet attribute macros (#12271) pallet-utility: Disallow none origin (#12321) Make automatic storage deposits resistant against changing deposit prices (#12083) Format templates and fix `--steps` default value (#12286) Bump `wasmtime` to 1.0.0 (#12317) Introduce 'intermediate_insert' method to hide implementation details (#12215) Bound staking storage items (#12230) Use `array-bytes` for All Array/Bytes/Hex Operations (#12190) BREAKING: Rename Origin (#12258) Use temporary db for benchmarking (#12254) rpc: Implement `chainSpec` RPC API (#12261) Import target block body during warp sync (#12300) Proper naming wrt expectations (#12311) [ci] Revert cancel-pipeline job (#12309)
      
        
      
      
  
    1 task
  
      
        
      
      
  
    5 tasks
  
      
        
      
      
  
    7 tasks
  
    
  vimukthi-git 
      pushed a commit
        to ComposableFi/composable
      that referenced
      this pull request
    
      Jan 18, 2023 
    
    
      
  
    
      
    
  
#### Intro Upgrade polkadot from v0.9.27 to v0.9.30 as a checkpoint, then to v0.9.33 (latest version without workspace dependencies) Require ComposableFi/composable-ibc#176 to be merged first. #### Migrations - v0.9.28 - [x] paritytech/polkadot#5582 - Nomination not present in our runtimes - v0.9.29 - [x] paritytech/substrate#12095 - Nomination not present in our runtimes - v0.9.30 - [x] paritytech/substrate#12034 - BagList/Staking not present in our runtimes - [x] paritytech/polkadot#5930 - Nomination/BagList/Staking not present in our runtimes - [x] paritytech/substrate#12230 - Staking not present in our runtimes - [x] paritytech/polkadot#5996 - Staking not present in our runtimes - [x] paritytech/substrate#12083 - Contracts not present in our runtimes Signed-off-by: cor <[email protected]> Co-authored-by: cor <[email protected]>
    
  ark0f 
      pushed a commit
        to gear-tech/substrate
      that referenced
      this pull request
    
      Feb 27, 2023 
    
    
      
  
    
      
    
  
…ices (paritytech#12083) * Require `FixedPointOperand` for Balances * Delay deposit calculation * Make refunds pro rata of consumed storage * Add storage migration * Fix clippy * Add liquidity checks * Fixe delayed deposit limit enforcement * Defer charges * Import Vec * Add try-runtime hooks for migration * Fix warning * Adapt to new OnRuntimeUpgrade trait * Apply suggestions from code review Co-authored-by: Sasha Gryaznov <[email protected]> * fmt * Apply suggestions from code review Co-authored-by: Sasha Gryaznov <[email protected]> * More suggestions from code review Co-authored-by: Sasha Gryaznov <[email protected]>
  
      Sign up for free
      to subscribe to this conversation on GitHub.
      Already have an account?
      Sign in.
  
      Labels
      
    A0-please_review
  Pull request needs code review. 
  
    C1-low
  PR touches the given topic and has a low impact on builders. 
  
    D2-notlive 💤
  PR contains changes in a runtime directory that is not deployed to a chain that requires an audit. 
  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.
  
    
  
    
Fixes #12064
Cumulus companion: paritytech/cumulus#1561
See the linked issue for the motivation to do this.
High level Changes
This PR does apply the following changes:
Add
FixedPointOperandtoCurrency::BalanceThis is needed to to fixed point math on balances. Of course we could solve that by adding more trait bounds to
pallet-contractsbut this is a lot of noise. I argue that this new bound does not constrain the balance any more than it already is. The trait is implemented for all primitive types anyways.Delay deposit calculation
Previously, the deposit was calculated every time changes to storage were made: The
storage_deposit_limitwas applied eagerly. The drawback of this is that refunds cannot offset charges that happen earlier making the order of storage changes matter with regard to the limit. With the new approach the limit is enforce at the latest point possible (when the last call frame returns) which makes the order of storage changes irrelevant. This change makes the next change much easier. This required to record all charges and apply them at the end of the contract execution.Make refunds pro rata of consumed storage
This is the actual change we wanted to make. See the linked issue for an explanation.
Storage Migration
This change requires a hefty storage migration. It needs to count all storage items of each contract. Generally, this cannot be done in a single block. However, we argue that it is early enough to do this change within a single block (no chain in existence which contains too many contracts). Please check if the upgrade would succeed within a block on your own chain before upgrading with
try-runtime. The migration contains pre and post checks.Porting Guide
This also introduces a small API change with regard to migrations: The
migratemodule is now private and instead we expose a type namedMigrationwhich can be put intoExecutivedirectly. No need to manually implementOnRuntimeUpgradeanymore.