Skip to content

Commit

Permalink
private field and comments
Browse files Browse the repository at this point in the history
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
  • Loading branch information
xermicus committed Oct 3, 2024
1 parent f325b72 commit 6fd2d01
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
8 changes: 5 additions & 3 deletions substrate/frame/revive/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1073,11 +1073,11 @@ where
let frame = self.top_frame_mut();
let contract = frame.contract_info.as_contract().inspect(|info| {
// Charge for immutable data stored during constructor execution.
if info.immutable_bytes == 0 {
if info.immutable_bytes() == 0 {
return;
};
let amount = StorageDeposit::Charge(
T::DepositPerByte::get().saturating_mul(info.immutable_bytes.into()),
T::DepositPerByte::get().saturating_mul(info.immutable_bytes().into()),
);
frame.nested_storage.charge_deposit(frame.account_id.clone(), amount);
});
Expand Down Expand Up @@ -1566,7 +1566,7 @@ where
}

let account_id = self.account_id().clone();
self.top_frame_mut().contract_info.get(&account_id).immutable_bytes = data.len() as u32;
self.top_frame_mut().contract_info.get(&account_id).set_immutable_bytes(data.len() as u32);
<ImmutableDataOf<T>>::insert(T::AddressMapper::to_address(&account_id), &data);

Ok(())
Expand Down Expand Up @@ -1691,6 +1691,8 @@ where
///
/// After running the constructor, the new immutable data is already stored in
/// `self.immutable_data` at the address of the (reverted) contract instantiation.
///
/// The `set_code_hash` contract API stays disabled until this change is implemented.
fn set_code_hash(&mut self, hash: H256) -> DispatchResult {
let frame = top_frame_mut!(self);

Expand Down
15 changes: 14 additions & 1 deletion substrate/frame/revive/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub struct ContractInfo<T: Config> {
/// calls.
delegate_dependencies: DelegateDependencyMap<T>,
/// The size of the immutable data of this contract.
pub immutable_bytes: u32,
immutable_bytes: u32,
}

impl<T: Config> ContractInfo<T> {
Expand Down Expand Up @@ -365,6 +365,19 @@ impl<T: Config> ContractInfo<T> {
pub fn load_code_hash(account: &AccountIdOf<T>) -> Option<sp_core::H256> {
<ContractInfoOf<T>>::get(&T::AddressMapper::to_address(account)).map(|i| i.code_hash)
}

/// Returns the amount of immutable bytes of this contract.
pub fn immutable_bytes(&self) -> u32 {
self.immutable_bytes
}

/// Set the number of immutable bytes of this contract.
///
/// Note: Changing the immutable bytes of a contract requires updating
/// the base deposit during the same transaction!
pub fn set_immutable_bytes(&mut self, immutable_bytes: u32) {
self.immutable_bytes = immutable_bytes
}
}

/// Information about what happened to the pre-existing value when calling [`ContractInfo::write`].
Expand Down
3 changes: 3 additions & 0 deletions substrate/frame/revive/src/wasm/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1965,6 +1965,9 @@ pub mod env {

/// Replace the contract code at the specified address with new code.
/// See [`pallet_revive_uapi::HostFn::set_code_hash`].
///
/// Disabled until the internal implementation takes care of collecting
/// the immutable data of the new code hash.
#[mutating]
fn set_code_hash(
&mut self,
Expand Down

0 comments on commit 6fd2d01

Please sign in to comment.