Skip to content

Commit

Permalink
Comments rewording
Browse files Browse the repository at this point in the history
  • Loading branch information
pgherveou committed Feb 19, 2024
1 parent 1073e03 commit e96f7c5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion substrate/frame/contracts/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub struct ContractInfo<T: Config> {
storage_base_deposit: BalanceOf<T>,
/// Map of code hashes and deposit balances.
///
/// Tracks the code hash and deposit held for adding delegate dependencies. Dependencies added
/// Tracks the code hash and deposit held for locking delegate dependencies. Dependencies added
/// to the map can not be removed from the chain state and can be safely used for delegate
/// calls.
delegate_dependencies: BoundedBTreeMap<CodeHash<T>, BalanceOf<T>, T::MaxDelegateDependencies>,
Expand Down
14 changes: 7 additions & 7 deletions substrate/frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5382,7 +5382,7 @@ fn locking_delegate_dependency_works() {
let (wasm_callee, code_hash) = compile_module::<Test>("dummy").unwrap();
let (wasm_other, other_code_hash) = compile_module::<Test>("call").unwrap();

// Define inputs with various actions to test adding / removing delegate_dependencies.
// Define inputs with various actions to test locking / unlocking delegate_dependencies.
// See the contract for more details.
let noop_input = (0u32, code_hash);
let lock_delegate_dependency_input = (1u32, code_hash);
Expand Down Expand Up @@ -5456,26 +5456,26 @@ fn locking_delegate_dependency_works() {
<Error<Test>>::CodeInUse
);

// Adding an already existing dependency should fail.
// Locking an already existing dependency should fail.
assert_err!(
call(&addr_caller, &lock_delegate_dependency_input).result,
Error::<Test>::DelegateDependencyAlreadyExists
);

// Adding a dependency to self should fail.
// Locking self should fail.
assert_err!(
call(&addr_caller, &(1u32, self_code_hash)).result,
Error::<Test>::CannotAddSelfAsDelegateDependency
);

// Adding more than the maximum allowed delegate_dependencies should fail.
// Locking more than the maximum allowed delegate_dependencies should fail.
Contracts::bare_upload_code(ALICE, wasm_other, None, Determinism::Enforced).unwrap();
assert_err!(
call(&addr_caller, &(1u32, other_code_hash)).result,
Error::<Test>::MaxDelegateDependenciesReached
);

// Removing dependency should work.
// Unlocking dependency should work.
assert_ok!(call(&addr_caller, &unlock_delegate_dependency_input).result);

// Dependency should be removed, and deposit should be returned.
Expand All @@ -5495,14 +5495,14 @@ fn locking_delegate_dependency_works() {
Error::<Test>::DelegateDependencyNotFound
);

// Adding a dependency with a storage limit too low should fail.
// Locking a dependency with a storage limit too low should fail.
DEFAULT_DEPOSIT_LIMIT.with(|c| *c.borrow_mut() = dependency_deposit - 1);
assert_err!(
call(&addr_caller, &lock_delegate_dependency_input).result,
Error::<Test>::StorageDepositLimitExhausted
);

// Since we removed the dependency we should now be able to remove the code.
// Since we unlocked the dependency we should now be able to remove the code.
assert_ok!(Contracts::remove_code(RuntimeOrigin::signed(ALICE), code_hash));

// Calling should fail since the delegated contract is not on chain anymore.
Expand Down
12 changes: 6 additions & 6 deletions substrate/frame/contracts/src/wasm/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ pub enum RuntimeCosts {
/// Weight of calling `instantiation_nonce`
InstantationNonce,
/// Weight of calling `lock_delegate_dependency`
AddDelegateDependency,
LockDelegateDependency,
/// Weight of calling `unlock_delegate_dependency`
RemoveDelegateDependency,
UnlockDelegateDependency,
}

impl RuntimeCosts {
Expand Down Expand Up @@ -330,8 +330,8 @@ impl RuntimeCosts {
ReentrantCount => s.reentrance_count,
AccountEntranceCount => s.account_reentrance_count,
InstantationNonce => s.instantiation_nonce,
AddDelegateDependency => s.lock_delegate_dependency,
RemoveDelegateDependency => s.unlock_delegate_dependency,
LockDelegateDependency => s.lock_delegate_dependency,
UnlockDelegateDependency => s.unlock_delegate_dependency,
};
RuntimeToken {
#[cfg(test)]
Expand Down Expand Up @@ -2320,7 +2320,7 @@ pub mod env {
/// See [`pallet_contracts_uapi::HostFn::lock_delegate_dependency`].
#[unstable]
fn lock_delegate_dependency(ctx: _, memory: _, code_hash_ptr: u32) -> Result<(), TrapReason> {
ctx.charge_gas(RuntimeCosts::AddDelegateDependency)?;
ctx.charge_gas(RuntimeCosts::LockDelegateDependency)?;
let code_hash = ctx.read_sandbox_memory_as(memory, code_hash_ptr)?;
ctx.ext.lock_delegate_dependency(code_hash)?;
Ok(())
Expand All @@ -2330,7 +2330,7 @@ pub mod env {
/// see [`pallet_contracts_uapi::HostFn::unlock_delegate_dependency`].
#[unstable]
fn unlock_delegate_dependency(ctx: _, memory: _, code_hash_ptr: u32) -> Result<(), TrapReason> {
ctx.charge_gas(RuntimeCosts::RemoveDelegateDependency)?;
ctx.charge_gas(RuntimeCosts::UnlockDelegateDependency)?;
let code_hash = ctx.read_sandbox_memory_as(memory, code_hash_ptr)?;
ctx.ext.unlock_delegate_dependency(&code_hash)?;
Ok(())
Expand Down

0 comments on commit e96f7c5

Please sign in to comment.