Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
save: added global
  • Loading branch information
agryaznov committed Feb 22, 2023
commit b2b7538c6eba4b3c48a322a3d08f9f9e2595f39b
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frame/contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ rand = { version = "0.8", optional = true, default-features = false }
rand_pcg = { version = "0.3", optional = true }

# Substrate Dependencies
environmental = { version = "1.1.4", default-features = false }
frame-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../benchmarking", optional = true }
frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" }
frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" }
Expand Down
28 changes: 23 additions & 5 deletions frame/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ use crate::{
weights::WeightInfo,
};
use codec::{Codec, Encode, HasCompact};
use environmental::*;
use frame_support::{
dispatch::{Dispatchable, GetDispatchInfo, Pays, PostDispatchInfo},
ensure,
Expand All @@ -125,6 +126,7 @@ use pallet_contracts_primitives::{
};
use scale_info::TypeInfo;
use smallvec::Array;
use sp_core::defer;
use sp_runtime::traits::{Convert, Hash, Saturating, StaticLookup};
use sp_std::{fmt::Debug, marker::PhantomData, prelude::*};

Expand Down Expand Up @@ -157,6 +159,10 @@ type DebugBufferVec<T> = BoundedVec<u8, <T as Config>::MaxDebugBufferLen>;
/// that this value makes sense for a memory location or length.
const SENTINEL: u32 = u32::MAX;

// TODO doc
// TODO think on renaming to reentrancy_guard
environmental!(executing_contract: bool);

#[frame_support::pallet]
pub mod pallet {
use super::*;
Expand Down Expand Up @@ -1248,13 +1254,25 @@ impl<T: Config> Pallet<T> {
input: I,
debug_message: Option<&mut DebugBufferVec<T>>,
) -> I::Output {
// check global here
// set global here

// check global here: fail if trying to re-enter
executing_contract::using(&mut false, || {
executing_contract::with(|f| {
if *f {
return Err::<(), Error<T>>(<Error<T>>::ContractNotFound.into()) // TODO: new Err
}
Ok(())
})
.unwrap()
})
.unwrap(); // TODO: refactor
// we are entering the contract: set global here
executing_contract::using(&mut false, || executing_contract::with(|f| *f = true));
// set global back when exiting the contract
defer! {
executing_contract::with(|f| *f = false);
};
// do stuff
input.run(debug_message)

// set global here
}

/// Deposit a pallet contracts event. Handles the conversion to the overarching event type.
Expand Down