diff --git a/frame/contracts/src/exec.rs b/frame/contracts/src/exec.rs index 5733d86b42cac..ff7ddabee9279 100644 --- a/frame/contracts/src/exec.rs +++ b/frame/contracts/src/exec.rs @@ -156,7 +156,7 @@ pub trait Ext: sealing::Sealed { take_old: bool, ) -> Result; - /// Sets new code hash for existing contract + /// Sets new code hash for existing contract. fn set_code_hash(&mut self, hash: CodeHash) -> Result<(), DispatchError>; /// Returns a reference to the account id of the caller. @@ -1021,10 +1021,10 @@ where } fn set_code_hash(&mut self, hash: CodeHash) -> Result<(), DispatchError> { - let top_frame = &mut self.top_frame_mut(); + increment_refcount::(hash)?; + let top_frame = self.top_frame_mut(); let prev_hash = top_frame.contract_info().code_hash.clone(); top_frame.contract_info().code_hash = hash; - increment_refcount::(hash)?; decrement_refcount::(prev_hash)?; Contracts::::deposit_event(Event::ContractCodeUpdated { contract: top_frame.account_id.clone(), diff --git a/frame/contracts/src/lib.rs b/frame/contracts/src/lib.rs index 77c3227179667..89327103184b0 100644 --- a/frame/contracts/src/lib.rs +++ b/frame/contracts/src/lib.rs @@ -560,11 +560,11 @@ pub mod pallet { /// A code with the specified hash was removed. CodeRemoved { code_hash: T::Hash }, - /// Contract code has been updated to one specified with code_hash + /// A contract code has changed its code. ContractCodeUpdated { /// The contract that has been updated. contract: T::AccountId, - /// New code hash that was set for the contract + /// New code hash that was set for the contract. code_hash: T::Hash, }, } diff --git a/frame/contracts/src/wasm/code_cache.rs b/frame/contracts/src/wasm/code_cache.rs index 2f292ab08cf98..2777eb4db283f 100644 --- a/frame/contracts/src/wasm/code_cache.rs +++ b/frame/contracts/src/wasm/code_cache.rs @@ -122,7 +122,7 @@ pub fn decrement_refcount(code_hash: CodeHash) -> Result<(), Dispa /// /// # Errors /// -/// DispatchError::CannotLookup is returned if there is no info for specified code_hash +/// `Error::CodeNotFound` is returned if the specified `code_hash` does not exist. pub fn increment_refcount(code_hash: CodeHash) -> Result<(), DispatchError> { >::mutate(code_hash, |existing| -> Result<(), DispatchError> { if let Some(info) = existing {