Function ink_env::restore_contract[][src]

pub fn restore_contract<T>(
    account_id: T::AccountId,
    code_hash: T::Hash,
    rent_allowance: T::Balance,
    filtered_keys: &[Key]
) where
    T: Environment
Expand description

Restores a smart contract in tombstone state.

Params

  • account_id: Account ID of the to-be-restored contract.
  • code_hash: Code hash of the to-be-restored contract.
  • rent_allowance: Rent allowance of the restored contract upon successful restoration.
  • filtered_keys: Storage keys to be excluded when calculating the tombstone hash, which is used to decide whether the original contract and the to-be-restored contract have matching storage.

Usage

A smart contract that has too few funds to pay for its storage fees can eventually be evicted. An evicted smart contract C leaves behind a tombstone associated with a hash that has been computed partially by its storage contents.

To restore contract C back to a fully working contract the normal process is to write another contract C2 with the only purpose to eventually have the absolutely same contract storage as C did when it was evicted. For that purpose C2 can use other storage keys that have not been in use by contract C. Once C2 contract storage matches the storage of C when it was evicted C2 can invoke this method in order to initiate restoration of C. A tombstone hash is calculated for C2 and if it matches the tombstone hash of C the restoration is going to be successful. The filtered_keys argument can be used to ignore the extraneous keys used by C2 but not used by C.

The process of such a smart contract restoration can generally be very expensive.

Note

  • filtered_keys can be used to ignore certain storage regions in the restorer contract to not influence the hash calculations.
  • Does not perform restoration right away but defers it to the end of the contract execution.
  • Restoration is canceled if there is no tombstone in the destination address or if the hashes don’t match. No changes are made in this case.